Unable to transpile dynamic circuits for backends
See original GitHub issueEnvironment
- Qiskit Terra version:
qiskit-terra==0.22.3
- Python version:
Python 3.10.8
- Operating system: macOS
What is happening?
I am trying to run some dynamic circuits (meaning classical conditional operations) on an ibmq backend by following some of the tutorials I have found on this. I am running into a couple of errors - the primary one that is confusing me is that I am trying to test out a very very simple dynamic circuit with just a single qubit and just a single if else statement. The problem is that I can not seem to transpile this circuit - I get transpiler error from the equivalence library. From what I can tell this error is not reported elsewhere, and I also think that my local Qiskit version is up to date. I also think that I am implementing the conditional correctly, for example I am not using the now potentially deprecated qc.x(0).c_if(cr[0], 1)
.
How can we reproduce the issue?
from qiskit.compiler import transpile
from qiskit import IBMQ
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
IBMQ.load_account()
provider = IBMQ.get_provider(hub='', group='', project='')
IBMQ_device = "ibm_auckland"
backend = provider.get_backend(IBMQ_device)
qr = QuantumRegister(1, name='q')
cr = ClassicalRegister(2, name='c')
qc = QuantumCircuit(qr, cr)
qc.h(0)
qc.measure(qr[0], cr[0])
with qc.if_test((cr[0], 1)) as else_:
qc.x(0)
with else_:
qc.z(0)
print(qc)
qc = transpile(qc, backend)
What should happen?
When I execute the code snippet returns the following error:
Traceback (most recent call last):
File "/Users/usr/dir/replicate.py", line 24, in <module>
circ = transpile(qc, backend)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/compiler/transpiler.py", line 382, in transpile
_serial_transpile_circuit(
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/compiler/transpiler.py", line 475, in _serial_transpile_circuit
result = pass_manager.run(circuit, callback=callback, output_name=output_name)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py", line 528, in run
return super().run(circuits, output_name, callback)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py", line 228, in run
return self._run_single_circuit(circuits, output_name, callback)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/passmanager.py", line 283, in _run_single_circuit
result = running_passmanager.run(circuit, output_name=output_name, callback=callback)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py", line 125, in run
dag = self._do_pass(pass_, dag, passset.options)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py", line 172, in _do_pass
dag = self._run_this_pass(pass_, dag)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/runningpassmanager.py", line 201, in _run_this_pass
new_dag = pass_.run(dag)
File "//anaconda3/envs/main/lib/python3.10/site-packages/qiskit/transpiler/passes/basis/basis_translator.py", line 186, in run
raise TranspilerError(
qiskit.transpiler.exceptions.TranspilerError: "Unable to map source basis {('h', 1), ('if_else', 1), ('measure', 1), ('z', 1), ('x', 1)} to target basis {'id', 'sx', 'cx', 'snapshot', 'delay', 'measure', 'rz', 'x', 'barrier', 'reset'} over library <qiskit.circuit.equivalence.EquivalenceLibrary object at 0x116b2f1f0>."
Any suggestions?
No response
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Yep, the module
qiskit_ibm_provider
fixes all of the problems. And adding the IfElseOp is not required.Please see the documentation linked above - you must use the new provider, not
IBMQ
.