This is a list of the operations that are built-in in Qmod.
For more information regarding classical types see the Statements section in the language reference.Members:
Name
Description
QuantumLambdaFunction
The definition of an anonymous function passed as operand to higher-level functions.
H
[Qmod core-library function].
S
[Qmod core-library function].
QBit
A type representing a single qubit.
QNum
QNum is a quantum variable that represents a numeric value, which can be either integer or fixed-point, encoded within a quantum register.
allocate
Initialize a quantum variable to a new quantum object in the zero state:.
bind
Reassign qubit or arrays of qubits by redirecting their logical identifiers.
if_
Conditionally executes quantum operations based on a symbolic or boolean expression.
control
Conditionally executes quantum operations based on the value of quantum variables or expressions.
skip_control
Applies quantum statements unconditionally.
assign
Initialize a scalar quantum variable using an arithmetic expression.
inplace_add
Add an arithmetic expression to a quantum variable.
inplace_xor
Bitwise-XOR a quantum variable with an arithmetic expression.
within_apply
Given two operations U and V, performs the sequence of operations U{−1}VU.
repeat
Executes a quantum loop a specified number of times, applying a quantum operation on each iteration.
power
Apply a quantum operation raised to a symbolic or integer power.
invert
Apply the inverse of a quantum gate.
phase
Applies a state-dependent or fixed phase shift (Z rotation) to the quantum state.
foreach
Loops through the elements of a classical list, applying a quantum operation on each iteration.
assign_amplitude_poly_sin
Encodes the value of the sine/cosine of a polynomial into the amplitude of the respective computational basis state:.
lookup_table
Reduces a classical function into a lookup table over all the possible values of the quantum numbers.
A type representing a single qubit.QBit serves both as a placeholder for a temporary, non-allocated qubit
and as the type of an allocated physical or logical qubit.
Conceptually, a qubit is a two-level quantum system, described by the
superposition of the computational basis states:∣0⟩=(10),∣1⟩=(01)Therefore, a qubit state is a linear combination:∣ψ⟩=α∣0⟩+β∣1⟩,where ( \alpha ) and ( \beta ) are complex numbers satisfying:∣α∣2+∣β∣2=1.Typical usage includes:
Representing an unallocated qubit before its allocation.
Acting as the output type for a qubit or an allocated qubit in the main function after calling an allocation function.
QNum is a quantum variable that represents a numeric value, which can be either integer or fixed-point,
encoded within a quantum register. It consists of an array of qubits for quantum representation and
classical metadata (number of fraction digits, sign) to define its numeric behavior.QNum enables numerical computation in quantum circuits, supporting both signed and unsigned
formats, as well as configurable fixed-point precision. It is a parameterizable scalar type,
meaning its behavior can depend on symbolic or compile-time values. The total number of
qubits (size) determines the resolution and range of representable values.Methods:
Initialize a quantum variable to a new quantum object in the zero state: \left|\text{out}\right\rangle = \left|0\right\rangle^{\otimes \text{num_qubits}}If ‘num_qubits’ is not specified, it will be inferred according to the type of ‘out’.
In case the quantum variable is of type QNum, its numeric attributes can be specified as
well.Parameters:
Reassign qubit or arrays of qubits by redirecting their logical identifiers.This operation rewires the logical identity of the source qubits to new objects given in destination.
For example, an array of two qubits X can be mapped to individual qubits Y and Z.Parameters:
Name
Type
Description
Default
source
Input[QVar] | list[Input[QVar]]
A qubit or list of initialized qubits to reassign.
required
destination
Output[QVar] | list[Output[QVar]]
A qubit or list of target qubits to bind to. Must match the number of qubits in source.
Conditionally executes quantum operations based on a symbolic or boolean expression.This function defines classical control flow within a quantum program. It allows quantum operations to be
conditionally executed based on symbolic expressions - such as parameters used in variational algorithms,
loop indices, or other classical variables affecting quantum control flow.Parameters:
Name
Type
Description
Default
condition
SymbolicExpr | bool
A symbolic or boolean expression evaluated at runtime to determine the execution path.
required
then
QCallable | Callable[[], Statements]
A quantum operation executed when condition evaluates to True.
required
else_
QCallable | Callable[[], Statements] | int
(Optional) A quantum operation executed when condition evaluates to False.
Conditionally executes quantum operations based on the value of quantum variables or expressions.This operation enables quantum control flow similar to classical if statements. It evaluates a quantum condition
and executes one of the provided quantum code blocks accordingly.Parameters:
Name
Type
Description
Default
ctrl
SymbolicExpr | QBit | QArray[QBit] | list[QVar]
A quantum control expression, which can be a logical expression, a single QBit, or a QArray[QBit]. If ctrl is a logical expression, stmt_block is executed when it evaluates to True. If ctrl is a QBit or QArray[QBit], stmt_block is executed if all qubits are in the `|1>` state.
required
stmt_block
QCallable | Callable[[], Statements]
The quantum operations to execute when the condition holds. This can be a QCallable or a function returning a Statements block.
required
else_block
QCallable | Callable[[], Statements] | None
(Optional) Quantum operations to execute when the condition does not hold.
Initialize a scalar quantum variable using an arithmetic expression.
If specified, the variable numeric properties (size, signedness, and fraction
digits) must match the expression properties.Equivalent to <target_var> |= <expression>.Parameters:
Given two operations U and V, performs the sequence of operations U{−1}VU.This operation is used to represent a sequence where the inverse gate U^{-1} is applied, followed by another operation V, and then U is applied to uncompute. This pattern is common in reversible
computation and quantum subroutines.Parameters:
Name
Type
Description
Default
within
Callable[[], Statements]
The unitary operation U to be computed and then uncomputed.
Executes a quantum loop a specified number of times, applying a quantum operation on each iteration.This operation provides quantum control flow similar to a classical for loop, enabling repeated
application of quantum operations based on classical loop variables.Parameters:
Name
Type
Description
Default
count
SymbolicExpr | int
An integer or symbolic expression specifying the number of loop iterations.
required
iteration
Callable[[int], Statements]
A callable that takes a single integer index and returns the quantum operations to be performed at each iteration.
Apply a quantum operation raised to a symbolic or integer power.This function enables exponentiation of a quantum gate, where the exponent can be a
symbolic expression or an integer. It is typically used within a quantum program
to repeat or scale quantum operations in a parameterized way.Parameters:
Name
Type
Description
Default
exponent
SymbolicExpr | int
The exponent value, either as an integer or a symbolic expression.
required
stmt_block
QCallable | Callable[[], Statements]
A callable that produces the quantum operation to be exponentiated.
invert(
stmt_block: QCallable | Callable[[], Statements]
) -> Any
Apply the inverse of a quantum gate.This function allows inversion of a quantum gate. It is typically used within a quantum program
to invert a sequence of operations.Parameters:
Name
Type
Description
Default
stmt_block
QCallable | Callable[[], Statements]
A callable that produces the quantum operation to be inverted.
Applies a state-dependent or fixed phase shift (Z rotation) to the quantum state.This operation multiplies each computational-basis state ∣x1,x2,…,xn⟩
by a complex phase factor θ∗{phaseexpr}(x1,x2,…,xn), where
phase_expr is a symbolic expression that contains quantum variables x1,x2,…,xn,
and theta is a scalar multiplier. If phase_expr contains no quantum variables,
all states are rotated by the same fixed angle.Parameters:
Name
Type
Description
Default
phase_expr
SymbolicExpr | float | None
A symbolic expression that evaluates to an angle (in radians) as a function of the state of the quantum variables occurring in it, if any, or otherwise a fixed value. Execution parameters are only allowed if no quantum variables occur in the expression.
None
theta
SymbolicExpr | float
(Optional, allowed only together with quantum expressions) A scalar multiplier for the evaluated expression, optionally containing execution parameters. Defaults to 1.0.
Loops through the elements of a classical list, applying a quantum operation on each iteration.This operation provides quantum control flow similar to a classical for ... in loop, enabling repeated
application of quantum operations based on classical loop variables.The iteration callable accepts one or more classical iteration variables.
If the iteration callable takes a single iteration variable, it will be assigned with the elements of ‘values’.
If the iteration callable takes two or more variables, the elements of ‘values’ will be
unpacked into them.Parameters:
Name
Type
Description
Default
values
SymbolicExpr | list[float] | list[list[float]]
A classical list.
required
iteration
Callable[..., Statements]
A callable that takes one or more iteration variables and returns the quantum operations to be performed at each iteration.
Encodes the value of the sine/cosine of a polynomial into the amplitude of the
respective computational basis state:∣x1,x2,…,xn⟩∣0⟩→cos(poly(x1,x2,…,xn))∣x1,x2,…,xn⟩∣0⟩+sin(poly(x1,x2,…,xn))∣x1,x2,…,xn⟩∣1⟩Parameters:
Name
Type
Description
Default
indicator
QBit
The quantum indicator qubit
required
expr
SymbolicExpr
A polynomial expression over quantum scalars x_1, x_2, \ldots, x_n