Qmod.
For more information regarding classical types see the Statements section in the language reference.
Members:
QuantumLambdaFunction
The definition of an anonymous function passed as operand to higher-level functions Methods:pos_rename_params
pos_rename_params: list[str] = pydantic.Field(default_factory=list, description='Mapping of the declared param to the actual variable name used')
body
body: StatementBlock = pydantic.Field(description='A list of function calls passed to the operator')
py_callable
py_callable: Callable
func_decl
func_decl: AnonQuantumOperandDeclaration
named_func_decl
named_func_decl: AnonQuantumOperandDeclaration
H
H(
target: QBit
) -> None
[Qmod core-library function]
Performs the Hadamard gate on a qubit.
This operation is represented by the following matrix:
Parameters:
S
S(
target: Const[QBit]
) -> None
[Qmod core-library function]
Performs the S gate on a qubit.
This operation is represented by the following matrix:
Parameters:
QBit
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:
Therefore, a qubit state is a linear combination:
where ( \alpha ) and ( \beta ) are complex numbers satisfying:
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
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:
Attributes:
fraction_digits
fraction_digits: CParamScalar | int
is_signed
is_signed: CParamScalar | bool
CONSTRUCTOR_DEPTH
allocate
allocate(
args: Any = (),
kwargs: Any =
) -> None
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:
bind
bind(
source: Input[QVar] | list[Input[QVar]],
destination: Output[QVar] | list[Output[QVar]]
) -> None
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:
if_
if_(
condition: SymbolicExpr | bool,
then: QCallable | Callable[[], Statements],
else_: QCallable | Callable[[], Statements] | int = _MISSING_VALUE
) -> None
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:
control
control(
ctrl: SymbolicExpr | QBit | QArray[QBit] | list[QVar],
stmt_block: QCallable | Callable[[], Statements],
else_block: QCallable | Callable[[], Statements] | None = None
) -> None
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:
skip_control
skip_control(
stmt_block: QCallable | Callable[[], Statements]
) -> None
Applies quantum statements unconditionally.
Parameters:
assign
assign(
expression: SymbolicExpr,
target_var: QScalar
) -> None
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:
inplace_add
inplace_add(
expression: SymbolicExpr,
target_var: QScalar
) -> None
Add an arithmetic expression to a quantum variable.
Equivalent to <target_var> += <expression>.
Parameters:
inplace_xor
inplace_xor(
expression: SymbolicExpr,
target_var: QScalar
) -> None
Bitwise-XOR a quantum variable with an arithmetic expression.
Equivalent to <target_var> ^= <expression>.
Parameters:
within_apply
within_apply(
within: Callable[[], Statements],
apply: Callable[[], Statements]
) -> None
Given two operations and , performs the composition of operations .
This operation is used to represent a sequence where the operation U is applied, followed by another operation V, and then U^{-1} is applied to uncompute. This pattern is common in reversible
computation and quantum subroutines.
Parameters:
repeat
repeat(
count: SymbolicExpr | int,
iteration: Callable[[int], Statements]
) -> None
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:
power
power(
exponent: SymbolicExpr | int,
stmt_block: QCallable | Callable[[], Statements]
) -> None
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:
invert
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:
phase
phase(
phase_expr: SymbolicExpr | float | None = None,
coefficient: SymbolicExpr | float = 1.0
) -> None
Applies a state-dependent or fixed phase shift (Z rotation) to the quantum state.
This operation multiplies each computational-basis state
by a complex phase factor , where
phase_expr is a symbolic expression that contains quantum variables ,
and coefficient is a scalar multiplier. If phase_expr contains no quantum variables,
all states are rotated by the same fixed angle.
Parameters:
foreach
foreach(
values: SymbolicExpr | Sequence[SymbolicExpr | int | float] | Sequence[Sequence[SymbolicExpr | int | float]],
iteration: Callable[…, Statements]
) -> None
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:
assign_amplitude_poly_sin
assign_amplitude_poly_sin(
indicator: QBit,
expr: SymbolicExpr
) -> None
Encodes the value of the sine/cosine of a polynomial into the amplitude of the
respective computational basis state:
Parameters:
lookup_table
lookup_table(
func: RealFunction,
targets: QScalar | list[QScalar]
) -> list[float]
Reduces a classical function into a lookup table over all the possible values
of the quantum numbers.
Parameters:
Returns:
- Type:
list[float] - The function’s lookup table options: show_source: false show_if_no_docstring: false