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

Running ALAPScheduleAnalysis directly on a circuit fails #13444

Open
eendebakpt opened this issue Nov 15, 2024 · 1 comment
Open

Running ALAPScheduleAnalysis directly on a circuit fails #13444

eendebakpt opened this issue Nov 15, 2024 · 1 comment
Labels
bug Something isn't working mod: transpiler Issues and PRs related to Transpiler
Milestone

Comments

@eendebakpt
Copy link
Contributor

Environment

  • Qiskit version: 1.2.4
  • Python version: 3.12
  • Operating system: Windows

What is happening?

Running the ALAPScheduleAnalysis pass directly on a circuit fails. Running it via a passmanager works.

How can we reproduce the issue?

A minimal example

import numpy as np
from qiskit.circuit import QuantumCircuit
from qiskit.transpiler import PassManager, InstructionDurations
from qiskit.transpiler.passes import ALAPScheduleAnalysis

durations = InstructionDurations( [("reset", None, 10),
     ("cz", None, 120), ("cx", None, 120), ("crx", None, 160),
     ("rx", None, 80), ('ry', None, 80), ('rz', None, 0),  ("measure", None, 30_000)]
)

circ = QuantumCircuit(2)
circ.rx(np.pi/2, 0)
circ.rz(-np.pi/2, 0)

pm = PassManager([ALAPScheduleAnalysis(durations)])
circ = pm.run(circ) # works

circ = QuantumCircuit(2)
circ.rx(np.pi/2, 0)
circ.rz(-np.pi/2, 0)

p=ALAPScheduleAnalysis(durations)
p(circ) # fails

What should happen?

Usually a qiskit pass can be applied directly to a quantum circuit, so it seems reasonable to expect the same from schedule passes.

Any suggestions?

No response

@eendebakpt eendebakpt added the bug Something isn't working label Nov 15, 2024
@jakelishman
Copy link
Member

ALAPScheduleAnalysis (and all the other built-in scheduling passes) make use of a PassManager feature of requiring that certain passes are run before them. In this case, I think it's the pass that just converts all time units into one unified thing (dt preferentially), but I honestly wouldn't be surprised at all to learn that that pass has a side-effect of initialising the analysis state for the other scheduling passes.

When you __call__ a transpiler pass cold, it skips all the pass-manager infrastructure that manages setting up the executor and handling the requirements, etc, which will be why it's not calling that correctly, and getting out-of-sync. I think the best way to take this is to have BasePass.__call__ simply instantiate a PassManager with self and return the result of running that on the input. That'll also reduce a lot of messy duplicated code, which has clearly got a bit out-of-sync with what PassManager itself does now.

@jakelishman jakelishman added the mod: transpiler Issues and PRs related to Transpiler label Nov 15, 2024
@jakelishman jakelishman modified the milestones: 1.3.1, 1.3.0 Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: transpiler Issues and PRs related to Transpiler
Projects
None yet
Development

No branches or pull requests

2 participants