The constructors module
The constructors module holds a collection of convenience functions for expression type constructions and quantum operations (e.g. unitary and Hermitian operators, projectors) as well as trainable and non-trainable parameters as symbols.
array_parameter(name, size)
A non-trainable list of inputs.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Array of parameters name.
TYPE:
|
size
|
Array size.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
An array of parameters as sized symbol expression.
TYPE:
|
Source code in qadence2_expressions/core/constructors.py
array_variable(name, size)
A trainable list of inputs.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Array of variables name.
TYPE:
|
size
|
Array size.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
An array of variables as sized symbol expression.
TYPE:
|
Source code in qadence2_expressions/core/constructors.py
function(name, *args)
Symbolic representation of a function.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Function's name.
TYPE:
|
args
|
Remaining function arguments.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
A function expression.
TYPE:
|
Source code in qadence2_expressions/core/constructors.py
parameter(name)
A non-trainable input.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Parameter's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
A parameter as a symbol expression.
TYPE:
|
parametric_operator(name, *args, join=None, **attributes)
A parametric operator.
A parametric operator takes a list of positional arguments and generates a function that takes a list of indices (or a target and control tuples) and return an Expression.
The join function is used to combine arguments of two parametric
operators of the same kind acting on the same qubit support.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The operator's name.
TYPE:
|
args
|
The remaining operator arguments.
TYPE:
|
join
|
A function to join parameter arguments.
TYPE:
|
attributes
|
Keywords used for compilation.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
A function to create a quantum operator.
TYPE:
|
Source code in qadence2_expressions/core/constructors.py
projector(base, index)
A projector operator.
A projector is a function that takes a list of indices (or a target and control tuples) and return an Expression with the orthogonality property.
| PARAMETER | DESCRIPTION |
|---|---|
base
|
The computational basis to project on.
TYPE:
|
index
|
The index in the basis to project on.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
A function to create a quantum operator expression.
TYPE:
|
Example:
Source code in qadence2_expressions/core/constructors.py
promote(x)
Type cast inputs as value type expressions.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
A valid expression or numerical value.
Numerical values are converted into
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
A value type or expression.
TYPE:
|
Source code in qadence2_expressions/core/constructors.py
symbol(identifier, **attributes)
Create a new symbol from the identifier if not protected.
| PARAMETER | DESCRIPTION |
|---|---|
identifier
|
Symbol's name.
TYPE:
|
Kwargs
attributes (Any): Keywords used as flags for compilation.
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
A symbol type expression.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SyntaxError
|
If argument is expression protected. |
Source code in qadence2_expressions/core/constructors.py
unitary_hermitian_operator(name)
A unitary Hermitian operator.
A Hermitian operator is a function that takes a list of indices (or a target and control tuples) and return an Expression with hermitian and unitary properties.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The operator's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable
|
A function to create a quantum operator expression.
TYPE:
|
Example:
Source code in qadence2_expressions/core/constructors.py
value(x)
Create a numerical expression from the value x.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Any numerical value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
An expression of type value.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the argument is non-numerical. |
Source code in qadence2_expressions/core/constructors.py
variable(name)
A trainable input.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Variable's name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Expression
|
A variable as a trainable symbol expression.
TYPE:
|