Skip to content

Types

Definition of all types supported in the IR.

This module is the defacto definition of the IR. A unit of IR code can only consist of instances of the classes defined in this module. An IR Model defines a complete set of instructions for a backend to execute as a task. The instructions a Model can take can be divided into two groups; classical and quantum related instructions:

  • Classical:
    • Alloc: Allocates memory for holding variable values.
    • Assign: Assigns a value to a variable.
    • Load: Retrieves a value from a variable.
    • Call: Executes a classical function.
  • Quantum:
    • AllocQubits: Allocates qubits for the computation.
    • QuInstruct: Executes a quantum instruction.
    • Support: Defines on which qubit(s) and with what role, target or control, a QuInstruct should act.

Alloc(size, trainable, **attributes)

Memory allocation for a parameter that is either a scalar value or an array of values.

With this class an allocation of memory is made for a parameter that is a scalar value, if size = 1 or an array of values of length n if size = n. The type for the allocation is defined by the backend, therefore it is not defined in the IR.

PARAMETER DESCRIPTION
size

Number of values stored in the parameter, if size = 1 the parameter is a scalar value if size > 1 the parameter is an array of values.

TYPE: int

trainable

Indicates whether the parameter can be changed during a training loop.

TYPE: bool

attributes

Extra flags and information to be used as instructions/suggestions by the backend.

TYPE: Any DEFAULT: {}

Source code in qadence2_ir/types.py
def __init__(self, size: int, trainable: bool, **attributes: Any) -> None:
    self.size = size
    self.is_trainable = trainable
    self.attrs = attributes

AllocQubits(num_qubits, qubit_positions=None, grid_type=None, grid_scale=1.0, connectivity=None, options=None)

Allocation of qubit in a register of a neutral-atom QPU.

PARAMETER DESCRIPTION
num_qubits

Number of qubits, i.e atoms, to be allocated.

TYPE: int

qubit_positions

A list of discrete coordinates for 2D grid, where (0,0) is the position at center of the grid. An empty list will indicate the backend is free to define the topology for devices that implement logical qubits.

TYPE: list[tuple[int, int]] | list[int] | None DEFAULT: None

grid_type

Allows to select the coordinates sets for 2D grids as "square" (orthogonal) or "triangular" (skew). A "linear" will allow the backend to define the shape of the register. When the grid_type is None the backend uses its default structure (particular useful when shuttling is available). Default value is None.

TYPE: Literal['linear', 'square', 'triangular'] | None DEFAULT: None

grid_scale

Adjust the distance between atoms based on a standard distance defined by the backend. Default value is 1.0.

TYPE: float DEFAULT: 1.0

connectivity

A dictionary that contains the interaction strength between connected qubit pairs. It is used with compiler backends that implement crossing-lattice strategies or gridless models, such as pyqtorch. If the connectivity graph is available, these backends may ignore the qubit_positions, grid_type, and grid_scale options.

TYPE: dict[tuple[int, int], float] | None DEFAULT: None

options

Extra register related properties that may not be supported by all backends.

TYPE: dict[str, Any] | None DEFAULT: None

Source code in qadence2_ir/types.py
def __init__(
    self,
    num_qubits: int,
    qubit_positions: list[tuple[int, int]] | list[int] | None = None,
    grid_type: Literal["linear", "square", "triangular"] | None = None,
    grid_scale: float = 1.0,
    connectivity: dict[tuple[int, int], float] | None = None,
    options: dict[str, Any] | None = None,
) -> None:
    self.num_qubits = num_qubits
    self.qubit_positions = qubit_positions or []
    self.grid_type = grid_type
    self.grid_scale = grid_scale
    self.connectivity = connectivity or dict()
    self.options = options or dict()

Assign(variable_name, value)

Assignment of a value to a variable.

PARAMETER DESCRIPTION
variable_name

The name of the variable to assign a value to.

TYPE: str

value

The value to be assigned to the variable.

TYPE: Any

Source code in qadence2_ir/types.py
def __init__(self, variable_name: str, value: Any) -> None:
    self.variable = variable_name
    self.value = value

Call(identifier, *args)

Instruction to call a classical function.

PARAMETER DESCRIPTION
identifier

The identifier of the function to call, i.e. its name.

TYPE: str

args

The arguments that the function should be called with.

TYPE: Any DEFAULT: ()

Source code in qadence2_ir/types.py
def __init__(self, identifier: str, *args: Any) -> None:
    self.identifier = identifier
    self.args = args

Load(variable_name)

Instruction to load the value of a variable.

PARAMETER DESCRIPTION
variable_name

The name of the variable to load.

TYPE: str

Source code in qadence2_ir/types.py
def __init__(self, variable_name: str) -> None:
    self.variable = variable_name

Model(register, inputs, instructions, directives=None, settings=None)

Aggregates the minimal information to construct sequence of instructions to execute on a QPU.

This class defines a unit of IR code. The structure of the class is mainly focused in neutral atoms devices but its agnostic nature may make it suitable for any quantum device.

PARAMETER DESCRIPTION
register

Describes the atomic arrangement of the neutral atom register.

TYPE: AllocQubits

instructions

A list of abstract instructions with their arguments that a backend can use to execute a sequence.

TYPE: list[QuInstruct | Assign]

directives

A dictionary containing QPU related options. For instance, it can be used to set the Rydberg level to be used or whether to allow digital-analog operations in the sequence.

TYPE: dict[str, Any] | None DEFAULT: None

settings

Backend specific configurations where the user can define for instance, the data type like int64.

TYPE: dict[str, Any] | None DEFAULT: None

Source code in qadence2_ir/types.py
def __init__(
    self,
    register: AllocQubits,
    inputs: dict[str, Alloc],
    instructions: list[QuInstruct | Assign],
    directives: dict[str, Any] | None = None,
    settings: dict[str, Any] | None = None,
) -> None:
    self.register = register
    self.directives = directives or dict()
    self.settings = settings or dict()
    self.inputs = inputs
    self.instructions = instructions

QuInstruct(name, support, *args, **attributes)

Instruction to apply a quantum operation to one or more qubit(s).

PARAMETER DESCRIPTION
name

The instruction name compatible with the standard instruction set.

TYPE: str

support

The index of qubits to which the instruction is applied to.

TYPE: Support

args

Arguments of the instruction such as angle, duration, amplitude etc.

TYPE: Any DEFAULT: ()

attributes

Extra flags and information to be used as instructions/suggestions by the backend.

TYPE: Any DEFAULT: {}

Source code in qadence2_ir/types.py
def __init__(self, name: str, support: Support, *args: Any, **attributes: Any):
    self.name = name
    self.support = support
    self.args = args
    self.attrs = attributes

Support(target, control=None)

Instruction that specifies the target and optionally control of a QuInstruct.

Generic representation of qubit support, specifying a target and control for a quantum instruction. For single qubit operations, a multiple index support indicates apply the operation for each index in the support. Both target and control lists must be ordered!

PARAMETER DESCRIPTION
target

Index or indices of qubits to which the operation is applied.

TYPE: tuple[int, ...]

control

Index or indices of qubits which to which the operation is conditioned to.

TYPE: tuple[int, ...] | None DEFAULT: None

Source code in qadence2_ir/types.py
def __init__(
    self,
    target: tuple[int, ...],
    control: tuple[int, ...] | None = None,
) -> None:
    self.target = target
    self.control = control or ()