Skip to content

Errors

qsimlab.errors

Exception hierarchy of qsimlab (see python/API.md §4).

Every exception derives from QsimError and from the closest built-in exception, so except ValueError keeps working:

>>> import qsimlab
>>> c = qsimlab.Circuit(2)
>>> try:
...     c.h(5)
... except IndexError as e:
...     print(type(e).__name__)
QubitIndexError

QsimError

Bases: Exception

Base class of every qsimlab error.

CircuitError

Bases: QsimError, ValueError

Invalid circuit construction: bad gate name or arity, repeated qubit, bad probability.

QubitIndexError

Bases: QsimError, IndexError

A qubit, classical bit or basis-state index is out of range.

UnsupportedOperationError

Bases: QsimError, ValueError

The request, engine or export format cannot handle an operation of the circuit.

ResourceLimitError

Bases: QsimError, MemoryError

A register or term count would exceed the budget.

Attributes needed and limit hold the requested and allowed amounts (bytes for memory, count for Pauli terms) when known.

EngineAbortedError

Bases: ResourceLimitError

A forced engine gave up (e.g. the exact MPS would have to truncate).

ParseError

Bases: QsimError, ValueError

OpenQASM or Stim source could not be parsed (the message names the line).

MissingDependencyError

Bases: QsimError, ImportError

An optional dependency (qiskit, cirq, stim) is needed but not installed.