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
I use placeholder instructions with one or more qubits and clbits to create circuits in different configurations.
The placeholders are created with the maximum amount of qubits and clbits needed, which might be more than needed for some specific configurations.
However, if I put one single-qubit instruction into a placeholder with 1 qubit and C clbits, circuit.decompose() fails with
qiskit.dagcircuit.exceptions.DAGCircuitError:
'Cannot replace node of width (1 qubits, C clbits) with instruction of mismatched width (1 qubits, 0 clbits).'
How can we reproduce the issue?
fromqiskitimportQuantumCircuitplaceholder=QuantumCircuit(1, 1)
placeholder.h(0)
# placeholder.x(0) # uncomment this line to make the example workpld_instr=placeholder.to_instruction()
circuit=QuantumCircuit(3, 3)
circuit.h(0)
circuit.append(placeholder, [0], [0])
circuit.x(1)
print(circuit)
print(circuit.decompose()) # FAILS
What should happen?
The decomposition pass should not fail, and behave the same as if multiple instructions would have been put into the placeholder. (See example when uncomment line 5)
Any suggestions?
As far as I see it, the problem arises because of this if-statement in the decomposition pass:
This maybe seems to be a optimization (?) that can quickly handle a single-qubit instruction. However, I think it does not handle the case when the instruction does not have the same amount of clbits as the placeholder.
The simplest fix would be to omit the if statement, and execute the else-statement
Environment
What is happening?
I use placeholder instructions with one or more qubits and clbits to create circuits in different configurations.
The placeholders are created with the maximum amount of qubits and clbits needed, which might be more than needed for some specific configurations.
However, if I put one single-qubit instruction into a placeholder with 1 qubit and C clbits,
circuit.decompose()
fails withHow can we reproduce the issue?
What should happen?
The decomposition pass should not fail, and behave the same as if multiple instructions would have been put into the placeholder. (See example when uncomment line 5)
Any suggestions?
As far as I see it, the problem arises because of this if-statement in the decomposition pass:
This maybe seems to be a optimization (?) that can quickly handle a single-qubit instruction. However, I think it does not handle the case when the instruction does not have the same amount of clbits as the placeholder.
The simplest fix would be to omit the if statement, and execute the else-statement
in any case.
The text was updated successfully, but these errors were encountered: