mimiqcircuits.backends.capabilities

Capability vocabulary, numeric limits, topology, and admission types.

A backend’s Backend.capabilities() returns a set of capability tokens drawn from CAPABILITY_VOCABULARY. A backend’s Backend.limits() returns a Limits instance, and Backend.topology() returns one of the Topology subclasses (AllToAll, CouplingMap, LinearChain).

Backend.can_handle() returns an AdmissionResult (Admissible, Marginal, or Inadmissible).

Module Attributes

Capability

Type of a capability token: a string such as "noise".

CAPABILITY_VOCABULARY

Capability tokens a backend may declare in Backend.capabilities().

CAP_PROBES

Registry of probe-circuit factories keyed by capability, used by the conformance tests to check that a backend rejects what it does not declare.

Functions

is_admissible(result)

Return whether an admission result accepts the circuit.

register_cap_probe(capability, factory)

Register a probe-circuit factory for capability in CAP_PROBES.

Classes

Admissible()

The backend can execute the circuit.

AdmissionResult()

Base class for the results of Backend.can_handle().

AllToAll()

Every pair of qubits can interact.

CouplingMap(edges)

Connectivity given as a list of edges.

Inadmissible(reason)

The backend cannot execute the circuit.

Limits([max_qubits, max_bond_dim, ...])

Numeric limits a backend declares in Backend.limits().

LinearChain(n)

Linear chain of n qubits, each coupled to its neighbours.

Marginal(warning)

The backend can execute the circuit, but it is near a limit (memory, bond dimension, runtime).

Topology()

Base class for the qubit connectivity a backend declares in Backend.topology().

Exceptions

UnsupportedCapabilityError(backend_name, ...)

Error for a feature the backend does not declare in Backend.capabilities().

Capability

Type of a capability token: a string such as "noise".

CAPABILITY_VOCABULARY: frozenset[str] = frozenset({'amplitude', 'batch', 'bond_dim', 'calibrated_noise', 'classical_bits', 'expectation_1q', 'expectation_2q', 'expectation_paulistring', 'expectation_state', 'feed_forward', 'final_measure_only', 'loss', 'midcircuit_measure', 'midcircuit_reset', 'noise', 'parametric', 'parametric_batch', 'pass_order_honored', 'reset_after_measure', 'sampling', 'schmidt_rank', 'shared_prefix_batch', 'streaming', 'while_statement', 'zvars'})

Capability tokens a backend may declare in Backend.capabilities(). Informational: backends may declare tokens outside this set; conformance tests warn but never fail on extras.

class Limits(max_qubits=None, max_bond_dim=None, max_classical_bits=None, max_zvars=None, max_samples=None, max_circuit_depth=None)[source]

Bases: object

Numeric limits a backend declares in Backend.limits().

None for a field means unbounded, or not applicable (such as max_bond_dim on a state-vector simulator). The default Backend.can_handle() checks max_qubits, max_classical_bits and max_zvars; the other fields are informational.

max_qubits

Largest number of qubits.

Type:

int or None

max_bond_dim

Largest bond dimension.

Type:

int or None

max_classical_bits

Largest number of classical bits.

Type:

int or None

max_zvars

Largest number of z-variables.

Type:

int or None

max_samples

Largest number of shots per execution.

Type:

int or None

max_circuit_depth

Largest circuit depth.

Type:

int or None

Examples

>>> from mimiqcircuits import *
>>> from mimiqcircuits.backends import Limits
>>> lim = Limits(max_qubits=30)
>>> lim.max_qubits, lim.max_samples
(30, None)
class Topology[source]

Bases: object

Base class for the qubit connectivity a backend declares in Backend.topology().

class AllToAll[source]

Bases: Topology

Every pair of qubits can interact. The default for simulators.

class CouplingMap(edges)[source]

Bases: Topology

Connectivity given as a list of edges.

Each edge (i, j) means qubits i and j can interact directly. Indices are 1-based.

edges

The coupled pairs.

Type:

tuple[tuple[int, int], …]

class LinearChain(n)[source]

Bases: Topology

Linear chain of n qubits, each coupled to its neighbours.

n

Number of qubits.

Type:

int

class AdmissionResult[source]

Bases: object

Base class for the results of Backend.can_handle().

class Admissible[source]

Bases: AdmissionResult

The backend can execute the circuit.

class Marginal(warning)[source]

Bases: AdmissionResult

The backend can execute the circuit, but it is near a limit (memory, bond dimension, runtime).

is_admissible() treats it as admissible.

warning

Message for the user.

Type:

str

class Inadmissible(reason)[source]

Bases: AdmissionResult

The backend cannot execute the circuit.

reason

Why the circuit is rejected.

Type:

str

is_admissible(result)[source]

Return whether an admission result accepts the circuit.

Parameters:

result (AdmissionResult) – The result of Backend.can_handle().

Returns:

True for Admissible and Marginal, False otherwise.

Return type:

bool

Examples

>>> from mimiqcircuits import *
>>> from mimiqcircuits.backends import (
...     Admissible, Inadmissible, Marginal, is_admissible)
>>> is_admissible(Admissible())
True
>>> is_admissible(Marginal(warning="close to the memory limit"))
True
>>> is_admissible(Inadmissible(reason="too many qubits"))
False
exception UnsupportedCapabilityError(backend_name, capability, detail='')[source]

Bases: Exception

Error for a feature the backend does not declare in Backend.capabilities().

Backends raise it when asked to run such a feature, instead of running something else in its place.

Parameters:
  • backend_name (str) – Name of the backend.

  • capability (Capability) – The capability token the circuit needs.

  • detail (str) – Optional extra text for the message.

CAP_PROBES: dict[str, Callable] = {'feed_forward': <function _probe_feed_forward>, 'loss': <function _probe_loss>, 'midcircuit_measure': <function _probe_midcircuit_measure>, 'midcircuit_reset': <function _probe_midcircuit_reset>, 'noise': <function _probe_noise>, 'parametric': <function _probe_parametric>, 'reset_after_measure': <function _probe_reset_after_measure>}

Registry of probe-circuit factories keyed by capability, used by the conformance tests to check that a backend rejects what it does not declare. Importing mimiqcircuits.backends registers the default probes; register_cap_probe() adds more.

register_cap_probe(capability, factory)[source]

Register a probe-circuit factory for capability in CAP_PROBES.

Conformance tests run each probe on every backend that does not declare its capability, and check that the backend rejects it. A factory registered for a capability that already has one replaces it.

Parameters:
  • capability (str) – The capability token.

  • factory (Callable) – A function of no arguments that returns a circuit whose execution needs capability.

Returns:

factory, unchanged.