-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Schedule with backend v2 #10564
Changes from all commits
6a3b145
3cd1192
58023f5
93a9262
2cc5451
a21cc84
b3607ee
bd1e169
d70796f
2a651dd
8d92531
9b2b80d
891c1bd
83a31b3
a62cf61
f7a1cdb
cf4357b
fb0a596
46345e7
84271e5
d2e2200
1d0e99f
9900130
ced9db8
5b38ba3
bc421ad
4205960
e27fdb6
5726a2b
9f9aef5
6f26131
3f8ce5a
4e4b707
86d0241
96ff260
b6e2cc3
8c16247
9522535
f256d45
2efde08
ef252c7
20ee4f7
3fa0fbf
5759677
e24962f
a3ab93c
31f6529
e36163f
93073d2
11f2d1c
6f5e7a0
c7d369f
da855bb
fb3a483
bac2221
1ef5a97
57eca29
2b18176
fbb9e3d
15d773d
545009d
c9042a1
2e59ebd
d37de97
ad5b9c3
9b8576a
0007270
d859ac9
f4bc1a9
d771f9d
b253d1c
609e238
9b4f56c
983d3e4
8d0f93a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
||
|
@@ -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. | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic is the same as that of |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new logic puts information into the target by |
||
Gate( | ||
gate="u3", | ||
qubits=[0], | ||
|
@@ -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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
pulse.cx(0, 1) | ||
|
||
with pulse.build(backend) as decoupled_bell_prep_and_measure: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed Target(meas_map=schedule_config.meas_map) the type of |
||
self.dt = dt |
There was a problem hiding this comment.
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 providedconfiguration
meas_map
andinst_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 inputdt
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
?