Search code examples
typeerrorqiskit

Combining quantum circuits in Qiskit


In Qiskit the instruction to add two quantum circuits

qc1 + qc2

produces the following error

"unsupported operand type(s) for +: 'QuantumCircuit' and 'QuantumCircuit'"

I'm guessing my library must be missing something but as I'm new to Qiskit and Python I'm not sure what?

I was expecting qc2 to be appended to qc1.


Solution

  • The + operator is no longer supported by QuantumCircuit. From Qiskit Terra 0.23. release notes (Upgrade section).

    The QuantumCircuit methods combine and extend have been removed following their deprecation in Qiskit Terra 0.17.0. This was done because these functions were simply less powerful versions of QuantumCircuit.compose(), which should be used instead.

    The removal of extend also means that the + and += operators are no longer defined for QuantumCircuit. Instead, you can use the & and &= operators respectively, which use QuantumCircuit.compose().