Skip to content

✨ Qiskit v2.0 Compatibility #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

simon1hofmann
Copy link
Collaborator

@simon1hofmann simon1hofmann commented Apr 16, 2025

Resolves #521

@github-project-automation github-project-automation bot moved this to In Progress in MQT Applications Apr 16, 2025
@simon1hofmann simon1hofmann changed the title ✨ Support qiskit 2.0.0 ✨ Qiskit v2.0 Compatibility Apr 16, 2025
@burgholzer
Copy link
Member

This is probably blocked by #429, right?

@simon1hofmann
Copy link
Collaborator Author

This is probably blocked by #429, right?

Not necessarily. The main problem is that in Qiskit v2.0, transpile does not accept the basis_gates argument with custom basis gates anymore.

From the migration guide (https://docs.quantum.ibm.com/migration-guides/qiskit-2.0): The basis_gates argument no longer accepts custom basis gates. The suggested alternative is the target argument, which can be built from scratch or through [Target.from_configuration](https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.Target#from_configuration) such as:

from qiskit.circuit.library import XGate
from qiskit.transpiler.target import Target
 
basis_gates = ["my_x", "cx"]
custom_name_mapping = {"my_x": XGate()}
target = Target.from_configuration(
    basis_gates=basis_gates, num_qubits=2, custom_name_mapping=custom_name_mapping
)
pm = generate_preset_pass_manager(target=target)

How should we handle that on the target independent level?
target_independent = transpile(qc, basis_gates=openqasm_gates)

with:

openqasm_gates= [ "u3", "u2", "u1", "cx", "id", "u0", "u", "p", "x", "y", "z", "h", "s", "sdg", "t", "tdg", "rx", "ry", "rz", "sx", "sxdg", "cz", "cy", "swap", "ch", "ccx", "cswap", "crx", "cry", "crz", "cu1", "cp", "cu3", "csx", "cu", "rxx", "rzz", "rccx", "rc3x", "c3x", "c3sqrtx", "c4x"]

@burgholzer
Copy link
Member

This is probably blocked by #429, right?

Not necessarily. The main problem is that in Qiskit v2.0, transpile does not accept the basis_gates argument with custom basis gates anymore.

From the migration guide (https://docs.quantum.ibm.com/migration-guides/qiskit-2.0): The basis_gates argument no longer accepts custom basis gates. The suggested alternative is the target argument, which can be built from scratch or through [Target.from_configuration](https://docs.quantum.ibm.com/api/qiskit/qiskit.transpiler.Target#from_configuration) such as:

from qiskit.circuit.library import XGate
from qiskit.transpiler.target import Target
 
basis_gates = ["my_x", "cx"]
custom_name_mapping = {"my_x": XGate()}
target = Target.from_configuration(
    basis_gates=basis_gates, num_qubits=2, custom_name_mapping=custom_name_mapping
)
pm = generate_preset_pass_manager(target=target)

How should we handle that on the target independent level? target_independent = transpile(qc, basis_gates=openqasm_gates)

with:

openqasm_gates= [ "u3", "u2", "u1", "cx", "id", "u0", "u", "p", "x", "y", "z", "h", "s", "sdg", "t", "tdg", "rx", "ry", "rz", "sx", "sxdg", "cz", "cy", "swap", "ch", "ccx", "cswap", "crx", "cry", "crz", "cu1", "cp", "cu3", "csx", "cu", "rxx", "rzz", "rccx", "rc3x", "c3x", "c3sqrtx", "c4x"]

Yeah. I saw that. But this basically means that we should be switching to defining gate sets not as lists of strings, but rather as Qiskit Target objects. And this is somewhat intertwined with the device refactor in #429.
Moving to Qiskit Targets is a reasonable thing to do and would probably fit nicely within #429.

As for the openqasm_gates: I would be heavily in favour of dropping these completely. They are an annoying artefact from the limit capabilities of OpenQASM 2.
As we now have an OpenQASM 3 output option, which should actually be the default going forward, the independent level should simply run transpile without a target.
With that, the algorithm level is just taking the circuit as is, while the independent level is applying device-independent optimisations. This is essentially how it was intended from the very beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ Qiskit v2.0 Compatability
2 participants