Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
H | oracle_out
# run num_it iterations
with Loop(eng, num_it):
# oracle adds a (-1)-phase to the solution
oracle(eng, x, oracle_out)
# reflection across uniform superposition
with Compute(eng):
All(H) | x
All(X) | x
with Control(eng, x[0:-1]):
Z | x[-1]
Uncompute(eng)
All(Measure) | x
Measure | oracle_out
eng.flush()
# return result
return [int(qubit) for qubit in x]
H | oracle_out
#run j iterations
with Loop(eng, j):
# oracle adds a (-1)-phase to the solution
oracle(eng, x, Dataset,threshold, oracle_out)
# reflection across uniform superposition
with Compute(eng):
All(H) | x
All(X) | x
with Control(eng, x[0:-1]):
Z | x[-1]
Uncompute(eng)
All(Measure) | x
Measure | oracle_out
#read the measure value
k=0
xvalue=0
while kthreshold:
return xvalue
m=m*landa
i=i+1
H | oracle_out
# run num_it iterations
with Loop(eng, num_it):
# oracle adds a (-1)-phase to the solution
oracle(eng, x, oracle_out)
# reflection across uniform superposition
with Compute(eng):
All(H) | x
All(X) | x
with Control(eng, x[0:-1]):
Z | x[-1]
Uncompute(eng)
All(Measure) | x
Measure | oracle_out
eng.flush()
# return result
return [int(qubit) for qubit in x]
"""
Marks the solution string 0,1,0,... by applying phase gate to the output bits,
conditioned on qubits being equal to the alternating bit-string.
Args:
eng (MainEngine): Main compiler engine the algorithm is being run on.
qubits (Qureg): n-qubit quantum register Grover search is run on.
output (Qubit): Output qubit to mark the solution by a phase gate with parameter phi.
"""
with Compute(eng):
All(X) | qubits[1::2]
with Control(eng, qubits):
Rz(phi) | output
Ph(phi/2) | output
Uncompute(eng)
H | oracle_out
#run j iterations
with Loop(eng, j):
# oracle adds a (-1)-phase to the solution
oracle(eng, x, Dataset,threshold, oracle_out)
# reflection across uniform superposition
with Compute(eng):
All(H) | x
All(X) | x
with Control(eng, x[0:-1]):
Z | x[-1]
Uncompute(eng)
All(Measure) | x
Measure | oracle_out
#read the measure value
k=0
xvalue=0
while kthreshold:
return xvalue
m=m*landa
i=i+1
Uncompute(eng)
# prepare the oracle output qubit (the one that is flipped to indicate the
# solution. start in state |1> s.t. a bit-flip turns into a e^(i*phi)-phase.
H | oracle_out
oracle_modified(eng, x, oracle_out, phi)
with Compute(eng):
All(H) | x
All(X) | x
with Control(eng, x[0:-1]):
Rz(varphi) | x[-1]
Ph(varphi/2) | x[-1]
Uncompute(eng)
All(Measure) | x
Measure | oracle_out
eng.flush()
# return result
return [int(qubit) for qubit in x]
def _decompose_rx(cmd):
""" Decompose the Rx gate."""
qubit = cmd.qubits[0]
eng = cmd.engine
angle = cmd.gate.angle
with Control(eng, cmd.control_qubits):
with Compute(eng):
H | qubit
Rz(angle) | qubit
Uncompute(eng)
"""
Marks the solution string 0, 1, 0,...,0 by flipping the
qubit,
conditioned on qubits being equal to the alternating bit-string.
Args:
eng (MainEngine): Main compiler engine the algorithm is being run on.
qubits (Qureg): n-qubit quantum register Grover search is run on.
output (Qubit): Output qubit to flip in order to mark the solution.
"""
with Compute(eng):
X | qubits[1]
with Control(eng, qubits):
X | output
Uncompute(eng)