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

Another Potential Solution to Schedule with V2 Fails #10298

Open
chuanqixu opened this issue Jun 16, 2023 · 1 comment
Open

Another Potential Solution to Schedule with V2 Fails #10298

chuanqixu opened this issue Jun 16, 2023 · 1 comment
Labels
bug Something isn't working mod: pulse Related to the Pulse module

Comments

@chuanqixu
Copy link

Environment

  • Qiskit Terra version: 0.24
  • Python version: any
  • Operating system: any

What is happening?

Currently, it does not support BackendV2 for scheduling.
I check backend.instruction_schedule_map, and it seems that the difference is that BackendV1 has the simultaneous measurement operation for all qubits, while BackendV2 does not have such operation.

How can we reproduce the issue?

Simply schedule the circuit, then it fails:

from qiskit import QuantumCircuit, schedule
from qiskit_ibm_provider import IBMProvider

provider = IBMProvider()

# Create a circuit
qc = QuantumCircuit(2)
qc.x(0)
qc.cx(0, 1)
qc.measure_all()

# Select a backend.
backend = provider.get_backend("ibm_lagos")

sched = schedule(qc, backend)

What should happen?

Error information:

Exception has occurred: PulseError
"We could not find a default measurement schedule called 'measure'. Please provide another name using the 'measure_name' keyword argument. For assistance, the instructions which are defined are: ['sx', 'id', 'x', 'rz', 'cx', 'measure']"
qiskit.pulse.exceptions.PulseError: "Operation 'measure' exists, but is only defined for qubits [0, 1, 2, 3, 4, 5, 6]."

The above exception was the direct cause of the following exception:

File "D:\qiskit_test\test.py", line 29, in
sched = schedule(qc, backend)
qiskit.pulse.exceptions.PulseError: "We could not find a default measurement schedule called 'measure'. Please provide another name using the 'measure_name' keyword argument. For assistance, the instructions which are defined are: ['sx', 'id', 'x', 'rz', 'cx', 'measure']"

Any suggestions?

I found some issues and PRs mentioning and solving this problem: #9488 , #9912 , #9987 , #10105 , #10200 .
Thanks to all these efforts, it seems that with many changes, this problem has already been solved.

One thing that confuses me is that qiskit.pulse.measure (in qiskit/pulse/macro.py) has one argument backend, which will be used to decide the version of the backend and then decide the way of scheduling measurements.
However, I checked all the references of measure, but there is no place passing the backend into it, except for test files.

The issue with the current schedule is that no backend parameter will be passed for this. So even passing BackendV2 into schedule, it still uses _measure_v1 to schedule and thus leading to the bug.
I check the whole process of schedule, where the call stack is:
qiskit.compiler.schedule -> qiskit.scheduler.schedule_circuit -> qiskit.scheduler.methods.as_late_as_possible (or as_soon_as_possible) -> qiskit.scheduler.lower_gates -> qiskit.pulse.measure.
If we can somehow passing the backend for qiskit.pulse.measure to differentiate the version of the backend, then this bug will be solved.

Without changing the function interfaces, I think the best option is to include the backend into ScheduleConfig.
I knew from the above issues and PRs that possibly ScheduleConfig will be deprecated in the future, but as one simple solution, we can add the backend as one parameter into ScheduleConfig.
In this way, we only need to change a few places to remove the bug.

Also, it may be reasonable to have a backend in ScheduleConfig, because this class is said to be "Container for information needed to schedule a QuantumCircuit into a pulse Schedule.".
Backend information is important for scheduling, such as on which backend you schedule this job.
Though it is not necessary, we can make this parameter to be optional.

@chuanqixu
Copy link
Author

chuanqixu commented Jun 16, 2023

Since I found #10285 which is striving to solve the bug, and also there are many discussions about how to change it but I have not participated in it, I only create one draft PR.
But if you are interested, you can check #10299, and possibly we can change it to regular PR if necessary.

@ShellyGarion ShellyGarion added the mod: pulse Related to the Pulse module label Dec 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: pulse Related to the Pulse module
Projects
None yet
Development

No branches or pull requests

2 participants