2
$\begingroup$

On which backends (Basic, AER, Simulation, IBMQ) is the qiskit.circuit.controlflow.if_else Operation implemented currently?

I want to create a circuit depending on qubit states, e.g.: `with circuit.if_test((qreg_c[cnt], 0)) as else_:

#add instruction to circuit

with else_:

# insert another instruction to circuit`

Normal "circuit.draw()" operation works, but when I try to run it on "qasm_simulator" I get the following error: QiskitError: "Cannot unroll the circuit to the given basis, ['u1', 'u2', 'u3', 'rz', 'sx', 'x', 'cx', 'id', 'unitary']. Instruction if_else not found in equivalence library and no rule found to expand."

So, how can this be solved?

$\endgroup$
1
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Jan 10, 2022 at 12:21

1 Answer 1

1
$\begingroup$

The latest release of qiskit-aer should support the if else operation in your quantum circuit. You can see this documented in the release notes here: https://qiskit.org/documentation/release_notes.html#aer-0-10-0

That being said there is a general limitation around the classical control flow instruction in qiskit right now in that the transpiler doesn't know how to work with them yet. So you're not able to run them through the transpiler and pass them to an Aer backend like you normally would you'll have to build your circuit in instructions supported by the simulator and pass your circuit directly to the run() method on the backend

$\endgroup$
3
  • $\begingroup$ So this is on the agenda and will be implemented for the aer-simulator somewhere in time. Am I right? $\endgroup$ Jan 11, 2022 at 10:04
  • $\begingroup$ It already works with the latest version of the aer simulator, you just can not transpile your circuit with if/else or loops in your circuit yet (which will be fixed in a future release). For example: ``` import qiskit from qiskit.providers.aer import AerSimulator qc = qiskit.QuantumCircuit(4, 4) qc.y(0) qc.h(qc.qubits[1:4]) qc.barrier() qc.measure(0, 0) with qc.if_test((0, 1)): qc.h(qc.qubits[1:4]) qc.measure(1, 1) qc.measure(2, 2) qc.measure(3, 3) job = AerSimulator(method="statevector").run(qc) ``` will work fine $\endgroup$ Jan 11, 2022 at 13:04
  • $\begingroup$ Thanks for the clarification. Seems I have to update my use of the aer-simulator ;-) $\endgroup$ Jan 11, 2022 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.