testing.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # import qcgpu
  2. # import perf
  3. # def run(num_qubits, depth):
  4. # state = qcgpu.State(num_qubits)
  5. # h = qcgpu.gate.h()
  6. # for i in range(num_qubits * depth):
  7. # state.apply_gate(h, i % num_qubits)
  8. import qcgpu
  9. import sys
  10. import time
  11. # ------------------------------------------
  12. # number of qubits and depth
  13. # ------------------------------------------
  14. if len(sys.argv) > 1:
  15. n = int(sys.argv[1])
  16. else:
  17. n = 16
  18. if len(sys.argv) > 1:
  19. depth = int(sys.argv[2])
  20. else:
  21. depth = 10
  22. print('Qubits: %d, Depth %d' % (n, depth))
  23. # ------------------------------------------
  24. # qubit register
  25. # ------------------------------------------
  26. state = qcgpu.State(n)
  27. # ------------------------------------------
  28. # circuit
  29. # ------------------------------------------
  30. h = qcgpu.gate.h()
  31. x = qcgpu.gate.x()
  32. sqrt_x = qcgpu.gate.sqrt_x()
  33. # timing -- get the start time
  34. start = time.time()
  35. # random circuit
  36. for level in range(depth):
  37. for q in range(n):
  38. state.apply_gate(h, q)
  39. state.apply_gate(sqrt_x, q)
  40. if q != 0:
  41. state.apply_controlled_gate(x, q, 0)
  42. # timing -- get the end time
  43. runtime = time.time() - start
  44. # print out the runtime
  45. print(runtime)