class QuantifySchedulerExporter(Exporter):
def __init__(
self, cycle_time: float = CYCLE_TIME, operation_cycles: OperationCycles | None = None, **kwargs: Any
) -> None:
super().__init__(**kwargs)
self._cycle_time = cycle_time
self._operation_cycles = operation_cycles
def export(self, circuit: Circuit) -> quantify_scheduler.Schedule:
"""Exports the given circuit to the [quantify-scheduler](https://quantify-os.org/docs/quantify-scheduler/)
format.
Args:
circuit (Circuit): The quantum circuit to export.
Returns:
The quantify-scheduler [Schedule](https://quantify-os.org/docs/quantify-scheduler/v0.26.0/autoapi/quantify_scheduler/index.html#quantify_scheduler.Schedule)
representation of the circuit.
"""
if "quantify_scheduler" not in globals():
msg = "quantify-scheduler is not installed, or cannot be installed on your system"
raise ModuleNotFoundError(msg)
try:
# Create circuit, with measure data
schedule_creator = _ScheduleCreator(circuit)
circuit.ir.accept(schedule_creator)
# Obtain ALAP reference timing for schedulables
schedulables = list(schedule_creator.schedule.schedulables.values())
if schedulables:
scheduler = _Scheduler(circuit.register_manager, schedulables, self._cycle_time, self._operation_cycles)
circuit.ir.reverse().accept(scheduler)
# Update timing constraints of schedulables
for name, schedulable in schedule_creator.schedule.schedulables.items():
schedulable["timing_constraints"] = [
scheduler.operation_record.schedulable_timing_constraints[name]
]
except UnsupportedGateError as e:
msg = (
f"cannot export circuit: {e}, "
"decompose all gates to the gate set supported by quantify-scheduler, i.e., "
"(init, reset, H, Rx, Ry, Rz, CNOT, CZ, measure)"
)
raise ExporterError(msg) from e
return schedule_creator.schedule