Errors#

Every error CUDA-Q Pulse raises on purpose derives from PulseError, so except cudaq_pulse.PulseError catches them all. Each also has the built-in base of its kind of error, so except ValueError or except RuntimeError catches it as it would the built-in one: InvalidValueError is a ValueError, NotFoundError and UnknownQuantumSystemError are KeyErrors, IndexOutOfRangeError is an IndexError, and CompilationError and NoProcessQuantumSystemError are RuntimeErrors.

exception cudaq_pulse.PulseError(*args, problems=())[source]#

Bases: Exception

Base class of every error cudaq-pulse raises on purpose.

Each subclass also has the built-in base its kind of error has in Python, so except ValueError, except KeyError or except RuntimeError catches it as it would the built-in error. Errors that the native extension raises while running MLIR passes are not subclasses yet, nor are some ValueError and TypeError for a malformed compile option or controller limit.

An error that found several problems at once lists them in problems, and its message shows the first ten.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

problems: tuple[Problem, ...] = ()#
property location: Problem | None#

The first problem that names a file, if any; else, for an error raised while a kernel was traced, the kernel line that raised it: file, line, source (the line’s text) and path (the function’s name), with the error’s message and fix, and as value the misspelled name a did_you_mean replaces.

An error that finds several problems at once, such as QuantumSystemDefinitionError, lists each as a Problem in problems:

class cudaq_pulse.Problem(
message,
path='',
value=UNSET,
fix='',
file=None,
line=None,
column=None,
source='',
)[source]#

Bases: object

One thing that is wrong, where it is, and how to fix it.

message says what is wrong; path where, in the terms of what the user wrote ("layout[2]", "controllers[0].drive_lines"); value is the offending value (Problem.UNSET when there is none); fix what to do. file, line and column locate it in a file, when it came from one; line and column count from 1, and source is that line’s text, stripped, when it was read.

Parameters:
  • message (str)

  • path (str)

  • value (Any)

  • fix (str)

  • file (str | None)

  • line (int | None)

  • column (int | None)

  • source (str)

UNSET: ClassVar[Any] = UNSET#
message: str#
path: str = ''#
value: Any = UNSET#
fix: str = ''#
file: str | None = None#
line: int | None = None#
column: int | None = None#
source: str = ''#

Arguments and names#

exception cudaq_pulse.InvalidValueError(*args, problems=())[source]#

Bases: PulseError, ValueError

An argument, option or setting has the right type but a value that cannot be used: a negative duration, an empty list, a shape that does not match.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.InvalidTypeError(*args, problems=())[source]#

Bases: PulseError, TypeError

An argument, option or callback result has a type that cannot be used, such as a string where a number is needed.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.NotFoundError(*args, problems=())[source]#

Bases: PulseError, KeyError

A name has nothing behind it: a calibration value, a handler, a parameter or a file that is not there. The message lists what there is.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.IndexOutOfRangeError(*args, problems=())[source]#

Bases: PulseError, IndexError

An index past the end of what it indexes, such as a qudit index past the qudits of a quantum system or register. The message says how many there are.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.UnsupportedError(*args, problems=())[source]#

Bases: PulseError, NotImplementedError

What was asked is not available yet, or not on this platform or Python version. It is a NotImplementedError, and so also a RuntimeError.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

Compiling#

exception cudaq_pulse.CompilationError(
*args,
problems=(),
code=None,
fix='',
did_you_mean=None,
misspelled=None,
)[source]#

Bases: PulseError, RuntimeError

A kernel cannot be traced or compiled: an unsupported construct, an operation given the wrong kind of argument, or invalid pulse IR. The message says what to write instead, and a note gives the kernel line.

code is the ErrorCode of the error; fix, when not empty, the part of the message that says what to write instead; did_you_mean, when not None, the name to write in place of the misspelled one, which location.value holds; and location, for an error raised while the kernel was traced, the kernel line that raised it.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

  • code (str | None)

  • fix (str)

  • did_you_mean (str | None)

  • misspelled (str | None)

Return type:

None

property code: ErrorCode#

The kind of error, an ErrorCode.

exception cudaq_pulse.TimingError(
*args,
problems=(),
code=None,
fix='',
did_you_mean=None,
misspelled=None,
)[source]#

Bases: CompilationError

A program cannot meet a timing it declares: a deadline for an answer, or a limit on its length. problems names each one that is missed.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

  • code (str | None)

  • fix (str)

  • did_you_mean (str | None)

  • misspelled (str | None)

Return type:

None

exception cudaq_pulse.compiler.UnsupportedInterpreterError(*args, problems=())[source]#

Bases: UnsupportedError

The running interpreter’s bytecode is not known to the kernel tracer.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

Error codes#

Every CompilationError has a code, an ErrorCode, so a program or a tool can act on the kind of error without reading the message. The codes are stable: a code keeps its meaning, and a new kind of error gets a new code. fix holds the part of the message that says what to write instead (empty when the message gives none), did_you_mean the name to write in place of a misspelled one, and location, for an error raised while the kernel is traced, a Problem with the kernel’s file, line and source (the text of that line), as path the name of the function and, with did_you_mean, as value the misspelled name. The message is the same as without them. For a kernel k that misspells an operation, and its qudit q:

try:
    pulse.compile(k).lower(q)
except pulse.CompilationError as error:
    if error.code == pulse.ErrorCode.UNKNOWN_NAME and error.did_you_mean:
        where = error.location
        fixed = where.source.replace(where.value, error.did_you_mean, 1)
        print(f"{where.file}:{where.line}: write {fixed!r}")

Code

What it means

unknown_name

A name the kernel calls or reads that nothing in its scope defines; did_you_mean names a close one.

unknown_attribute

An attribute the value does not have; did_you_mean names a close one.

unassigned_name

A name read before it is assigned on the path traced.

wrong_argument

An argument of the wrong kind, or the wrong number of them.

unsupported_construct

Python the kernel language does not trace, such as a while loop or try.

runtime_value

A value known only when the program runs, such as a measurement result, used where tracing needs its value.

symbolic_parameter

A float parameter whose value compiling needs.

invalid_duration

A duration that is not a whole number of cycles, or that mixes times with numbers of cycles.

invalid_waveform

A waveform that cannot be made.

calibration

A calibration that cannot play, or that the trace cannot read.

limit_exceeded

A program larger than a limit of the compiler.

kernel_raised

An assert that failed, or a raise, in the kernel.

python_error

Python code of the kernel that failed as it would outside one; the message holds Python’s error.

control_system

A program the control system cannot play as written.

schedule_block

A kernel called with its own schedule= that the program cannot schedule on its own, such as under rcp; fix says whether to compile with flatten_schedules=True.

timing

A missed deadline or length limit (TimingError).

controller_limit

A limit of the controller exceeded (ControllerLimitError).

other

Any other compilation error.

class cudaq_pulse.ErrorCode(*values)[source]#

Bases: StrEnum

What kind of CompilationError an error is: its code.

The codes are stable, so a program, a test or a tool can act on one without reading the message. Each member is a string; the plain string ("unknown_name") compares equal to it.

UNKNOWN_NAME = 'unknown_name'#

A name the kernel calls or reads that nothing in its scope defines, such as a misspelled operation; did_you_mean names a close one.

UNKNOWN_ATTRIBUTE = 'unknown_attribute'#

An attribute the value does not have, such as a misspelled method of a line; did_you_mean names a close one.

UNASSIGNED_NAME = 'unassigned_name'#

A name read before it is assigned on the path the trace took.

WRONG_ARGUMENT = 'wrong_argument'#

An operation given an argument of the wrong kind, such as a qudit where it takes a line, or the wrong number of arguments.

UNSUPPORTED_CONSTRUCT = 'unsupported_construct'#

Python the kernel language does not trace: a while loop, try, a generator, a class definition.

RUNTIME_VALUE = 'runtime_value'#

A value known only when the program runs, such as a measurement result, used where tracing needs its value: compared, converted, iterated or hashed; or a branch on one that does what a branch taken at run time cannot.

SYMBOLIC_PARAMETER = 'symbolic_parameter'#

A float parameter whose value the program needs while it compiles (SymbolicValueError).

INVALID_DURATION = 'invalid_duration'#

A duration or time that is not a whole number of clock cycles, a float where a duration takes an int or a time, or arithmetic that mixes times with numbers of cycles.

INVALID_WAVEFORM = 'invalid_waveform'#

A waveform that cannot be made: a custom() envelope that returns what is not a number, waveform arithmetic on different durations, samples made for another rate.

CALIBRATION = 'calibration'#

A calibration the kernel plays that cannot play, or that its trace cannot read.

LIMIT_EXCEEDED = 'limit_exceeded'#

A program larger than a limit of the compiler: more operations than the controller holds, a loop unrolled past its limit, kernel calls nested too deep.

KERNEL_RAISED = 'kernel_raised'#

An assert that failed, or a raise, in the kernel.

PYTHON_ERROR = 'python_error'#

Python code of the kernel that failed as it would outside one: a subscript, an unpacking, an operator or a helper call that raised; the message holds Python’s error.

CONTROL_SYSTEM = 'control_system'#

A program the control system cannot play as written: a link it does not have, a qudit the quantum system does not define, a call across its controllers.

SCHEDULE_BLOCK = 'schedule_block'#

A kernel called with its own schedule= that the program cannot schedule on its own: under rcp or alap_rcp, which schedule a whole program, or with a max_duration_cycles that flatten_schedules=True cannot hold. fix says whether to compile with flatten_schedules=True or without it.

TIMING = 'timing'#

A program that misses a timing it declares (TimingError).

CONTROLLER_LIMIT = 'controller_limit'#

A program over a limit of its controller (ControllerLimitError).

OTHER = 'other'#

Any other compilation error; the message says what is wrong.

Running#

exception cudaq_pulse.ExecutionError(*args, problems=())[source]#

Bases: PulseError, RuntimeError

Running a compiled program failed: a simulation, a classical call or a GPU launch.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.InternalError(*args, problems=())[source]#

Bases: PulseError, RuntimeError

A bug in cudaq-pulse: a check that a valid program never fails. The message asks for a report with the kernel that raised it.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

Quantum systems#

exception cudaq_pulse.QuantumSystemDefinitionError(message='', *, problems=())[source]#

Bases: PulseError, ValueError

A quantum system’s definition is wrong: pulse.quantum_system() lists every problem of its config or file in problems, each with its path in the config (and, for a file, its line and column).

Parameters:
  • message (str)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.NoQuantumSystemError(*args, problems=())[source]#

Bases: NoProcessQuantumSystemError

A kernel was called without qudit handles and was not compiled for a quantum system, so it has no quantum system to run on. The process quantum system is never used for a kernel call.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.NoProcessQuantumSystemError(*args, problems=())[source]#

Bases: PulseError, RuntimeError

quantum_system() was called with no argument and CUDAQ_PULSE_QUANTUM_SYSTEM names no process quantum system.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.QuantumSystemMismatchError(*args, problems=())[source]#

Bases: PulseError, RuntimeError

A kernel call mixes handles of different quantum systems, or of an unpinned one.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.quantum_systems.UnknownQuantumSystemError(*args, problems=())[source]#

Bases: NotFoundError

A quantum system name, given to quantum_system(), in a system file or in CUDAQ_PULSE_QUANTUM_SYSTEM, is not registered; the message lists the registered ones.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

GPU simulation#

pulse.simulate(..., backend="gpu") raises one of the three subclasses of GpuRuntimeError (cudaq_pulse.GpuRuntimeError), an ExecutionError, when GPU simulation cannot run; see GPU Runtime Errors.

exception cudaq_pulse.runtime.GpuRuntimeError(*args, problems=())[source]#

Bases: ExecutionError

Base class for every reason GPU execution cannot proceed.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.runtime.GpuSupportNotBuiltError(*args, problems=())[source]#

Bases: GpuRuntimeError

This cudaq-pulse build does not contain the GPU runtime.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.runtime.GpuRuntimeLoadError(*args, problems=())[source]#

Bases: GpuRuntimeError

The GPU runtime is part of this build but could not be loaded.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.runtime.GpuDeviceUnavailableError(*args, problems=())[source]#

Bases: GpuRuntimeError

The GPU runtime loaded, but no usable NVIDIA device or driver exists.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

Controller backends#

Compiling for a controller whose limits a program exceeds raises ControllerLimitError; finding a backend raises a BackendError. See Controller Backends API.

exception cudaq_pulse.controller.ControllerLimitError(violations, *, system=False, usage=None)[source]#

Bases: CompilationError

A scheduled program exceeds a limit of the controller it is for.

violations has every limit exceeded: a tuple, or past 10,000 of them in rolled loops a sequence that builds each one when read, with an exact len(). For a control system with processors, usage is the program’s UsageReport: what each processor holds against its limits, and each limit exceeded with by how much (usage.exceeded); the message ends with its table.

Parameters:
  • violations (Sequence[str])

  • system (bool)

  • usage (UsageReport | None)

Return type:

None

violations: Sequence[str]#
exception cudaq_pulse.backends.BackendError(*args, problems=())[source]#

Bases: PulseError

A controller backend cannot be found or used.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.backends.BackendNotFoundError(*args, problems=())[source]#

Bases: BackendError, NotFoundError

No backend of that name is installed or registered.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

exception cudaq_pulse.backends.IncompatibleBackendError(*args, problems=())[source]#

Bases: BackendError, TypeError

A backend fails to load, is not a Backend, or reads none of the export formats this version writes.

Parameters:
  • args (object)

  • problems (tuple[Problem, ...])

Return type:

None

Warnings#

exception cudaq_pulse.PulseWarning[source]#

Bases: UserWarning

Base class of the warnings cudaq-pulse issues, so that warnings.filterwarnings("error", category=pulse.PulseWarning) turns them all into errors.

exception cudaq_pulse.UpgradeNotice[source]#

Bases: PulseWarning

Something still works but has a newer form, such as a file in an older format; the message names the newer form. Issued once per cause.

exception cudaq_pulse.UnitWarning[source]#

Bases: PulseWarning

A number given without units that is probably not what was meant: a bare number as a duration, wait or other time of a pulse, which counts clock cycles, or a frequency so far below the quantum system’s carriers that it is probably in MHz or kHz rather than Hz.

Issued while a kernel compiled with unit_warnings=True traces, at the kernel line; warnings.filterwarnings("error", category=pulse.UnitWarning) makes each one an error.

See unit warnings for what unit_warnings=True checks.