Skip to content

qoolqit.program

program

Classes:

  • QuantumProgram

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

QuantumProgram

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 property

compiled_sequence: Sequence

The Pulser sequence compiled to a specific device.

drive property

drive: Drive

The driving waveforms.

is_compiled property

is_compiled: bool

Check if the program has been compiled.

register property

register: Register

The register of qubits.

compile_to

compile_to(
    device: Device,
    profile: Literal["default", "max_energy"]
    | CompilerProfile = DEFAULT,
    device_max_duration_ratio: float | None = None,
) -> None

Compiles the quantum program for execution on a specific device.

The compilation process translates a program to make it runnable on a specific device:

  • Dimensionalization: Rescale the drive amplitude and the register positions to physical units compatible with the device.
  • Translation: Translate the program to a lower-level representation (Pulser) that can be executed on the device.

There are two compilation profiles:

  • "default": Compile the program as it is. The drive and the register positions must respect the hardware constraints of the device which can be inspected using device.specs(). The CompilerProfile.WORKING_POINT is deprecated aliases for this profile.
  • "max_energy": Scale 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.

The following option does NOT preserve the input program, but rather adapts the program to the device's constraints. Programs compiled this way are not portable across devices.

  • device_max_duration_ratio: Rescale the drive duration to a fraction of the device's maximum allowed duration. Useful in adiabatic protocols where one simply seeks to minimize the time derivative of the drive's amplitude.

Parameters:

  • device (Device) –

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

  • profile (Literal['default', 'max_energy'] | CompilerProfile, default: DEFAULT ) –

    The compilation profile used to translate the program. Defaults to CompilerProfile.DEFAULT.

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

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

Raises:

  • TypeError

    If device is not a QoolQit Device.

  • ValueError

    If device_max_duration_ratio is set but the device has no maximum allowed duration, or if it is not in the range (0, 1].

  • CompilationError

    If the compilation fails due to device constraints.

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

    The compilation process translates a program to make it runnable on a specific device:

    - Dimensionalization: Rescale the drive amplitude and the register positions to
        physical units compatible with the device.
    - Translation: Translate the program to a lower-level representation (Pulser) that
        can be executed on the device.

    There are two compilation profiles:

    - "default": Compile the program as it is. The drive and the register positions
        must respect the hardware constraints of the device which can be inspected
        using `device.specs()`. The `CompilerProfile.WORKING_POINT` is deprecated
        aliases for this profile.
    - "max_energy": Scale 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.

    The following option does NOT preserve the input program, but rather adapts the program
    to the device's constraints. Programs compiled this way are not portable across devices.

    - device_max_duration_ratio: Rescale the drive duration to a fraction of the
        device's maximum allowed duration. Useful in adiabatic protocols where one simply
        seeks 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 profile used to translate the program.
            Defaults to CompilerProfile.DEFAULT.
        device_max_duration_ratio: The fraction of the device's maximum allowed duration
            to set the program duration to, or None to leave it unset. Must be a number
            in the range (0, 1]. Can only be set if the device has a maximum allowed
            duration.

    Raises:
        TypeError: If `device` is not a QoolQit Device.
        ValueError: If `device_max_duration_ratio` is set but the device has no maximum
            allowed duration, or if it is not in the range (0, 1].
        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."
            )

    profile = CompilerProfile(profile)

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