Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def oracle(circ):
- """
- Implements an oracle that flips the sign of states that contain P = 1.
- """
- circ.cu3(pi, pi, 0, net[0], net[1])
- circ.cu3(pi, pi, 0, net[0], net[1])
- return circ
- def u_gate(circ):
- """
- Implements the U gate that flips states about the average amplitude.
- """
- # Implements the quantum circuit that converts ψ -> |000...0>
- circ.u3(-1*probToAngle(0.35), 0, 0, net[0])
- circ.u3(-1*probToAngle(0.76), 0, 0, net[1])
- circ.u3(-1*probToAngle(0.39), 0, 0, net[2])
- # Flipping the |000...0> state using a triple controlled Z gate condtioned on P, E and H,
- # and applied to the ancilla
- circ.x(net)
- circ.cu1(pi/4, net[0], net[3])
- circ.cx(net[0], net[1])
- circ.cu1(-pi/4, net[1], net[3])
- circ.cx(net[0], net[1])
- circ.cu1(pi/4, net[1], net[3])
- circ.cx(net[1], net[2])
- circ.cu1(-pi/4, net[2], net[3])
- circ.cx(net[0], net[2])
- circ.cu1(pi/4, net[2], net[3])
- circ.cx(net[1], net[2])
- circ.cu1(-pi/4, net[2], net[3])
- circ.cx(net[0], net[2])
- circ.cu1(pi/4, net[2], net[3])
- circ.x(net)
- # Implements the quantum circuit that converts |000...0> -> ψ
- circ.u3(probToAngle(0.35), 0, 0, net[0])
- circ.u3(probToAngle(0.76), 0, 0, net[1])
- circ.u3(probToAngle(0.39), 0, 0, net[2])
- return circ
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement