I am following the examples given in this qiskit article about the Grover's algorithm.
I am trying to use this method that is given:
def diffuser(nqubits):
qc = QuantumCircuit(nqubits)
# Apply transformation |s> -> |00..0> (H-gates)
for qubit in range(nqubits):
qc.h(qubit)
# Apply transformation |00..0> -> |11..1> (X-gates)
for qubit in range(nqubits):
qc.x(qubit)
# Do multi-controlled-Z gate
qc.h(nqubits-1)
qc.mct(list(range(nqubits-1)), nqubits-1) # multi-controlled-toffoli
qc.h(nqubits-1)
# Apply transformation |11..1> -> |00..0>
for qubit in range(nqubits):
qc.x(qubit)
# Apply transformation |00..0> -> |s>
for qubit in range(nqubits):
qc.h(qubit)
# We will return the diffuser as a gate
U_s = qc.to_gate()
U_s.name = "U$_s$"
return U_s
With this code:
backend = Aer.get_backend("statevector_simulator")
circuit = QuantumCircuit(psi) #psi is my quantumregister variable
# code to implement Hadamard transform and oracle
circuit.append(diffuser(3), psi) #psi is a 3 qubit quantum register
job = backend.run(c)
I think the issue is with the circuit.append()
method; it only occurs when I uncomment that line.
The error I get is below:
Simulation failed and returned the following error message:
ERROR: [Experiment 0] Circuit circuit-91 contains invalid instructions {"gates": {U$_s$}} for "statevector" method.
When I add this line of code to the end of the file:
v = job.result().get_statevector(c).measure()[0]
to get the output of the code, I end up with this error:
qiskit.exceptions.QiskitError: 'Data for experiment "circuit-91" could not be found.'
Does anybody know why this is happening?