Skip to content

Commit

Permalink
Fix UnassignedDurationError of update_from_instruction_schedule_map (#…
Browse files Browse the repository at this point in the history
…10447)

* fix UnassignedDurationError of update_from_instruction_schedule_map

* add test

* add reno

* rename test

* fix reno

* Update releasenotes/notes/fix-update-from-instruction-schedule-map-d1cba4e4db4b679e.yaml

---------

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
  • Loading branch information
to24toro and nkanazawa1989 authored Jul 20, 2023
1 parent d13f0bb commit ac29776
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
8 changes: 6 additions & 2 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from qiskit.transpiler.instruction_durations import InstructionDurations
from qiskit.transpiler.timing_constraints import TimingConstraints
from qiskit.providers.exceptions import BackendPropertyError
from qiskit.pulse.exceptions import PulseError
from qiskit.pulse.exceptions import PulseError, UnassignedDurationError
from qiskit.utils.deprecation import deprecate_arg, deprecate_func
from qiskit.exceptions import QiskitError

Expand Down Expand Up @@ -505,7 +505,11 @@ def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, err
# It only copies user-provided calibration from the inst map.
# Backend defined entry must already exist in Target.
if self.dt is not None:
duration = entry.get_schedule().duration * self.dt
try:
duration = entry.get_schedule().duration * self.dt
except UnassignedDurationError:
# duration of schedule is parameterized
duration = None
else:
duration = None
props = InstructionProperties(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fixed an failure of :meth:`.Target.update_from_instruction_schedule_map` when
the argument ``inst_map`` has schedule with unassigned duration.
14 changes: 14 additions & 0 deletions test/python/transpiler/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,20 @@ def test_update_from_instruction_schedule_map_add_instruction(self):
target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()})
self.assertEqual(inst_map, target.instruction_schedule_map())

def test_update_from_instruction_schedule_map_with_schedule_parameter(self):
self.pulse_target.dt = None
inst_map = InstructionScheduleMap()
duration = Parameter("duration")

with pulse.build(name="sx_q0") as custom_sx:
pulse.play(pulse.Constant(duration, 0.2), pulse.DriveChannel(0))

inst_map.add("sx", 0, custom_sx, ["duration"])

target = Target(dt=3e-7)
target.update_from_instruction_schedule_map(inst_map, {"sx": SXGate()})
self.assertEqual(inst_map, target.instruction_schedule_map())

def test_update_from_instruction_schedule_map_update_schedule(self):
self.pulse_target.dt = None
inst_map = InstructionScheduleMap()
Expand Down

0 comments on commit ac29776

Please sign in to comment.