classiq 0.39.0__py3-none-any.whl → 0.40.0__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 +1 -0
- classiq/applications/chemistry/chemistry_model_constructor.py +1 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +5 -6
- classiq/applications/combinatorial_helpers/optimization_model.py +7 -6
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +0 -10
- classiq/applications/combinatorial_optimization/__init__.py +2 -0
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +2 -2
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +5 -5
- classiq/interface/backend/quantum_backend_providers.py +7 -7
- classiq/interface/executor/execution_preferences.py +4 -9
- classiq/interface/generator/application_apis/chemistry_declarations.py +2 -4
- classiq/interface/generator/application_apis/finance_declarations.py +1 -1
- classiq/interface/generator/arith/arithmetic_expression_validator.py +2 -0
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +82 -0
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +21 -0
- classiq/interface/generator/expressions/qmod_sized_proxy.py +22 -0
- classiq/interface/generator/functions/builtins/core_library/atomic_quantum_functions.py +8 -6
- classiq/interface/generator/functions/builtins/core_library/exponentiation_functions.py +10 -4
- classiq/interface/generator/functions/builtins/open_lib_functions.py +624 -76
- classiq/interface/generator/functions/classical_type.py +29 -17
- classiq/interface/generator/model/preferences/preferences.py +4 -2
- classiq/interface/model/control.py +104 -8
- classiq/interface/model/quantum_type.py +6 -5
- classiq/interface/model/resolvers/function_call_resolver.py +0 -5
- classiq/interface/model/statement_block.py +1 -4
- classiq/qmod/__init__.py +6 -2
- classiq/qmod/builtins/classical_functions.py +30 -35
- classiq/qmod/builtins/functions.py +213 -153
- classiq/qmod/builtins/operations.py +78 -24
- classiq/qmod/builtins/structs.py +50 -48
- classiq/qmod/declaration_inferrer.py +30 -18
- classiq/qmod/native/expression_to_qmod.py +5 -4
- classiq/qmod/native/pretty_printer.py +7 -14
- classiq/qmod/qmod_constant.py +7 -7
- classiq/qmod/qmod_parameter.py +54 -33
- classiq/qmod/qmod_struct.py +2 -2
- classiq/qmod/qmod_variable.py +40 -29
- classiq/qmod/quantum_callable.py +7 -4
- classiq/qmod/quantum_expandable.py +19 -13
- classiq/qmod/quantum_function.py +25 -2
- classiq/qmod/symbolic.py +78 -68
- classiq/qmod/symbolic_expr.py +1 -1
- classiq/qmod/symbolic_type.py +1 -4
- classiq/qmod/utilities.py +29 -0
- {classiq-0.39.0.dist-info → classiq-0.40.0.dist-info}/METADATA +1 -1
- {classiq-0.39.0.dist-info → classiq-0.40.0.dist-info}/RECORD +48 -50
- classiq/interface/executor/error_mitigation.py +0 -6
- classiq/interface/generator/functions/builtins/core_library/chemistry_functions.py +0 -0
- classiq/interface/model/quantum_if_operation.py +0 -94
- {classiq-0.39.0.dist-info → classiq-0.40.0.dist-info}/WHEEL +0 -0
classiq/qmod/symbolic.py
CHANGED
@@ -1,10 +1,21 @@
|
|
1
1
|
import sys
|
2
|
-
from typing import
|
2
|
+
from typing import (
|
3
|
+
TYPE_CHECKING,
|
4
|
+
Any,
|
5
|
+
List,
|
6
|
+
Optional,
|
7
|
+
Tuple,
|
8
|
+
Type,
|
9
|
+
TypeVar,
|
10
|
+
get_args,
|
11
|
+
get_origin,
|
12
|
+
overload,
|
13
|
+
)
|
3
14
|
|
4
15
|
from classiq.exceptions import ClassiqValueError
|
5
16
|
from classiq.qmod import model_state_container
|
6
17
|
from classiq.qmod.declaration_inferrer import python_type_to_qmod
|
7
|
-
from classiq.qmod.qmod_parameter import
|
18
|
+
from classiq.qmod.qmod_parameter import CParam, CParamScalar, QParam, create_param
|
8
19
|
from classiq.qmod.symbolic_expr import SymbolicExpr
|
9
20
|
from classiq.qmod.symbolic_type import SymbolicTypes
|
10
21
|
|
@@ -15,20 +26,18 @@ GoldenRatio = SymbolicExpr("GoldenRatio")
|
|
15
26
|
EulerGamma = SymbolicExpr("EulerGamma")
|
16
27
|
Catalan = SymbolicExpr("Catalan")
|
17
28
|
|
29
|
+
T = TypeVar("T", bound=CParam)
|
30
|
+
|
18
31
|
|
19
32
|
@overload
|
20
|
-
def symbolic_function(
|
21
|
-
*args: SymbolicTypes, return_type: None = None
|
22
|
-
) -> QParamScalar: ...
|
33
|
+
def symbolic_function(*args: Any, return_type: None = None) -> CParamScalar: ...
|
23
34
|
|
24
35
|
|
25
36
|
@overload
|
26
|
-
def symbolic_function(*args:
|
37
|
+
def symbolic_function(*args: Any, return_type: Type[T]) -> T: ...
|
27
38
|
|
28
39
|
|
29
|
-
def symbolic_function(
|
30
|
-
*args: SymbolicTypes, return_type: Optional[Type[QParam]] = None
|
31
|
-
) -> QParam:
|
40
|
+
def symbolic_function(*args: Any, return_type: Optional[Type[T]] = None) -> CParam:
|
32
41
|
qmodule = (
|
33
42
|
model_state_container.QMODULE
|
34
43
|
) # FIXME: https://classiq.atlassian.net/browse/CAD-15126
|
@@ -36,14 +45,15 @@ def symbolic_function(
|
|
36
45
|
expr = f"{sys._getframe(1).f_code.co_name}({','.join(str_args)})"
|
37
46
|
|
38
47
|
if return_type is None:
|
39
|
-
return
|
48
|
+
return CParamScalar(expr)
|
40
49
|
|
41
|
-
if get_origin(return_type) is
|
42
|
-
|
43
|
-
|
44
|
-
|
50
|
+
if get_origin(return_type) is QParam:
|
51
|
+
return_type = get_args(return_type)[0]
|
52
|
+
|
53
|
+
if TYPE_CHECKING:
|
54
|
+
assert return_type is not None
|
45
55
|
|
46
|
-
qmod_type = python_type_to_qmod(
|
56
|
+
qmod_type = python_type_to_qmod(return_type, qmodule=qmodule)
|
47
57
|
if qmod_type is None:
|
48
58
|
raise ClassiqValueError(
|
49
59
|
f"Unsupported return type for symbolic function: {return_type}"
|
@@ -56,211 +66,211 @@ def symbolic_function(
|
|
56
66
|
)
|
57
67
|
|
58
68
|
|
59
|
-
def sin(x: SymbolicTypes) ->
|
69
|
+
def sin(x: SymbolicTypes) -> CParamScalar:
|
60
70
|
return symbolic_function(x)
|
61
71
|
|
62
72
|
|
63
|
-
def cos(x: SymbolicTypes) ->
|
73
|
+
def cos(x: SymbolicTypes) -> CParamScalar:
|
64
74
|
return symbolic_function(x)
|
65
75
|
|
66
76
|
|
67
|
-
def tan(x: SymbolicTypes) ->
|
77
|
+
def tan(x: SymbolicTypes) -> CParamScalar:
|
68
78
|
return symbolic_function(x)
|
69
79
|
|
70
80
|
|
71
|
-
def cot(x: SymbolicTypes) ->
|
81
|
+
def cot(x: SymbolicTypes) -> CParamScalar:
|
72
82
|
return symbolic_function(x)
|
73
83
|
|
74
84
|
|
75
|
-
def sec(x: SymbolicTypes) ->
|
85
|
+
def sec(x: SymbolicTypes) -> CParamScalar:
|
76
86
|
return symbolic_function(x)
|
77
87
|
|
78
88
|
|
79
|
-
def csc(x: SymbolicTypes) ->
|
89
|
+
def csc(x: SymbolicTypes) -> CParamScalar:
|
80
90
|
return symbolic_function(x)
|
81
91
|
|
82
92
|
|
83
|
-
def asin(x: SymbolicTypes) ->
|
93
|
+
def asin(x: SymbolicTypes) -> CParamScalar:
|
84
94
|
return symbolic_function(x)
|
85
95
|
|
86
96
|
|
87
|
-
def acos(x: SymbolicTypes) ->
|
97
|
+
def acos(x: SymbolicTypes) -> CParamScalar:
|
88
98
|
return symbolic_function(x)
|
89
99
|
|
90
100
|
|
91
|
-
def atan(x: SymbolicTypes) ->
|
101
|
+
def atan(x: SymbolicTypes) -> CParamScalar:
|
92
102
|
return symbolic_function(x)
|
93
103
|
|
94
104
|
|
95
|
-
def acot(x: SymbolicTypes) ->
|
105
|
+
def acot(x: SymbolicTypes) -> CParamScalar:
|
96
106
|
return symbolic_function(x)
|
97
107
|
|
98
108
|
|
99
|
-
def asec(x: SymbolicTypes) ->
|
109
|
+
def asec(x: SymbolicTypes) -> CParamScalar:
|
100
110
|
return symbolic_function(x)
|
101
111
|
|
102
112
|
|
103
|
-
def acsc(x: SymbolicTypes) ->
|
113
|
+
def acsc(x: SymbolicTypes) -> CParamScalar:
|
104
114
|
return symbolic_function(x)
|
105
115
|
|
106
116
|
|
107
|
-
def sinh(x: SymbolicTypes) ->
|
117
|
+
def sinh(x: SymbolicTypes) -> CParamScalar:
|
108
118
|
return symbolic_function(x)
|
109
119
|
|
110
120
|
|
111
|
-
def cosh(x: SymbolicTypes) ->
|
121
|
+
def cosh(x: SymbolicTypes) -> CParamScalar:
|
112
122
|
return symbolic_function(x)
|
113
123
|
|
114
124
|
|
115
|
-
def tanh(x: SymbolicTypes) ->
|
125
|
+
def tanh(x: SymbolicTypes) -> CParamScalar:
|
116
126
|
return symbolic_function(x)
|
117
127
|
|
118
128
|
|
119
|
-
def coth(x: SymbolicTypes) ->
|
129
|
+
def coth(x: SymbolicTypes) -> CParamScalar:
|
120
130
|
return symbolic_function(x)
|
121
131
|
|
122
132
|
|
123
|
-
def sech(x: SymbolicTypes) ->
|
133
|
+
def sech(x: SymbolicTypes) -> CParamScalar:
|
124
134
|
return symbolic_function(x)
|
125
135
|
|
126
136
|
|
127
|
-
def csch(x: SymbolicTypes) ->
|
137
|
+
def csch(x: SymbolicTypes) -> CParamScalar:
|
128
138
|
return symbolic_function(x)
|
129
139
|
|
130
140
|
|
131
|
-
def asinh(x: SymbolicTypes) ->
|
141
|
+
def asinh(x: SymbolicTypes) -> CParamScalar:
|
132
142
|
return symbolic_function(x)
|
133
143
|
|
134
144
|
|
135
|
-
def acosh(x: SymbolicTypes) ->
|
145
|
+
def acosh(x: SymbolicTypes) -> CParamScalar:
|
136
146
|
return symbolic_function(x)
|
137
147
|
|
138
148
|
|
139
|
-
def atanh(x: SymbolicTypes) ->
|
149
|
+
def atanh(x: SymbolicTypes) -> CParamScalar:
|
140
150
|
return symbolic_function(x)
|
141
151
|
|
142
152
|
|
143
|
-
def acoth(x: SymbolicTypes) ->
|
153
|
+
def acoth(x: SymbolicTypes) -> CParamScalar:
|
144
154
|
return symbolic_function(x)
|
145
155
|
|
146
156
|
|
147
|
-
def asech(x: SymbolicTypes) ->
|
157
|
+
def asech(x: SymbolicTypes) -> CParamScalar:
|
148
158
|
return symbolic_function(x)
|
149
159
|
|
150
160
|
|
151
|
-
def exp(x: SymbolicTypes) ->
|
161
|
+
def exp(x: SymbolicTypes) -> CParamScalar:
|
152
162
|
return symbolic_function(x)
|
153
163
|
|
154
164
|
|
155
|
-
def log(x: SymbolicTypes, base: SymbolicTypes = E) ->
|
165
|
+
def log(x: SymbolicTypes, base: SymbolicTypes = E) -> CParamScalar:
|
156
166
|
return symbolic_function(x, base)
|
157
167
|
|
158
168
|
|
159
|
-
def ln(x: SymbolicTypes) ->
|
169
|
+
def ln(x: SymbolicTypes) -> CParamScalar:
|
160
170
|
return symbolic_function(x)
|
161
171
|
|
162
172
|
|
163
|
-
def sqrt(x: SymbolicTypes) ->
|
173
|
+
def sqrt(x: SymbolicTypes) -> CParamScalar:
|
164
174
|
return symbolic_function(x)
|
165
175
|
|
166
176
|
|
167
|
-
def abs(x: SymbolicTypes) ->
|
177
|
+
def abs(x: SymbolicTypes) -> CParamScalar:
|
168
178
|
return symbolic_function(x)
|
169
179
|
|
170
180
|
|
171
|
-
def floor(x: SymbolicTypes) ->
|
181
|
+
def floor(x: SymbolicTypes) -> CParamScalar:
|
172
182
|
return symbolic_function(x)
|
173
183
|
|
174
184
|
|
175
|
-
def ceiling(x: SymbolicTypes) ->
|
185
|
+
def ceiling(x: SymbolicTypes) -> CParamScalar:
|
176
186
|
return symbolic_function(x)
|
177
187
|
|
178
188
|
|
179
|
-
def erf(x: SymbolicTypes) ->
|
189
|
+
def erf(x: SymbolicTypes) -> CParamScalar:
|
180
190
|
return symbolic_function(x)
|
181
191
|
|
182
192
|
|
183
|
-
def erfc(x: SymbolicTypes) ->
|
193
|
+
def erfc(x: SymbolicTypes) -> CParamScalar:
|
184
194
|
return symbolic_function(x)
|
185
195
|
|
186
196
|
|
187
|
-
def gamma(x: SymbolicTypes) ->
|
197
|
+
def gamma(x: SymbolicTypes) -> CParamScalar:
|
188
198
|
return symbolic_function(x)
|
189
199
|
|
190
200
|
|
191
|
-
def beta(x: SymbolicTypes) ->
|
201
|
+
def beta(x: SymbolicTypes) -> CParamScalar:
|
192
202
|
return symbolic_function(x)
|
193
203
|
|
194
204
|
|
195
|
-
def besselj(x: SymbolicTypes) ->
|
205
|
+
def besselj(x: SymbolicTypes) -> CParamScalar:
|
196
206
|
return symbolic_function(x)
|
197
207
|
|
198
208
|
|
199
|
-
def bessely(x: SymbolicTypes) ->
|
209
|
+
def bessely(x: SymbolicTypes) -> CParamScalar:
|
200
210
|
return symbolic_function(x)
|
201
211
|
|
202
212
|
|
203
|
-
def besseli(x: SymbolicTypes) ->
|
213
|
+
def besseli(x: SymbolicTypes) -> CParamScalar:
|
204
214
|
return symbolic_function(x)
|
205
215
|
|
206
216
|
|
207
|
-
def besselk(x: SymbolicTypes) ->
|
217
|
+
def besselk(x: SymbolicTypes) -> CParamScalar:
|
208
218
|
return symbolic_function(x)
|
209
219
|
|
210
220
|
|
211
|
-
def dirichlet_eta(x: SymbolicTypes) ->
|
221
|
+
def dirichlet_eta(x: SymbolicTypes) -> CParamScalar:
|
212
222
|
return symbolic_function(x)
|
213
223
|
|
214
224
|
|
215
|
-
def polygamma(x: SymbolicTypes) ->
|
225
|
+
def polygamma(x: SymbolicTypes) -> CParamScalar:
|
216
226
|
return symbolic_function(x)
|
217
227
|
|
218
228
|
|
219
|
-
def loggamma(x: SymbolicTypes) ->
|
229
|
+
def loggamma(x: SymbolicTypes) -> CParamScalar:
|
220
230
|
return symbolic_function(x)
|
221
231
|
|
222
232
|
|
223
|
-
def factorial(x: SymbolicTypes) ->
|
233
|
+
def factorial(x: SymbolicTypes) -> CParamScalar:
|
224
234
|
return symbolic_function(x)
|
225
235
|
|
226
236
|
|
227
|
-
def binomial(x: SymbolicTypes) ->
|
237
|
+
def binomial(x: SymbolicTypes) -> CParamScalar:
|
228
238
|
return symbolic_function(x)
|
229
239
|
|
230
240
|
|
231
|
-
def subfactorial(x: SymbolicTypes) ->
|
241
|
+
def subfactorial(x: SymbolicTypes) -> CParamScalar:
|
232
242
|
return symbolic_function(x)
|
233
243
|
|
234
244
|
|
235
|
-
def primorial(x: SymbolicTypes) ->
|
245
|
+
def primorial(x: SymbolicTypes) -> CParamScalar:
|
236
246
|
return symbolic_function(x)
|
237
247
|
|
238
248
|
|
239
|
-
def bell(x: SymbolicTypes) ->
|
249
|
+
def bell(x: SymbolicTypes) -> CParamScalar:
|
240
250
|
return symbolic_function(x)
|
241
251
|
|
242
252
|
|
243
|
-
def bernoulli(x: SymbolicTypes) ->
|
253
|
+
def bernoulli(x: SymbolicTypes) -> CParamScalar:
|
244
254
|
return symbolic_function(x)
|
245
255
|
|
246
256
|
|
247
|
-
def euler(x: SymbolicTypes) ->
|
257
|
+
def euler(x: SymbolicTypes) -> CParamScalar:
|
248
258
|
return symbolic_function(x)
|
249
259
|
|
250
260
|
|
251
|
-
def catalan(x: SymbolicTypes) ->
|
261
|
+
def catalan(x: SymbolicTypes) -> CParamScalar:
|
252
262
|
return symbolic_function(x)
|
253
263
|
|
254
264
|
|
255
|
-
def Piecewise(*args: Tuple[SymbolicTypes, SymbolicTypes]) ->
|
265
|
+
def Piecewise(*args: Tuple[SymbolicTypes, SymbolicTypes]) -> CParamScalar: # noqa: N802
|
256
266
|
return symbolic_function(*args)
|
257
267
|
|
258
268
|
|
259
|
-
def max(x: SymbolicTypes, y: SymbolicTypes) ->
|
269
|
+
def max(x: SymbolicTypes, y: SymbolicTypes) -> CParamScalar:
|
260
270
|
return symbolic_function(x, y)
|
261
271
|
|
262
272
|
|
263
|
-
def min(x: SymbolicTypes, y: SymbolicTypes) ->
|
273
|
+
def min(x: SymbolicTypes, y: SymbolicTypes) -> CParamScalar:
|
264
274
|
return symbolic_function(x, y)
|
265
275
|
|
266
276
|
|
@@ -276,7 +286,7 @@ def logical_not(x: SymbolicTypes) -> SymbolicExpr:
|
|
276
286
|
return SymbolicExpr._unary_op(x, "not")
|
277
287
|
|
278
288
|
|
279
|
-
def mod_inverse(a: SymbolicTypes, m: SymbolicTypes) ->
|
289
|
+
def mod_inverse(a: SymbolicTypes, m: SymbolicTypes) -> CParamScalar:
|
280
290
|
return symbolic_function(a, m)
|
281
291
|
|
282
292
|
|
classiq/qmod/symbolic_expr.py
CHANGED
classiq/qmod/symbolic_type.py
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
from typing import Tuple, Union
|
2
2
|
|
3
|
-
from classiq.qmod.qmod_parameter import QParam
|
4
3
|
from classiq.qmod.symbolic_expr import SymbolicExpr
|
5
4
|
|
6
|
-
SymbolicTypes = Union[
|
7
|
-
QParam, SymbolicExpr, int, float, bool, Tuple["SymbolicTypes", ...]
|
8
|
-
]
|
5
|
+
SymbolicTypes = Union[SymbolicExpr, int, float, bool, Tuple["SymbolicTypes", ...]]
|
classiq/qmod/utilities.py
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
import inspect
|
2
|
+
import itertools
|
1
3
|
import keyword
|
2
4
|
import sys
|
5
|
+
from types import FrameType
|
3
6
|
from typing import get_args, get_origin
|
4
7
|
|
8
|
+
from classiq.interface.ast_node import SourceReference
|
9
|
+
|
5
10
|
DEFAULT_DECIMAL_PRECISION = 4
|
6
11
|
|
7
12
|
|
@@ -25,3 +30,27 @@ def version_portable_get_args(py_type: type) -> tuple:
|
|
25
30
|
return get_args(py_type) # The result of __class_getitem__
|
26
31
|
else:
|
27
32
|
return get_args(py_type)[0]
|
33
|
+
|
34
|
+
|
35
|
+
def get_source_ref(frame: FrameType) -> SourceReference:
|
36
|
+
filename = inspect.getfile(frame)
|
37
|
+
lineno = frame.f_lineno
|
38
|
+
if sys.version_info[0:2] < (3, 11) or frame.f_lasti < 0:
|
39
|
+
source_ref = SourceReference(
|
40
|
+
file_name=filename,
|
41
|
+
start_line=lineno,
|
42
|
+
start_column=-1,
|
43
|
+
end_line=-1,
|
44
|
+
end_column=-1,
|
45
|
+
)
|
46
|
+
else:
|
47
|
+
positions_gen = frame.f_code.co_positions()
|
48
|
+
positions = next(itertools.islice(positions_gen, frame.f_lasti // 2, None))
|
49
|
+
source_ref = SourceReference(
|
50
|
+
file_name=filename,
|
51
|
+
start_line=positions[0],
|
52
|
+
start_column=positions[2],
|
53
|
+
end_line=positions[1],
|
54
|
+
end_column=positions[3],
|
55
|
+
)
|
56
|
+
return source_ref
|