def _parse_instruction_durations(backend, inst_durations, dt, circuits): """Create a list of ``InstructionDuration``s. If ``inst_durations`` is provided, the backend will be ignored, otherwise, the durations will be populated from the backend. If any circuits have gate calibrations, those calibration durations would take precedence over backend durations, but be superceded by ``inst_duration``s. """ if not inst_durations: backend_durations = InstructionDurations() try: backend_durations = InstructionDurations.from_backend(backend) except AttributeError: pass durations = [] for circ in circuits: circ_durations = InstructionDurations() if not inst_durations: circ_durations.update(backend_durations, dt or backend_durations.dt) if circ.calibrations: cal_durations = [] for gate, gate_cals in circ.calibrations.items(): for (qubits, _), schedule in gate_cals.items(): cal_durations.append((gate, qubits, schedule.duration)) circ_durations.update(cal_durations, circ_durations.dt) if inst_durations: circ_durations.update(inst_durations, dt or getattr(inst_durations, 'dt', None)) durations.append(circ_durations) return durations
def _parse_instruction_durations(backend, inst_durations, dt, num_circuits): durations = None if inst_durations is None and backend: try: backend_durations = InstructionDurations.from_backend(backend) except AttributeError: backend_durations = InstructionDurations() durations = backend_durations.update(None, dt) else: durations = InstructionDurations( inst_durations, dt or getattr(inst_durations, 'dt', None)) if not isinstance(durations, list): durations = [durations] * num_circuits return durations