I am trying to solve the boolean problem (x1 or x2) and (~x1 or ~x2 or x3) using Grover's algorithm. The only measured bits are q0, q1, and q2. This is my oracle:
def prob_6_oracle():
num_qubits = 7
qc = QuantumCircuit(num_qubits)
#(x1 or x2) = ~(~x1 and ~x2) stored in q3
qc.x([0,1])
qc.ccx(0,1,3)
qc.x([0,1])
qc.x(3)
qc.barrier()
#(~x1 or ~x2) = ~(x1 and x2) stored in q4
qc.ccx(0,1,4)
qc.x(4)
qc.barrier()
#(q4 or x3) = ~(~q4 and ~x3)
qc.x([2,4])
qc.ccx(2,4,5)
qc.x([2,4])
qc.x(5)
qc.barrier()
qc.ccx(3,5,6)
qc.barrier()
#qc.z(6)
qc.cz(6, [0,1,2])
# Decompute
qc.barrier()
qc.ccx(3,5,6)
qc.x(5)
qc.x([2,4])
qc.ccx(2,4,5)
qc.x([2,4])
qc.x(4)
qc.ccx(0,1,4)
qc.x(3)
qc.x([0,1])
qc.ccx(0,1,3)
qc.x([0,1])
return qc
Both qc.z() and qc.cz() does not work to provide me with the correct solutions. I am instead receiving an equal distribution of solutions. I am using the Qiskit GroverOperator, and have it iterating twice.
