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

Schedule with backend v2 #10564

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6a3b145
fix measure_v2
to24toro May 22, 2023
3cd1192
modify measure_all
to24toro May 23, 2023
58023f5
dispatch backend
to24toro May 23, 2023
93a9262
add test of the builder with backendV2
to24toro May 24, 2023
2cc5451
reconfigure test codes and some func
to24toro May 26, 2023
a21cc84
refactoring
to24toro May 26, 2023
b3607ee
add reno
to24toro May 31, 2023
bd1e169
fix _measure_v2
to24toro May 31, 2023
d70796f
fix backend.meas_map in measure_v2
to24toro May 31, 2023
2a651dd
fix reno
to24toro May 31, 2023
8d92531
delete get_qubit_channels from utils
to24toro Jun 5, 2023
9b2b80d
add get_qubits_channels in qubit_channels
to24toro Jun 5, 2023
891c1bd
recostruct test about the builder with backendV2
to24toro Jun 5, 2023
83a31b3
add meas_map to Target class
to24toro Jun 5, 2023
a62cf61
add target to schedule func
to24toro Jun 13, 2023
f7a1cdb
Merge branch 'main' into feature/target_from_cofiguration
to24toro Jun 13, 2023
cf4357b
fix after mergin main branch
to24toro Jun 13, 2023
fb0a596
Merge branch 'feature/replace_scheduleconfig_with_target' into featur…
to24toro Jun 13, 2023
46345e7
schedule with backendV2
to24toro Jun 15, 2023
84271e5
add deprecate_arg to schedule
to24toro Jun 15, 2023
d2e2200
add test to builder_v2
to24toro Jun 20, 2023
1d0e99f
make scheduleConfig None
to24toro Jun 20, 2023
9900130
delete deprecate_arg
to24toro Jun 20, 2023
ced9db8
Merge branch 'main' into feature/add_target_to_schedule
to24toro Jun 28, 2023
5b38ba3
Merge branch 'main' into feature/add_target_to_schedule
to24toro Jul 6, 2023
bc421ad
change schedule_logic
to24toro Jul 12, 2023
4205960
change sequence logic
to24toro Jul 12, 2023
e27fdb6
convert target to Optional in macros.measure
to24toro Jul 12, 2023
5726a2b
change the type of meas_map in scheduleconfig
to24toro Jul 12, 2023
9f9aef5
add convert_to_target wrapper
to24toro Jul 12, 2023
6f26131
delete import math from test_builder_v2
to24toro Jul 19, 2023
3f8ce5a
Merge branch 'main' into feature/add_target_to_schedule
to24toro Jul 19, 2023
4e4b707
format by black
to24toro Jul 19, 2023
86d0241
add target arg to schedule
to24toro Jul 19, 2023
96ff260
modify to pass some tests
to24toro Jul 19, 2023
b6e2cc3
fix UnassignedDurationError of update_from_instruction_schedule_map
to24toro Jul 19, 2023
8c16247
add test
to24toro Jul 19, 2023
9522535
add reno
to24toro Jul 19, 2023
f256d45
rename test
to24toro Jul 19, 2023
2efde08
fix reno
to24toro Jul 19, 2023
ef252c7
Update releasenotes/notes/fix-update-from-instruction-schedule-map-d1…
nkanazawa1989 Jul 19, 2023
20ee4f7
Merge branch 'main' into feature/add_target_to_schedule
to24toro Jul 19, 2023
3fa0fbf
Merge remote-tracking branch 'origin/fix/update_from_instruction_sche…
to24toro Jul 19, 2023
5759677
fix documents about meas_map
to24toro Jun 18, 2023
e24962f
format target.py
to24toro Jun 27, 2023
a3ab93c
add reno
to24toro Jun 27, 2023
31f6529
add meas_map to target in convert_to_target
to24toro Jul 6, 2023
e36163f
add the more description about meas_map
to24toro Jul 6, 2023
93073d2
Update releasenotes/notes/enable_target_aware_meas_map-0d8542402a74e9…
to24toro Jul 6, 2023
11f2d1c
fix test_meas_map
to24toro Jul 6, 2023
6f5e7a0
remove format_meas_map
to24toro Jul 6, 2023
c7d369f
rename meas_map in target to concurrent_measuments
to24toro Jul 12, 2023
da855bb
change reno
to24toro Jul 12, 2023
fb3a483
remove Unused Union Dict
to24toro Jul 12, 2023
bac2221
concurrent_measurements set as getattr(configuration, meas_map)
to24toro Jul 12, 2023
1ef5a97
Update qiskit/transpiler/target.py
to24toro Jul 19, 2023
57eca29
Update qiskit/transpiler/target.py
to24toro Jul 19, 2023
2b18176
format
to24toro Jul 19, 2023
fbb9e3d
dispatching schedule
to24toro Jul 28, 2023
15d773d
change test codes
to24toro Jul 28, 2023
545009d
Merge branch 'main' into feature/add_target_to_schedule
to24toro Jul 28, 2023
c9042a1
change target.py
to24toro Aug 1, 2023
2e59ebd
fake_openpulse2q
to24toro Aug 1, 2023
d37de97
sequence
to24toro Aug 2, 2023
ad5b9c3
test_scheduler
to24toro Aug 2, 2023
9b8576a
test_3q_schedule
to24toro Aug 4, 2023
0007270
delete print
to24toro Aug 4, 2023
d859ac9
Merge branch 'main' into feature/schedule_with_backendV2
to24toro Aug 4, 2023
f4bc1a9
macros.py
to24toro Aug 4, 2023
d771f9d
Delete enable_target_aware_meas_map-0d8542402a74e9d8.yaml
to24toro Aug 4, 2023
b253d1c
Delete fix-update-from-instruction-schedule-map-d1cba4e4db4b679e.yaml
to24toro Aug 4, 2023
609e238
update_from_instruction_schedule_map
to24toro Aug 15, 2023
9b4f56c
fixup! update_from_instruction_schedule_map
to24toro Aug 22, 2023
983d3e4
add ignore_instruction options
to24toro Oct 7, 2023
8d0f93a
Merge branch 'main' into feature/schedule_with_backendV2
to24toro Nov 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions qiskit/compiler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.exceptions import QiskitError
from qiskit.pulse import InstructionScheduleMap, Schedule
from qiskit.providers.backend import Backend
from qiskit.scheduler import ScheduleConfig
from qiskit.providers.backend import Backend, BackendV1, BackendV2
from qiskit.providers.backend_compat import convert_to_target
from qiskit.transpiler import Target
from qiskit.scheduler.schedule_circuit import schedule_circuit
from qiskit.tools.parallel import parallel_map

Expand All @@ -42,6 +43,7 @@ def schedule(
meas_map: Optional[List[List[int]]] = None,
dt: Optional[float] = None,
method: Optional[Union[str, List[str]]] = None,
target: Optional[Target] = None,
) -> Union[Schedule, List[Schedule]]:
"""
Schedule a circuit to a pulse ``Schedule``, using the backend, according to any specified
Expand All @@ -58,6 +60,9 @@ def schedule(
which contain time information, dt is required. If not provided, it will be
obtained from the backend configuration
method: Optionally specify a particular scheduling method
target: The optional :class:`~.Target` representing the target backend. If ``None``,
defaults to the ``backend``\'s ``target``, constructed from convert_to_target,
or prepared from ``meas_map`` and ``inst_map``

Returns:
A pulse ``Schedule`` that implements the input circuit
Expand All @@ -67,36 +72,36 @@ def schedule(
"""
arg_circuits_list = isinstance(circuits, list)
start_time = time()
if backend and getattr(backend, "version", 0) > 1:
if inst_map is None:
inst_map = backend.instruction_schedule_map
if meas_map is None:
meas_map = backend.meas_map
if dt is None:
dt = backend.dt
else:
if inst_map is None:
if backend is None:
raise QiskitError(
"Must supply either a backend or InstructionScheduleMap for scheduling passes."
)
defaults = backend.defaults()
if target is None:
if isinstance(backend, BackendV2):
target = backend.target
if inst_map:
target.update_from_instruction_schedule_map(inst_map=inst_map)
elif isinstance(backend, BackendV1):
defaults = backend.defaults() if hasattr(backend, "defaults") else None
if defaults is None:
raise QiskitError(
"The backend defaults are unavailable. The backend may not support pulse."
)
inst_map = defaults.instruction_schedule_map
if meas_map is None:
if backend is None:
if backend.configuration() is not None:
target = convert_to_target(
configuration=backend.configuration(),
properties=backend.properties(),
defaults=defaults,
)
if inst_map:
target.update_from_instruction_schedule_map(inst_map=inst_map)
else:
raise QiskitError("Must specify backend that has a configuration.")
else:
if meas_map and inst_map:
target = Target(concurrent_measurements=meas_map, dt=dt)
target.update_from_instruction_schedule_map(inst_map=inst_map)
else:
Comment on lines +75 to +100
Copy link
Contributor Author

@to24toro to24toro Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is here:
if target is not provided

  1. backendV2 case
  2. backendV1 case
  3. backendV1 has configuration
  4. raise QiskitError
  5. backend is not provided
  6. meas_map and inst_map are provided. Is it correct? If either one is not provided, this logic outputs the error.

What I concerns about is how to handle dt because the input dt is only reflected on the case that any backend is not provided.
Is this any solution for this? Do we need to implement a new function like update_from_dt?

raise QiskitError(
"Must supply either a backend or a meas_map for scheduling passes."
"Must specify either target, backend, "
"or both meas_map and inst_map for scheduling passes."
)
meas_map = backend.configuration().meas_map
if dt is None:
if backend is not None:
dt = backend.configuration().dt

schedule_config = ScheduleConfig(inst_map=inst_map, meas_map=meas_map, dt=dt)
circuits = circuits if isinstance(circuits, list) else [circuits]
schedules = parallel_map(schedule_circuit, circuits, (schedule_config, method, backend))
end_time = time()
Expand Down
51 changes: 34 additions & 17 deletions qiskit/compiler/sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.exceptions import QiskitError
from qiskit.providers.backend import Backend
from qiskit.providers.backend import Backend, BackendV1, BackendV2
from qiskit.providers.backend_compat import convert_to_target
from qiskit.pulse import InstructionScheduleMap, Schedule
from qiskit.scheduler import ScheduleConfig
from qiskit.transpiler import Target
from qiskit.scheduler.sequence import sequence as _sequence


Expand All @@ -29,6 +30,7 @@ def sequence(
inst_map: Optional[InstructionScheduleMap] = None,
meas_map: Optional[List[List[int]]] = None,
dt: Optional[float] = None,
target: Optional[Target] = None,
) -> Union[Schedule, List[Schedule]]:
"""
Schedule a scheduled circuit to a pulse ``Schedule``, using the backend.
Expand All @@ -43,27 +45,42 @@ def sequence(
dt: The output sample rate of backend control electronics. For scheduled circuits
which contain time information, dt is required. If not provided, it will be
obtained from the backend configuration
target: The optional :class:`~.Target` representing the target backend. If ``None``,
defaults to the ``backend``\'s ``target``, constructed from convert_to_target,
or prepared from ``meas_map`` and ``inst_map``


Returns:
A pulse ``Schedule`` that implements the input circuit

Raises:
QiskitError: If ``inst_map`` and ``meas_map`` are not passed and ``backend`` is not passed
"""
if inst_map is None:
if backend is None:
raise QiskitError("Must supply either a backend or inst_map for sequencing.")
inst_map = backend.defaults().instruction_schedule_map
if meas_map is None:
if backend is None:
raise QiskitError("Must supply either a backend or a meas_map for sequencing.")
meas_map = backend.configuration().meas_map
if dt is None:
if backend is None:
raise QiskitError("Must supply either a backend or a dt for sequencing.")
dt = backend.configuration().dt

schedule_config = ScheduleConfig(inst_map=inst_map, meas_map=meas_map, dt=dt)
if target is None:
if isinstance(backend, BackendV2):
target = backend.target
if inst_map:
target.update_from_instruction_schedule_map(inst_map=inst_map)
elif isinstance(backend, BackendV1):
if backend.configuration() is not None:
target = convert_to_target(
configuration=backend.configuration(),
properties=backend.properties(),
defaults=backend.defaults() if hasattr(backend, "defaults") else None,
)
if inst_map:
target.update_from_instruction_schedule_map(inst_map=inst_map)
else:
raise QiskitError("Must specify backend that has a configuration.")
else:
if meas_map and inst_map:
target = Target(concurrent_measurements=meas_map, dt=dt)
target.update_from_instruction_schedule_map(inst_map=inst_map)
else:
raise QiskitError(
"Must specify either target, backend, "
"or both meas_map and inst_map for scheduling passes."
)
Comment on lines +59 to +83
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic is the same as that of schedule.

circuits = scheduled_circuits if isinstance(scheduled_circuits, list) else [scheduled_circuits]
schedules = [_sequence(circuit, schedule_config) for circuit in circuits]
schedules = [_sequence(circuit, target=target) for circuit in circuits]
return schedules[0] if len(schedules) == 1 else schedules
26 changes: 25 additions & 1 deletion qiskit/providers/fake_provider/fake_openpulse_2q.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ def __init__(self):
Nduv(date=mock_time, name="gate_length", unit="ns", value=0.0),
],
),
Gate(
gate="u1",
qubits=[1],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=0.0),
],
),
Gate(
gate="u2",
qubits=[0],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=2 * dt),
],
),
Gate(
gate="u2",
qubits=[1],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=2 * dt),
],
),
Comment on lines +304 to +327
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new logic puts information into the target by convert_to_target, but requires a property with sufficient information. So I added for test.

Gate(
gate="u3",
qubits=[0],
Expand All @@ -314,7 +338,7 @@ def __init__(self):
qubits=[1],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=4 * dt),
Nduv(date=mock_time, name="gate_length", unit="ns", value=2 * dt),
],
),
Gate(
Expand Down
100 changes: 100 additions & 0 deletions qiskit/providers/fake_provider/fake_openpulse_3q.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""
Fake backend supporting OpenPulse.
"""
import datetime

from qiskit.providers.models import (
GateConfig,
Expand All @@ -21,6 +22,7 @@
Command,
UchannelLO,
)
from qiskit.providers.models.backendproperties import Nduv, Gate, BackendProperties
from qiskit.qobj import PulseQobjInstruction

from .fake_backend import FakeBackend
Expand Down Expand Up @@ -326,7 +328,105 @@ def __init__(self):
],
}
)
mock_time = datetime.datetime.now()
dt = 1.3333
self._properties = BackendProperties(
backend_name="fake_openpulse_3q",
backend_version="0.0.0",
last_update_date=mock_time,
qubits=[
[
Nduv(date=mock_time, name="T1", unit="µs", value=71.9500421005539),
Nduv(date=mock_time, name="T2", unit="µs", value=69.4240447362455),
Nduv(date=mock_time, name="frequency", unit="MHz", value=4919.96800692),
Nduv(date=mock_time, name="readout_error", unit="", value=0.02),
],
[
Nduv(date=mock_time, name="T1", unit="µs", value=81.9500421005539),
Nduv(date=mock_time, name="T2", unit="µs", value=75.5598482446578),
Nduv(date=mock_time, name="frequency", unit="GHz", value=5.01996800692),
Nduv(date=mock_time, name="readout_error", unit="", value=0.02),
],
[
Nduv(date=mock_time, name="T1", unit="µs", value=81.9500421005539),
Nduv(date=mock_time, name="T2", unit="µs", value=75.5598482446578),
Nduv(date=mock_time, name="frequency", unit="GHz", value=5.01996800692),
Nduv(date=mock_time, name="readout_error", unit="", value=0.02),
],
],
gates=[
Gate(
gate="u1",
qubits=[0],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=0.0),
],
),
Gate(
gate="u1",
qubits=[1],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=0.0),
],
),
Gate(
gate="u1",
qubits=[2],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=0.0),
],
),
Gate(
gate="u3",
qubits=[0],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=2 * dt),
],
),
Gate(
gate="u3",
qubits=[1],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=2 * dt),
],
),
Gate(
gate="u3",
qubits=[2],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=0.06),
Nduv(date=mock_time, name="gate_length", unit="ns", value=2 * dt),
],
),
Gate(
gate="cx",
qubits=[0, 1],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=1.0),
Nduv(date=mock_time, name="gate_length", unit="ns", value=22 * dt),
],
),
Gate(
gate="cx",
qubits=[1, 2],
parameters=[
Nduv(date=mock_time, name="gate_error", unit="", value=1.0),
Nduv(date=mock_time, name="gate_length", unit="ns", value=22 * dt),
],
),
],
general=[],
)
super().__init__(configuration)

def defaults(self): # pylint: disable=missing-function-docstring
return self._defaults

def properties(self):
"""Return the measured characteristics of the backend."""
return self._properties
2 changes: 1 addition & 1 deletion qiskit/pulse/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
d2 = pulse.DriveChannel(2)

with pulse.build(backend) as bell_prep:
pulse.u2(0, math.pi, 0)
pulse.u3(1.57, 0, math.pi, 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FakeOpenPulse3Q doesn't support u2 gate and this results in the error in the new logic because target doesn't include u2 gate info.

pulse.cx(0, 1)

with pulse.build(backend) as decoupled_bell_prep_and_measure:
Expand Down
9 changes: 6 additions & 3 deletions qiskit/pulse/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
def measure(
qubits: List[int],
backend=None,
target: Optional[Target] = None,
inst_map: Optional[InstructionScheduleMap] = None,
meas_map: Optional[Union[List[List[int]], Dict[int, List[int]]]] = None,
qubit_mem_slots: Optional[Dict[int, int]] = None,
Expand All @@ -51,6 +52,7 @@ def measure(
qubits: List of qubits to be measured.
backend (Union[Backend, BaseBackend]): A backend instance, which contains
hardware-specific data required for scheduling.
target: The :class:`~.Target` representing the target backend.
inst_map: Mapping of circuit operations to pulse schedules. If None, defaults to the
``instruction_schedule_map`` of ``backend``.
meas_map: List of sets of qubits that must be measured together. If None, defaults to
Expand All @@ -63,12 +65,13 @@ def measure(
"""

# backend is V2.
if isinstance(backend, BackendV2):
if isinstance(backend, BackendV2) or target:
meas_map = meas_map or getattr(backend, "meas_map", None)

return _measure_v2(
qubits=qubits,
target=backend.target,
meas_map=meas_map or backend.meas_map,
target=target or backend.target,
meas_map=meas_map or target.concurrent_measurements,
qubit_mem_slots=qubit_mem_slots or dict(zip(qubits, range(len(qubits)))),
measure_name=measure_name,
)
Expand Down
3 changes: 1 addition & 2 deletions qiskit/scheduler/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from typing import List

from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap
from qiskit.pulse.utils import format_meas_map


class ScheduleConfig:
Expand All @@ -31,5 +30,5 @@ def __init__(self, inst_map: InstructionScheduleMap, meas_map: List[List[int]],
dt: Sample duration.
"""
self.inst_map = inst_map
self.meas_map = format_meas_map(meas_map)
self.meas_map = meas_map
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed format_meas_map .
When I make target class like this

Target(meas_map=schedule_config.meas_map)

the type of meas_map is restricted to list (#10258 (comment)).

self.dt = dt
Loading
Loading