Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

test_against_circuit_model.py 2.0KB

pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
pirms 8 gadiem
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from abp.graphstate import GraphState
  2. from abp.qi import CircuitModel
  3. from abp import clifford
  4. import numpy as np
  5. import random
  6. from tqdm import tqdm
  7. REPEATS = 100
  8. def test_single_qubit(n=1):
  9. """ A multi qubit test with Hadamards only"""
  10. for repeat in tqdm(range(REPEATS), desc="Testing against circuit model"):
  11. g = GraphState([0])
  12. c = CircuitModel(1)
  13. for i in range(100):
  14. op = random.randint(0, 23)
  15. g.act_local_rotation(0, op)
  16. c.act_local_rotation(0, clifford.unitaries[op])
  17. assert g.to_state_vector() == c
  18. def test_hadamard_only_multiqubit(n=6):
  19. """ A multi qubit test with Hadamards only"""
  20. for repeat in tqdm(range(REPEATS), desc="Testing against circuit model"):
  21. g = GraphState(range(n))
  22. c = CircuitModel(n)
  23. for i in range(n):
  24. g.act_hadamard(i)
  25. c.act_hadamard(i)
  26. assert g.to_state_vector() == c
  27. for i in range(100):
  28. a, b = np.random.randint(0, n - 1, 2)
  29. if a != b:
  30. g.act_cz(a, b)
  31. c.act_cz(a, b)
  32. assert g.to_state_vector() == c
  33. def test_all_multiqubit(n=4):
  34. """ A multi qubit test with arbitrary local rotations """
  35. g = GraphState(range(n))
  36. c = CircuitModel(n)
  37. for i in range(10):
  38. qubit = np.random.randint(0, n - 1)
  39. rotation = np.random.randint(0, 24 - 1)
  40. g.act_local_rotation(qubit, rotation)
  41. c.act_local_rotation(qubit, clifford.unitaries[rotation])
  42. assert g.to_state_vector() == c
  43. for repeat in tqdm(range(REPEATS), desc="Testing against circuit model"):
  44. a, b = np.random.randint(0, n - 1, 2)
  45. if a != b:
  46. g.act_cz(a, b)
  47. c.act_cz(a, b)
  48. assert np.allclose(np.sum(np.abs(c.state) ** 2), 1)
  49. assert np.allclose(
  50. np.sum(np.abs(g.to_state_vector().state) ** 2), 1)
  51. assert g.to_state_vector() == c
  52. assert g.to_state_vector() == c