Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

test_cphase_against_anders.py 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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)
  30. def _test_match():
  31. """ Tests that they actually match """
  32. ab_cz_table = get_ab_cz_table()
  33. rows = it.product([0, 1], it.combinations_with_replacement(range(24), 2))
  34. for bond, (c1, c2) in rows:
  35. assert np.all(ab_cz_table == clifford.cz_table)