Bladeren bron

Fix mistake in CZ table generation

Using `combinations` instead of `combinations_with_replacement` was
leading to entries of the form [ ... , i, i] being excluded from the CZ
table.
master
Pete Shadbolt 8 jaren geleden
bovenliggende
commit
5666c6ea17
2 gewijzigde bestanden met toevoegingen van 13 en 2 verwijderingen
  1. +2
    -2
      abp/clifford.py
  2. +11
    -0
      tests/test_clifford.py

+ 2
- 2
abp/clifford.py Bestand weergeven

@@ -106,7 +106,7 @@ def get_cz_table(unitaries):

# And now build the CZ table
cz_table = np.zeros((2, 24, 24, 3))
rows = list(it.product([0, 1], it.combinations(range(24), 2)))
rows = list(it.product([0, 1], it.combinations_with_replacement(range(24), 2)))
# CZ is symmetric so we only need combinations
for bond, (c1, c2) in tqdm(rows, desc="Building CZ table"):
newbond, c1p, c2p = find_cz(bond, c1, c2, commuters, state_table)
@@ -135,7 +135,7 @@ except IOError:
conjugation_table = get_conjugation_table(unitaries)
times_table = get_times_table(unitaries)
cz_table = get_cz_table(unitaries)
# Write it all to disk
np.save("unitaries.npy", unitaries)
np.save("conjugation_table.npy", conjugation_table)


+ 11
- 0
tests/test_clifford.py Bestand weergeven

@@ -65,3 +65,14 @@ def test_conjugation_table():
def test_times_table():
""" Check the times table """
assert clifford.times_table[0][4] == 4

def test_cz_table_is_symmetric():
""" Test the CZ table is symmetric """
for bond, (a, b) in it.product([0, 1], it.combinations(xrange(24), 2)):
_, a1, a2 = clifford.cz_table[bond, a, b]
_, b1, b2 = clifford.cz_table[bond, b, a]
assert (a1,a2) == (b2, b1)

def test_cz_table_makes_sense():
""" Test the CZ table is symmetric """
assert all(clifford.cz_table[0, 0, 0] == [1, 0, 0])

Laden…
Annuleren
Opslaan