Skip to content

Commit

Permalink
add ignore_instruction options
Browse files Browse the repository at this point in the history
  • Loading branch information
to24toro committed Oct 7, 2023
1 parent 9b4f56c commit c7dfb53
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions qiskit/transpiler/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ def update_instruction_properties(self, instruction, qargs, properties):
self._instruction_durations = None
self._instruction_schedule_map = None

def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, error_dict=None):
def update_from_instruction_schedule_map(
self, inst_map, inst_name_map=None, error_dict=None, ignore_instruction=None
):
"""Update the target from an instruction schedule map.
If the input instruction schedule map contains new instructions not in
Expand All @@ -479,14 +481,23 @@ def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, err
a when updating the ``Target`` the error value will be pulled from
this dictionary. If one is not found in ``error_dict`` then
``None`` will be used.
ignore_instruction (list): An optionional list filterring out gates
that are ignored when updating the ``Target`` from the instruction
schedule map.
"""
# ['u1', 'u2', 'u3'] is set as the default because the
# current IBM providers don't support them as basis gates.
if ignore_instruction is None:
ignore_instruction = ["u1", "u2", "u3"]
get_calibration = getattr(inst_map, "_get_calibration_entry")

# Expand name mapping with custom gate name provided by user.
qiskit_inst_name_map = get_standard_gate_name_mapping()
if inst_name_map is not None:
qiskit_inst_name_map.update(inst_name_map)
for inst_name in inst_map.instructions:
if inst_name in ignore_instruction:
continue
# Prepare dictionary of instruction properties
out_props = {}
for qargs in inst_map.qubits_with_instruction(inst_name):
Expand All @@ -500,9 +511,7 @@ def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, err
props = None

entry = get_calibration(inst_name, qargs)
if getattr(props, "_calibration", None) != entry:
if not entry.user_provided:
continue
if entry.user_provided and getattr(props, "_calibration", None) != entry:
if self.dt is not None:
try:
duration = entry.get_schedule().duration * self.dt
Expand All @@ -515,6 +524,8 @@ def update_from_instruction_schedule_map(self, inst_map, inst_name_map=None, err
duration=duration,
calibration=entry,
)
else:
duration = None
try:
# Update gate error if provided.
props.error = error_dict[inst_name][qargs]
Expand Down

0 comments on commit c7dfb53

Please sign in to comment.