Skip to content

Commit

Permalink
monkey patch Qiskit/qiskit#11727
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 committed Feb 6, 2024
1 parent e491895 commit 45f0c83
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion qiskit_ibm_runtime/transpiler/passes/scheduling/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,40 @@ def from_backend(cls, backend: Backend) -> "DynamicCircuitInstructionDurations":
DynamicInstructionDurations: The InstructionDurations constructed from backend.
"""
if isinstance(backend, BackendV1):
return super(DynamicCircuitInstructionDurations, cls).from_backend(backend)
# TODO Remove once https://github.com/Qiskit/qiskit/pull/11727 gets released in qiskit 0.46.1
# From here ---------------------------------------
def patch_from_backend(cls, backend: Backend):
"""
REMOVE me once https://github.com/Qiskit/qiskit/pull/11727 gets released in qiskit 0.46.1
"""
instruction_durations = []
backend_properties = backend.properties()
if hasattr(backend_properties, "_gates"):
for gate, insts in backend_properties._gates.items():
for qubits, props in insts.items():
if "gate_length" in props:
gate_length = props["gate_length"][
0
] # Throw away datetime at index 1
instruction_durations.append((gate, qubits, gate_length, "s"))
for q, props in backend.properties()._qubits.items():
if "readout_length" in props:
readout_length = props["readout_length"][
0
] # Throw away datetime at index 1
instruction_durations.append(("measure", [q], readout_length, "s"))
try:
dt = backend.configuration().dt
except AttributeError:
dt = None

return cls(instruction_durations, dt=dt)

return patch_from_backend(DynamicCircuitInstructionDurations, backend)
# To here ---------------------------------------
return super(DynamicCircuitInstructionDurations, cls).from_backend(
backend
) # pylint: disable=unreachable

# Get durations from target if BackendV2
return cls.from_target(backend.target)
Expand Down

0 comments on commit 45f0c83

Please sign in to comment.