Skip to content

Default BladeConfig can lead to compilation failure #462

Description

@abussy-pasqal

BladeConfig has no device by default, but QuantumProgram.compile_to does. Forgetting to set the device in BladeConfig may lead to a compilation error, whose cause could be hard to pinpoint.

Example to reproduce

import numpy as np
from qoolqit import Register, QuantumProgram, Drive, ConstantWaveform, AnalogDevice
from qoolqit.embedding import Blade, BladeConfig

np.random.seed(1048)
# Small non-zero coefficient to get large distances
matrix = 0.0001 * np.array([[0, 1, 0], [1, 0, 0], [0, 0, 0]])

device = AnalogDevice()

# config = BladeConfig(device=device) # compiles
config = BladeConfig() # does not compile
embedder = Blade(config)
graph = embedder.embed(matrix)
register = Register.from_graph(graph)

max_duration = device.specs["max_duration"]
max_amplitude = device.specs["max_amplitude"]
assert max_duration is not None
assert max_amplitude is not None
drive = Drive(amplitude=ConstantWaveform(0.9 * max_duration, 0.1 * max_amplitude))

program = QuantumProgram(register, drive)
program.compile_to(device, profile="max_energy")

which fails with the error

Traceback (most recent call last):
  File "******/qoolqit/test.py", line 24, in <module>
    program.compile_to(device, profile="max_energy")
  File ******/qoolqit/qoolqit/program.py", line 162, in compile_to
    self._compiled_sequence = compiler.compile_sequence()
  File ******/qoolqit/qoolqit/execution/sequence_compiler.py", line 75, in compile_sequence
    raise error
  File "******/qoolqit/qoolqit/execution/sequence_compiler.py", line 67, in compile_sequence
    return self._compilation_function(
  File "******/qoolqit/qoolqit/execution/compilation_functions.py", line 118, in basic_compilation
    _validate_program_max_energy_profile(register, drive, device, device_max_duration_ratio)
  File ******/qoolqit/qoolqit/execution/compilation_functions.py", line 299, in _validate_program_max_energy_profile
    raise CompilationError(msg_init + msg)
qoolqit.exceptions.CompilationError: After rescaling the input program to the maximum energy scale available for the selected device, the following exception was raised:

The register's maximum radial distance went over the maximum value allowed.
To compile this program on the selected device `AnalogDevice`, the maximum radial distance must be below 11.155274433927701

Possible solutions

  1. Remove the default value for device in BladeConfig, forcing the user to specifiy the device (or None). But that would also force to specify a config in Blade.embed.
  2. Make an early validation in QuantumProgram.compile_to with a meaningful error

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions