Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.2KB

  1. import json
  2. import numpy as np
  3. from abp import clifford, qi
  4. import sys
  5. import os
  6. import itertools as it
  7. from string import maketrans
  8. def get_ab_cz_table():
  9. """ Load anders and briegel's CZ table """
  10. filename = "anders_briegel/cphase.tbl"
  11. filename = os.path.join(os.path.dirname(sys.path[0]), filename)
  12. with open(filename) as f:
  13. s = f.read().translate(maketrans("{}", "[]"))
  14. return np.array(json.loads(s))
  15. def test_cz_table():
  16. """ Does our clifford code work with anders & briegel's table? """
  17. state_table = clifford.get_state_table(clifford.unitaries)
  18. ab_cz_table = get_ab_cz_table()
  19. rows = it.product([0, 1], it.combinations_with_replacement(range(24), 2))
  20. for bond, (c1, c2) in rows:
  21. # Pick the input state
  22. input_state = state_table[bond, c1, c2]
  23. # Go and compute the output
  24. computed_output = np.dot(qi.cz, input_state)
  25. computed_output = qi.normalize_global_phase(computed_output)
  26. # Now look up the answer in the table
  27. bondp, c1p, c2p = ab_cz_table[bond, c1, c2]
  28. table_output = state_table[bondp, c1p, c2p]
  29. assert np.allclose(computed_output, table_output)