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

Control flow operations are not usable jointly with custom gate calibrations #13728

Open
arthurostrauss opened this issue Jan 24, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@arthurostrauss
Copy link
Contributor

Environment

  • Qiskit version: 1.3.2
  • Python version: 3.10
  • Operating system: Mac OS Sequoia

What is happening?

The issue arises due to the way Qiskit handles control flow structures like for_loop when applying transpilation passes. Specifically, the for_loop construct internally stores a new QuantumCircuit object that does not retain the physical qubit mapping intended for the calibrated custom gate (as defined in the backend target object).

When the transpilation pipeline reaches the HighLevelSynthesis pass, the method _definitely_skip_node should return True if the gate already has a valid calibration. However, it does not because the physical qubits referenced in the circuit structure do not align with those recorded in the initial_layout during pass execution.

How can we reproduce the issue?

`from qiskit.circuit import QuantumCircuit, ParameterVector, Gate, Parameter
from qiskit import pulse, schedule, transpile
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.transpiler import InstructionProperties, generate_preset_pass_manager, CouplingMap

params = [Parameter(f'a_{i}') for i in range(2)]
qc = QuantumCircuit(2)
ecr_cal = Gate(name='ecr_cal', num_qubits=2, params=params)
qc_loop = QuantumCircuit(2)
qc.append(ecr_cal, [0, 1])
with qc_loop.for_loop([0, 3]) as i:
qc_loop.compose(qc, inplace=True)

backend = GenericBackendV2(num_qubits=4,
basis_gates=["x", "sx", "ecr", "rz", "measure", "reset"],
coupling_map=CouplingMap.from_full(4),
calibrate_instructions=True,
control_flow=True)

with pulse.build(backend, name="custom_sched") as custom_sched:
pulse.play(pulse.Constant(100, params[0]), pulse.DriveChannel(3))
pulse.play(pulse.Constant(100, params[1]), pulse.DriveChannel(4))

backend.target.add_instruction(ecr_cal, properties={(3,4): InstructionProperties(calibration=custom_sched)})
pm = generate_preset_pass_manager(optimization_level=1,
backend=backend,
initial_layout=(3,4))

transpiled_circ = pm.run(qc_loop)
transpiled_circ.draw('mpl')`

What should happen?

The transpilation process should correctly recognize that the ecr_cal gate, mapped to physical qubits (3,4), already has a calibration, and avoid unnecessary synthesis steps.
Instead of skipping synthesis, the transpiler does not identify the calibration, likely due to the for_loop internally storing logical qubit indices instead of physical qubits.

Any suggestions?

A potential solution could involve ensuring that physical qubit mappings are correctly maintained within control flow constructs, or updating the handling of control flow operations within transpilation passes to correctly propagate the intended qubit mappings.

@arthurostrauss arthurostrauss added the bug Something isn't working label Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant