Closed chenchenchen321 closed 11 months ago
The same error when mcrx gate and mcry gate are used in PQC.
This seems to be caused by #8723, as the transpiled circuit contains CUGate
s where the parameter is still unbound. As a workaround until that is fixed you could use the RXGate
with two controls:
from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.circuit.library import RXGate
from qiskit import Aer, transpile
beta = Parameter('θ')
gate = RXGate(beta).control(2)
circ = QuantumCircuit(3)
circ.append(gate, [0, 1, 2])
circ.measure_all()
backend = Aer.get_backend('aer_simulator')
bound = circ.bind_parameters([2])
tqc = transpile(bound, backend)
job = backend.run(tqc)
counts = job.result().get_counts()
print(counts)
This should have been fixed by #11032. Feel free to re-open if that's not the case.
Environment
What is happening?
Running the circuit will result in an error when a CRX gate is controlled in the parameterized circuit.
How can we reproduce the issue?
Input:
Output:
Simulation failed and returned the following error message: ERROR: Failed to load qobj: Unable to cast Python instance to C++ type (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)
But if we use cry gate, the result is correct: Input:
Output:
{'0000': 1024}
If we replace c1 = circ.control(1) with c1 = circ.control(2), the result is also correct:
Input:
beta = Parameter('θ') circ = QuantumCircuit(3) circ.cry(beta, 2, 0) c1 = circ.control(2) c1.measure_all() backend = Aer.get_backend('aer_simulator') c = transpile(c1, backend) circuits=c.bind_parameters({c.parameters[0]: 2}) job = backend.run(circuits) counts = job.result().get_counts() print(counts)
Output:
{'0000': 1024}
What should happen?
Expected answer
{'0000': 1024}
Any suggestions?
No response