From 5666c6ea17d7e0712c26827deeff4466b4434487 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Fri, 6 May 2016 15:13:05 +0100 Subject: [PATCH] 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. --- abp/clifford.py | 4 ++-- tests/test_clifford.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/abp/clifford.py b/abp/clifford.py index c93cf56..b62b5ab 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -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) diff --git a/tests/test_clifford.py b/tests/test_clifford.py index 14353f6..5bbf5da 100644 --- a/tests/test_clifford.py +++ b/tests/test_clifford.py @@ -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])