Anders and Briegel in Python
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

103 satır
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. mock = pytest.importorskip("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 list(range(REPEATS)):
  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 list(range(REPEATS)):
  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 list(range(REPEATS)):
  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 space:
  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 space:
  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 space:
  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