You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
QuantumCircuit.compose runs normally if qubits argument has duplicate values. If you try to compose two circuits after converting to dag, DAGCircuit.compose raises an error. Introduced after #4762 .
Steps to reproduce the problem
n = 3
qc = QuantumCircuit(n)
qc.h(range(n))
m = 2
circ = QuantumCircuit(m)
circ.z(range(m))
circ.cx(0, 1)
new_circuit = qc.compose(circ, qubits=[1, 1])
print(new_circuit)
┌───┐
q_0: ┤ H ├──────────
├───┤┌───┐┌───┐
q_1: ┤ H ├┤ Z ├┤ Z ├
├───┤└───┘└───┘
q_2: ┤ H ├──────────
└───┘
I'm a little hesitant to adding checks in the compose method because it might slow down the usage and this use-case is obviously a wrong input, so that users won't be surprised if it doesn't work. But if the DAGCircuitError is too cryptic, we could improve it there? This would not give us additional overhead when users use compose correctly but would still give a proper error message.
Edit: Maybe it would be better to actually do include the check in compose. If we notice it causes performance issues we can also add a flag that deactivates the checks or use a private method like _append?
Information
What is the current behavior?
QuantumCircuit.compose
runs normally ifqubits
argument has duplicate values. If you try to compose two circuits after converting to dag,DAGCircuit.compose
raises an error. Introduced after #4762 .Steps to reproduce the problem
But
What is the expected behavior?
As duplicate values in
qubits
is not a valid input,QuantumCircuit.compose
should raise an error.Suggested solutions
Similar to
DAGCircuit.compose
The text was updated successfully, but these errors were encountered: