Skip to content

Commit

Permalink
test_scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
to24toro committed Aug 3, 2023
1 parent d37de97 commit 66fd45d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
14 changes: 10 additions & 4 deletions qiskit/compiler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,29 @@ def schedule(
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."
)
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,
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 inst_map:
target = Target(concurrent_measurements=meas_map)
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 inst_map for scheduling passes."
"Must specify either target, backend,\
or both meas_map and inst_map for scheduling passes."
)
circuits = circuits if isinstance(circuits, list) else [circuits]
schedules = parallel_map(schedule_circuit, circuits, (None, target, method))
Expand Down
4 changes: 2 additions & 2 deletions qiskit/compiler/sequencer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def sequence(
else:
raise QiskitError("Must specify backend that has a configuration.")
else:
if inst_map:
target = Target(concurrent_measurements=meas_map)
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(
Expand Down
4 changes: 2 additions & 2 deletions test/python/compiler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_instruction_map_and_backend_not_supplied(self):
"""Test instruction map and backend not supplied."""
with self.assertRaisesRegex(
QiskitError,
r"Must supply either a backend or InstructionScheduleMap for scheduling passes.",
r"Must specify either target, backend, or both meas_map and inst_map for scheduling passes.",
):
schedule(self.circ)

Expand All @@ -61,7 +61,7 @@ def test_measurement_map_and_backend_not_supplied(self):
"""Test measurement map and backend not supplied."""
with self.assertRaisesRegex(
QiskitError,
r"Must supply either a backend or a meas_map for scheduling passes.",
r"Must specify either target, backend, or both meas_map and inst_map for scheduling passes.",
):
schedule(self.circ, inst_map=InstructionScheduleMap())

Expand Down
3 changes: 2 additions & 1 deletion test/python/pulse/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def test_complex_build(self):
pulse.u2(0, pi / 2, 1)
pulse.u2(0, pi / 2, 0)
pulse.measure(0)

print(schedule.instructions)
# prepare and schedule circuits that will be used.
single_u2_qc = circuit.QuantumCircuit(2)
single_u2_qc.append(circuit.library.U2Gate(0, pi / 2), [1])
Expand All @@ -914,6 +914,7 @@ def test_complex_build(self):
sequential_reference.insert(delay_dur, single_u2_sched, inplace=True)

# align right
print(single_u2_sched.duration)
align_right_reference = pulse.Schedule()
align_right_reference += pulse.Play(library.Constant(long_dur, 0.1), d2)
align_right_reference.insert(
Expand Down
9 changes: 4 additions & 5 deletions test/python/pulse/test_builder_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ def test_complex_build(self):
d0 = pulse.DriveChannel(0)
d1 = pulse.DriveChannel(1)
d2 = pulse.DriveChannel(2)
delay_dur = 30
short_dur = 20
long_dur = 49
delay_dur = 300
short_dur = 200
long_dur = 810

with pulse.build(self.backend) as schedule:
with pulse.align_sequential():
Expand All @@ -471,7 +471,6 @@ def test_complex_build(self):
pulse.u2(0, np.pi / 2, 1)
pulse.u2(0, np.pi / 2, 0)
pulse.measure(0)

# prepare and schedule circuits that will be used.
single_u2_qc = circuit.QuantumCircuit(2)
single_u2_qc.append(circuit.library.U2Gate(0, np.pi / 2), [1])
Expand Down Expand Up @@ -505,7 +504,7 @@ def test_complex_build(self):

# measurement
measure_reference = macros.measure(
qubits=[0], inst_map=self.inst_map, meas_map=self.configuration.meas_map
qubits=[0], backend=self.backend, meas_map=self.backend.meas_map
)
reference = pulse.Schedule()
reference += sequential_reference
Expand Down

0 comments on commit 66fd45d

Please sign in to comment.