Anders and Briegel in Python
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

test_against_anders_and_briegel.py 3.8KB

8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
8 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. from abp import GraphState, CircuitModel, clifford
  2. import numpy as np
  3. from numpy import random
  4. from tqdm import tqdm
  5. import itertools as it
  6. import mock
  7. REPEATS = 100
  8. DEPTH = 100
  9. PAULIS = ("px", "py", "pz")
  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(list(range(REPEATS)), "Testing local rotations"):
  17. circuit = [(0, random.choice(list(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(list(range(24)), list(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(list(range(24)), list(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(list(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(list(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(list(range(REPEATS)), desc="Testing CZ and Hadamard against A&B"):
  40. circuit = random.choice(["cz"] * 10 + list(range(24)), DEPTH)
  41. circuit = [(mock.random_pair(n), gate) if gate == "cz"
  42. else (random.choice(list(range(n))), gate)
  43. for gate in circuit]
  44. mock.test_circuit(circuit, n)
  45. def test_single_qubit_measurement():
  46. """ Determinstic test of all single-qubit situations """
  47. space = it.product(list(range(24)), PAULIS, (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
  55. def test_two_qubit_measurement():
  56. """ Various two-qubit measurements on a Bell state"""
  57. for measurement, outcome in it.product(PAULIS, (0, 1)):
  58. circuit = mock.bell_pair()
  59. a = mock.circuit_to_state(mock.ABPWrapper, 2, circuit)
  60. b = mock.circuit_to_state(mock.AndersWrapper, 2, circuit)
  61. assert a.measure(0, measurement, outcome) == \
  62. b.measure(0, measurement, outcome)
  63. assert a == b
  64. def test_graph_state_measurement(n = 10):
  65. """ Measuring random graph states """
  66. space = list(it.product(list(range(REPEATS)), PAULIS, (0, 1)))
  67. for i, measurement, outcome in tqdm(space, "Measuring random graph states"):
  68. circuit = mock.random_graph_circuit(n, DEPTH)
  69. a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
  70. b = mock.circuit_to_state(mock.AndersWrapper, n, circuit)
  71. a.measure(0, measurement, outcome)
  72. b.measure(0, measurement, outcome)
  73. assert a == b
  74. def test_stabilizer_state_measurement(n = 10):
  75. """ Measuring random stabilizer states """
  76. space = list(it.product(list(range(REPEATS)), PAULIS, (0, 1)))
  77. for i, measurement, outcome in tqdm(space, "Measuring random stabilizer states"):
  78. circuit = mock.random_stabilizer_circuit(n, DEPTH)
  79. a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
  80. b = mock.circuit_to_state(mock.AndersWrapper, n, circuit)
  81. a.measure(0, measurement, outcome)
  82. b.measure(0, measurement, outcome)
  83. assert a == b