question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to transpile dynamic circuits for backends

See original GitHub issue

Environment

  • 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:closed
  • Created 9 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
epelofske-LANLcommented, Dec 14, 2022

Yep, the module qiskit_ibm_provider fixes all of the problems. And adding the IfElseOp is not required.

0reactions
taalexandercommented, Dec 14, 2022

Please see the documentation linked above - you must use the new provider, not IBMQ.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic circuits (conditionals) do not work with current ...
Does not work with dynamic circuits (meaning they have if/else ... from qiskit.circuit.library import XGate from qiskit.transpiler import ...
Read more >
Access systems with your account - IBM Quantum
Backends represent either a simulator or a real quantum computer, and are responsible for running quantum circuits and/or pulse schedules and returning results....
Read more >
Dynamic Quantum Circuits, Lesson 1 | by Brian N. Siegelwax
I had to change all of the above in my template. qc = transpile(qc, backend, initial_layout=[0,1]). It probably works without the initial_layout ...
Read more >
Dynamic Circuits - Day 10 of 12 Days of Qiskit - YouTube
Watch Nick throw caution to the wind by live-coding and executing examples of dynamic circuits. Dynamic circuits allow branching (if/then ...
Read more >
qiskit.providers.ibmq.IBMQBackend
Backend class interfacing with an IBM Quantum Experience device. ... assemble, transpile from qiskit.circuit.random import random_circuit ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found