Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. def oracle(circ):
  2. """
  3. Implements an oracle that flips the sign of states that contain P = 1.
  4. """
  5. circ.cu3(pi, pi, 0, net[0], net[1])
  6. circ.cu3(pi, pi, 0, net[0], net[1])
  7. return circ
  8.  
  9.  
  10. def u_gate(circ):
  11. """
  12. Implements the U gate that flips states about the average amplitude.
  13. """
  14. # Implements the quantum circuit that converts ψ -> |000...0>
  15. circ.u3(-1*probToAngle(0.35), 0, 0, net[0])
  16. circ.u3(-1*probToAngle(0.76), 0, 0, net[1])
  17. circ.u3(-1*probToAngle(0.39), 0, 0, net[2])
  18.  
  19. # Flipping the |000...0> state using a triple controlled Z gate condtioned on P, E and H,
  20. # and applied to the ancilla
  21. circ.x(net)
  22. circ.cu1(pi/4, net[0], net[3])
  23. circ.cx(net[0], net[1])
  24. circ.cu1(-pi/4, net[1], net[3])
  25. circ.cx(net[0], net[1])
  26. circ.cu1(pi/4, net[1], net[3])
  27. circ.cx(net[1], net[2])
  28. circ.cu1(-pi/4, net[2], net[3])
  29. circ.cx(net[0], net[2])
  30. circ.cu1(pi/4, net[2], net[3])
  31. circ.cx(net[1], net[2])
  32. circ.cu1(-pi/4, net[2], net[3])
  33. circ.cx(net[0], net[2])
  34. circ.cu1(pi/4, net[2], net[3])
  35. circ.x(net)
  36.  
  37. # Implements the quantum circuit that converts |000...0> -> ψ
  38. circ.u3(probToAngle(0.35), 0, 0, net[0])
  39. circ.u3(probToAngle(0.76), 0, 0, net[1])
  40. circ.u3(probToAngle(0.39), 0, 0, net[2])
  41.  
  42. return circ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement