Index
operations
bind
bind(
source: Union[Input[QVar], List[Input[QVar]]],
destination: Union[Output[QVar], List[Output[QVar]]],
) -> None
control
control(
ctrl: Union[SymbolicExpr, QBit, QArray[QBit]],
stmt_block: Union[QCallable, Callable[[], None]],
) -> None
if_
if_(
condition: Union[SymbolicExpr, bool],
then: Union[QCallable, Callable[[], None]],
else_: Union[
QCallable, Callable[[], None], int
] = _MISSING_VALUE,
) -> None
phase
phase(expr: SymbolicExpr, theta: float = 1.0) -> None
power
power(
exponent: Union[SymbolicExpr, int],
stmt_block: Union[QCallable, Callable[[], None]],
) -> None
repeat
repeat(
count: Union[SymbolicExpr, int],
iteration: Callable[[int], None],
) -> None
within_apply
within_apply(
within: Callable[[], None], apply: Callable[[], None]
) -> None
functions
BUILTIN_FUNCTION_DECLARATIONS
BUILTIN_FUNCTION_DECLARATIONS = {name: _Mmy2vIlafor func_decl in STD_QMOD_OPERATORS + OPEN_LIB_DECLS + CORE_LIB_DECLS}
CORE_LIB_DECLS
CORE_LIB_DECLS = [
func_decl
for func in (
molecule_ucc,
molecule_hva,
molecule_hartree_fock,
fock_hamiltonian_ucc,
fock_hamiltonian_hva,
fock_hamiltonian_hartree_fock,
log_normal_finance,
gaussian_finance,
pauli_feature_map,
bloch_sphere_feature_map,
H,
X,
Y,
Z,
I,
S,
T,
SDG,
TDG,
PHASE,
RX,
RY,
RZ,
R,
RXX,
RYY,
RZZ,
CH,
CX,
CY,
CZ,
CRX,
CRY,
CRZ,
CPHASE,
SWAP,
IDENTITY,
prepare_state,
prepare_amplitudes,
unitary,
add,
modular_add,
integer_xor,
U,
CCX,
allocate,
free,
randomized_benchmarking,
inplace_prepare_state,
inplace_prepare_amplitudes,
single_pauli_exponent,
suzuki_trotter,
qdrift,
exponentiation_with_depth_constraint,
)
]
Input
Input = _Q
OPEN_LIB_DECLS
OPEN_LIB_DECLS = [
func_decl
for func in (
qpe_flexible,
qpe,
_single_pauli,
linear_pauli_rotations,
amplitude_estimation,
phase_oracle,
reflect_about_zero,
grover_diffuser,
grover_operator,
grover_search,
hadamard_transform,
apply_to_all,
qft_no_swap,
qft_space_add_const,
cc_modular_add,
c_modular_multiply,
multiswap,
inplace_c_modular_multiply,
modular_exp,
qsvt_step,
qsvt,
projector_controlled_phase,
qsvt_inversion,
allocate_num,
qaoa_mixer_layer,
qaoa_cost_layer,
qaoa_layer,
qaoa_init,
qaoa_penalty,
full_hea,
swap_test,
prepare_uniform_trimmed_state,
prepare_uniform_interval_state,
prepare_ghz_state,
prepare_exponential_state,
prepare_bell_state,
inplace_prepare_int,
prepare_int,
switch,
qct_qst_type1,
qct_qst_type2,
qct_type2,
qst_type2,
modular_increment,
qft,
_ctrl_x,
_prepare_uniform_trimmed_state_step,
_qct_d_operator,
_qct_pi_operator,
_check_msb,
)
]
Output
Output = _Q
CArray
CArray(expr: str)
Bases: CParam
, ArrayBase[_P]
len
len: int
CBool
CBool(expr: str)
Bases: CParam
CInt
CInt(expr: str)
Bases: CParam
CReal
CReal(expr: str)
Bases: CParam
FinanceFunction
FockHamiltonianProblem
GaussianModel
LogNormalModel
MoleculeProblem
Pauli
Bases: IntEnum
Enumeration for the Pauli matrices used in quantum computing.
The Pauli matrices are fundamental operations in quantum computing, and this enum assigns integer values to represent each matrix.
I
I = 0
I (int): Identity matrix, represented by the integer 0.
\(I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\)
X
X = 1
X (int): Pauli-X matrix, represented by the integer 1.
\(X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\)
Y
Y = 2
Y (int): Pauli-Y matrix, represented by the integer 2.
\(Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\)
Z
Z = 3
Z (int): Pauli-Z matrix, represented by the integer 3.
\(Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\)
PauliTerm
A term in a Hamiltonian, represented as a product of Pauli operators.
Attributes:
Name | Type | Description |
---|---|---|
pauli |
CArray[Pauli]
|
The list of the chosen Pauli operators in the term, corresponds to a product of them. |
coefficient |
CReal
|
The coefficient of the term (floating number). |
QArray
QArray(
name: Union[str, HandleBinding],
element_type: Union[_GenericAlias, QuantumType] = QBit,
length: Optional[
Union[int, SymbolicExpr, Expression]
] = None,
_expr_str: Optional[str] = None,
)
Bases: ArrayBase[_P]
, QVar
len
len: Union[CParamScalar, int]
get_qmod_type
get_qmod_type() -> QuantumBitvector
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QArray
QBit
QBit(
origin: Union[str, HandleBinding],
*,
_expr_str: Optional[str] = None,
depth: int = 2
)
Bases: QScalar
get_qmod_type
get_qmod_type() -> QuantumType
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QBit
QCallable
Bases: Generic[P]
, ABC
CURRENT_EXPANDABLE
CURRENT_EXPANDABLE: Optional[QExpandableInterface] = None
FRAME_DEPTH
FRAME_DEPTH = 1
func_decl
func_decl: AnonQuantumFunctionDeclaration
create_quantum_function_call
create_quantum_function_call(
source_ref_: SourceReference, *args: Any, **kwargs: Any
) -> QuantumFunctionCall
QCallableList
Bases: QCallable
, Generic[P]
, ABC
len
len: int
QNum
QNum(
name: Union[str, HandleBinding],
size: Union[int, CInt, Expression, None] = None,
is_signed: Union[
bool, Expression, SymbolicExpr, None
] = None,
fraction_digits: Union[
int, CInt, Expression, None
] = None,
_expr_str: Optional[str] = None,
)
Bases: Generic[_P]
, QScalar
fraction_digits
fraction_digits: Union[CParamScalar, int]
is_signed
is_signed: Union[CParamScalar, bool]
get_qmod_type
get_qmod_type() -> QuantumType
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QNum
QSVMFeatureMapPauli
CCX
[Qmod core-library function]
Applies the Pauli-X gate to the target qubit, conditioned on the two control qubits (Toffoli).
This operation is represented by the following matrix:
More information can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
QArray[QBit, Literal[2]]
|
The control qubits. |
required |
target |
QBit
|
The qubit to apply the conditioned Pauli-X gate on. |
required |
Link: Reference Manual
CH
[Qmod core-library function]
Applies the Hadamard gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the Hadamard gate on. |
required |
Link: Reference Manual
CPHASE
[Qmod core-library function]
Applies the PHASE gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the PHASE gate on. |
required |
Link: Reference Manual
CRX
[Qmod core-library function]
Applies the RX gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the RX gate on. |
required |
Link: Reference Manual
CRY
[Qmod core-library function]
Applies the RY gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the RY gate on. |
required |
Link: Reference Manual
CRZ
[Qmod core-library function]
Applies the RZ gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the RZ gate on. |
required |
Link: Reference Manual
CX
[Qmod core-library function]
Applies the Pauli-X gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the Pauli-X gate on. |
required |
Link: Reference Manual
CY
[Qmod core-library function]
Applies the Pauli-Y gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the Pauli-Y gate on. |
required |
Link: Reference Manual
CZ
[Qmod core-library function]
Applies the Pauli-Z gate to the target qubit, conditioned on the control qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
control |
QBit
|
The control qubit. |
required |
target |
QBit
|
The qubit to apply the Pauli-Z gate on. |
required |
Link: Reference Manual
H
H(target: QBit) -> None
[Qmod core-library function]
Performs the Hadamard gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the Hadamard gate to. |
required |
Link: Reference Manual
I
I(target: QBit) -> None
[Qmod core-library function]
Performs the identity gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the identity gate to. |
required |
Link: Reference Manual
IDENTITY
[Qmod core-library function]
Does nothing.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QArray[QBit]
|
The qubits to apply the IDENTITY gate on. |
required |
Link: Reference Manual
PHASE
[Qmod core-library function]
Performs the phase gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The phase angle in radians. |
required |
target |
QBit
|
The qubit to apply the phase gate to. |
required |
Link: Reference Manual
R
[Qmod core-library function]
Performs a rotation of \(\theta\) around the \(cos(\phi)\hat{x} + sin(\phi)\hat{y}\) axis on a qubit.
This operation is represented by the following matrix:
More information on this gate can be found in the Qiskit documentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
phi |
CReal
|
The phase angle in radians. |
required |
target |
QBit
|
The qubit to apply the general single-qubit rotation gate to. |
required |
Link: Reference Manual
RX
[Qmod core-library function]
Performs the Pauli-X rotation gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
target |
QBit
|
The qubit to apply the Pauli-X rotation gate to. |
required |
Link: Reference Manual
RXX
[Qmod core-library function]
Performs the XX rotation gate on a pair of qubits.
This operation is represented by the following matrix:
For more information on quantum logic gates, see Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
target |
QArray[QBit, Literal[2]]
|
The pair of qubits to apply the XX rotation gate to. |
required |
Link: Reference Manual
RY
[Qmod core-library function]
Performs the Pauli-Y rotation gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
target |
QBit
|
The qubit to apply the Pauli-Y rotation gate to. |
required |
Link: Reference Manual
RYY
[Qmod core-library function]
Performs the YY rotation gate on a pair of qubits.
This operation is represented by the following matrix:
For more information on quantum logic gates, see Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
target |
QArray[QBit, Literal[2]]
|
The pair of qubits to apply the YY rotation gate to. |
required |
Link: Reference Manual
RZ
[Qmod core-library function]
Performs the Pauli-Z rotation gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
target |
QBit
|
The qubit to apply the Pauli-Z rotation gate to. |
required |
Link: Reference Manual
RZZ
[Qmod core-library function]
Performs the ZZ rotation gate on a pair of qubits.
This operation is represented by the following matrix:
For more information on quantum logic gates, see Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The rotation angle in radians. |
required |
target |
QArray[QBit, Literal[2]]
|
The pair of qubits to apply the ZZ rotation gate to. |
required |
Link: Reference Manual
S
S(target: QBit) -> None
[Qmod core-library function]
Performs the S gate on a qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the S gate to. |
required |
Link: Reference Manual
SDG
SDG(target: QBit) -> None
[Qmod core-library function]
Performs the S-dagger gate on a qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the S-dagger gate to. |
required |
Link: Reference Manual
SWAP
[Qmod core-library function]
Swaps the states of two qubits.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qbit0 |
QBit
|
The first qubit. |
required |
qbit1 |
QBit
|
The second qubit. |
required |
Link: Reference Manual
T
T(target: QBit) -> None
[Qmod core-library function]
Performs the T gate on a qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the T gate to. |
required |
Link: Reference Manual
TDG
TDG(target: QBit) -> None
[Qmod core-library function]
Performs the T-dagger gate on a qubit.
This operation is represented by the following matrix:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the T-dagger gate to. |
required |
Link: Reference Manual
U
[Qmod core-library function]
Performs a general single-qubit unitary gate that applies phase and rotation with three Euler angles on a qubit.
This operation is represented by the following matrix:
More information on this gate can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta |
CReal
|
The first Euler angle in radians. |
required |
phi |
CReal
|
The second Euler angle in radians. |
required |
lam |
CReal
|
The third Euler angle in radians. |
required |
gam |
CReal
|
The global phase angle in radians. |
required |
target |
QBit
|
The qubit to apply the general single-qubit unitary gate to. |
required |
Link: Reference Manual
X
X(target: QBit) -> None
[Qmod core-library function]
Performs the Pauli-X gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the Pauli-X gate to. |
required |
Link: Reference Manual
Y
Y(target: QBit) -> None
[Qmod core-library function]
Performs the Pauli-Y gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the Pauli-Y gate to. |
required |
Link: Reference Manual
Z
Z(target: QBit) -> None
[Qmod core-library function]
Performs the Pauli-Z gate on a qubit.
This operation is represented by the following matrix:
More information on quantum logic gates can be found on Wikipedia.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QBit
|
The qubit to apply the Pauli-Z gate to. |
required |
Link: Reference Manual
add
add(
left: QArray[QBit],
right: QArray[QBit],
result: Output[
QArray[
QBit,
Literal[
"Max(get_field(left, 'len'), get_field(right, 'len')) + 1"
],
]
],
) -> None
allocate
[Qmod core-library function]
Allocates the specified number of qubits to a given quantum variable and initializes them in the zero state:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubits |
CInt
|
The number of qubits to allocate. Must be a positive integer. |
required |
out |
Output[QArray[QBit, Literal['num_qubits']]]
|
The quantum variable that will receive the allocated qubits. Must be uninitialized before allocation. For more information on quantum variable initialization, see here. |
required |
Notes
- If the output variable has been declared with a specific number of qubits, the number of qubits allocated must match the declared number.
- The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
allocate_num
allocate_num(
num_qubits: CInt,
is_signed: CBool,
fraction_digits: CInt,
out: Output[
QNum[
Literal["num_qubits"],
Literal["is_signed"],
Literal["fraction_digits"],
]
],
) -> None
[Qmod Classiq-library function]
Initializes a quantum number with the given number of qubits, sign, and fractional digits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubits |
CInt
|
The number of qubits to allocate. |
required |
is_signed |
CBool
|
Whether the number is signed or unsigned. |
required |
fraction_digits |
CInt
|
The number of fractional digits. |
required |
Further reading is available on the reference manual
amplitude_estimation
amplitude_estimation(
oracle: QCallable[QArray[QBit]],
space_transform: QCallable[QArray[QBit]],
phase: QNum,
packed_vars: QArray[QBit],
) -> None
[Qmod Classiq-library function]
Estimate the probability of a state being marked by the operand oracle
as a "good state."
The algorithm prepares the state in the packed_vars
register and estimates the probability of this state being marked by the oracle as a "good state."
This is done using the Quantum Phase Estimation (QPE) algorithm, where the unitary for QPE is the Grover operator, which is composed of the oracle
and space_transform
operators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oracle |
QCallable[QArray[QBit]]
|
The oracle operator that marks the "good" state. This operator should flip the sign of the amplitude of the "good" state. |
required |
space_transform |
QCallable[QArray[QBit]]
|
The space transform operator (which is known also the state preparation operator), which is first applied to prepare the state before the QPE, and then used inside the Grover operator. |
required |
phase |
QNum
|
Assuming this variable starts from the zero state -this variable output holds the \(phase=\theta\) result in the [0,1] domain, which relates to the estimated probability \(a\) through \(a=\sin^2(\pi \theta)\). |
required |
packed_vars |
QArray[QBit]
|
The variable that holds the state to be estimated. Assumed to be in the zero state at the beginning of the algorithm. |
required |
apply_to_all
[Qmod Classiq-library function]
Applies the single-qubit operand gate_operand
to each qubit in the qubit
array target
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gate_operand |
QCallable[QBit]
|
The single-qubit gate to apply to each qubit in the array. |
required |
target |
QArray[QBit]
|
The qubit array to apply the gate to. |
required |
bloch_sphere_feature_map
bloch_sphere_feature_map(
feature_dimension: CInt,
qbv: QArray[
QBit, Literal["ceiling(feature_dimension / 2)"]
],
) -> None
c_modular_multiply
[Qmod Classiq-library function]
Performs out-of-place multiplication of a quantum number x
by a classical number a
modulo classical number n
,
controlled by a quantum bit ctrl
and adds the result to a quantum array b
. Applies \(b += xa \mod n\) if ctrl=1
, and the identity otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
CInt
|
The modulo number. Should be non-negative. |
required |
a |
CInt
|
The classical factor. Should be non-negative. |
required |
b |
QArray[QBit]
|
The quantum number added to the multiplication result. Stores the result of the multiplication. |
required |
x |
QArray[QBit]
|
The quantum factor. |
required |
ctrl |
QBit
|
The control bit. |
required |
cc_modular_add
[Qmod Classiq-library function]
Adds a constant a
to a quantum number phi_b
modulo the constant n
, controlled by 2 qubits.
The quantum number phi_b
and the constant a
are assumed to be in the QFT space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
CInt
|
The modulo number. |
required |
a |
CInt
|
The constant to add to the quantum number. |
required |
phi_b |
QArray[QBit]
|
The quantum number to which the constant is added. |
required |
c1 |
QBit
|
a control qubit. |
required |
c2 |
QBit
|
a control qubit. |
required |
exponentiation_with_depth_constraint
exponentiation_with_depth_constraint(
pauli_operator: CArray[PauliTerm],
evolution_coefficient: CReal,
max_depth: CInt,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(pauli_operator[0], 'pauli'), 'len')"
],
],
) -> None
[Qmod core-library function]
Exponentiates a Pauli operator via the Suzuki-Trotter decomposition with a depth constraint. The Suzuki-Trotter decomposition is a method for approximating the exponential of a sum of operators by a product of exponentials of each operator. This function automatically determines the order and number of repetitions of the Suzuki-Trotter decomposition to minimize the error given a depth constraint.
See A. M. Childs et al., Toward the first quantum simulation with quantum speedup (2017).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pauli_operator |
CArray[PauliTerm]
|
The Pauli operator to be exponentiated. |
required |
evolution_coefficient |
CReal
|
A global coefficient multiplying the Pauli operator. |
required |
max_depth |
CInt
|
The maximum depth of the exponentiation. |
required |
qbv |
QArray[QBit, Literal["get_field(get_field(pauli_operator[0], 'pauli'), 'len')"]]
|
The target quantum variable of the exponentiation. |
required |
fock_hamiltonian_hartree_fock
fock_hamiltonian_hartree_fock(
fock_hamiltonian_problem: FockHamiltonianProblem,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(fock_hamiltonian_problem_to_hamiltonian(fock_hamiltonian_problem)[0], 'pauli'), 'len')"
],
],
) -> None
fock_hamiltonian_hva
fock_hamiltonian_hva(
fock_hamiltonian_problem: FockHamiltonianProblem,
reps: CInt,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(fock_hamiltonian_problem_to_hamiltonian(fock_hamiltonian_problem)[0], 'pauli'), 'len')"
],
],
) -> None
fock_hamiltonian_ucc
fock_hamiltonian_ucc(
fock_hamiltonian_problem: FockHamiltonianProblem,
excitations: CArray[CInt],
qbv: QArray[
QBit,
Literal[
"get_field(get_field(fock_hamiltonian_problem_to_hamiltonian(fock_hamiltonian_problem)[0], 'pauli'), 'len')"
],
],
) -> None
free
[Qmod core-library function]
Releases the qubits allocated to a quantum variable, allowing them to be reused.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_ |
Input[QArray[QBit]]
|
The quantum variable that will be freed. Must be initialized before. For more information on quantum variable initialization, see here. |
required |
Note
This operation does not uncompute the qubits. It is the responsibility of the user to ensure that the qubits are at the zero state before freeing them.
full_hea
full_hea(
num_qubits: CInt,
is_parametrized: CArray[CInt],
angle_params: CArray[CReal],
connectivity_map: CArray[CArray[CInt]],
reps: CInt,
operands_1qubit: QCallableList[CReal, QBit],
operands_2qubit: QCallableList[CReal, QBit, QBit],
x: QArray[QBit, Literal["num_qubits"]],
) -> None
[Qmod Classiq-library function]
Implements an ansatz on a qubit array x
with the given 1-qubit and 2-qubit operations.
The number of ansatz layers is given in argument reps
.
Each layer applies the 1-qubit operands in operands_1qubit
to all the qubits in x
.
Next, it applies the 2-qubit operands in operands_2qubit
to qubits (i, j) for each
pair of indices (i, j) in connectivity_map
.
The list is_parametrized
specifies whether the operands in operands_1qubit
and
operands_2qubit
are parametric (expect a classical argument).
is_parametrized
is a list of flags (0 and 1 integers) of length
len(operands_1qubit) + len(operands_2qubit)
.
The first len(operands_1qubit)
flags refer to the operands_1qubit
operands and
the next len(operands_2qubit)
flags refer to the operands_2qubit
operands.
The classical arguments to the parametric operands are given in argument
angle_params
.
angle_params
concatenates a set of arguments for each ansatz layer.
Each set contains an argument for each qubit in x
times the number
of parametric operands in operands_1qubit
.
These are followed by an argument for each mapping pair in connectivity_map
times
the number of parametric operands in operands_2qubit
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubits |
CInt
|
The length of qubit array x |
required |
is_parametrized |
CArray[CInt]
|
A list of 0 and 1 flags |
required |
connectivity_map |
CArray[CArray[CInt]]
|
A list of pairs of qubit indices |
required |
reps |
CInt
|
The number of ansatz layers |
required |
operands_1qubit |
QCallableList[CReal, QBit]
|
A list of operations on a single qubit |
required |
operands_2qubit |
QCallableList[CReal, QBit, QBit]
|
A list of operations on two qubits |
required |
x |
QArray[QBit, Literal['num_qubits']]
|
The quantum object to be transformed by the ansatz |
required |
gaussian_finance
gaussian_finance(
finance_model: GaussianModel,
finance_function: FinanceFunction,
func_port: QArray[
QBit,
Literal[
"get_field(finance_model, 'num_qubits') + get_field(get_field(finance_model, 'rhos'), 'len') + floor(log(sum(get_field(finance_model, 'loss')), 2)) + 1"
],
],
obj_port: QBit,
) -> None
grover_diffuser
[Qmod Classiq-library function]
Reflects the given state about the A|0> state, where A
is the space_transform
parameter. It is defined as:
where \(S_0\) is the reflection about the |0> state (see reflect_about_zero
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
space_transform |
QCallable[QArray[QBit]]
|
The operator which encodes the axis of reflection. |
required |
packed_vars |
QArray[QBit]
|
The state to which to apply the diffuser. |
required |
grover_operator
grover_operator(
oracle: QCallable[QArray[QBit]],
space_transform: QCallable[QArray[QBit]],
packed_vars: QArray[QBit],
) -> None
[Qmod Classiq-library function]
Applies the grover operator, defined by:
where \(S_{\psi_1}\) is a reflection about marked states, and \(S_{\psi_0}\) is a reflection about a given state defined by \(|\psi_0 angle = A|0 angle\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oracle |
QCallable[QArray[QBit]]
|
A unitary operator which adds a phase of (-1) to marked states. |
required |
space_transform |
QCallable[QArray[QBit]]
|
The operator which creates \(|\psi_0 angle\), the initial state, used by the diffuser to reflect about it. |
required |
packed_vars |
QArray[QBit]
|
The state to which to apply the grover operator. |
required |
For further reading, see:
grover_search
[Qmod Classiq-library function]
Applies Grover search algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reps |
CInt
|
Number of repetitions of the grover operator. |
required |
oracle |
QCallable[QArray[QBit]]
|
An oracle that marks the solution. |
required |
packed_vars |
QArray[QBit]
|
Packed form of the variable to apply the grover operator on. |
required |
Returns: None
Links
hadamard_transform
[Qmod Classiq-library function]
Applies Hadamard transform to the target qubits.
Corresponds to the braket notation:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QArray[QBit]
|
qubits to apply to Hadamard transform to. |
required |
inplace_c_modular_multiply
[Qmod Classiq-library function]
Performs multiplication of a quantum number x
by a classical number a
modulo classical number n
,
controlled by a quantum bit ctrl
. Applies \(x=xa \mod n\) if ctrl=1
, and the identity otherwise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
CInt
|
The modulo number. Should be non-negative. |
required |
a |
CInt
|
The classical factor. Should be non-negative. |
required |
x |
QArray[QBit]
|
The quantum factor. |
required |
ctrl |
QBit
|
The control bit. |
required |
inplace_prepare_amplitudes
inplace_prepare_amplitudes(
amplitudes: CArray[CReal],
bound: CReal,
target: QArray[
QBit,
Literal["log(get_field(amplitudes, 'len'), 2)"],
],
) -> None
[Qmod core-library function]
Transforms a given quantum variable in the state |0> to the state per the specified amplitudes
(similar to prepare_amplitudes
but preformed on an initialized variable).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amplitudes |
CArray[CReal]
|
The amplitudes to initialize the quantum variable. Must be a valid real quantum state vector, i.e., the sum of squares should be 1. Must have a valid length (a power of 2). |
required |
bound |
CReal
|
An error bound, expressed as the \(L^{2}\) norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number. |
required |
target |
QArray[QBit, Literal["log(get_field(amplitudes, 'len'), 2)"]]
|
The quantum variable to act upon. |
required |
This is useful as part of quantum building blocks like the Grover diffuser operator, \(\left|\psi\right\rangle\left\langle\psi\right| \left( 2\left|0\right\rangle\left\langle0\right| - \mathcal{I} \right)\), where the output state of the oracle is reflected about this state.
inplace_prepare_int
[Qmod Classiq-library function]
Transitions a quantum variable in the zero state \(|0\rangle\) into the computational basis state \(|\text{value}\rangle\). In the general case, the function performs a bitwise-XOR, i.e. transitions the state \(|\psi\rangle\) into \(|\psi \oplus \text{value}\rangle\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
CInt
|
The value to assign to the quantum variable. |
required |
target |
QArray[QBit]
|
The quantum variable to act upon. |
required |
Note
If the value cannot fit into the quantum variable, it is truncated, i.e. treated as the value modulo \(2^\text{target.size}\).
inplace_prepare_state
inplace_prepare_state(
probabilities: CArray[CReal],
bound: CReal,
target: QArray[
QBit,
Literal["log(get_field(probabilities, 'len'), 2)"],
],
) -> None
[Qmod core-library function]
Transforms a given quantum variable in the state |0> to the state per the specified probability distribution
(similar to prepare_state
but preformed on an initialized variable).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probabilities |
CArray[CReal]
|
The probability distribution corresponding to the quantum variable state. Must be a valid probability distribution, i.e., a list of non-negative real numbers that sum to 1. Must have a valid length (a power of 2). |
required |
bound |
CReal
|
An error bound, expressed as the \(L^{2}\) norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number. |
required |
target |
QArray[QBit, Literal["log(get_field(probabilities, 'len'), 2)"]]
|
The quantum variable to act upon. |
required |
This is useful as part of quantum building blocks like the Grover diffuser operator, \(\left|\psi\right\rangle\left\langle\psi\right| \left( 2\left|0\right\rangle\left\langle0\right| - \mathcal{I} \right)\), where the output state of the oracle is reflected about this state.
linear_pauli_rotations
linear_pauli_rotations(
bases: CArray[Pauli],
slopes: CArray[CReal],
offsets: CArray[CReal],
x: QArray[QBit],
q: QArray[QBit],
) -> None
[Qmod Classiq-library function]
Performs a rotation on a series of \(m\) target qubits, where the rotation angle is a linear function of an \(n\)-qubit control register.
Corresponds to the braket notation:
where \(\left|x ight angle\) is the control register, \(\left|q ight angle\) is the target register, each \(P_{k}\) is one of the three Pauli matrices \(X\), \(Y\), or \(Z\), and \(a_{k}\), \(b_{k}\) are the user given slopes and offsets, respectively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bases |
CArray[Pauli]
|
List of Pauli Enums. |
required |
slopes |
CArray[CReal]
|
Rotation slopes for each of the given Pauli bases. |
required |
offsets |
CArray[CReal]
|
Rotation offsets for each of the given Pauli bases. |
required |
x |
QArray[QBit]
|
Quantum state to apply the rotation based on its value. |
required |
q |
QArray[QBit]
|
List of indicator qubits for each of the given Pauli bases. |
required |
Notice that bases, slopes, offset and q should be of the same size.
Links
log_normal_finance
log_normal_finance(
finance_model: LogNormalModel,
finance_function: FinanceFunction,
func_port: QArray[
QBit,
Literal["get_field(finance_model, 'num_qubits')"],
],
obj_port: QBit,
) -> None
modular_exp
[Qmod Classiq-library function]
Raises a classical integer a
to the power of a quantum number x
modulo classical integer n
times a quantum number power
. Performs \(power=(a^x \mod n)*power\) in-place.
(and specifically if at the input \(power=1\), at the output \(power=a^x \mod n\)).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
CInt
|
The modulus number. Should be non-negative. |
required |
a |
CInt
|
The base of the exponentiation. Should be non-negative. |
required |
x |
QArray[QBit]
|
The power of the exponentiation. |
required |
power |
QArray[QBit]
|
A quantum number which multiplies the modular exponentiation and holds the output. |
required |
modular_increment
[Qmod Classiq-library function]
Adds \(a\) to \(x\) modulo the range of \(x\), assumed that \(x\) is a non-negative integer and \(a\) is an integer. Mathematically it is described as:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
CInt
|
A classical integer to be added to x. |
required |
x |
QNum
|
A quantum number that is assumed to be non-negative integer. |
required |
molecule_hartree_fock
molecule_hartree_fock(
molecule_problem: MoleculeProblem,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(molecule_problem_to_hamiltonian(molecule_problem)[0], 'pauli'), 'len')"
],
],
) -> None
molecule_hva
molecule_hva(
molecule_problem: MoleculeProblem,
reps: CInt,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(molecule_problem_to_hamiltonian(molecule_problem)[0], 'pauli'), 'len')"
],
],
) -> None
molecule_ucc
molecule_ucc(
molecule_problem: MoleculeProblem,
excitations: CArray[CInt],
qbv: QArray[
QBit,
Literal[
"get_field(get_field(molecule_problem_to_hamiltonian(molecule_problem)[0], 'pauli'), 'len')"
],
],
) -> None
multiswap
[Qmod Classiq-library function]
Swaps the qubit states between two arrays. Qubits of respective indices are swapped, and additional qubits in the longer array are left unchanged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
QArray[QBit]
|
The first array |
required |
y |
QArray[QBit]
|
The second array |
required |
pauli_feature_map
pauli_feature_map(
feature_map: QSVMFeatureMapPauli,
qbv: QArray[
QBit,
Literal[
"get_field(feature_map, 'feature_dimension')"
],
],
) -> None
phase_oracle
[Qmod Classiq-library function]
Creates a phase oracle operator based on a predicate function.
Applies a predicate function and marks "good" and "bad" states with a phase flip. If the predicate is marked as \(\chi\), and the oracle is marked as \(S_\chi\), then:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
predicate |
QCallable[QArray[QBit], QBit]
|
A predicate function that takes a QArray of QBits and sets a single QBit |1> if the predicate is true, and |0> otherwise. |
required |
target |
QArray[QBit]
|
The target QArray of QBits to apply the phase oracle to. |
required |
prepare_amplitudes
prepare_amplitudes(
amplitudes: CArray[CReal],
bound: CReal,
out: Output[
QArray[
QBit,
Literal["log(get_field(amplitudes, 'len'), 2)"],
]
],
) -> None
[Qmod core-library function]
Initializes a quantum variable in a state corresponding to the given amplitudes:
with \(i = 0, 1, 2, ..., \text{len(amplitudes)}-1\) corresponding to computational basis states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amplitudes |
CArray[CReal]
|
The amplitudes to initialize the quantum variable. Must be a valid real quantum state vector, i.e., the sum of squares should be 1. Must have a valid length (a power of 2). |
required |
bound |
CReal
|
An error bound, expressed as the \(L^{2}\) norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number. |
required |
out |
Output[QArray[QBit, Literal["log(get_field(amplitudes, 'len'), 2)"]]]
|
The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see here. |
required |
Notes
- If the output variable has been declared with a specific number of qubits, the number of qubits formed by the distribution must match the declared number.
- The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
prepare_bell_state
[Qmod Classiq-library function]
Initializes a quantum array of size 2 in one of the four Bell states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_num |
CInt
|
The number of the Bell state to be prepared. Must be an integer between 0 and 3. |
required |
q |
Output[QArray[QBit, Literal[2]]]
|
The quantum variable that will receive the initialized state. Must be uninitialized. |
required |
Bell States
The four Bell states are defined as follows (each state correlates to an integer between 0 and 3 as defined by the state_num
argument):
If state_num
= 0 the function prepares the Bell state:
If state_num
= 1 the function prepares the Bell state:
If state_num
= 2 the function prepares the Bell state:
If state_num
= 3 the function prepares the Bell state:
Notes
The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
prepare_exponential_state
[Qmod Classiq-library function]
Prepares a quantum state with exponentially decreasing amplitudes. The state is prepared in the computational basis, with the amplitudes of the states decreasing exponentially with the index of the state:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rate |
CInt
|
The rate of the exponential decay. |
required |
q |
QArray[QBit]
|
The quantum register to prepare. |
required |
Further reading is available on the reference manual
prepare_ghz_state
[Qmod Classiq-library function]
Initializes a quantum variable in a Greenberger-Horne-Zeilinger (GHZ) state. i.e., a balanced superposition of all ones and all zeros, on an arbitrary number of qubits..
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size |
CInt
|
The number of qubits in the GHZ state. Must be a positive integer. |
required |
q |
Output[QArray[QBit]]
|
The quantum variable that will receive the initialized state. Must be uninitialized. |
required |
Notes
The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
prepare_int
prepare_int(
value: CInt,
out: Output[
QNum[
Literal["floor(log(value, 2)) + 1"],
Literal[False],
Literal[0],
]
],
) -> None
[Qmod Classiq-library function]
Initializes a quantum variable to the computational basis state \(|\text{value}\rangle\). The number of allocated qubits is automatically computed from the value, and is the minimal number required for representation in the computational basis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
CInt
|
The value to assign to the quantum variable. |
required |
out |
Output[QNum[Literal['floor(log(value, 2)) + 1'], Literal[False], Literal[0]]]
|
The allocated quantum variable. Must be uninitialized. For more information on quantum variable initialization, see here. |
required |
Note
If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
prepare_state
prepare_state(
probabilities: CArray[CReal],
bound: CReal,
out: Output[
QArray[
QBit,
Literal[
"log(get_field(probabilities, 'len'), 2)"
],
]
],
) -> None
[Qmod core-library function]
Initializes a quantum variable in a state corresponding to a given probability distribution:
with \(i = 0, 1, 2, ..., \text{len(amplitudes)}-1\) corresponding to computational basis states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probabilities |
CArray[CReal]
|
The probability distribution to initialize the quantum variable. Must be a valid probability distribution, i.e., a list of non-negative real numbers that sum to 1. Must have a valid length (a power of 2). |
required |
bound |
CReal
|
An error bound, expressed as the \(L^{2}\) norm between the expected and actual distributions. A larger bound can reduce the circuit size at the expense of accuracy. Must be a positive real number. |
required |
out |
Output[QArray[QBit, Literal["log(get_field(probabilities, 'len'), 2)"]]]
|
The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see here. |
required |
Notes
- If the output variable has been declared with a specific number of qubits, the number of qubits formed by the distribution must match the declared number.
- The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
prepare_uniform_interval_state
[Qmod Classiq-library function]
Initializes a quantum variable in a uniform superposition of the specified interval in the computational basis states:
The number of allocated qubits would be \(\left\lceil\log_2{\left(\text{end}\right)}\right\rceil\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start |
CInt
|
The lower bound of the interval to load (inclusive). |
required |
end |
CInt
|
The upper bound of the interval to load (exclusive). |
required |
q |
QArray[QBit]
|
The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see here. |
required |
Notes
- If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
- The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
prepare_uniform_trimmed_state
[Qmod Classiq-library function]
Initializes a quantum variable in a uniform superposition of the first m
computational basis states:
The number of allocated qubits would be \(\left\lceil\log_2{m}\right\rceil\).
The function is especially useful when m
is not a power of 2.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m |
CInt
|
The number of states to load in the superposition. |
required |
q |
QArray[QBit]
|
The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see here. |
required |
Notes
- If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
- The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
projector_controlled_phase
projector_controlled_phase(
phase: CReal,
proj_cnot: QCallable[QArray[QBit], QBit],
qvar: QArray[QBit],
aux: QBit,
) -> None
[Qmod Classiq-library function]
Assigns a phase to the entire subspace determined by the given projector. Corresponds to the operation:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
phase_seq |
A rotation phase. |
required | |
proj_cnot |
QCallable[QArray[QBit], QBit]
|
Projector-controlled-not unitary that sets an auxilliary qubit to |1> when the state is in the projection. |
required |
qvar |
QArray[QBit]
|
The quantum variable to which the rotation applies, which resides in the entire block encoding space. |
required |
aux |
QBit
|
A zero auxilliary qubit, used for the projector-controlled-phase rotation. Given as an inout so that qsvt can be used as a building-block in a larger algorithm. |
required |
Further reading in Classiq Library
qaoa_cost_layer
[Qmod Classiq-library function]
Applies the cost layer to the QAOA model.
This function integrates the problem-specific cost function into the QAOA model's objective function. The cost layer represents the primary objective that the QAOA algorithm seeks to optimize, such as minimizing energy or maximizing profit, depending on the application.
For more details on defining cost functions in QAOA models using Pyomo, see: Problem Formulation Args: g: The rotation parameter for the cost layer (prefactor). hamiltonian: The Hamiltonian terms for the QAOA model. target: The target quantum array variable.
qaoa_init
[Qmod Classiq-library function]
Initializes the QAOA circuit by applying the Hadamard gate to all qubits.
In the Quantum Approximate Optimization Algorithm (QAOA), the initial state is a uniform superposition created by applying the Hadamard gate to each qubit. This function prepares the qubits for the subsequent application of the cost and mixer layers by preparing them in an equal superposition state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QArray[QBit]
|
The target quantum array variable. |
required |
qaoa_layer
[Qmod Classiq-library function]
Applies the QAOA layer, which concatenates the cost layer and the mixer layer.
The qaoa_layer
function integrates both the cost and mixer layers, essential components of the
Quantum Approximate Optimization Algorithm (QAOA). The cost layer encodes the problem's objective,
while the mixer layer introduces quantum superposition and drives the search across the solution space.
For more details mon the QAOA problem formulation, please see the following tutorial Args: g: The rotation parameter for the cost layer. b: The rotation parameter for the mixer layer. hamiltonian: The Hamiltonian terms for the QAOA model. target: The target quantum array variable.
qaoa_mixer_layer
[Qmod Classiq-library function]
Applies the mixer layer for the QAOA algorithm.
The mixer layer is a sequence of X
gates applied to each qubit in the target quantum
array variable.
Please refer to the QAOA mixer tutorial for an example
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
CReal
|
The rotation parameter for the mixer layer. |
required |
target |
QArray[QBit]
|
The target quantum array. |
required |
qaoa_penalty
qaoa_penalty(
num_qubits: CInt,
params_list: CArray[CReal],
hamiltonian: CArray[PauliTerm],
target: QArray[QBit, Literal["num_qubits"]],
) -> None
[Qmod Classiq-library function]
Applies the penalty layer to the QAOA model.
This function adds a penalty term to the objective function of the QAOA model to enforce certain constraints (e.g., binary or integer variables) during the optimization process.
Please refer to the Optimization Problem tutorial for details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubits |
CInt
|
The number of qubits in the quantum circuit. |
required |
hamiltonian |
CArray[PauliTerm]
|
The Hamiltonian terms for the QAOA model. |
required |
target |
QArray[QBit, Literal['num_qubits']]
|
The target quantum array variable. |
required |
qct_qst_type1
[Qmod Classiq-library function]
Applies the quantum discrete cosine (DCT) and sine (DST)
transform of type 1 to the qubit array x
.
Corresponds to the matrix (with \(n\equiv\)x.len
):
$$ \left( egin{array}{ccc|c} {} &{} &{} \ {}&{ m DCT}^{(1)}(2^{n-1}+1) & {}& 0\ {} &{} &{} \ \hline {} & 0 & {} & i{ m DST}^{(1)}(2^{n-1}-1) \end{array}
ight) $$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
QArray[QBit]
|
The qubit array to apply the transform to. |
required |
qct_qst_type2
[Qmod Classiq-library function]
Applies the quantum discrete cosine (DCT) and sine (DST)
transform of type 2 to the qubit array x
concatenated with q
, with q
being the MSB.
Corresponds to the matrix (with \(n\equiv\)x.len
+1):
$$ \left( egin{array}{c|c} { m DCT}^{(2)}(2^{n-1}) & 0\ \hline 0 & -{ m DST}^{(2)}(2^{n-1}) \end{array}
ight) $$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
QArray[QBit]
|
The LSB part of the qubit array to apply the transform to. |
required |
q |
QBit
|
The MSB of the qubit array to apply the transform to. |
required |
qct_type2
qdrift
qdrift(
pauli_operator: CArray[PauliTerm],
evolution_coefficient: CReal,
num_qdrift: CInt,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(pauli_operator[0], 'pauli'), 'len')"
],
],
) -> None
[Qmod core-library function]
Exponentiates a Pauli operator using the QDrift method. The QDrift method is a stochastic method based on the Trotter decomposition for approximating the exponential of a sum of operators by a product of exponentials of each operator. The QDrift method randomizes the order of the operators in the product of exponentials to stochastically reduce the error of the approximation. The error of the QDrift method decreases as the number of QDrift steps increases.
See E. Campbell, Random Compiler for Fast Hamiltonian Simulation (2019).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pauli_operator |
CArray[PauliTerm]
|
The Pauli operator to be exponentiated. |
required |
evolution_coefficient |
CReal
|
A global evolution coefficient multiplying the Pauli operator. |
required |
num_qdrift |
The number of QDrift steps. |
required | |
qbv |
QArray[QBit, Literal["get_field(get_field(pauli_operator[0], 'pauli'), 'len')"]]
|
The target quantum variable of the exponentiation. |
required |
qft
[Qmod Classiq-library function]
Performs the Quantum Fourier Transform (QFT) on target
in-place.
Implements the following transformation:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target |
QArray[QBit]
|
The quantum object to be transformed |
required |
Further reading in Classiq Library: Link: qft library reference
qft_no_swap
qft_space_add_const
[Qmod Classiq-library function]
Adds a constant to a quantum number (in the Fourier space) using the Quantum Fourier Transform (QFT) Adder algorithm.
Assuming that the input phi_b
has n
qubits, the result will be \(\phi_b+=value \mod 2^n\).
To perform the full algorithm, use: within_apply(lambda: QFT(phi_b), qft_space_add_const(value, phi_b))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
CInt
|
The constant to add to the quantum number. |
required |
phi_b |
QArray[QBit]
|
The quantum number (at the aft space) to which the constant is added. |
required |
qfunc
qfunc(
func: Optional[Callable] = None,
*,
external: bool = False,
generative: bool = False
) -> Union[Callable[[Callable], QCallable], QCallable]
qpe
[Qmod Classiq-library function]
Implements the standard Quantum Phase Estimation (QPE) algorithm, which estimates the phase (eigenvalue) associated with an eigenstate of a given unitary operator \(U\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unitary |
QCallable
|
A callable representing the unitary operator \(U\), whose eigenvalue is to be estimated. |
required |
phase |
QNum
|
The quantum variable that represents the estimated phase (eigenvalue), assuming initialized to zero. |
required |
Further reading in Classiq Library: Link: qpe library reference
qpe_flexible
[Qmod Classiq-library function]
Implements the Quantum Phase Estimation (QPE) algorithm, which estimates the phase (eigenvalue) associated with an eigenstate of a given unitary operator \(U\). This is a flexible version that allows the user to provide a callable that generates the unitary operator \(U^k\) for a given integer \(k\), offering greater flexibility in handling different quantum circuits using some powering rule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unitary_with_power |
QCallable[CInt]
|
A callable that returns the unitary operator \(U^k\) given an integer \(k\). This callable is used to control the application of powers of the unitary operator. |
required |
phase |
QNum
|
The quantum variable that represents the estimated phase (eigenvalue), assuming initialized to zero. |
required |
Further reading in Classiq Library: Link: qpe library reference
qst_type2
qsvt
qsvt(
phase_seq: CArray[CReal],
proj_cnot_1: QCallable[QArray[QBit], QBit],
proj_cnot_2: QCallable[QArray[QBit], QBit],
u: QCallable[QArray[QBit]],
qvar: QArray[QBit],
aux: QBit,
) -> None
[Qmod Classiq-library function]
Implements the Quantum Singular Value Transformation (QSVT) - an algorithmic framework, used to apply polynomial transformations of degree d
on the singular values of a block encoded matrix, given as the unitary u
. Given a unitary \(U\), a list of phase angles \(\phi_1, \phi_2, ..., \phi_{d+1}\) and 2 projector-controlled-not operands \(C_{\Pi}NOT,C_{ ilde{\Pi}}NOT\), the QSVT sequence is as follows:
Given a unitary \(U\), a list of phase angles \(\phi_1, \phi_2, ..., \phi_{d+1}\) and 2 projector-controlled-not operands \(C_{\Pi}NOT,C_{ ilde{\Pi}}NOT\), the QSVT sequence is as follows:
for odd \(d\), and:
for even \(d\).
Each of the \(\Pi\)s is a projector-controlled-phase unitary, according to the given projectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
phase_seq |
CArray[CReal]
|
A sequence of phase angles of length d+1. |
required |
proj_cnot_1 |
QCallable[QArray[QBit], QBit]
|
Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block. |
required |
proj_cnot_2 |
QCallable[QArray[QBit], QBit]
|
Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block. |
required |
u |
QCallable[QArray[QBit]]
|
A block encoded unitary matrix. |
required |
qvar |
QArray[QBit]
|
The quantum variable to which U is applied, which resides in the entire block encoding space. |
required |
aux |
QBit
|
A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm. |
required |
Further reading in Classiq Library
qsvt_inversion
qsvt_inversion(
phase_seq: CArray[CReal],
block_encoding_cnot: QCallable[QArray[QBit], QBit],
u: QCallable[QArray[QBit]],
qvar: QArray[QBit],
aux: QBit,
) -> None
[Qmod Classiq-library function]
Implements matrix inversion on a given block-encoding of a square matrix, using the QSVT framework. Applies a polynomial approximation
of the inverse of the singular values of the matrix encoded in u
. The phases for the polynomial should be pre-calculated and passed into the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
phase_seq |
CArray[CReal]
|
A sequence of phase angles of length d+1, corresponding to an odd polynomial approximation of the scaled inverse function. |
required |
block_encoding_cnot |
QCallable[QArray[QBit], QBit]
|
Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block. |
required |
u |
QCallable[QArray[QBit]]
|
A block encoded unitary matrix. |
required |
qvar |
QArray[QBit]
|
The quantum variable to which U is applied, which resides in the entire block encoding space. |
required |
aux |
QBit
|
A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm. |
required |
For usage example, see: QSVT matrix inversion example
qsvt_step
qsvt_step(
phase1: CReal,
phase2: CReal,
proj_cnot_1: QCallable[QArray[QBit], QBit],
proj_cnot_2: QCallable[QArray[QBit], QBit],
u: QCallable[QArray[QBit]],
qvar: QArray[QBit],
aux: QBit,
) -> None
[Qmod Classiq-library function]
Applies a single QSVT step, composed of 2 projector-controlled-phase rotations, and applications of the block encoding unitary u
and its inverse:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
phase1 |
CReal
|
1st rotation phase. |
required |
phase2 |
CReal
|
2nd rotation phase. |
required |
proj_cnot_1 |
QCallable[QArray[QBit], QBit]
|
Projector-controlled-not unitary that locates the encoded matrix columns within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block. |
required |
proj_cnot_2 |
QCallable[QArray[QBit], QBit]
|
Projector-controlled-not unitary that locates the encoded matrix rows within U. Accepts a quantum variable of the same size as qvar, and a qubit that is set to |1> when the state is in the block. |
required |
u |
QCallable[QArray[QBit]]
|
A block encoded unitary matrix. |
required |
qvar |
QArray[QBit]
|
The quantum variable to which U is applied, which resides in the entire block encoding space. |
required |
aux |
QBit
|
A zero auxilliary qubit, used for the projector-controlled-phase rotations. Given as an inout so that qsvt can be used as a building-block in a larger algorithm. |
required |
Further reading in Classiq Library
randomized_benchmarking
reflect_about_zero
[Qmod Classiq-library function]
Reflects the state about the |0> state (i.e. applies a (-1) phase to all states
besides the |0> state). Implements the operator $S_0$:
$$
egin{equation}
S_0|{x}
angle = (-1)^{(x e0)}|{x} angle= (2|{0} angle\langle{0}|-I)|{x} angle \end{equation} $$
Args:
packed_vars: The quantum state to reflect.
single_pauli_exponent
single_pauli_exponent(
pauli_string: CArray[Pauli],
coefficient: CReal,
qbv: QArray[
QBit, Literal["get_field(pauli_string, 'len')"]
],
) -> None
[Qmod core-library function]
Exponentiates the specified single Pauli operator multiplied by some coefficient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pauli_string |
CArray[Pauli]
|
The Pauli operator to be exponentiated. |
required |
coefficient |
CReal
|
A coefficient multiplying the Pauli operator. |
required |
qbv |
QArray[QBit, Literal["get_field(pauli_string, 'len')"]]
|
The target quantum variable of the exponentiation. |
required |
suzuki_trotter
suzuki_trotter(
pauli_operator: CArray[PauliTerm],
evolution_coefficient: CReal,
order: CInt,
repetitions: CInt,
qbv: QArray[
QBit,
Literal[
"get_field(get_field(pauli_operator[0], 'pauli'), 'len')"
],
],
) -> None
[Qmod core-library function]
Applies the Suzuki-Trotter decomposition to a Pauli operator. The Suzuki-Trotter decomposition is a method for approximating the exponential of a sum of operators by a product of exponentials of each operator. The Suzuki-Trotter decomposition of a given order nullifies the error of the Taylor series expansion of the product of exponentials up to that order. The error of a Suzuki-Trotter decomposition decreases as the order and number of repetitions increase.
See N. Hatano and M. Suzuki, Finding Exponential Product Formulas of Higher Orders (2005).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pauli_operator |
CArray[PauliTerm]
|
The Pauli operator to be exponentiated. |
required |
evolution_coefficient |
CReal
|
A global evolution coefficient multiplying the Pauli operator. |
required |
order |
CInt
|
The order of the Suzuki-Trotter decomposition. |
required |
repetitions |
CInt
|
The number of repetitions of the Suzuki-Trotter decomposition. |
required |
qbv |
QArray[QBit, Literal["get_field(get_field(pauli_operator[0], 'pauli'), 'len')"]]
|
The target quantum variable of the exponentiation. |
required |
swap_test
[Qmod Classiq-library function]
Tests the overlap (in terms of fidelity) of two quantum states.
The fidelity of state1
and state2
is calculated from the probability of measuring test
qubit in the state 0 as follows:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state1 |
QArray[QBit]
|
A quantum state to check its overlap with state2. |
required |
state2 |
QArray[QBit]
|
A quantum state to check its overlap with state1. |
required |
test |
Output[QBit]
|
A qubit for which the probability of measuring 0 is \(0.5*(|\langle state1 | state2 \rangle |^2+1)\) |
required |
Example
Further reading in the Classiq library is found here.
unitary
unitary(
elements: CArray[CArray[CReal]],
target: QArray[
QBit,
Literal["log(get_field(elements[0], 'len'), 2)"],
],
) -> None
[Qmod core-library function]
Applies a unitary matrix on a quantum state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elements |
CArray[CArray[CReal]]
|
A 2d array of complex numbers representing the unitary matrix. This matrix must be unitary. |
required |
target |
QArray[QBit, Literal["log(get_field(elements[0], 'len'), 2)"]]
|
The quantum state to apply the unitary on. Should be of corresponding size. |
required |
Links: Reference Manual
enums
BUILTIN_ENUM_DECLARATIONS
BUILTIN_ENUM_DECLARATIONS = {__name__: EnumDeclaration(name=__name__, members={name: _qc2Lfor enum_val in enum_def})for enum_def in values() if isinstance(enum_def, type) and issubclass(enum_def, IntEnum) and enum_def is not IntEnum}
Element
Bases: IntEnum
Ac
Ac = 88
Ag
Ag = 46
Al
Al = 12
Am
Am = 94
Ar
Ar = 17
As
As = 32
At
At = 84
Au
Au = 78
B
B = 4
Ba
Ba = 55
Be
Be = 3
Bh
Bh = 106
Bi
Bi = 82
Bk
Bk = 96
Br
Br = 34
C
C = 5
Ca
Ca = 19
Cd
Cd = 47
Ce
Ce = 57
Cf
Cf = 97
Cl
Cl = 16
Cm
Cm = 95
Cn
Cn = 111
Co
Co = 26
Cr
Cr = 23
Cs
Cs = 54
Cu
Cu = 28
Db
Db = 104
Ds
Ds = 109
Dy
Dy = 65
Er
Er = 67
Es
Es = 98
Eu
Eu = 62
F
F = 8
Fe
Fe = 25
Fl
Fl = 113
Fm
Fm = 99
Fr
Fr = 86
Ga
Ga = 30
Gd
Gd = 63
Ge
Ge = 31
H
H = 0
He
He = 1
Hf
Hf = 71
Hg
Hg = 79
Ho
Ho = 66
Hs
Hs = 107
I
I = 52
In
In = 48
Ir
Ir = 76
K
K = 18
Kr
Kr = 35
La
La = 56
Li
Li = 2
Lr
Lr = 102
Lu
Lu = 70
Lv
Lv = 115
Mc
Mc = 114
Md
Md = 100
Mg
Mg = 11
Mn
Mn = 24
Mo
Mo = 41
Mt
Mt = 108
N
N = 6
Na
Na = 10
Nb
Nb = 40
Nd
Nd = 59
Ne
Ne = 9
Nh
Nh = 112
Ni
Ni = 27
No
No = 101
Np
Np = 92
O
O = 7
Og
Og = 117
Os
Os = 75
P
P = 14
Pa
Pa = 90
Pb
Pb = 81
Pd
Pd = 45
Pm
Pm = 60
Po
Po = 83
Pr
Pr = 58
Pt
Pt = 77
Pu
Pu = 93
Ra
Ra = 87
Rb
Rb = 36
Re
Re = 74
Rf
Rf = 103
Rg
Rg = 110
Rh
Rh = 44
Rn
Rn = 85
Ru
Ru = 43
S
S = 15
Sb
Sb = 50
Sc
Sc = 20
Se
Se = 33
Sg
Sg = 105
Si
Si = 13
Sm
Sm = 61
Sn
Sn = 49
Sr
Sr = 37
Ta
Ta = 72
Tb
Tb = 64
Tc
Tc = 42
Te
Te = 51
Th
Th = 89
Ti
Ti = 21
Tl
Tl = 80
Tm
Tm = 68
Ts
Ts = 116
U
U = 91
V
V = 22
W
W = 73
Xe
Xe = 53
Y
Y = 38
Yb
Yb = 69
Zn
Zn = 29
Zr
Zr = 39
FermionMapping
Bases: IntEnum
BRAVYI_KITAEV
BRAVYI_KITAEV = 2
FAST_BRAVYI_KITAEV
FAST_BRAVYI_KITAEV = 3
JORDAN_WIGNER
JORDAN_WIGNER = 0
PARITY
PARITY = 1
FinanceFunctionType
Bases: IntEnum
EUROPEAN_CALL_OPTION
EUROPEAN_CALL_OPTION = 3
SHORTFALL
SHORTFALL = 1
VAR
VAR = 0
X_SQUARE
X_SQUARE = 2
LadderOperator
Bases: IntEnum
MINUS
MINUS = 1
PLUS
PLUS = 0
Optimizer
Bases: IntEnum
ADAM
ADAM = 5
COBYLA
COBYLA = 1
L_BFGS_B
L_BFGS_B = 3
NELDER_MEAD
NELDER_MEAD = 4
SPSA
SPSA = 2
Pauli
Bases: IntEnum
Enumeration for the Pauli matrices used in quantum computing.
The Pauli matrices are fundamental operations in quantum computing, and this enum assigns integer values to represent each matrix.
I
I = 0
I (int): Identity matrix, represented by the integer 0.
\(I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\)
X
X = 1
X (int): Pauli-X matrix, represented by the integer 1.
\(X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\)
Y
Y = 2
Y (int): Pauli-Y matrix, represented by the integer 2.
\(Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}\)
Z
Z = 3
Z (int): Pauli-Z matrix, represented by the integer 3.
\(Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\)
QSVMFeatureMapEntanglement
Bases: IntEnum
CIRCULAR
CIRCULAR = 2
FULL
FULL = 0
LINEAR
LINEAR = 1
PAIRWISE
PAIRWISE = 4
SCA
SCA = 3
structs
BUILTIN_STRUCT_DECLARATIONS
BUILTIN_STRUCT_DECLARATIONS = {
__name__: StructDeclaration(
name=__name__,
variables={
name: convert(type)
for field in fields(struct_decl)
},
)
for struct_decl in values()
if is_dataclass(struct_decl)
}
ChemistryAtom
CombinatorialOptimizationSolution
FinanceFunction
FockHamiltonianProblem
GaussianModel
LadderTerm
LogNormalModel
MoleculeProblem
PauliTerm
A term in a Hamiltonian, represented as a product of Pauli operators.
Attributes:
Name | Type | Description |
---|---|---|
pauli |
CArray[Pauli]
|
The list of the chosen Pauli operators in the term, corresponds to a product of them. |
coefficient |
CReal
|
The coefficient of the term (floating number). |
classical_execution_primitives
CARRAY_SEPARATOR
CARRAY_SEPARATOR: Final[str] = '_'
ExecutionParams
ExecutionParams = Dict[
str, Union[float, int, List[int], List[float]]
]
batch_estimate
batch_estimate(
hamiltonian: List[QmodPyStruct],
batch_execution_params: List[ExecutionParams],
) -> EstimationResults
batch_sample
batch_sample(
batch_execution_params: List[ExecutionParams],
) -> MultipleExecutionDetails
estimate
estimate(
hamiltonian: List[QmodPyStruct],
execution_params: Optional[ExecutionParams] = None,
) -> EstimationResult
iqae
iqae(
epsilon: float,
alpha: float,
execution_params: Optional[ExecutionParams] = None,
) -> IQAEResult
molecule_ground_state_solution_post_process
molecule_ground_state_solution_post_process(
problem: QmodPyStruct, vqe_result: VQESolverResult
) -> QmodPyStruct
qae_with_qpe_result_post_processing
qae_with_qpe_result_post_processing(
estimation_register_size: int,
estimation_method: QaeWithQpeEstimationMethod,
result: ExecutionDetails,
) -> float
qsvm_full_run
qsvm_full_run(
train_data: Data,
train_labels: Labels,
test_data: Data,
test_labels: Labels,
predict_data: Data,
) -> QmodPyStruct
save
save(values_to_save: dict) -> None
vqe
vqe(
hamiltonian: List[QmodPyStruct],
maximize: bool,
initial_point: List[float],
optimizer: Optimizer,
max_iteration: int,
tolerance: float,
step_size: float,
skip_compute_variance: bool,
alpha_cvar: float,
) -> VQESolverResult
classical_functions
ChemistryAtom
CombinatorialOptimizationSolution
FinanceFunction
FockHamiltonianProblem
GaussianModel
LadderTerm
LogNormalModel
MoleculeProblem
PauliTerm
A term in a Hamiltonian, represented as a product of Pauli operators.
Attributes:
Name | Type | Description |
---|---|---|
pauli |
CArray[Pauli]
|
The list of the chosen Pauli operators in the term, corresponds to a product of them. |
coefficient |
CReal
|
The coefficient of the term (floating number). |
QSVMFeatureMapPauli
QsvmResult
fock_hamiltonian_problem_to_hamiltonian
fock_hamiltonian_problem_to_hamiltonian(
problem: FockHamiltonianProblem,
) -> CArray[PauliTerm]
gaussian_finance_post_process
gaussian_finance_post_process(
finance_model: GaussianModel,
estimation_method: FinanceFunction,
probability: CReal,
) -> CReal
grid_entangler_graph
grid_entangler_graph(
num_qubits: CInt,
schmidt_rank: CInt,
grid_randomization: CBool,
) -> CArray[CArray[CInt]]
log_normal_finance_post_process
log_normal_finance_post_process(
finance_model: LogNormalModel,
estimation_method: FinanceFunction,
probability: CReal,
) -> CReal
molecule_problem_to_hamiltonian
molecule_problem_to_hamiltonian(
problem: MoleculeProblem,
) -> CArray[PauliTerm]
qfunc
DEC_QFUNCS
DEC_QFUNCS: List[QFunc] = []
GEN_QFUNCS
GEN_QFUNCS: List[GenerativeQFunc] = []
qfunc
qfunc(
func: Optional[Callable] = None,
*,
external: bool = False,
generative: bool = False
) -> Union[Callable[[Callable], QCallable], QCallable]
set_discovered_functions
set_discovered_functions(
dec_funcs: List[QFunc], gen_funcs: List[GenerativeQFunc]
) -> None
QBit
QBit(
origin: Union[str, HandleBinding],
*,
_expr_str: Optional[str] = None,
depth: int = 2
)
Bases: QScalar
get_qmod_type
get_qmod_type() -> QuantumType
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QBit
QNum
QNum(
name: Union[str, HandleBinding],
size: Union[int, CInt, Expression, None] = None,
is_signed: Union[
bool, Expression, SymbolicExpr, None
] = None,
fraction_digits: Union[
int, CInt, Expression, None
] = None,
_expr_str: Optional[str] = None,
)
Bases: Generic[_P]
, QScalar
fraction_digits
fraction_digits: Union[CParamScalar, int]
is_signed
is_signed: Union[CParamScalar, bool]
get_qmod_type
get_qmod_type() -> QuantumType
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QNum
QArray
QArray(
name: Union[str, HandleBinding],
element_type: Union[_GenericAlias, QuantumType] = QBit,
length: Optional[
Union[int, SymbolicExpr, Expression]
] = None,
_expr_str: Optional[str] = None,
)
Bases: ArrayBase[_P]
, QVar
len
len: Union[CParamScalar, int]
get_qmod_type
get_qmod_type() -> QuantumBitvector
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QArray
CInt
CInt(expr: str)
Bases: CParam
CReal
CReal(expr: str)
Bases: CParam
CBool
CBool(expr: str)
Bases: CParam
CArray
CArray(expr: str)
Bases: CParam
, ArrayBase[_P]
len
len: int
QCallable
Bases: Generic[P]
, ABC
CURRENT_EXPANDABLE
CURRENT_EXPANDABLE: Optional[QExpandableInterface] = None
FRAME_DEPTH
FRAME_DEPTH = 1
func_decl
func_decl: AnonQuantumFunctionDeclaration
create_quantum_function_call
create_quantum_function_call(
source_ref_: SourceReference, *args: Any, **kwargs: Any
) -> QuantumFunctionCall
QCallableList
Bases: QCallable
, Generic[P]
, ABC
len
len: int
QStruct
QStruct(
name: Union[str, HandleBinding],
_struct_name: Optional[str] = None,
_fields: Optional[Mapping[str, QVar]] = None,
_expr_str: Optional[str] = None,
)
Bases: QVar
get_qmod_type
get_qmod_type() -> QuantumType
to_qmod_quantum_type
to_qmod_quantum_type(type_hint: Any) -> QuantumType
to_qvar
to_qvar(
origin: Union[str, HandleBinding],
type_hint: Any,
expr_str: Optional[str],
) -> QStruct
QConstant
QConstant(name: str, py_type: type, value: Any)
Bases: SymbolicExpr
CURRENT_QMODULE
CURRENT_QMODULE: Optional[ModelStateContainer] = None
add_to_model
add_to_model() -> None
set_current_model
set_current_model(qmodule: ModelStateContainer) -> None
cfunc
cfunc
cfunc(
func: Optional[Callable] = None,
) -> Union[Callable[[Callable], CFunc], CFunc]
get_caller_locals
get_caller_locals() -> Dict[str, Any]
Print the local variables in the caller's frame.
create_model
create_model(
entry_point: Union[QFunc, GenerativeQFunc],
constraints: Optional[Constraints] = None,
execution_preferences: Optional[
ExecutionPreferences
] = None,
preferences: Optional[Preferences] = None,
classical_execution_function: Optional[CFunc] = None,
out_file: Optional[str] = None,
) -> SerializedModel
Create a serialized model from a given Qmod entry function and additional parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_point |
Union[QFunc, GenerativeQFunc]
|
The entry point function for the model, which must be a QFunc named 'main'. |
required |
constraints |
Optional[Constraints]
|
Constraints for the synthesis of the model. See Constraints (Optional). |
None
|
execution_preferences |
Optional[ExecutionPreferences]
|
Preferences for the execution of the model. See ExecutionPreferences (Optional). |
None
|
preferences |
Optional[Preferences]
|
Preferences for the synthesis of the model. See Preferences (Optional). |
None
|
classical_execution_function |
Optional[CFunc]
|
A function for the classical execution logic, which must be a CFunc (Optional). |
None
|
out_file |
Optional[str]
|
File path to write the Qmod model in native Qmod representation to (Optional). |
None
|
Returns:
Name | Type | Description |
---|---|---|
SerializedModel |
SerializedModel
|
A serialized model. |
Raises:
Type | Description |
---|---|
ClassiqError
|
If the entry point function is not named 'main'. |
symbolic
Catalan
Catalan = SymbolicExpr('Catalan', False)
E
E = SymbolicExpr('E', False)
EulerGamma
EulerGamma = SymbolicExpr('EulerGamma', False)
GoldenRatio
GoldenRatio = SymbolicExpr('GoldenRatio', False)
I
I = SymbolicExpr('I', False)
T
T = TypeVar('T', bound=CParam)
pi
pi = SymbolicExpr('pi', False)
Piecewise
Piecewise(
*args: Tuple[SymbolicTypes, SymbolicTypes]
) -> CParamScalar
abs
abs(x: SymbolicTypes) -> CParamScalar
acos
acos(x: SymbolicTypes) -> CParamScalar
acosh
acosh(x: SymbolicTypes) -> CParamScalar
acot
acot(x: SymbolicTypes) -> CParamScalar
acoth
acoth(x: SymbolicTypes) -> CParamScalar
acsc
acsc(x: SymbolicTypes) -> CParamScalar
asec
asec(x: SymbolicTypes) -> CParamScalar
asech
asech(x: SymbolicTypes) -> CParamScalar
asin
asin(x: SymbolicTypes) -> CParamScalar
asinh
asinh(x: SymbolicTypes) -> CParamScalar
atan
atan(x: SymbolicTypes) -> CParamScalar
atanh
atanh(x: SymbolicTypes) -> CParamScalar
bell
bell(x: SymbolicTypes) -> CParamScalar
bernoulli
bernoulli(x: SymbolicTypes) -> CParamScalar
besseli
besseli(x: SymbolicTypes) -> CParamScalar
besselj
besselj(x: SymbolicTypes) -> CParamScalar
besselk
besselk(x: SymbolicTypes) -> CParamScalar
bessely
bessely(x: SymbolicTypes) -> CParamScalar
beta
beta(x: SymbolicTypes) -> CParamScalar
binomial
binomial(x: SymbolicTypes) -> CParamScalar
catalan
catalan(x: SymbolicTypes) -> CParamScalar
ceiling
ceiling(x: SymbolicTypes) -> CParamScalar
cos
cos(x: SymbolicTypes) -> CParamScalar
cosh
cosh(x: SymbolicTypes) -> CParamScalar
cot
cot(x: SymbolicTypes) -> CParamScalar
coth
coth(x: SymbolicTypes) -> CParamScalar
csc
csc(x: SymbolicTypes) -> CParamScalar
csch
csch(x: SymbolicTypes) -> CParamScalar
dirichlet_eta
dirichlet_eta(x: SymbolicTypes) -> CParamScalar
erf
erf(x: SymbolicTypes) -> CParamScalar
erfc
erfc(x: SymbolicTypes) -> CParamScalar
euler
euler(x: SymbolicTypes) -> CParamScalar
exp
exp(x: SymbolicTypes) -> CParamScalar
factorial
factorial(x: SymbolicTypes) -> CParamScalar
floor
floor(x: SymbolicTypes) -> CParamScalar
gamma
gamma(x: SymbolicTypes) -> CParamScalar
ln
ln(x: SymbolicTypes) -> CParamScalar
log
log(
x: SymbolicTypes, base: SymbolicTypes = E
) -> CParamScalar
loggamma
loggamma(x: SymbolicTypes) -> CParamScalar
logical_and
logical_and(
x: SymbolicTypes, y: SymbolicTypes
) -> SymbolicExpr
logical_not
logical_not(x: SymbolicTypes) -> SymbolicExpr
logical_or
logical_or(
x: SymbolicTypes, y: SymbolicTypes
) -> SymbolicExpr
max
max(x: SymbolicTypes, y: SymbolicTypes) -> CParamScalar
min
min(x: SymbolicTypes, y: SymbolicTypes) -> CParamScalar
mod_inverse
mod_inverse(
a: SymbolicTypes, m: SymbolicTypes
) -> CParamScalar
polygamma
polygamma(x: SymbolicTypes) -> CParamScalar
primorial
primorial(x: SymbolicTypes) -> CParamScalar
sec
sec(x: SymbolicTypes) -> CParamScalar
sech
sech(x: SymbolicTypes) -> CParamScalar
sin
sin(x: SymbolicTypes) -> CParamScalar
sinh
sinh(x: SymbolicTypes) -> CParamScalar
sqrt
sqrt(x: SymbolicTypes) -> CParamScalar
subfactorial
subfactorial(x: SymbolicTypes) -> CParamScalar
subscript
subscript(
amplitudes: Union[
List[float],
List[CReal],
List[CParamScalar],
CArray[CReal],
],
index: QNum,
) -> CParamScalar
sum
sum(arr: SymbolicTypes) -> CParamScalar
tan
tan(x: SymbolicTypes) -> CParamScalar
tanh
tanh(x: SymbolicTypes) -> CParamScalar
synthesize
synthesize(
serialized_model: SerializedModel,
auto_show: bool = False,
) -> SerializedQuantumProgram
Synthesize a model with the Classiq engine to receive a quantum program. More details
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serialized_model |
SerializedModel
|
A model object serialized as a string. |
required |
auto_show |
bool
|
boolean. whether to call |
False
|
Returns:
Name | Type | Description |
---|---|---|
SerializedQuantumProgram |
SerializedQuantumProgram
|
Quantum program serialized as a string. (See: QuantumProgram) |
execute
execute(
quantum_program: SerializedQuantumProgram,
) -> ExecutionJob
Execute a quantum program. The preferences for execution are set on the quantum program using the method set_execution_preferences
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantum_program |
SerializedQuantumProgram
|
The quantum program to execute. This is the result of the synthesize method. |
required |
Returns:
Name | Type | Description |
---|---|---|
ExecutionJob |
ExecutionJob
|
The result of the execution. |
For examples please see Execution Documentation
ExecutionSession
ExecutionSession(
quantum_program: Program,
execution_preferences: Optional[
ExecutionPreferences
] = None,
)
A session for executing a quantum program.
ExecutionSession
allows to execute the quantum program with different parameters and operations without the need to re-synthesize the model.
Attributes:
Name | Type | Description |
---|---|---|
quantum_program |
Union[SerializedQuantumProgram, QuantumProgram]
|
The quantum program to execute. |
execution_preferences |
Optional[ExecutionPreferences]
|
Execution preferences for the Quantum Program. |
qprog
qprog: SerializedQuantumProgram
Returns:
Name | Type | Description |
---|---|---|
SerializedQuantumProgram |
SerializedQuantumProgram
|
The serialized quantum program (str). See |
batch_estimate
batch_estimate(
hamiltonian: Hamiltonian,
parameters: List[ExecutionParams],
) -> List[EstimationResult]
Estimates the expectation value of the given Hamiltonian multiple times using the quantum program, with the given parameters for each iteration. The number of estimations is determined by the length of the parameters list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hamiltonian |
Hamiltonian
|
The Hamiltonian to estimate the expectation value of. |
required |
parameters |
List[ExecutionParams]
|
A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
required |
Returns:
Type | Description |
---|---|
List[EstimationResult]
|
List[EstimationResult]: The results of all the estimation iterations. |
batch_sample
batch_sample(
parameters: List[ExecutionParams],
) -> List[ExecutionDetails]
Samples the quantum program multiple times with the given parameters for each iteration. The number of samples is determined by the length of the parameters list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
List[ExecutionParams]
|
A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
required |
Returns:
Type | Description |
---|---|
List[ExecutionDetails]
|
List[ExecutionDetails]: The results of all the sampling iterations. |
estimate
estimate(
hamiltonian: Hamiltonian,
parameters: Optional[ExecutionParams] = None,
) -> EstimationResult
Estimates the expectation value of the given Hamiltonian using the quantum program.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hamiltonian |
Hamiltonian
|
The Hamiltonian to estimate the expectation value of. |
required |
parameters |
Optional[ExecutionParams]
|
The values to set for the parameters of the quantum program when estimating. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
None
|
Returns:
Name | Type | Description |
---|---|---|
EstimationResult |
EstimationResult
|
The result of the estimation. |
sample
sample(
parameters: Optional[ExecutionParams] = None,
) -> ExecutionDetails
Samples the quantum program with the given parameters, if any.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
Optional[ExecutionParams]
|
The values to set for the parameters of the quantum program when sampling. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
None
|
Returns:
Type | Description |
---|---|
ExecutionDetails
|
The result of the sampling. |
submit_batch_estimate
submit_batch_estimate(
hamiltonian: Hamiltonian,
parameters: List[ExecutionParams],
) -> ExecutionJob
Initiates an execution job with the batch_estimate
primitive.
This is a non-blocking version of batch_estimate
: it gets the same parameters and initiates the same execution job, but instead
of waiting for the result, it returns the job object immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hamiltonian |
Hamiltonian
|
The Hamiltonian to estimate the expectation value of. |
required |
parameters |
List[ExecutionParams]
|
A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
required |
Returns:
Type | Description |
---|---|
ExecutionJob
|
The execution job. |
submit_batch_sample
submit_batch_sample(
parameters: List[ExecutionParams],
) -> ExecutionJob
Initiates an execution job with the batch_sample
primitive.
This is a non-blocking version of batch_sample
: it gets the same parameters and initiates the same execution job, but instead
of waiting for the result, it returns the job object immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
List[ExecutionParams]
|
A list of the parameters for each iteration. Each item is a dictionary where each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
required |
Returns:
Type | Description |
---|---|
ExecutionJob
|
The execution job. |
submit_estimate
submit_estimate(
hamiltonian: Hamiltonian,
parameters: Optional[ExecutionParams] = None,
) -> ExecutionJob
Initiates an execution job with the estimate
primitive.
This is a non-blocking version of estimate
: it gets the same parameters and initiates the same execution job, but instead
of waiting for the result, it returns the job object immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hamiltonian |
Hamiltonian
|
The Hamiltonian to estimate the expectation value of. |
required |
parameters |
Optional[ExecutionParams]
|
The values to set for the parameters of the quantum program when estimating. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
None
|
Returns:
Type | Description |
---|---|
ExecutionJob
|
The execution job. |
submit_sample
submit_sample(
parameters: Optional[ExecutionParams] = None,
) -> ExecutionJob
Initiates an execution job with the sample
primitive.
This is a non-blocking version of sample
: it gets the same parameters and initiates the same execution job, but instead
of waiting for the result, it returns the job object immediately.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters |
Optional[ExecutionParams]
|
The values to set for the parameters of the quantum program when sampling. Each key should be the name of a parameter in the quantum program (parameters of the main function), and the value should be the value to set for that parameter. |
None
|
Returns:
Type | Description |
---|---|
ExecutionJob
|
The execution job. |
update_execution_preferences
update_execution_preferences(
execution_preferences: Optional[ExecutionPreferences],
) -> None
Update the execution preferences for the session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
execution_preferences |
Optional[ExecutionPreferences]
|
The execution preferences to update. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
set_execution_preferences
set_execution_preferences(
serialized_model: SerializedModel,
execution_preferences: Optional[
ExecutionPreferences
] = None,
**kwargs: Any
) -> SerializedModel
Overrides the execution preferences of a (serialized) model and returns the updated model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
serialized_model |
SerializedModel
|
A serialization of the defined model. |
required |
execution_preferences |
Optional[ExecutionPreferences]
|
The new execution preferences to be set for the model. Can be passed as keyword arguments. |
None
|
Returns: SerializedModel: The model with the attached execution preferences.
For more examples please see: set_execution_preferences
ExecutionPreferences
Bases: BaseModel
Represents the execution settings for running a quantum program. Execution preferences for running a quantum program.
For more details, refer to: `ExecutionPreferences example: ExecutionPreferences..
Attributes:
Name | Type | Description |
---|---|---|
noise_properties |
Optional[NoiseProperties]
|
Properties defining the noise in the quantum circuit. Defaults to |
random_seed |
int
|
The random seed used for the execution. Defaults to a randomly generated seed. |
backend_preferences |
BackendPreferencesTypes
|
Preferences for the backend used to execute the circuit. Defaults to the Classiq Simulator. |
num_shots |
Optional[PositiveInt]
|
The number of shots (executions) to be performed. |
transpile_to_hardware |
TranspilationOption
|
Option to transpile the circuit to the hardware's basis gates
before execution. Defaults to |
job_name |
Optional[str]
|
The name of the job, with a minimum length of 1 character. |
backend_preferences
backend_preferences: BackendPreferencesTypes = (
backend_preferences_field(backend_name=SIMULATOR)
)
job_name
job_name: Optional[str] = Field(
min_length=1, description="The job name"
)
noise_properties
noise_properties: Optional[NoiseProperties] = Field(
default=None,
description="Properties of the noise in the circuit",
)
num_shots
num_shots: Optional[PositiveInt] = Field(default=None)
random_seed
random_seed: int = Field(
default_factory=create_random_seed,
description="The random seed used for the execution",
)
transpile_to_hardware
transpile_to_hardware: TranspilationOption = Field(
default=DECOMPOSE,
description="Transpile the circuit to the hardware basis gates before execution",
title="Transpilation Option",
)
BackendPreferences
Bases: BaseModel
Preferences for the execution of the quantum program.
For more details, refer to: BackendPreferences
Attributes:
Name | Type | Description |
---|---|---|
backend_service_provider |
str
|
Provider company or cloud for the requested backend. |
backend_name |
str
|
Name of the requested backend or target. |
backend_name
backend_name: str = Field(
...,
description="Name of the requested backend or target.",
)
backend_service_provider
backend_service_provider: str = Field(
...,
description="Provider company or cloud for the requested backend.",
)
batch_preferences
batch_preferences(
*, backend_names: Iterable[str], **kwargs: Any
) -> List[BackendPreferences]
is_nvidia_backend
is_nvidia_backend() -> bool
validate_backend_service_provider
validate_backend_service_provider(
backend_service_provider: Any,
) -> Provider
Provider
Bases: StrEnum
This class defines all Providers that Classiq supports. This is mainly used in backend_preferences when specifying where do we want to execute the defined model.
ALICE_AND_BOB
ALICE_AND_BOB = 'Alice & Bob'
AMAZON_BRAKET
AMAZON_BRAKET = 'Amazon Braket'
AZURE_QUANTUM
AZURE_QUANTUM = 'Azure Quantum'
CLASSIQ
CLASSIQ = 'Classiq'
GOOGLE = 'Google'
IBM_QUANTUM
IBM_QUANTUM = 'IBM Quantum'
INTEL
INTEL = 'Intel'
IONQ
IONQ = 'IonQ'
OQC
OQC = 'OQC'
id
id: ProviderIDEnum
AzureBackendPreferences
Bases: BackendPreferences
This class inherits from BackendPreferences. This is where you specify Azure Quantum preferences. See usage in the Azure Backend Documentation.
Attributes:
Name | Type | Description |
---|---|---|
location |
str
|
Azure personal resource region. Defaults to |
credentials |
Optional[AzureCredential]
|
The service principal credential to access personal quantum workspace. Defaults to |
ionq_error_mitigation_flag |
Optional[bool]
|
Error mitigation configuration upon running on IonQ through Azure. Defaults to |
backend_service_provider
backend_service_provider: AZURE_QUANTUM
credentials
credentials: Optional[AzureCredential] = Field(
default=None,
description="The service principal credential to access personal quantum workspace",
)
ionq_error_mitigation_flag
ionq_error_mitigation_flag: Optional[bool] = Field(
default=False,
description="Error mitigation configuration upon running on IonQ through Azure.",
)
location
location: str = Field(
default="East US",
description="Azure personal resource region",
)
run_through_classiq
run_through_classiq: bool
Returns: True
if there are no Azure Credentials.
Therefore you will be running through Classiq's credentials.
AzureBackendPreferences
Bases: BackendPreferences
This class inherits from BackendPreferences. This is where you specify Azure Quantum preferences. See usage in the Azure Backend Documentation.
Attributes:
Name | Type | Description |
---|---|---|
location |
str
|
Azure personal resource region. Defaults to |
credentials |
Optional[AzureCredential]
|
The service principal credential to access personal quantum workspace. Defaults to |
ionq_error_mitigation_flag |
Optional[bool]
|
Error mitigation configuration upon running on IonQ through Azure. Defaults to |
backend_service_provider
backend_service_provider: AZURE_QUANTUM
credentials
credentials: Optional[AzureCredential] = Field(
default=None,
description="The service principal credential to access personal quantum workspace",
)
ionq_error_mitigation_flag
ionq_error_mitigation_flag: Optional[bool] = Field(
default=False,
description="Error mitigation configuration upon running on IonQ through Azure.",
)
location
location: str = Field(
default="East US",
description="Azure personal resource region",
)
run_through_classiq
run_through_classiq: bool
Returns: True
if there are no Azure Credentials.
Therefore you will be running through Classiq's credentials.
AzureCredential
Bases: BaseSettings
Represents the credentials and configuration required to authenticate with Azure services.
Attributes:
Name | Type | Description |
---|---|---|
tenant_id |
str
|
Azure Tenant ID used to identify the directory in which the application is registered. |
client_id |
str
|
Azure Client ID, also known as the application ID, which is used to authenticate the application. |
client_secret |
str
|
Azure Client Secret associated with the application, used for authentication. |
resource_id |
PydanticAzureResourceIDType
|
Azure Resource ID, including the subscription ID, resource group, and workspace, typically used for personal resources. |
client_id
client_id: str = Field(description='Azure Client ID')
client_secret
client_secret: str = Field(
description="Azure Client Secret"
)
resource_id
resource_id: PydanticAzureResourceIDType = Field(
description="Azure Resource ID (including Azure subscription ID, resource group and workspace), for personal resource"
)
tenant_id
tenant_id: str = Field(description='Azure Tenant ID')
Config
case_sensitive
case_sensitive = False
env_prefix
env_prefix = 'AZURE_'
title
title = 'Azure Service Principal Credential'
AzureQuantumBackendNames
Bases: StrEnum
AzureQuantum backend names which Classiq Supports running on.
IONQ_ARIA_1
IONQ_ARIA_1 = 'ionq.qpu.aria-1'
IONQ_ARIA_2
IONQ_ARIA_2 = 'ionq.qpu.aria-2'
IONQ_QPU
IONQ_QPU = 'ionq.qpu'
IONQ_QPU_FORTE
IONQ_QPU_FORTE = 'ionq.qpu.forte-1'
IONQ_SIMULATOR
IONQ_SIMULATOR = 'ionq.simulator'
MICROSOFT_ESTIMATOR
MICROSOFT_ESTIMATOR = 'microsoft.estimator'
MICROSOFT_FULLSTATE_SIMULATOR
MICROSOFT_FULLSTATE_SIMULATOR = (
"microsoft.simulator.fullstate"
)
QCI_MACHINE1
QCI_MACHINE1 = 'qci.machine1'
QCI_NOISY_SIMULATOR
QCI_NOISY_SIMULATOR = 'qci.simulator.noisy'
QCI_SIMULATOR
QCI_SIMULATOR = 'qci.simulator'
QUANTINUUM_API_VALIDATOR1_1
QUANTINUUM_API_VALIDATOR1_1 = 'quantinuum.sim.h1-1sc'
QUANTINUUM_API_VALIDATOR1_2
QUANTINUUM_API_VALIDATOR1_2 = 'quantinuum.sim.h1-2sc'
QUANTINUUM_API_VALIDATOR2_1
QUANTINUUM_API_VALIDATOR2_1 = 'quantinuum.sim.h2-1sc'
QUANTINUUM_QPU1_1
QUANTINUUM_QPU1_1 = 'quantinuum.qpu.h1-1'
QUANTINUUM_QPU1_2
QUANTINUUM_QPU1_2 = 'quantinuum.qpu.h1-2'
QUANTINUUM_QPU2
QUANTINUUM_QPU2 = 'quantinuum.qpu.h2-1'
QUANTINUUM_SIMULATOR1_1
QUANTINUUM_SIMULATOR1_1 = 'quantinuum.sim.h1-1e'
QUANTINUUM_SIMULATOR1_2
QUANTINUUM_SIMULATOR1_2 = 'quantinuum.sim.h1-2e'
QUANTINUUM_SIMULATOR2
QUANTINUUM_SIMULATOR2 = 'quantinuum.sim.h2-1e'
RIGETTI_ANKAA2
RIGETTI_ANKAA2 = 'rigetti.qpu.ankaa-2'
RIGETTI_ANKAA9
RIGETTI_ANKAA9 = 'rigetti.qpu.ankaa-9q-1'
RIGETTI_SIMULATOR
RIGETTI_SIMULATOR = 'rigetti.sim.qvm'
ClassiqBackendPreferences
Bases: BackendPreferences
Represents backend preferences specific to Classiq quantum computing targets.
This class is used to configure the backend options for executing quantum circuits on Classiq's platform.
The relevant backend names for Classiq targets are specified in ClassiqSimulatorBackendNames
& ClassiqNvidiaBackendNames
.
For more details, refer to the Classiq Backend Documentation.
backend_service_provider
backend_service_provider: CLASSIQ
is_nvidia_backend
is_nvidia_backend() -> bool
ClassiqSimulatorBackendNames
Bases: StrEnum
The simulator backends available in the Classiq provider.
SIMULATOR
SIMULATOR = 'simulator'
SIMULATOR_DENSITY_MATRIX
SIMULATOR_DENSITY_MATRIX = 'simulator_density_matrix'
SIMULATOR_MATRIX_PRODUCT_STATE
SIMULATOR_MATRIX_PRODUCT_STATE = (
"simulator_matrix_product_state"
)
SIMULATOR_STATEVECTOR
SIMULATOR_STATEVECTOR = 'simulator_statevector'
IBMBackendPreferences
Bases: BackendPreferences
Represents the backend preferences specific to IBM Quantum services.
Inherits from BackendPreferences
and adds additional fields and validations
specific to IBM Quantum backends.
Attributes:
Name | Type | Description |
---|---|---|
backend_service_provider |
IBM_QUANTUM
|
Indicates the backend service provider as IBM Quantum. |
access_token |
Optional[str]
|
The IBM Quantum access token to be used with IBM Quantum hosted backends. Defaults to |
provider |
IBMBackendProvider
|
Specifications for identifying a single IBM Quantum provider. Defaults to a new |
qctrl_api_key |
Optional[str]
|
QCTRL API key to access QCTRL optimization abilities. |
See examples in the IBM Quantum Backend Documentation.
access_token
access_token: Optional[str] = Field(
default=None,
description="IBM Quantum access token to be used with IBM Quantum hosted backends",
)
backend_service_provider
backend_service_provider: IBM_QUANTUM
provider
provider: IBMBackendProvider = Field(
default_factory=IBMBackendProvider,
description="Provider specs. for identifying a single IBM Quantum provider.",
)
qctrl_api_key
qctrl_api_key: Optional[str] = Field(
default=None,
description="QCTRL API key to access QCTRL optimization abilities",
)
IBMBackendProvider
Bases: BaseModel
Represents the provider specs for identifying an IBM Quantum backend.
Attributes:
Name | Type | Description |
---|---|---|
hub |
str
|
hub parameter of IBM Quantum provider. Defaults to |
group |
str
|
group parameter of IBM Quantum provider. Defaults to |
project |
str
|
project parameter of IBM Quantum provider. Defaults to |
group
group: str = 'open'
hub
hub: str = 'ibm-q'
project
project: str = 'main'
AwsBackendPreferences
Bases: BackendPreferences
AWS-specific backend preferences for quantum computing tasks using Amazon Braket.
This class contains configuration options specific to Amazon Braket, including the AWS role
ARN, S3 bucket details, and the folder path within the S3 bucket. It extends the base
BackendPreferences
class to provide additional properties required for interaction with
Amazon Braket.
Attributes:
Name | Type | Description |
---|---|---|
backend_service_provider |
AMAZON_BRAKET
|
The service provider for the backend, which is Amazon Braket. |
aws_role_arn |
PydanticAwsRoleArn
|
The Amazon Resource Name (ARN) of the role that will be assumed for execution on your Braket account. This is a required field and should be provided to allow secure and authorized access to AWS resources. |
s3_bucket_name |
str
|
The name of the S3 bucket where results and other related data will be stored. This field should contain a valid S3 bucket name under your AWS account. |
s3_folder |
PydanticS3BucketKey
|
The folder path within the specified S3 bucket. This allows for organizing results and data under a specific directory within the S3 bucket. |
For more details, refer to: AwsBackendPreferences examples
aws_role_arn
aws_role_arn: PydanticAwsRoleArn = Field(
description="ARN of the role to be assumed for execution on your Braket account."
)
backend_service_provider
backend_service_provider: AMAZON_BRAKET
s3_bucket_name
s3_bucket_name: str = Field(description='S3 Bucket Name')
s3_folder
s3_folder: PydanticS3BucketKey = Field(
description="S3 Folder Path Within The S3 Bucket"
)
AmazonBraketBackendNames
Bases: StrEnum
Amazon Braket backend names which Classiq Supports running on.
AMAZON_BRAKET_ASPEN_11
AMAZON_BRAKET_ASPEN_11 = 'Aspen-11'
AMAZON_BRAKET_DM1
AMAZON_BRAKET_DM1 = 'dm1'
AMAZON_BRAKET_IONQ
AMAZON_BRAKET_IONQ = 'IonQ Device'
AMAZON_BRAKET_LUCY
AMAZON_BRAKET_LUCY = 'Lucy'
AMAZON_BRAKET_M_1
AMAZON_BRAKET_M_1 = 'Aspen-M-1'
AMAZON_BRAKET_SV1
AMAZON_BRAKET_SV1 = 'SV1'
AMAZON_BRAKET_TN1
AMAZON_BRAKET_TN1 = 'TN1'
IonqBackendPreferences
Bases: BackendPreferences
Represents the backend preferences specific to IonQ services.
Inherits from BackendPreferences
and adds additional fields and configurations
specific to IonQ backends
Attributes:
Name | Type | Description |
---|---|---|
backend_service_provider |
IONQ
|
Indicates the backend service provider as IonQ. |
api_key |
PydanticIonQApiKeyType
|
The IonQ API key required for accessing IonQ's quantum computing services. |
error_mitigation |
bool
|
A configuration option to enable or disable error mitigation during execution. Defaults to |
See examples in the IonQ Backend Documentation.
api_key
api_key: PydanticIonQApiKeyType = Field(
..., description="IonQ API key"
)
backend_service_provider
backend_service_provider: IONQ
error_mitigation
error_mitigation: bool = Field(
default=False,
description="Error mitigation configuration.",
)
IonqBackendNames
Bases: StrEnum
IonQ backend names which Classiq Supports running on.
ARIA_1
ARIA_1 = 'qpu.aria-1'
ARIA_2
ARIA_2 = 'qpu.aria-2'
FORTE_1
FORTE_1 = 'qpu.forte-1'
HARMONY
HARMONY = 'qpu.harmony'
SIMULATOR
SIMULATOR = 'simulator'
ClassiqNvidiaBackendNames
Bases: StrEnum
Classiq's Nvidia simulator backend names.
SIMULATOR
SIMULATOR = 'nvidia_state_vector_simulator'
GCPBackendPreferences
Bases: BackendPreferences
Represents the backend preferences specific to Google Cloud Platform (GCP) services.
Inherits from BackendPreferences
and sets the backend service provider to Google.
Attributes:
Name | Type | Description |
---|---|---|
backend_service_provider |
GOOGLE
|
Indicates the backend service provider as Google, |
See examples in the Google Cloud Backend Documentation.
backend_service_provider
backend_service_provider: GOOGLE
is_nvidia_backend
is_nvidia_backend() -> bool
AliceBobBackendPreferences
Bases: BackendPreferences
Backend preferences specific to Alice&Bob for quantum computing tasks.
This class includes configuration options for setting up a backend using Alice&Bob's quantum hardware.
It extends the base BackendPreferences
class and provides additional parameters required for working
with Alice&Bob's cat qubits, including settings for photon dissipation rates, repetition code distance,
and the average number of photons.
Attributes:
Name | Type | Description |
---|---|---|
backend_service_provider |
ALICE_BOB
|
The service provider for the backend, which is Alice&Bob. |
distance |
Optional[int]
|
The number of times information is duplicated in the repetition code. - Tooltip: Phase-flip probability decreases exponentially with this parameter, bit-flip probability increases linearly. - Supported Values: 3 to 300, though practical values are usually lower than 30. - Default: None. |
kappa_1 |
Optional[float]
|
The rate at which the cat qubit loses one photon, creating a bit-flip. - Tooltip: Lower values mean lower error rates. - Supported Values: 10 to 10^5. Current hardware is at ~10^3. - Default: None. |
kappa_2 |
Optional[float]
|
The rate at which the cat qubit is stabilized using two-photon dissipation. - Tooltip: Higher values mean lower error rates. - Supported Values: 100 to 10^9. Current hardware is at ~10^5. - Default: None. |
average_nb_photons |
Optional[float]
|
The average number of photons. - Tooltip: Bit-flip probability decreases exponentially with this parameter, phase-flip probability increases linearly. - Supported Values: 4 to 10^5, though practical values are usually lower than 30. - Default: None. |
api_key |
str
|
The API key required to access Alice&Bob's quantum hardware. - Required: Yes. |
For more details, refer to the Alice&Bob Backend Documentation.
api_key
api_key: PydanticAliceBobApiKeyType = Field(
..., description="AliceBob API key"
)
average_nb_photons
average_nb_photons: Optional[float] = Field(
default=None, description="Average number of photons"
)
backend_service_provider
backend_service_provider: ALICE_BOB
distance
distance: Optional[int] = Field(
default=None, description="Repetition code distance"
)
kappa_1
kappa_1: Optional[float] = Field(
default=None,
description="One-photon dissipation rate (Hz)",
)
kappa_2
kappa_2: Optional[float] = Field(
default=None,
description="Two-photon dissipation rate (Hz)",
)
parameters
parameters: Dict[str, Any]
AliceBobBackendNames
Bases: StrEnum
Alice & Bob backend names which Classiq Supports running on.
LOGICAL_EARLY
LOGICAL_EARLY = 'LOGICAL_EARLY'
LOGICAL_TARGET
LOGICAL_TARGET = 'LOGICAL_TARGET'
PERFECT_QUBITS
PERFECT_QUBITS = 'PERFECT_QUBITS'
TRANSMONS
TRANSMONS = 'TRANSMONS'
OQCBackendPreferences
Bases: BackendPreferences
This class inherits from BackendPreferences
.
This is where you specify OQC preferences.
Attributes:
Name | Type | Description |
---|---|---|
username |
str
|
OQC username |
password |
str
|
OQC password |
backend_service_provider
backend_service_provider: OQC
password
password: str = Field(description='OQC password')
username
username: str = Field(description='OQC username')
OQCBackendNames
Bases: StrEnum
OQC backend names which Classiq Supports running on.
LUCY
LUCY = 'Lucy'
show
show(quantum_program: SerializedQuantumProgram) -> None
Displays the interactive representation of the quantum program in the Classiq IDE.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
quantum_program |
SerializedQuantumProgram
|
The serialized quantum program to be displayed. |
required |
Links
QuantumProgram
Bases: VersionedModel
, CircuitCodeInterface
creation_time
creation_time: str = Field(
default_factory=_get_formatted_utc_current_time
)
data
data: GeneratedCircuitData
debug_info
debug_info: Optional[List[FunctionDebugInfoInterface]]
execution_primitives_input
execution_primitives_input: Optional[PrimitivesInput] = (
Field(default=None)
)
hardware_data
hardware_data: SynthesisHardwareData
initial_values
initial_values: Optional[InitialConditions]
model
model: ExecutionModel
program_circuit
program_circuit: CircuitCodeInterface
program_id
program_id: str = Field(default_factory=get_uuid_as_str)
synthesis_duration
synthesis_duration: Optional[SynthesisStepDurations]
transpiled_circuit
transpiled_circuit: Optional[TranspiledCircuitData]
from_qprog
from_qprog(qprog: str) -> QuantumProgram
Creates a QuantumProgram
instance from a raw quantum program string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qprog |
str
|
The raw quantum program in string format. |
required |
Returns:
Name | Type | Description |
---|---|---|
QuantumProgram |
QuantumProgram
|
The |
get_registers_initialization
get_registers_initialization(
initial_values: InitialConditions,
) -> Dict[RegisterName, RegisterInitialization]
save_results
save_results(
filename: Optional[Union[str, Path]] = None
) -> None
Saves quantum program results as json into a file.
Parameters:
filename (Union[str, Path]): Optional, path + filename of file.
If filename supplied add .json
suffix.
Returns:
None
to_base_program
to_base_program() -> QuantumBaseCode
to_program
to_program(
initial_values: Optional[InitialConditions] = None,
instruction_set: Optional[QuantumInstructionSet] = None,
) -> QuantumCode
Preferences
Bases: BaseModel
Preferences for synthesizing a quantum circuit.
Attributes:
Name | Type | Description |
---|---|---|
machine_precision |
int
|
Specifies the precision used for quantum operations.
Defaults to |
backend_service_provider |
str
|
The provider company or cloud service for the
requested backend. Defaults to |
backend_name |
str
|
The name of the requested backend or target. Defaults to |
custom_hardware_settings |
CustomHardwareSettings
|
Defines custom hardware settings for optimization. This field is ignored if backend preferences are specified. |
debug_mode |
bool
|
If |
output_format |
List[QuantumFormat]
|
Lists the output format(s)
for the quantum circuit. Defaults to |
pretty_qasm |
bool
|
If |
qasm3 |
Optional[bool]
|
If |
transpilation_option |
TranspilationOption
|
Sets the transpilation option to
optimize the circuit. Defaults to |
solovay_kitaev_max_iterations |
Optional[int]
|
Specifies the
maximum number of iterations for the Solovay-Kitaev algorithm, if used.
Defaults to |
timeout_seconds |
int
|
Timeout setting for circuit synthesis
in seconds. Defaults to |
optimization_timeout_seconds |
Optional[int]
|
Specifies the
timeout for optimization in seconds, or |
random_seed |
int
|
Random seed for circuit synthesis. |
Raises:
Type | Description |
---|---|
ClassiqValueError
|
|
ValueError
|
|
backend_name
backend_name: Optional[
Union[PydanticBackendName, AllBackendsNameByVendor]
] = Field(
default=None,
description="Name of the requested backend or target.",
)
backend_preferences
backend_preferences: Optional[BackendPreferences]
Returns the backend preferences. If the backend preferences are not provided, the function sets the backend preferences according to backend name and provider.
backend_service_provider
backend_service_provider: Optional[
Union[Provider, ProviderVendor, str]
] = Field(
default=None,
description="Provider company or cloud for the requested backend.",
)
custom_hardware_settings
custom_hardware_settings: CustomHardwareSettings = Field(
default_factory=CustomHardwareSettings,
description="Custom hardware settings which will be used during optimization. This field is ignored if backend preferences are given.",
)
debug_mode
debug_mode: bool = Field(
default=True,
description="Add debug information to the synthesized result. Setting this option to False can potentially speed up the synthesis, and is recommended for executing iterative algorithms.",
)
machine_precision
machine_precision: PydanticMachinePrecision = (
DEFAULT_MACHINE_PRECISION
)
optimization_timeout_seconds
optimization_timeout_seconds: Optional[PositiveInt] = Field(
default=None,
description="Optimization timeout in seconds, or None for no optimization timeout (will still timeout when the generation timeout is over)",
)
output_format
output_format: PydanticConstrainedQuantumFormatList = Field(
default=[QASM],
description="The quantum circuit output format(s). ",
)
pretty_qasm
pretty_qasm: bool = Field(
True,
description="Prettify the OpenQASM2 outputs (use line breaks inside the gate declarations).",
)
qasm3
qasm3: Optional[bool] = Field(
None,
description="Output OpenQASM 3.0 instead of OpenQASM 2.0. Relevant only for the `qasm` and `transpiled_circuit.qasm` attributes of `GeneratedCircuit`.",
)
random_seed
random_seed: int = Field(
default_factory=create_random_seed,
description="The random seed used for the generation",
)
solovay_kitaev_max_iterations
solovay_kitaev_max_iterations: Optional[PositiveInt] = (
Field(
None,
description="Maximum iterations for the Solovay-Kitaev algorithm (if applied).",
)
)
timeout_seconds
timeout_seconds: PositiveInt = Field(
default=300, description="Generation timeout in seconds"
)
transpilation_option
transpilation_option: TranspilationOption = Field(
default=AUTO_OPTIMIZE,
description="If true, the returned result will contain a transpiled circuit and its depth",
)
make_output_format_list
make_output_format_list(output_format: Any) -> List
optimization_timeout_less_than_generation_timeout
optimization_timeout_less_than_generation_timeout(
optimization_timeout_seconds: Optional[PositiveInt],
values: Dict[str, Any],
) -> Optional[PositiveInt]
validate_backend
validate_backend(values: Dict[str, Any]) -> Dict[str, Any]
validate_backend_service_provider
validate_backend_service_provider(
backend_service_provider: Any,
) -> Optional[Provider]
validate_output_format
validate_output_format(
output_format: PydanticConstrainedQuantumFormatList,
values: Dict[str, Any],
) -> PydanticConstrainedQuantumFormatList
Constraints
Bases: BaseModel
Constraints for the quantum circuit synthesis engine.
This class is used to specify constraints such as maximum width, depth, gate count, and optimization parameters for the synthesis engine, guiding the generation of quantum circuits that satisfy these constraints.
Attributes:
Name | Type | Description |
---|---|---|
max_width |
int
|
Maximum number of qubits allowed in the generated quantum circuit.
Defaults to |
max_depth |
int
|
Maximum depth of the generated quantum circuit. Defaults to |
max_gate_count |
Dict[TranspilerBasisGates, int]
|
A dictionary specifying the maximum allowed count for each type of gate in the quantum circuit. Defaults to an empty dictionary. |
optimization_parameter |
OptimizationParameterType
|
Determines if and how the synthesis engine should optimize
the solution. Defaults to |
max_depth
max_depth: Optional[PositiveInt] = None
max_gate_count
max_gate_count: Dict[
TranspilerBasisGates, NonNegativeInt
] = Field(default_factory=lambda: defaultdict(int))
max_width
max_width: Optional[PositiveInt] = Field(
default=None,
description="Maximum number of qubits in generated quantum circuit",
)
optimization_parameter
optimization_parameter: OptimizationParameterType = Field(
default=NO_OPTIMIZATION,
description="If set, the synthesis engine optimizes the solution according to that chosen parameter",
)