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,357 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
3
|
+
from classiq.qmod.cparam import CArray, CBool, CInt, CReal
|
4
|
+
from classiq.qmod.qfunc import qfunc
|
5
|
+
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum
|
6
|
+
|
7
|
+
|
8
|
+
@qfunc(external=True)
|
9
|
+
def allocate(
|
10
|
+
num_qubits: CInt, out: Output[QArray[QBit, Literal["num_qubits"]]]
|
11
|
+
) -> None:
|
12
|
+
"""
|
13
|
+
[Qmod core-library function]
|
14
|
+
|
15
|
+
Allocates the specified number of qubits to a given quantum variable and initializes
|
16
|
+
them in the zero state:
|
17
|
+
|
18
|
+
$$
|
19
|
+
\\left|\\text{out}\\right\\rangle = \\left|0\\right\\rangle^{\\otimes \\text{num_qubits}}
|
20
|
+
$$
|
21
|
+
|
22
|
+
Args:
|
23
|
+
num_qubits: The number of qubits to allocate. Must be a positive integer.
|
24
|
+
out: The quantum variable that will receive the allocated qubits. Must be uninitialized before allocation. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
25
|
+
|
26
|
+
Notes:
|
27
|
+
1. If the output variable has been declared with a specific number of qubits, the number of qubits allocated must match the declared number.
|
28
|
+
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
29
|
+
|
30
|
+
"""
|
31
|
+
pass
|
32
|
+
|
33
|
+
|
34
|
+
@qfunc(external=True)
|
35
|
+
def allocate_num(
|
36
|
+
num_qubits: CInt,
|
37
|
+
is_signed: CBool,
|
38
|
+
fraction_digits: CInt,
|
39
|
+
out: Output[
|
40
|
+
QNum[Literal["num_qubits"], Literal["is_signed"], Literal["fraction_digits"]]
|
41
|
+
],
|
42
|
+
) -> None:
|
43
|
+
"""
|
44
|
+
[Qmod Classiq-library function]
|
45
|
+
|
46
|
+
Initializes a quantum number with the given number of qubits, sign, and fractional digits.
|
47
|
+
|
48
|
+
Args:
|
49
|
+
num_qubits: The number of qubits to allocate.
|
50
|
+
is_signed: Whether the number is signed or unsigned.
|
51
|
+
fraction_digits: The number of fractional digits.
|
52
|
+
|
53
|
+
Further reading is available on the [reference manual](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-types#allocate-num)
|
54
|
+
|
55
|
+
"""
|
56
|
+
pass
|
57
|
+
|
58
|
+
|
59
|
+
@qfunc(external=True)
|
60
|
+
def free(in_: Input[QArray[QBit]]) -> None:
|
61
|
+
"""
|
62
|
+
[Qmod core-library function]
|
63
|
+
|
64
|
+
Releases the qubits allocated to a quantum variable, allowing them to be reused.
|
65
|
+
|
66
|
+
Args:
|
67
|
+
in_: The quantum variable that will be freed. Must be initialized before. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
68
|
+
|
69
|
+
Note:
|
70
|
+
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.
|
71
|
+
"""
|
72
|
+
pass
|
73
|
+
|
74
|
+
|
75
|
+
@qfunc(external=True)
|
76
|
+
def prepare_state(
|
77
|
+
probabilities: CArray[CReal],
|
78
|
+
bound: CReal,
|
79
|
+
out: Output[QArray[QBit, Literal["log(get_field(probabilities, 'len'), 2)"]]],
|
80
|
+
) -> None:
|
81
|
+
"""
|
82
|
+
[Qmod core-library function]
|
83
|
+
|
84
|
+
Initializes a quantum variable in a state corresponding to a given probability distribution:
|
85
|
+
|
86
|
+
$$
|
87
|
+
\\left|\\text{out}\\right\\rangle = \\sum_{i=0}^{\\text{len(probabilities)}-1} \\sqrt{\\text{probabilities}[i]} \\left|i\\right\\rangle
|
88
|
+
$$
|
89
|
+
|
90
|
+
with $i = 0, 1, 2, ..., \\text{len(amplitudes)}-1$ corresponding to computational basis states.
|
91
|
+
|
92
|
+
Args:
|
93
|
+
probabilities: 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).
|
94
|
+
bound: 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.
|
95
|
+
out: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
96
|
+
|
97
|
+
Notes:
|
98
|
+
1. 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.
|
99
|
+
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
100
|
+
|
101
|
+
"""
|
102
|
+
pass
|
103
|
+
|
104
|
+
|
105
|
+
@qfunc(external=True)
|
106
|
+
def prepare_amplitudes(
|
107
|
+
amplitudes: CArray[CReal],
|
108
|
+
bound: CReal,
|
109
|
+
out: Output[QArray[QBit, Literal["log(get_field(amplitudes, 'len'), 2)"]]],
|
110
|
+
) -> None:
|
111
|
+
"""
|
112
|
+
[Qmod core-library function]
|
113
|
+
|
114
|
+
Initializes a quantum variable in a state corresponding to the given amplitudes:
|
115
|
+
|
116
|
+
$$
|
117
|
+
\\left|\\text{out}\\right\\rangle = \\sum_{i=0}^{\\text{len(amplitudes)}-1} \\text{amplitudes}[i] \\left|i\\right\\rangle
|
118
|
+
$$
|
119
|
+
|
120
|
+
with $i = 0, 1, 2, ..., \\text{len(amplitudes)}-1$ corresponding to computational basis states.
|
121
|
+
|
122
|
+
Args:
|
123
|
+
amplitudes: 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).
|
124
|
+
bound: 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.
|
125
|
+
out: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
126
|
+
|
127
|
+
Notes:
|
128
|
+
1. 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.
|
129
|
+
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
130
|
+
|
131
|
+
"""
|
132
|
+
pass
|
133
|
+
|
134
|
+
|
135
|
+
@qfunc(external=True)
|
136
|
+
def inplace_prepare_state(
|
137
|
+
probabilities: CArray[CReal],
|
138
|
+
bound: CReal,
|
139
|
+
target: QArray[QBit, Literal["log(get_field(probabilities, 'len'), 2)"]],
|
140
|
+
) -> None:
|
141
|
+
"""
|
142
|
+
[Qmod core-library function]
|
143
|
+
|
144
|
+
Transforms a given quantum variable in the state |0> to the state per the specified probability distribution
|
145
|
+
(similar to `prepare_state` but preformed on an initialized variable).
|
146
|
+
|
147
|
+
Args:
|
148
|
+
probabilities: 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).
|
149
|
+
bound: 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.
|
150
|
+
target: The quantum variable to act upon.
|
151
|
+
|
152
|
+
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.
|
153
|
+
|
154
|
+
"""
|
155
|
+
pass
|
156
|
+
|
157
|
+
|
158
|
+
@qfunc(external=True)
|
159
|
+
def inplace_prepare_amplitudes(
|
160
|
+
amplitudes: CArray[CReal],
|
161
|
+
bound: CReal,
|
162
|
+
target: QArray[QBit, Literal["log(get_field(amplitudes, 'len'), 2)"]],
|
163
|
+
) -> None:
|
164
|
+
"""
|
165
|
+
[Qmod core-library function]
|
166
|
+
|
167
|
+
Transforms a given quantum variable in the state |0> to the state per the specified amplitudes
|
168
|
+
(similar to `prepare_amplitudes` but preformed on an initialized variable).
|
169
|
+
|
170
|
+
Args:
|
171
|
+
amplitudes: 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).
|
172
|
+
bound: 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.
|
173
|
+
target: The quantum variable to act upon.
|
174
|
+
|
175
|
+
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.
|
176
|
+
|
177
|
+
"""
|
178
|
+
pass
|
179
|
+
|
180
|
+
|
181
|
+
@qfunc(external=True)
|
182
|
+
def _prepare_uniform_trimmed_state_step(
|
183
|
+
size_lsb: CInt, ctrl_val: CInt, lsbs_val: CInt, ctrl_var: QNum, rotation_var: QBit
|
184
|
+
) -> None:
|
185
|
+
pass
|
186
|
+
|
187
|
+
|
188
|
+
@qfunc(external=True)
|
189
|
+
def prepare_uniform_trimmed_state(m: CInt, q: QArray[QBit]) -> None:
|
190
|
+
"""
|
191
|
+
[Qmod Classiq-library function]
|
192
|
+
|
193
|
+
Initializes a quantum variable in a uniform superposition of the first `m` computational basis states:
|
194
|
+
|
195
|
+
$$
|
196
|
+
\\left|\\text{q}\\right\\rangle = \\frac{1}{\\sqrt{m}}\\sum_{i=0}^{m-1}{|i\\rangle}
|
197
|
+
$$
|
198
|
+
|
199
|
+
The number of allocated qubits would be $\\left\\lceil\\log_2{m}\\right\\rceil$.
|
200
|
+
The function is especially useful when `m` is not a power of 2.
|
201
|
+
|
202
|
+
Args:
|
203
|
+
m: The number of states to load in the superposition.
|
204
|
+
q: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
205
|
+
|
206
|
+
Notes:
|
207
|
+
1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
|
208
|
+
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
209
|
+
"""
|
210
|
+
pass
|
211
|
+
|
212
|
+
|
213
|
+
@qfunc(external=True)
|
214
|
+
def prepare_uniform_interval_state(start: CInt, end: CInt, q: QArray[QBit]) -> None:
|
215
|
+
"""
|
216
|
+
[Qmod Classiq-library function]
|
217
|
+
|
218
|
+
Initializes a quantum variable in a uniform superposition of the specified interval in the computational basis states:
|
219
|
+
|
220
|
+
$$
|
221
|
+
\\left|\\text{q}\\right\\rangle = \\frac{1}{\\sqrt{\\text{end} - \\text{start}}}\\sum_{i=\\text{start}}^{\\text{end}-1}{|i\\rangle}
|
222
|
+
$$
|
223
|
+
|
224
|
+
The number of allocated qubits would be $\\left\\lceil\\log_2{\\left(\\text{end}\\right)}\\right\\rceil$.
|
225
|
+
|
226
|
+
Args:
|
227
|
+
start: The lower bound of the interval to load (inclusive).
|
228
|
+
end: The upper bound of the interval to load (exclusive).
|
229
|
+
q: The quantum variable that will receive the initialized state. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
230
|
+
|
231
|
+
Notes:
|
232
|
+
1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
|
233
|
+
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
234
|
+
"""
|
235
|
+
pass
|
236
|
+
|
237
|
+
|
238
|
+
@qfunc(external=True)
|
239
|
+
def prepare_ghz_state(size: CInt, q: Output[QArray[QBit]]) -> None:
|
240
|
+
"""
|
241
|
+
[Qmod Classiq-library function]
|
242
|
+
|
243
|
+
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..
|
244
|
+
|
245
|
+
Args:
|
246
|
+
size: The number of qubits in the GHZ state. Must be a positive integer.
|
247
|
+
q: The quantum variable that will receive the initialized state. Must be uninitialized.
|
248
|
+
|
249
|
+
Notes:
|
250
|
+
The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
251
|
+
|
252
|
+
|
253
|
+
"""
|
254
|
+
pass
|
255
|
+
|
256
|
+
|
257
|
+
@qfunc(external=True)
|
258
|
+
def prepare_exponential_state(rate: CInt, q: QArray[QBit]) -> None:
|
259
|
+
"""
|
260
|
+
|
261
|
+
[Qmod Classiq-library function]
|
262
|
+
|
263
|
+
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:
|
264
|
+
|
265
|
+
$$
|
266
|
+
P(n) = \\frac{1}{Z} e^{- \\text{rate} \\cdot n}
|
267
|
+
$$
|
268
|
+
|
269
|
+
Args:
|
270
|
+
rate: The rate of the exponential decay.
|
271
|
+
q: The quantum register to prepare.
|
272
|
+
|
273
|
+
Further reading is available on the [reference manual](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state)
|
274
|
+
"""
|
275
|
+
pass
|
276
|
+
|
277
|
+
|
278
|
+
@qfunc(external=True)
|
279
|
+
def prepare_bell_state(state_num: CInt, q: Output[QArray[QBit, Literal[2]]]) -> None:
|
280
|
+
"""
|
281
|
+
[Qmod Classiq-library function]
|
282
|
+
|
283
|
+
Initializes a quantum array of size 2 in one of the four Bell states.
|
284
|
+
|
285
|
+
Args:
|
286
|
+
state_num: The number of the Bell state to be prepared. Must be an integer between 0 and 3.
|
287
|
+
q: The quantum variable that will receive the initialized state. Must be uninitialized.
|
288
|
+
|
289
|
+
Bell States:
|
290
|
+
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):
|
291
|
+
|
292
|
+
If `state_num` = 0 the function prepares the Bell state:
|
293
|
+
|
294
|
+
$$
|
295
|
+
\\left|\\Phi^+\\right\\rangle = \\frac{1}{\\sqrt{2}} \\left( \\left| 00 \\right\\rangle + \\left| 11 \\right\\rangle \\right)
|
296
|
+
$$
|
297
|
+
|
298
|
+
If `state_num` = 1 the function prepares the Bell state:
|
299
|
+
|
300
|
+
$$
|
301
|
+
\\left|\\Phi^-\\right\\rangle = \\frac{1}{\\sqrt{2}} \\left( \\left| 00 \\right\\rangle - \\left| 11 \\right\\rangle \\right)
|
302
|
+
$$
|
303
|
+
|
304
|
+
If `state_num` = 2 the function prepares the Bell state:
|
305
|
+
|
306
|
+
$$
|
307
|
+
\\left|\\Psi^+\\right\\rangle = \\frac{1}{\\sqrt{2}} \\left( \\left| 01 \\right\\rangle + \\left| 10 \\right\\rangle \\right)
|
308
|
+
$$
|
309
|
+
|
310
|
+
If `state_num` = 3 the function prepares the Bell state:
|
311
|
+
|
312
|
+
$$
|
313
|
+
\\left|\\Psi^-\\right\\rangle = \\frac{1}{\\sqrt{2}} \\left( \\left| 01 \\right\\rangle - \\left| 10 \\right\\rangle \\right)
|
314
|
+
$$
|
315
|
+
|
316
|
+
Notes:
|
317
|
+
The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
318
|
+
|
319
|
+
|
320
|
+
"""
|
321
|
+
pass
|
322
|
+
|
323
|
+
|
324
|
+
@qfunc(external=True)
|
325
|
+
def inplace_prepare_int(value: CInt, target: QArray[QBit]) -> None:
|
326
|
+
"""
|
327
|
+
[Qmod Classiq-library function]
|
328
|
+
|
329
|
+
Transitions a quantum variable in the zero state $|0\\rangle$ into the computational basis state $|\\text{value}\\rangle$.
|
330
|
+
In the general case, the function performs a bitwise-XOR, i.e. transitions the state $|\\psi\\rangle$ into $|\\psi \\oplus \\text{value}\\rangle$.
|
331
|
+
|
332
|
+
Args:
|
333
|
+
value: The value to assign to the quantum variable.
|
334
|
+
target: The quantum variable to act upon.
|
335
|
+
|
336
|
+
Note:
|
337
|
+
If the value cannot fit into the quantum variable, it is truncated, i.e. treated as the value modulo $2^\\text{target.size}$.
|
338
|
+
"""
|
339
|
+
pass
|
340
|
+
|
341
|
+
|
342
|
+
@qfunc(external=True)
|
343
|
+
def prepare_int(value: CInt, out: Output[QNum]) -> None:
|
344
|
+
"""
|
345
|
+
[Qmod Classiq-library function]
|
346
|
+
|
347
|
+
Initializes a quantum variable to the computational basis state $|\\text{value}\\rangle$.
|
348
|
+
The number of allocated qubits is automatically computed from the value, and is the minimal number required for representation in the computational basis.
|
349
|
+
|
350
|
+
Args:
|
351
|
+
value: The value to assign to the quantum variable.
|
352
|
+
out: The allocated quantum variable. Must be uninitialized. For more information on quantum variable initialization, see [here](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-variables/).
|
353
|
+
|
354
|
+
Note:
|
355
|
+
If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
|
356
|
+
"""
|
357
|
+
pass
|
@@ -0,0 +1,25 @@
|
|
1
|
+
from classiq.qmod.qfunc import qfunc
|
2
|
+
from classiq.qmod.qmod_variable import Output, QArray, QBit
|
3
|
+
|
4
|
+
|
5
|
+
@qfunc(external=True)
|
6
|
+
def swap_test(state1: QArray[QBit], state2: QArray[QBit], test: Output[QBit]) -> None:
|
7
|
+
"""
|
8
|
+
[Qmod Classiq-library function]
|
9
|
+
|
10
|
+
Tests the overlap (in terms of fidelity) of two quantum states.
|
11
|
+
The fidelity of `state1` and `state2` is calculated from the probability of measuring `test` qubit in the state 0 as follows:
|
12
|
+
|
13
|
+
$$
|
14
|
+
|\\langle state1 | state2 \\rangle |^2 = 2*Prob(test=0)-1
|
15
|
+
$$
|
16
|
+
|
17
|
+
Args:
|
18
|
+
state1: A quantum state to check its overlap with state2.
|
19
|
+
state2: A quantum state to check its overlap with state1.
|
20
|
+
test: A qubit for which the probability of measuring 0 is $0.5*(|\\langle state1 | state2 \\rangle |^2+1)$
|
21
|
+
|
22
|
+
Example:
|
23
|
+
Further reading in the Classiq library is found [here](https://docs.classiq.io/latest/explore/algorithms/swap_test/swap_test/).
|
24
|
+
"""
|
25
|
+
pass
|
classiq/qmod/builtins/structs.py
CHANGED
@@ -1,64 +1,73 @@
|
|
1
|
-
|
1
|
+
from dataclasses import dataclass, fields, is_dataclass
|
2
2
|
|
3
|
-
from
|
3
|
+
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
4
4
|
|
5
5
|
from classiq.qmod.builtins.enums import LadderOperator, Pauli
|
6
|
-
from classiq.qmod.
|
6
|
+
from classiq.qmod.cparam import CArray, CBool, CInt, CReal
|
7
|
+
from classiq.qmod.python_classical_type import PythonClassicalType
|
7
8
|
|
8
9
|
|
9
10
|
@dataclass
|
10
11
|
class PauliTerm:
|
11
|
-
|
12
|
-
|
12
|
+
"""
|
13
|
+
A term in a Hamiltonian, represented as a product of Pauli operators.
|
13
14
|
|
15
|
+
Attributes:
|
16
|
+
pauli (CArray[Pauli]): The list of the chosen Pauli operators in the term, corresponds to a product of them.
|
17
|
+
coefficient (CReal): The coefficient of the term (floating number).
|
18
|
+
"""
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
mapping: CInt
|
18
|
-
z2_symmetries: CBool
|
19
|
-
molecule: "Molecule"
|
20
|
-
freeze_core: CBool
|
21
|
-
remove_orbitals: CArray[CInt]
|
20
|
+
pauli: CArray[Pauli]
|
21
|
+
coefficient: CReal
|
22
22
|
|
23
23
|
|
24
24
|
@dataclass
|
25
|
-
class
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
class Position:
|
26
|
+
x: CReal
|
27
|
+
y: CReal
|
28
|
+
z: CReal
|
29
29
|
|
30
30
|
|
31
31
|
@dataclass
|
32
32
|
class ChemistryAtom:
|
33
33
|
element: CInt
|
34
|
-
position:
|
34
|
+
position: Position
|
35
35
|
|
36
36
|
|
37
37
|
@dataclass
|
38
|
-
class
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
class Molecule:
|
39
|
+
atoms: CArray[ChemistryAtom]
|
40
|
+
spin: CInt
|
41
|
+
charge: CInt
|
42
42
|
|
43
43
|
|
44
44
|
@dataclass
|
45
|
-
class
|
45
|
+
class MoleculeProblem:
|
46
46
|
mapping: CInt
|
47
47
|
z2_symmetries: CBool
|
48
|
-
|
49
|
-
|
48
|
+
molecule: Molecule
|
49
|
+
freeze_core: CBool
|
50
|
+
remove_orbitals: CArray[CInt]
|
51
|
+
|
52
|
+
|
53
|
+
@dataclass
|
54
|
+
class LadderOp:
|
55
|
+
op: LadderOperator
|
56
|
+
index: CInt
|
50
57
|
|
51
58
|
|
52
59
|
@dataclass
|
53
60
|
class LadderTerm:
|
54
61
|
coefficient: CReal
|
55
|
-
ops: CArray[
|
62
|
+
ops: CArray[LadderOp]
|
56
63
|
|
57
64
|
|
58
65
|
@dataclass
|
59
|
-
class
|
60
|
-
|
61
|
-
|
66
|
+
class FockHamiltonianProblem:
|
67
|
+
mapping: CInt
|
68
|
+
z2_symmetries: CBool
|
69
|
+
terms: CArray[LadderTerm]
|
70
|
+
num_particles: CArray[CInt]
|
62
71
|
|
63
72
|
|
64
73
|
@dataclass
|
@@ -111,6 +120,19 @@ class QSVMFeatureMapPauli:
|
|
111
120
|
paulis: CArray[CArray[Pauli]]
|
112
121
|
|
113
122
|
|
123
|
+
BUILTIN_STRUCT_DECLARATIONS = {
|
124
|
+
struct_decl.__name__: StructDeclaration(
|
125
|
+
name=struct_decl.__name__,
|
126
|
+
variables={
|
127
|
+
field.name: PythonClassicalType().convert(field.type)
|
128
|
+
for field in fields(struct_decl)
|
129
|
+
},
|
130
|
+
)
|
131
|
+
for struct_decl in vars().values()
|
132
|
+
if is_dataclass(struct_decl)
|
133
|
+
}
|
134
|
+
|
135
|
+
|
114
136
|
__all__ = [
|
115
137
|
"PauliTerm",
|
116
138
|
"MoleculeProblem",
|
classiq/qmod/cparam.py
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
import sys
|
2
|
+
from typing import ( # type: ignore[attr-defined]
|
3
|
+
TYPE_CHECKING,
|
4
|
+
Any,
|
5
|
+
Generic,
|
6
|
+
Union,
|
7
|
+
_GenericAlias,
|
8
|
+
)
|
9
|
+
|
10
|
+
from typing_extensions import ParamSpec
|
11
|
+
|
12
|
+
from classiq.qmod.symbolic_expr import Symbolic, SymbolicExpr
|
13
|
+
|
14
|
+
if TYPE_CHECKING:
|
15
|
+
from classiq.qmod.qmod_variable import QNum
|
16
|
+
|
17
|
+
SymbolicSuperclass = SymbolicExpr
|
18
|
+
else:
|
19
|
+
SymbolicSuperclass = Symbolic
|
20
|
+
|
21
|
+
|
22
|
+
class CParam(SymbolicSuperclass):
|
23
|
+
def __init__(self, expr: str) -> None:
|
24
|
+
super().__init__(expr, False)
|
25
|
+
|
26
|
+
|
27
|
+
class CInt(CParam):
|
28
|
+
pass
|
29
|
+
|
30
|
+
|
31
|
+
class CReal(CParam):
|
32
|
+
pass
|
33
|
+
|
34
|
+
|
35
|
+
class CBool(CParam):
|
36
|
+
pass
|
37
|
+
|
38
|
+
|
39
|
+
_P = ParamSpec("_P")
|
40
|
+
|
41
|
+
|
42
|
+
class ArrayBase(Generic[_P]):
|
43
|
+
# Support comma-separated generic args in older Python versions
|
44
|
+
if sys.version_info[0:2] < (3, 10):
|
45
|
+
|
46
|
+
def __class_getitem__(cls, args) -> _GenericAlias:
|
47
|
+
return _GenericAlias(cls, args)
|
48
|
+
|
49
|
+
|
50
|
+
class CArray(CParam, ArrayBase[_P]):
|
51
|
+
if TYPE_CHECKING:
|
52
|
+
|
53
|
+
@property
|
54
|
+
def len(self) -> int: ...
|
55
|
+
|
56
|
+
def __getitem__(self, idx: Union[int, CInt, slice, "QNum"]) -> Any: ...
|
57
|
+
|
58
|
+
|
59
|
+
Array = CArray
|
60
|
+
|
61
|
+
|
62
|
+
class CParamScalar(CParam, SymbolicExpr):
|
63
|
+
def __hash__(self) -> int:
|
64
|
+
return hash(str(self))
|