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.

69 lines
2.2KB

  1. from abp import GraphState, CircuitModel, clifford
  2. from anders_briegel import graphsim
  3. import numpy as np
  4. from numpy import random
  5. from tqdm import tqdm
  6. import itertools as it
  7. import mock
  8. REPEATS = 100
  9. DEPTH = 100
  10. def test_hadamard():
  11. """ Test hadamards """
  12. circuit = [(0, "hadamard")]
  13. mock.test_circuit(circuit, 1)
  14. def test_local_rotations():
  15. """ Test local rotations """
  16. for i in tqdm(range(REPEATS), "Testing local rotations"):
  17. circuit = [(0, random.choice(range(24))) for j in range(DEPTH)]
  18. mock.test_circuit(circuit, 1)
  19. def test_times_table():
  20. """ Test times table """
  21. for i, j in it.product(range(24), range(24)):
  22. circuit = [(0, i), (0, j)]
  23. mock.test_circuit(circuit, 1)
  24. def test_cz_table():
  25. """ Test the CZ table """
  26. for i, j in it.product(range(24), range(24)):
  27. circuit = [(0, i), (1, j), ((0, 1), "cz")]
  28. mock.test_circuit(circuit, 2)
  29. def test_cz_hadamard(n=10):
  30. """ Test CZs and Hadamards at random """
  31. for i in tqdm(range(REPEATS), desc="Testing CZ and Hadamard against A&B"):
  32. circuit = random.choice(["cz", "hadamard"], DEPTH)
  33. circuit = [(mock.random_pair(n), gate) if gate == "cz"
  34. else (random.choice(range(n)), gate)
  35. for gate in circuit]
  36. mock.test_circuit(circuit, n)
  37. def test_all(n=10):
  38. """ Test everything"""
  39. for i in tqdm(range(REPEATS), desc="Testing CZ and Hadamard against A&B"):
  40. circuit = random.choice(["cz"] * 10 + range(24), DEPTH)
  41. circuit = [(mock.random_pair(n), gate) if gate == "cz"
  42. else (random.choice(range(n)), gate)
  43. for gate in circuit]
  44. mock.test_circuit(circuit, n)
  45. def test_single_qubit_measurement():
  46. """ Check that single qubits work """
  47. space = it.product(range(24), ("px", "py", "pz"), (0, 1))
  48. for rotation, measurement, outcome in tqdm(space, "Testing single qubit measurements"):
  49. a = mock.circuit_to_state(mock.ABPWrapper, 1, [(0, rotation)])
  50. b = mock.circuit_to_state(mock.AndersWrapper, 1, [(0, rotation)])
  51. result_a = a.measure(0, measurement, outcome)
  52. result_b = b.measure(0, measurement, outcome)
  53. assert result_a == result_b
  54. assert a == b