Anders and Briegel in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

105 wiersze
3.6KB

  1. from abp import GraphState, CircuitModel, clifford
  2. import numpy as np
  3. from numpy import random
  4. import itertools as it
  5. import pytest
  6. import mock
  7. ab = pytest.importorskip("ab")
  8. REPEATS = 100
  9. DEPTH = 100
  10. PAULIS = ("px", "py", "pz")
  11. def test_hadamard():
  12. """ Test hadamards """
  13. circuit = [(0, "hadamard")]
  14. ab.test_circuit(circuit, 1)
  15. def test_local_rotations():
  16. """ Test local rotations """
  17. for i in list(range(REPEATS)):
  18. circuit = [(0, random.choice(list(range(24)))) for j in range(DEPTH)]
  19. ab.test_circuit(circuit, 1)
  20. def test_times_table():
  21. """ Test times table """
  22. for i, j in it.product(list(range(24)), list(range(24))):
  23. circuit = [(0, i), (0, j)]
  24. ab.test_circuit(circuit, 1)
  25. def test_cz_table():
  26. """ Test the CZ table """
  27. for i, j in it.product(list(range(24)), list(range(24))):
  28. circuit = [(0, i), (1, j), ((0, 1), "cz")]
  29. ab.test_circuit(circuit, 2)
  30. def test_cz_hadamard(n=10):
  31. """ Test CZs and Hadamards at random """
  32. for i in list(range(REPEATS)):
  33. circuit = random.choice(["cz", "hadamard"], DEPTH)
  34. circuit = [(mock.random_pair(n), gate) if gate == "cz"
  35. else (random.choice(list(range(n))), gate)
  36. for gate in circuit]
  37. ab.test_circuit(circuit, n)
  38. def test_all(n=10):
  39. """ Test everything """
  40. for i in list(range(REPEATS)):
  41. circuit = random.choice(["cz"] * 10 + list(range(24)), DEPTH)
  42. circuit = [(mock.random_pair(n), gate) if gate == "cz"
  43. else (random.choice(list(range(n))), gate)
  44. for gate in circuit]
  45. ab.test_circuit(circuit, n)
  46. def test_single_qubit_measurement():
  47. """ Determinstic test of all single-qubit situations """
  48. space = it.product(list(range(24)), PAULIS, (0, 1))
  49. for rotation, measurement, outcome in space:
  50. a = mock.circuit_to_state(mock.ABPWrapper, 1, [(0, rotation)])
  51. b = mock.circuit_to_state(mock.AndersWrapper, 1, [(0, rotation)])
  52. result_a = a.measure(0, measurement, outcome)
  53. result_b = b.measure(0, measurement, outcome)
  54. assert result_a == result_b
  55. assert a == b
  56. def test_two_qubit_measurement():
  57. """ Various two-qubit measurements on a Bell state"""
  58. for measurement, outcome in it.product(PAULIS, (0, 1)):
  59. circuit = mock.bell_pair()
  60. a = mock.circuit_to_state(mock.ABPWrapper, 2, circuit)
  61. b = mock.circuit_to_state(mock.AndersWrapper, 2, circuit)
  62. assert a.measure(0, measurement, outcome) == \
  63. b.measure(0, measurement, outcome)
  64. assert a == b
  65. def test_graph_state_measurement(n = 10):
  66. """ Measuring random graph states """
  67. space = list(it.product(list(range(REPEATS)), PAULIS, (0, 1)))
  68. for i, measurement, outcome in space:
  69. circuit = mock.random_graph_circuit(n, DEPTH)
  70. a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
  71. b = mock.circuit_to_state(mock.AndersWrapper, n, circuit)
  72. a.measure(0, measurement, outcome)
  73. b.measure(0, measurement, outcome)
  74. assert a == b
  75. def test_stabilizer_state_measurement(n = 10):
  76. """ Measuring random stabilizer states """
  77. space = list(it.product(list(range(REPEATS)), PAULIS, (0, 1)))
  78. for i, measurement, outcome in space:
  79. circuit = mock.random_stabilizer_circuit(n, DEPTH)
  80. a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
  81. b = mock.circuit_to_state(mock.AndersWrapper, n, circuit)
  82. a.measure(0, measurement, outcome)
  83. b.measure(0, measurement, outcome)
  84. assert a == b