classiq 0.45.1__py3-none-any.whl → 0.46.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- classiq/__init__.py +0 -1
- classiq/_internals/__init__.py +20 -0
- classiq/_internals/authentication/authentication.py +11 -0
- classiq/analyzer/analyzer.py +12 -10
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +1 -1
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +1 -1
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +1 -1
- classiq/applications/libraries/qmci_library.py +4 -9
- classiq/execution/execution_session.py +68 -7
- classiq/executor.py +14 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +189 -0
- classiq/interface/backend/quantum_backend_providers.py +38 -0
- classiq/interface/debug_info/debug_info.py +22 -2
- classiq/interface/exceptions.py +16 -1
- classiq/interface/executor/execution_preferences.py +18 -0
- classiq/interface/generator/application_apis/chemistry_declarations.py +1 -177
- classiq/interface/generator/application_apis/combinatorial_optimization_declarations.py +0 -12
- classiq/interface/generator/application_apis/finance_declarations.py +8 -43
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -78
- classiq/interface/generator/builtin_api_builder.py +0 -3
- classiq/interface/generator/functions/__init__.py +0 -2
- classiq/interface/generator/functions/builtins/__init__.py +0 -15
- classiq/interface/generator/generated_circuit_data.py +2 -0
- classiq/interface/generator/hardware/hardware_data.py +37 -0
- classiq/interface/generator/model/constraints.py +18 -1
- classiq/interface/generator/model/preferences/preferences.py +53 -1
- classiq/interface/generator/model/quantum_register.py +1 -1
- classiq/interface/generator/quantum_program.py +10 -2
- classiq/interface/generator/transpiler_basis_gates.py +4 -0
- classiq/interface/generator/types/builtin_enum_declarations.py +136 -21
- classiq/interface/generator/types/enum_declaration.py +1 -3
- classiq/interface/generator/types/struct_declaration.py +1 -3
- classiq/interface/hardware.py +5 -0
- classiq/interface/ide/visual_model.py +1 -1
- classiq/interface/model/classical_parameter_declaration.py +6 -0
- classiq/interface/model/inplace_binary_operation.py +0 -14
- classiq/interface/model/model.py +1 -18
- classiq/interface/model/port_declaration.py +4 -2
- classiq/interface/model/quantum_function_declaration.py +19 -6
- classiq/interface/model/quantum_lambda_function.py +11 -1
- classiq/interface/model/quantum_variable_declaration.py +1 -1
- classiq/model_expansions/__init__.py +0 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +250 -0
- classiq/model_expansions/capturing/__init__.py +0 -0
- classiq/model_expansions/capturing/captured_var_manager.py +50 -0
- classiq/model_expansions/capturing/mangling_utils.py +17 -0
- classiq/model_expansions/capturing/propagated_var_stack.py +180 -0
- classiq/model_expansions/closure.py +160 -0
- classiq/model_expansions/debug_flag.py +3 -0
- classiq/model_expansions/evaluators/__init__.py +0 -0
- classiq/model_expansions/evaluators/arg_type_match.py +160 -0
- classiq/model_expansions/evaluators/argument_types.py +42 -0
- classiq/model_expansions/evaluators/classical_expression.py +36 -0
- classiq/model_expansions/evaluators/control.py +144 -0
- classiq/model_expansions/evaluators/parameter_types.py +227 -0
- classiq/model_expansions/evaluators/quantum_type_utils.py +235 -0
- classiq/model_expansions/evaluators/type_type_match.py +90 -0
- classiq/model_expansions/expression_evaluator.py +125 -0
- classiq/model_expansions/expression_renamer.py +76 -0
- classiq/model_expansions/function_builder.py +192 -0
- classiq/model_expansions/generative_functions.py +101 -0
- classiq/model_expansions/interpreter.py +365 -0
- classiq/model_expansions/model_tables.py +105 -0
- classiq/model_expansions/quantum_operations/__init__.py +19 -0
- classiq/model_expansions/quantum_operations/bind.py +64 -0
- classiq/model_expansions/quantum_operations/classicalif.py +39 -0
- classiq/model_expansions/quantum_operations/control.py +235 -0
- classiq/model_expansions/quantum_operations/emitter.py +215 -0
- classiq/model_expansions/quantum_operations/expression_operation.py +218 -0
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +250 -0
- classiq/model_expansions/quantum_operations/invert.py +38 -0
- classiq/model_expansions/quantum_operations/power.py +74 -0
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +174 -0
- classiq/model_expansions/quantum_operations/quantum_function_call.py +15 -0
- classiq/model_expansions/quantum_operations/repeat.py +33 -0
- classiq/model_expansions/quantum_operations/variable_decleration.py +28 -0
- classiq/model_expansions/quantum_operations/within_apply.py +46 -0
- classiq/model_expansions/scope.py +226 -0
- classiq/model_expansions/scope_initialization.py +136 -0
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/arithmetics.py +49 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +150 -0
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +113 -0
- classiq/model_expansions/utils/__init__.py +0 -0
- classiq/model_expansions/utils/counted_name_allocator.py +11 -0
- classiq/model_expansions/visitors/__init__.py +0 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +214 -0
- classiq/model_expansions/visitors/variable_references.py +115 -0
- classiq/qmod/__init__.py +1 -3
- classiq/qmod/builtins/enums.py +33 -2
- classiq/qmod/builtins/functions/__init__.py +251 -0
- classiq/qmod/builtins/functions/amplitude_estimation.py +27 -0
- classiq/qmod/builtins/functions/arithmetic.py +68 -0
- classiq/qmod/builtins/functions/benchmarking.py +8 -0
- classiq/qmod/builtins/functions/chemistry.py +91 -0
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +105 -0
- classiq/qmod/builtins/functions/exponentiation.py +111 -0
- classiq/qmod/builtins/functions/finance.py +34 -0
- classiq/qmod/builtins/functions/grover.py +178 -0
- classiq/qmod/builtins/functions/hea.py +59 -0
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +65 -0
- classiq/qmod/builtins/functions/modular_exponentiation.py +137 -0
- classiq/qmod/builtins/functions/operators.py +22 -0
- classiq/qmod/builtins/functions/qaoa_penalty.py +116 -0
- classiq/qmod/builtins/functions/qft.py +23 -0
- classiq/qmod/builtins/functions/qpe.py +39 -0
- classiq/qmod/builtins/functions/qsvm.py +24 -0
- classiq/qmod/builtins/functions/qsvt.py +136 -0
- classiq/qmod/builtins/functions/standard_gates.py +739 -0
- classiq/qmod/builtins/functions/state_preparation.py +357 -0
- classiq/qmod/builtins/functions/swap_test.py +25 -0
- classiq/qmod/builtins/structs.py +50 -28
- classiq/qmod/cparam.py +64 -0
- classiq/qmod/create_model_function.py +190 -0
- classiq/qmod/declaration_inferrer.py +52 -81
- classiq/qmod/expression_query.py +16 -0
- classiq/qmod/generative.py +48 -0
- classiq/qmod/model_state_container.py +1 -2
- classiq/qmod/native/pretty_printer.py +7 -11
- classiq/qmod/pretty_print/pretty_printer.py +7 -11
- classiq/qmod/python_classical_type.py +67 -0
- classiq/qmod/qfunc.py +19 -4
- classiq/qmod/qmod_parameter.py +15 -64
- classiq/qmod/qmod_variable.py +27 -45
- classiq/qmod/quantum_callable.py +1 -1
- classiq/qmod/quantum_expandable.py +10 -4
- classiq/qmod/quantum_function.py +22 -40
- classiq/qmod/semantics/error_manager.py +22 -10
- classiq/qmod/semantics/static_semantics_visitor.py +10 -12
- classiq/qmod/semantics/validation/types_validation.py +6 -7
- classiq/qmod/utilities.py +2 -2
- classiq/qmod/write_qmod.py +14 -0
- classiq/show.py +10 -0
- classiq/synthesis.py +46 -2
- {classiq-0.45.1.dist-info → classiq-0.46.1.dist-info}/METADATA +1 -1
- {classiq-0.45.1.dist-info → classiq-0.46.1.dist-info}/RECORD +138 -74
- classiq/interface/generator/functions/builtins/core_library/__init__.py +0 -16
- classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +0 -710
- classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +0 -105
- classiq/interface/generator/functions/builtins/open_lib_functions.py +0 -2489
- classiq/interface/generator/functions/builtins/quantum_operators.py +0 -24
- classiq/interface/generator/types/builtin_struct_declarations/__init__.py +0 -1
- classiq/interface/generator/types/builtin_struct_declarations/pauli_struct_declarations.py +0 -21
- classiq/qmod/builtins/functions.py +0 -1029
- {classiq-0.45.1.dist-info → classiq-0.46.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
3
|
+
from classiq.qmod.builtins.enums import Pauli
|
4
|
+
from classiq.qmod.builtins.structs import (
|
5
|
+
PauliTerm,
|
6
|
+
)
|
7
|
+
from classiq.qmod.qfunc import qfunc
|
8
|
+
from classiq.qmod.qmod_parameter import CArray, CInt, CReal
|
9
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
10
|
+
|
11
|
+
|
12
|
+
@qfunc(external=True)
|
13
|
+
def single_pauli_exponent(
|
14
|
+
pauli_string: CArray[Pauli],
|
15
|
+
coefficient: CReal,
|
16
|
+
qbv: QArray[QBit, Literal["get_field(pauli_string, 'len')"]],
|
17
|
+
) -> None:
|
18
|
+
"""
|
19
|
+
[Qmod core-library function]
|
20
|
+
|
21
|
+
Exponentiates the specified single Pauli operator multiplied by some coefficient.
|
22
|
+
|
23
|
+
Args:
|
24
|
+
pauli_string: The Pauli operator to be exponentiated.
|
25
|
+
coefficient: A coefficient multiplying the Pauli operator.
|
26
|
+
qbv: The target quantum variable of the exponentiation.
|
27
|
+
"""
|
28
|
+
pass
|
29
|
+
|
30
|
+
|
31
|
+
@qfunc(external=True)
|
32
|
+
def suzuki_trotter(
|
33
|
+
pauli_operator: CArray[PauliTerm],
|
34
|
+
evolution_coefficient: CReal,
|
35
|
+
order: CInt,
|
36
|
+
repetitions: CInt,
|
37
|
+
qbv: QArray[
|
38
|
+
QBit, Literal["get_field(get_field(pauli_operator[0], 'pauli'), 'len')"]
|
39
|
+
],
|
40
|
+
) -> None:
|
41
|
+
"""
|
42
|
+
[Qmod core-library function]
|
43
|
+
|
44
|
+
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.
|
45
|
+
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.
|
46
|
+
The error of a Suzuki-Trotter decomposition decreases as the order and number of repetitions increase.
|
47
|
+
|
48
|
+
See [N. Hatano and M. Suzuki, Finding Exponential Product Formulas of Higher Orders (2005)](https://arxiv.org/abs/math-ph/0506007).
|
49
|
+
|
50
|
+
Args:
|
51
|
+
pauli_operator: The Pauli operator to be exponentiated.
|
52
|
+
evolution_coefficient: A global evolution coefficient multiplying the Pauli operator.
|
53
|
+
order: The order of the Suzuki-Trotter decomposition.
|
54
|
+
repetitions: The number of repetitions of the Suzuki-Trotter decomposition.
|
55
|
+
qbv: The target quantum variable of the exponentiation.
|
56
|
+
"""
|
57
|
+
pass
|
58
|
+
|
59
|
+
|
60
|
+
@qfunc(external=True)
|
61
|
+
def qdrift(
|
62
|
+
pauli_operator: CArray[PauliTerm],
|
63
|
+
evolution_coefficient: CReal,
|
64
|
+
num_qdrift: CInt,
|
65
|
+
qbv: QArray[
|
66
|
+
QBit, Literal["get_field(get_field(pauli_operator[0], 'pauli'), 'len')"]
|
67
|
+
],
|
68
|
+
) -> None:
|
69
|
+
"""
|
70
|
+
[Qmod core-library function]
|
71
|
+
|
72
|
+
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.
|
73
|
+
The QDrift method randomizes the order of the operators in the product of exponentials to stochastically reduce the error of the approximation.
|
74
|
+
The error of the QDrift method decreases as the number of QDrift steps increases.
|
75
|
+
|
76
|
+
See [E. Campbell, Random Compiler for Fast Hamiltonian Simulation (2019)](https://arxiv.org/abs/1811.08017).
|
77
|
+
|
78
|
+
Args:
|
79
|
+
pauli_operator: The Pauli operator to be exponentiated.
|
80
|
+
evolution_coefficient: A global evolution coefficient multiplying the Pauli operator.
|
81
|
+
num_qdrift : The number of QDrift steps.
|
82
|
+
qbv: The target quantum variable of the exponentiation.
|
83
|
+
"""
|
84
|
+
pass
|
85
|
+
|
86
|
+
|
87
|
+
@qfunc(external=True)
|
88
|
+
def exponentiation_with_depth_constraint(
|
89
|
+
pauli_operator: CArray[PauliTerm],
|
90
|
+
evolution_coefficient: CReal,
|
91
|
+
max_depth: CInt,
|
92
|
+
qbv: QArray[
|
93
|
+
QBit, Literal["get_field(get_field(pauli_operator[0], 'pauli'), 'len')"]
|
94
|
+
],
|
95
|
+
) -> None:
|
96
|
+
"""
|
97
|
+
[Qmod core-library function]
|
98
|
+
|
99
|
+
Exponentiates a Pauli operator via the Suzuki-Trotter decomposition with a depth constraint.
|
100
|
+
The Suzuki-Trotter decomposition is a method for approximating the exponential of a sum of operators by a product of exponentials of each operator.
|
101
|
+
This function automatically determines the order and number of repetitions of the Suzuki-Trotter decomposition to minimize the error given a depth constraint.
|
102
|
+
|
103
|
+
See [A. M. Childs et al., Toward the first quantum simulation with quantum speedup (2017)](https://arxiv.org/abs/1711.10980).
|
104
|
+
|
105
|
+
Args:
|
106
|
+
pauli_operator: The Pauli operator to be exponentiated.
|
107
|
+
evolution_coefficient: A global coefficient multiplying the Pauli operator.
|
108
|
+
max_depth: The maximum depth of the exponentiation.
|
109
|
+
qbv: The target quantum variable of the exponentiation.
|
110
|
+
"""
|
111
|
+
pass
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
3
|
+
from classiq.qmod.builtins.structs import (
|
4
|
+
FinanceFunction,
|
5
|
+
GaussianModel,
|
6
|
+
LogNormalModel,
|
7
|
+
)
|
8
|
+
from classiq.qmod.qfunc import qfunc
|
9
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
10
|
+
|
11
|
+
|
12
|
+
@qfunc(external=True)
|
13
|
+
def log_normal_finance(
|
14
|
+
finance_model: LogNormalModel,
|
15
|
+
finance_function: FinanceFunction,
|
16
|
+
func_port: QArray[QBit, Literal["get_field(finance_model, 'num_qubits')"]],
|
17
|
+
obj_port: QBit,
|
18
|
+
) -> None:
|
19
|
+
pass
|
20
|
+
|
21
|
+
|
22
|
+
@qfunc(external=True)
|
23
|
+
def gaussian_finance(
|
24
|
+
finance_model: GaussianModel,
|
25
|
+
finance_function: FinanceFunction,
|
26
|
+
func_port: QArray[
|
27
|
+
QBit,
|
28
|
+
Literal[
|
29
|
+
"get_field(finance_model, 'num_qubits') + get_field(get_field(finance_model, 'rhos'), 'len') + floor(log(sum(get_field(finance_model, 'loss')), 2)) + 1"
|
30
|
+
],
|
31
|
+
],
|
32
|
+
obj_port: QBit,
|
33
|
+
) -> None:
|
34
|
+
pass
|
@@ -0,0 +1,178 @@
|
|
1
|
+
from typing_extensions import Annotated
|
2
|
+
|
3
|
+
from classiq.qmod.qfunc import qfunc
|
4
|
+
from classiq.qmod.qmod_parameter import CInt
|
5
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
6
|
+
from classiq.qmod.quantum_callable import QCallable
|
7
|
+
|
8
|
+
|
9
|
+
@qfunc(external=True)
|
10
|
+
def phase_oracle(
|
11
|
+
predicate: QCallable[QArray[QBit], QBit], target: QArray[QBit]
|
12
|
+
) -> None:
|
13
|
+
"""
|
14
|
+
[Qmod Classiq-library function]
|
15
|
+
|
16
|
+
Creates a phase oracle operator based on a predicate function.
|
17
|
+
|
18
|
+
Applies a predicate function and marks "good" and "bad" states with a phase flip.
|
19
|
+
If the predicate is marked as $\\chi$, and the oracle is marked as $S_\\chi$, then:
|
20
|
+
|
21
|
+
|
22
|
+
$$
|
23
|
+
S_\\chi\\lvert x \rangle =
|
24
|
+
\begin{cases}
|
25
|
+
-\\lvert x \rangle & \text{if } \\chi(x) = 1 \\
|
26
|
+
\\phantom{-} \\lvert x \rangle & \text{if } \\chi(x) = 0
|
27
|
+
\\end{cases}
|
28
|
+
$$
|
29
|
+
|
30
|
+
Args:
|
31
|
+
predicate: A predicate function that takes a QArray of QBits and sets a single QBit |1> if the predicate is true, and |0> otherwise.
|
32
|
+
target: The target QArray of QBits to apply the phase oracle to.
|
33
|
+
|
34
|
+
Usage Examples:
|
35
|
+
[Grover Algorithm](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator/)
|
36
|
+
|
37
|
+
[Hidden shift](https://docs.classiq.io/latest/explore/algorithms/algebraic/hidden_shift/hidden_shift/)
|
38
|
+
"""
|
39
|
+
pass
|
40
|
+
|
41
|
+
|
42
|
+
@qfunc(external=True)
|
43
|
+
def reflect_about_zero(packed_vars: QArray[QBit]) -> None:
|
44
|
+
"""
|
45
|
+
[Qmod Classiq-library function]
|
46
|
+
|
47
|
+
Reflects the state about the |0> state (i.e. applies a (-1) phase to all states
|
48
|
+
besides the |0> state). Implements the operator $S_0$:
|
49
|
+
|
50
|
+
$$
|
51
|
+
\begin{equation}
|
52
|
+
S_0|{x}\rangle = (-1)^{(x\ne0)}|{x}\rangle= (2|{0}\rangle\\langle{0}|-I)|{x}\rangle
|
53
|
+
\\end{equation}
|
54
|
+
$$
|
55
|
+
|
56
|
+
Args:
|
57
|
+
packed_vars: The quantum state to reflect.
|
58
|
+
"""
|
59
|
+
pass
|
60
|
+
|
61
|
+
|
62
|
+
@qfunc(external=True)
|
63
|
+
def grover_diffuser(
|
64
|
+
space_transform: QCallable[QArray[QBit]], packed_vars: QArray[QBit]
|
65
|
+
) -> None:
|
66
|
+
"""
|
67
|
+
[Qmod Classiq-library function]
|
68
|
+
|
69
|
+
Reflects the given state about the A|0> state, where A
|
70
|
+
is the `space_transform` parameter. It is defined as:
|
71
|
+
|
72
|
+
$$
|
73
|
+
\begin{equation}
|
74
|
+
D = A S_0 A^{\\dagger}
|
75
|
+
\\end{equation}
|
76
|
+
$$
|
77
|
+
|
78
|
+
where $S_0$ is the reflection about the |0> state (see `reflect_about_zero`).
|
79
|
+
|
80
|
+
Args:
|
81
|
+
space_transform: The operator which encodes the axis of reflection.
|
82
|
+
packed_vars: The state to which to apply the diffuser.
|
83
|
+
"""
|
84
|
+
pass
|
85
|
+
|
86
|
+
|
87
|
+
@qfunc(external=True)
|
88
|
+
def grover_operator(
|
89
|
+
oracle: QCallable[QArray[QBit]],
|
90
|
+
space_transform: QCallable[QArray[QBit]],
|
91
|
+
packed_vars: QArray[QBit],
|
92
|
+
) -> None:
|
93
|
+
"""
|
94
|
+
[Qmod Classiq-library function]
|
95
|
+
|
96
|
+
Applies the grover operator, defined by:
|
97
|
+
|
98
|
+
$$
|
99
|
+
Q=S_{\\psi_0}S_{\\psi_1}
|
100
|
+
$$
|
101
|
+
|
102
|
+
where $S_{\\psi_1}$ is a reflection about marked states, and $S_{\\psi_0}$ is a reflection
|
103
|
+
about a given state defined by $|\\psi_0\rangle = A|0\rangle$.
|
104
|
+
|
105
|
+
|
106
|
+
Args:
|
107
|
+
oracle: A unitary operator which adds a phase of (-1) to marked states.
|
108
|
+
space_transform: The operator which creates $|\\psi_0\rangle$, the initial state, used by the diffuser to reflect about it.
|
109
|
+
packed_vars: The state to which to apply the grover operator.
|
110
|
+
|
111
|
+
|
112
|
+
For further reading, see:
|
113
|
+
|
114
|
+
- [The Grover Operator notebook](../explore/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator/)
|
115
|
+
- [Wikipedia page](https://en.wikipedia.org/wiki/Grover%27s_algorithm).
|
116
|
+
|
117
|
+
"""
|
118
|
+
pass
|
119
|
+
|
120
|
+
|
121
|
+
@qfunc(external=True)
|
122
|
+
def grover_search(
|
123
|
+
reps: CInt, oracle: QCallable[QArray[QBit]], packed_vars: QArray[QBit]
|
124
|
+
) -> None:
|
125
|
+
"""
|
126
|
+
[Qmod Classiq-library function]
|
127
|
+
|
128
|
+
Applies Grover search algorithm.
|
129
|
+
|
130
|
+
Args:
|
131
|
+
reps: Number of repetitions of the grover operator.
|
132
|
+
oracle: An oracle that marks the solution.
|
133
|
+
packed_vars: Packed form of the variable to apply the grover operator on.
|
134
|
+
|
135
|
+
Returns: None
|
136
|
+
|
137
|
+
Links:
|
138
|
+
[Grover Algorithm](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/grover_operator/grover_operator/)
|
139
|
+
|
140
|
+
"""
|
141
|
+
pass
|
142
|
+
|
143
|
+
|
144
|
+
@qfunc(external=True)
|
145
|
+
def hadamard_transform(target: QArray[QBit]) -> None:
|
146
|
+
"""
|
147
|
+
[Qmod Classiq-library function]
|
148
|
+
|
149
|
+
Applies Hadamard transform to the target qubits.
|
150
|
+
|
151
|
+
Corresponds to the braket notation:
|
152
|
+
|
153
|
+
$$
|
154
|
+
H^{\\otimes n} |x\rangle = \frac{1}{\\sqrt{2^n}} \\sum_{y=0}^{2^n - 1} (-1)^{x \\cdot y} |y\rangle
|
155
|
+
$$
|
156
|
+
|
157
|
+
Args:
|
158
|
+
target: qubits to apply to Hadamard transform to.
|
159
|
+
|
160
|
+
"""
|
161
|
+
pass
|
162
|
+
|
163
|
+
|
164
|
+
@qfunc(external=True)
|
165
|
+
def apply_to_all(
|
166
|
+
gate_operand: QCallable[Annotated[QBit, "target"]], target: QArray[QBit]
|
167
|
+
) -> None:
|
168
|
+
"""
|
169
|
+
[Qmod Classiq-library function]
|
170
|
+
|
171
|
+
Applies the single-qubit operand `gate_operand` to each qubit in the qubit
|
172
|
+
array `target`.
|
173
|
+
|
174
|
+
Args:
|
175
|
+
gate_operand: The single-qubit gate to apply to each qubit in the array.
|
176
|
+
target: The qubit array to apply the gate to.
|
177
|
+
"""
|
178
|
+
pass
|
@@ -0,0 +1,59 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
3
|
+
from typing_extensions import Annotated
|
4
|
+
|
5
|
+
from classiq.qmod.qfunc import qfunc
|
6
|
+
from classiq.qmod.qmod_parameter import CArray, CInt, CReal
|
7
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
8
|
+
from classiq.qmod.quantum_callable import QCallableList
|
9
|
+
|
10
|
+
|
11
|
+
@qfunc(external=True)
|
12
|
+
def full_hea(
|
13
|
+
num_qubits: CInt,
|
14
|
+
is_parametrized: CArray[CInt],
|
15
|
+
angle_params: CArray[CReal],
|
16
|
+
connectivity_map: CArray[CArray[CInt]],
|
17
|
+
reps: CInt,
|
18
|
+
operands_1qubit: QCallableList[Annotated[CReal, "angle"], Annotated[QBit, "q"]],
|
19
|
+
operands_2qubit: QCallableList[
|
20
|
+
Annotated[CReal, "angle"], Annotated[QBit, "q1"], Annotated[QBit, "q2"]
|
21
|
+
],
|
22
|
+
x: QArray[QBit, Literal["num_qubits"]],
|
23
|
+
) -> None:
|
24
|
+
"""
|
25
|
+
[Qmod Classiq-library function]
|
26
|
+
|
27
|
+
Implements an ansatz on a qubit array `x` with the given 1-qubit and 2-qubit operations.
|
28
|
+
|
29
|
+
The number of ansatz layers is given in argument `reps`.
|
30
|
+
Each layer applies the 1-qubit operands in `operands_1qubit` to all the qubits in `x`.
|
31
|
+
Next, it applies the 2-qubit operands in `operands_2qubit` to qubits (i, j) for each
|
32
|
+
pair of indices (i, j) in `connectivity_map`.
|
33
|
+
|
34
|
+
The list `is_parametrized` specifies whether the operands in `operands_1qubit` and
|
35
|
+
`operands_2qubit` are parametric (expect a classical argument).
|
36
|
+
`is_parametrized` is a list of flags (0 and 1 integers) of length
|
37
|
+
`len(operands_1qubit) + len(operands_2qubit)`.
|
38
|
+
The first `len(operands_1qubit)` flags refer to the `operands_1qubit` operands and
|
39
|
+
the next `len(operands_2qubit)` flags refer to the `operands_2qubit` operands.
|
40
|
+
|
41
|
+
The classical arguments to the parametric operands are given in argument
|
42
|
+
`angle_params`.
|
43
|
+
`angle_params` concatenates a set of arguments for each ansatz layer.
|
44
|
+
Each set contains an argument for each qubit in `x` times the number
|
45
|
+
of parametric operands in `operands_1qubit`.
|
46
|
+
These are followed by an argument for each mapping pair in `connectivity_map` times
|
47
|
+
the number of parametric operands in `operands_2qubit`.
|
48
|
+
|
49
|
+
Args:
|
50
|
+
num_qubits: The length of qubit array x
|
51
|
+
is_parametrized: A list of 0 and 1 flags
|
52
|
+
angle_params A list of arguments to gate
|
53
|
+
connectivity_map: A list of pairs of qubit indices
|
54
|
+
reps: The number of ansatz layers
|
55
|
+
operands_1qubit: A list of operations on a single qubit
|
56
|
+
operands_2qubit: A list of operations on two qubits
|
57
|
+
x: The quantum object to be transformed by the ansatz
|
58
|
+
"""
|
59
|
+
pass
|
@@ -0,0 +1,65 @@
|
|
1
|
+
from typing_extensions import Annotated
|
2
|
+
|
3
|
+
from classiq.qmod.builtins.enums import Pauli
|
4
|
+
from classiq.qmod.qfunc import qfunc
|
5
|
+
from classiq.qmod.qmod_parameter import CArray, CReal
|
6
|
+
from classiq.qmod.qmod_variable import QArray, QBit
|
7
|
+
from classiq.qmod.quantum_callable import QCallable
|
8
|
+
|
9
|
+
|
10
|
+
@qfunc(external=True)
|
11
|
+
def _single_pauli(
|
12
|
+
slope: CReal,
|
13
|
+
offset: CReal,
|
14
|
+
q1_qfunc: QCallable[Annotated[CReal, "theta"], Annotated[QBit, "target"]],
|
15
|
+
x: QArray[QBit],
|
16
|
+
q: QBit,
|
17
|
+
) -> None:
|
18
|
+
pass
|
19
|
+
|
20
|
+
|
21
|
+
@qfunc(external=True)
|
22
|
+
def linear_pauli_rotations(
|
23
|
+
bases: CArray[Pauli],
|
24
|
+
slopes: CArray[CReal],
|
25
|
+
offsets: CArray[CReal],
|
26
|
+
x: QArray[QBit],
|
27
|
+
q: QArray[QBit],
|
28
|
+
) -> None:
|
29
|
+
"""
|
30
|
+
[Qmod Classiq-library function]
|
31
|
+
|
32
|
+
Performs a rotation on a series of $m$ target qubits,
|
33
|
+
where the rotation angle is a linear function of an $n$-qubit
|
34
|
+
control register.
|
35
|
+
|
36
|
+
Corresponds to the braket notation:
|
37
|
+
|
38
|
+
$$
|
39
|
+
\\left|x\right\rangle _{n}\\left|q\right\rangle
|
40
|
+
_{m}\rightarrow\\left|x\right\rangle
|
41
|
+
_{n}\\prod_{k=1}^{m}\\left(\\cos\\left(\frac{a_{k}}{2}x+\frac{b_{k}}{2}\right)-
|
42
|
+
i\\sin\\left(\frac{a_{k}}{2}x+\frac{b_{k}}{2}\right)P_{k}\right)\\left|q_{k}\right\rangle
|
43
|
+
$$
|
44
|
+
|
45
|
+
where $\\left|x\right\rangle$ is the control register,
|
46
|
+
$\\left|q\right\rangle$ is the target register, each $P_{k}$ is one of
|
47
|
+
the three Pauli matrices $X$, $Y$, or $Z$, and $a_{k}$, $b_{k}$ are
|
48
|
+
the user given slopes and offsets, respectively.
|
49
|
+
|
50
|
+
Args:
|
51
|
+
bases: List of Pauli Enums.
|
52
|
+
slopes: Rotation slopes for each of the given Pauli bases.
|
53
|
+
offsets: Rotation offsets for each of the given Pauli bases.
|
54
|
+
x: Quantum state to apply the rotation based on its value.
|
55
|
+
q: List of indicator qubits for each of the given Pauli bases.
|
56
|
+
|
57
|
+
Notice that bases, slopes, offset and q should be of the same size.
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
Links:
|
62
|
+
[linear_pauli_rotations](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/linear_pauli_rotations/linear_pauli_rotations)
|
63
|
+
"""
|
64
|
+
|
65
|
+
pass
|
@@ -0,0 +1,137 @@
|
|
1
|
+
from classiq.qmod.qfunc import qfunc
|
2
|
+
from classiq.qmod.qmod_parameter import CInt
|
3
|
+
from classiq.qmod.qmod_variable import QArray, QBit, QNum
|
4
|
+
|
5
|
+
|
6
|
+
@qfunc(external=True)
|
7
|
+
def qft_no_swap(qbv: QArray[QBit]) -> None:
|
8
|
+
"""
|
9
|
+
[Qmod Classiq-library function]
|
10
|
+
|
11
|
+
Applies the Quantum Fourier Transform (QFT) without the swap gates.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
qbv: The quantum number to which the QFT is applied.
|
15
|
+
|
16
|
+
"""
|
17
|
+
pass
|
18
|
+
|
19
|
+
|
20
|
+
@qfunc(external=True)
|
21
|
+
def _check_msb(ref: CInt, x: QArray[QBit], aux: QBit) -> None:
|
22
|
+
pass
|
23
|
+
|
24
|
+
|
25
|
+
@qfunc(external=True)
|
26
|
+
def _ctrl_x(ref: CInt, ctrl: QNum, aux: QBit) -> None:
|
27
|
+
pass
|
28
|
+
|
29
|
+
|
30
|
+
@qfunc(external=True)
|
31
|
+
def qft_space_add_const(value: CInt, phi_b: QArray[QBit]) -> None:
|
32
|
+
"""
|
33
|
+
[Qmod Classiq-library function]
|
34
|
+
|
35
|
+
Adds a constant to a quantum number (in the Fourier space) using the Quantum Fourier Transform (QFT) Adder algorithm.
|
36
|
+
Assuming that the input `phi_b` has `n` qubits, the result will be $\\phi_b+=value \\mod 2^n$.
|
37
|
+
|
38
|
+
To perform the full algorithm, use:
|
39
|
+
within_apply(lambda: QFT(phi_b), qft_space_add_const(value, phi_b))
|
40
|
+
|
41
|
+
Args:
|
42
|
+
value: The constant to add to the quantum number.
|
43
|
+
phi_b: The quantum number (at the aft space) to which the constant is added.
|
44
|
+
|
45
|
+
"""
|
46
|
+
pass
|
47
|
+
|
48
|
+
|
49
|
+
@qfunc(external=True)
|
50
|
+
def cc_modular_add(n: CInt, a: CInt, phi_b: QArray[QBit], c1: QBit, c2: QBit) -> None:
|
51
|
+
"""
|
52
|
+
[Qmod Classiq-library function]
|
53
|
+
|
54
|
+
Adds a constant `a` to a quantum number `phi_b` modulo the constant `n`, controlled by 2 qubits.
|
55
|
+
The quantum number `phi_b` and the constant `a` are assumed to be in the QFT space.
|
56
|
+
|
57
|
+
Args:
|
58
|
+
n: The modulo number.
|
59
|
+
a: The constant to add to the quantum number.
|
60
|
+
phi_b: The quantum number to which the constant is added.
|
61
|
+
c1: a control qubit.
|
62
|
+
c2: a control qubit.
|
63
|
+
|
64
|
+
"""
|
65
|
+
pass
|
66
|
+
|
67
|
+
|
68
|
+
@qfunc(external=True)
|
69
|
+
def c_modular_multiply(
|
70
|
+
n: CInt, a: CInt, b: QArray[QBit], x: QArray[QBit], ctrl: QBit
|
71
|
+
) -> None:
|
72
|
+
"""
|
73
|
+
[Qmod Classiq-library function]
|
74
|
+
|
75
|
+
Performs out-of-place multiplication of a quantum number `x` by a classical number `a` modulo classical number `n`,
|
76
|
+
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.
|
77
|
+
|
78
|
+
Args:
|
79
|
+
n: The modulo number. Should be non-negative.
|
80
|
+
a: The classical factor. Should be non-negative.
|
81
|
+
b: The quantum number added to the multiplication result. Stores the result of the multiplication.
|
82
|
+
x: The quantum factor.
|
83
|
+
ctrl: The control bit.
|
84
|
+
"""
|
85
|
+
pass
|
86
|
+
|
87
|
+
|
88
|
+
@qfunc(external=True)
|
89
|
+
def multiswap(x: QArray[QBit], y: QArray[QBit]) -> None:
|
90
|
+
"""
|
91
|
+
[Qmod Classiq-library function]
|
92
|
+
|
93
|
+
Swaps the qubit states between two arrays.
|
94
|
+
Qubits of respective indices are swapped, and additional qubits in the longer array are left unchanged.
|
95
|
+
|
96
|
+
Args:
|
97
|
+
x: The first array
|
98
|
+
y: The second array
|
99
|
+
|
100
|
+
"""
|
101
|
+
pass
|
102
|
+
|
103
|
+
|
104
|
+
@qfunc(external=True)
|
105
|
+
def inplace_c_modular_multiply(n: CInt, a: CInt, x: QArray[QBit], ctrl: QBit) -> None:
|
106
|
+
"""
|
107
|
+
[Qmod Classiq-library function]
|
108
|
+
|
109
|
+
Performs multiplication of a quantum number `x` by a classical number `a` modulo classical number `n`,
|
110
|
+
controlled by a quantum bit `ctrl`. Applies $x=xa \\mod n$ if `ctrl=1`, and the identity otherwise.
|
111
|
+
|
112
|
+
Args:
|
113
|
+
n: The modulo number. Should be non-negative.
|
114
|
+
a: The classical factor. Should be non-negative.
|
115
|
+
x: The quantum factor.
|
116
|
+
ctrl: The control bit.
|
117
|
+
"""
|
118
|
+
pass
|
119
|
+
|
120
|
+
|
121
|
+
@qfunc(external=True)
|
122
|
+
def modular_exp(n: CInt, a: CInt, x: QArray[QBit], power: QArray[QBit]) -> None:
|
123
|
+
"""
|
124
|
+
[Qmod Classiq-library function]
|
125
|
+
|
126
|
+
Raises a classical integer `a` to the power of a quantum number `x` modulo classical integer `n`
|
127
|
+
times a quantum number `power`. Performs $power=(a^x \\mod n)*power$ in-place.
|
128
|
+
(and specifically if at the input $power=1$, at the output $power=a^x \\mod n$).
|
129
|
+
|
130
|
+
Args:
|
131
|
+
n: The modulus number. Should be non-negative.
|
132
|
+
a: The base of the exponentiation. Should be non-negative.
|
133
|
+
x: The power of the exponentiation.
|
134
|
+
power: A quantum number which multiplies the modular exponentiation and holds the output.
|
135
|
+
|
136
|
+
"""
|
137
|
+
pass
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from classiq.qmod.cparam import CInt
|
2
|
+
from classiq.qmod.qfunc import qfunc
|
3
|
+
from classiq.qmod.quantum_callable import QCallable, QCallableList
|
4
|
+
|
5
|
+
|
6
|
+
@qfunc(external=True)
|
7
|
+
def permute(
|
8
|
+
functions: QCallableList,
|
9
|
+
) -> None:
|
10
|
+
pass
|
11
|
+
|
12
|
+
|
13
|
+
@qfunc(external=True)
|
14
|
+
def apply(
|
15
|
+
operand: QCallable,
|
16
|
+
) -> None:
|
17
|
+
pass
|
18
|
+
|
19
|
+
|
20
|
+
@qfunc(external=True)
|
21
|
+
def switch(selector: CInt, cases: QCallableList) -> None:
|
22
|
+
pass
|