qiskit
qiskit copied to clipboard
`basis_gates` do not take priority over `backend` in `generate_preset_pass_manager`
Environment
- Qiskit version: 1.0.0rc1
- Python version: 3.11
- Operating system: MacOS
What is happening?
When using both backend
and basis_gates
params, seems like the backend takes priority, in spite of what the documentation says:
backend (Backend) – An optional backend object which can be used as the source of the default values for the basis_gates, inst_map, couplig_map, backend_properties, instruction_durations, timing_constraints, and target. If any of those other arguments are specified in addition to backend they will take precedence over the value contained in the backend.
This is a difference in behavior from transpile()
, in which transpile(qc, backend, basis_gates)
ignores the backend.
How can we reproduce the issue?
from qiskit.transpiler.preset_passmanagers.level1 import level_1_pass_manager
from qiskit.transpiler import PassManagerConfig
from qiskit.providers.fake_provider import FakeNairobiV2
backend = FakeNairobiV2()
pmc = PassManagerConfig.from_backend(backend, basis_gates=["cx", "x"])
pm = level_1_pass_manager(pmc)
pm.run(circuit)
What should happen?
For a complex enough circuit
, it should raise a TranspilerError
because transpilation would have not been possible with basis gates ["cx", "x"]
(incomplete basis).
Any suggestions?
No response
Please can you clarify the Qiskit version you're using, but also: your title mentions generate_preset_pass_manager
but the code block doesn't use it. I imagine the same behaviour is between both, but could you just check the code block is what you wanted to show as well?
This is probably the case for BackendV2
but not BackendV1
. I've talked about some of the complications in allowing the basis_gates
override for Target
-based potentially heterogeneous backends in a previous comment: https://github.com/Qiskit/qiskit/issues/11405#issuecomment-1857995232, which might provide some background. This might mean that the most immediate thing we can do about this is to fix any out-of-date documentation; making meaningful helper methods to override a Target
with BackendV1
-era properties involves a few maybe tricky interface decisions.
As an immediate workaround, I think something like
from qiskit.transpiler import Target
backend = SomeV2Backend()
target = Target.from_configuration(["cx", "x"], backend.num_qubits, backend.target.build_coupling_map())
pm = generate_preset_pass_manager(target=target, ...)
might work for you. That will rebuild a new Target
with the particular basis gates overides, but the number of qubits and induced coupling map (making some BackendV1
-like assumptions) of the one you have.
Sorry I missed the qiskit version in the original post: it's 1.0.0rc1.
Indeed the code doesn't use generate_preset_pass_manager
directly but
pmc = PassManagerConfig.from_backend(backend, basis_gates=["cx", "x"])
pm = level_1_pass_manager(pmc)
pm.run(circuit)
should behave similarly to transpile(qc, backend, basis_gates)
.
The mention to generate_preset_pass_manager
was to help identify the root cause of the problem.