Skip to content

qoolqit.program

program

Classes:

  • QuantumProgram

    A program representing a Sequence acting on a Register of qubits.

QuantumProgram(register: Register, drive: Drive)

A program representing a Sequence acting on a Register of qubits.

Parameters:

  • register

    (Register) –

    the register of qubits, defining their positions.

  • drive

    (Drive) –

    the drive acting on qubits, defining amplitude, detuning and phase.

Methods:

  • compile_to

    Compiles the quantum program for execution on a specific device.

Attributes:

Source code in qoolqit/program.py
def __init__(
    self,
    register: Register,
    drive: Drive,
) -> None:

    if not isinstance(register, Register):
        raise TypeError("`register` must be of type Register.")
    self._register = register

    if not isinstance(drive, Drive):
        raise TypeError("`drive` must be of type Drive.")
    if drive.dmm is not None:
        dmm_weights = drive.dmm.weights
        for qid in dmm_weights.keys():
            if qid not in register.qubits:
                raise ValueError(
                    "In this QuantumProgram, the drive's detuning modulator map (DMM) "
                    f"and the register do not match: qubit {qid} appears in the DMM "
                    "but is not defined in the register."
                )

    self._drive = drive
    self._compiled_sequence: PulserSequence | None = None

compiled_sequence: PulserSequence property

The Pulser sequence compiled to a specific device.

drive: Drive property

The driving waveforms.

is_compiled: bool property

Check if the program has been compiled.

register: Register property

The register of qubits.

compile_to(device: Device, profile: CompilerProfile = CompilerProfile.MAX_ENERGY, device_max_duration_ratio: float | None = None) -> None

Compiles the quantum program for execution on a specific device.

The compilation process adapts the program to the device's constraints while preserving the relative ratios of the original program parameters. Different compilation profiles optimize for specific objectives:

  • CompilerProfile.MAX_ENERGY (default): Scales the program to utilize the device's maximum capabilities. The drive amplitude and the register positions are rescaled to achieve respectively the maximum amplitude and the minimum pairwise distance compatible with the input program and the device's constraints.
  • CompilerProfile.WORKING_POINT: .

Further options DO NOT preserve the input program, but rather adapts the program to the device's constraint. Programs compiled this way are not guaranteed to be portable across devices.

  • device_max_duration_ratio: Rescale the drive duration to a fraction of the device's maximum allowed duration. This option is useful in adiabatic protocols where one simply seek to minimize the time derivative of the drive's amplitude.

Parameters:

  • device
    (Device) –

    The target device for compilation. Must be a QoolQit Device.

  • profile
    (CompilerProfile, default: MAX_ENERGY ) –

    The compilation strategy to optimize the program. Defaults to CompilerProfile.MAX_ENERGY.

  • device_max_duration_ratio
    (float | None, default: None ) –

    Whether to set the program duration to a fraction of the device's maximum allowed duration. Must be a number in the range (0, 1]. Can only be set if the device has a maximum allowed duration.

Raises:

Source code in qoolqit/program.py
def compile_to(
    self,
    device: Device,
    profile: CompilerProfile = CompilerProfile.MAX_ENERGY,
    device_max_duration_ratio: float | None = None,
) -> None:
    """Compiles the quantum program for execution on a specific device.

    The compilation process adapts the program to the device's constraints while
    preserving the relative ratios of the original program parameters. Different
    compilation profiles optimize for specific objectives:

    - CompilerProfile.MAX_ENERGY (default): Scales the program to utilize the device's
        maximum capabilities. The drive amplitude and the register positions are rescaled
        to achieve respectively the maximum amplitude and the minimum pairwise distance
        compatible with the input program and the device's constraints.
    - CompilerProfile.WORKING_POINT: .

    Further options DO NOT preserve the input program, but rather adapts the program to
    the device's constraint. Programs compiled this way are not guaranteed to be portable
    across devices.

    - device_max_duration_ratio: Rescale the drive duration to a fraction of the
        device's maximum allowed duration.
        This option is useful in adiabatic protocols where one simply seek to
        minimize the time derivative of the drive's amplitude.

    Args:
        device: The target device for compilation. Must be a QoolQit Device.
        profile: The compilation strategy to optimize the program.
            Defaults to CompilerProfile.MAX_ENERGY.
        device_max_duration_ratio: Whether to set the program duration to a fraction of
            the device's maximum allowed duration. Must be a number in the range (0, 1].
            Can only be set if the device has a maximum allowed duration.

    Raises:
        CompilationError: If the compilation fails due to device constraints.
    """
    if not isinstance(device, Device):
        raise TypeError("`device` must be of type `qoolqit.devices.Device`.")

    if device_max_duration_ratio is not None:
        if device._max_duration is None:
            raise ValueError(
                "Cannot set `device_max_duration_ratio` because the target device "
                "does not have a maximum allowed duration."
            )
        if not (0 < device_max_duration_ratio <= 1):
            raise ValueError(
                "`device_max_duration_ratio` must be between 0 and 1, "
                f"got {device_max_duration_ratio} instead."
            )

    # Check if device supports DMM and has a DMM channel
    if self.drive.dmm is not None:
        if not device._device.dmm_channels:
            raise CompilationError(
                "The device does not support DMM. Please use a device that supports DMM."
            )

    compiler = SequenceCompiler(
        self.register, self.drive, device, profile, device_max_duration_ratio
    )
    self._device = device
    self._compiled_sequence = compiler.compile_sequence()