Skip to content
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

AI Transpiler transpiling to non native gates #152

Open
RedWyrm13 opened this issue Feb 7, 2025 · 1 comment
Open

AI Transpiler transpiling to non native gates #152

RedWyrm13 opened this issue Feb 7, 2025 · 1 comment

Comments

@RedWyrm13
Copy link

I am using the AI transpiler on the QAOA Ansatz and trying to run it on ibm_kyiv and I am getting this error "'The instruction u3 on qubits (34,) is not supported by the target system. Circuits that do not match the target hardware definition are no longer supported after March 4, 2024. See the transpilation documentation (https://docs.quantum.ibm.com/guides/transpile) for instructions to transform circuits and the primitive examples (https://docs.quantum.ibm.com/guides/primitives-examples) to see this coupled with operator transformations.'"

Here is the relevant code:

ansatz = QAOAAnsatz(hamiltonian,reps).decompose().decompose().decompose()

ai_passmanager = PassManager([
    AIRouting(backend=backend, optimization_level=3, layout_mode="optimize", local_mode=True)
])

ansatz_isa = ai_passmanager.run(ansatz)

with Session(backend=backend) as session:
    # If using qiskit-ibm-runtime<0.24.0, change `mode=` to `session=`

    num_shots = 10000 * (2**hamiltonian.num_qubits) 
    estimator = Estimator(mode=session)
    estimator.options.default_shots = num_shots

    # Set simple error suppression/mitigation options
    estimator.options.dynamical_decoupling.enable = True
    estimator.options.dynamical_decoupling.sequence_type = "XY4"
    estimator.options.twirling.enable_gates = True
    estimator.options.twirling.num_randomizations = "auto"

    optimizer_results = optimize(estimator, ansatz_isa, hamiltonian)
@victor-villar
Copy link
Collaborator

victor-villar commented Feb 10, 2025

Hi @RedWyrm13 !
In your code you are only applying the routing pass to the circuit. In order to run the circuit in the real backend there are some other extra passes that needs to be present.
I think the easiest way would be to generate a preset manager and then add the ai_routing pass at the appropriate step:

from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit.transpiler import PassManager
from qiskit_ibm_transpiler.ai.routing import AIRouting

ai_routing = PassManager([
    AIRouting(backend=backend, optimization_level=3, layout_mode="optimize", local_mode=True)
 ])
pm = generate_preset_pass_manager(backend=backend)

pm.layout = None
pm.routing = ai_routing

ansatz_isa = pm.run(ansatz)
....

I think that should work. Let us know if you find other issues.


Also you can use the generate_ai_passmanager function that would create a pass manager with ai_routing plus some other passes to improve the results depending on your input options (as well as all qiskit passes needed to run the circuit in the real hardware):

from qiskit_ibm_transpiler.ai_passmanager import generate_ai_pass_manager

pm_ai = generate_ai_pass_manager(backend=backend,ai_optimization_level=3, optimization_level=1, ai_layout_mode="optimize")

ansatz_isa = pm_ai.run(ansatz)
....

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

No branches or pull requests

2 participants