classiq 0.94.1__py3-none-any.whl → 0.95.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.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/_internals/authentication/auth0.py +32 -3
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +31 -50
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/token_manager.py +5 -4
- classiq/applications/__init__.py +2 -2
- classiq/applications/qsp/qsp.py +6 -5
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +10 -0
- classiq/interface/_version.py +1 -1
- classiq/interface/backend/backend_preferences.py +11 -6
- classiq/interface/exceptions.py +0 -4
- classiq/interface/generator/application_apis/__init__.py +0 -1
- classiq/interface/generator/function_param_list.py +0 -2
- classiq/interface/generator/generated_circuit_data.py +1 -6
- classiq/interface/generator/quantum_program.py +0 -4
- classiq/interface/generator/transpiler_basis_gates.py +3 -0
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -9
- classiq/interface/interface_version.py +1 -1
- classiq/interface/model/block.py +4 -0
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +7 -0
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/power.py +4 -0
- classiq/interface/model/quantum_statement.py +8 -1
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/model_expansions/interpreters/base_interpreter.py +1 -1
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/visitors/symbolic_param_inference.py +3 -3
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +14 -3
- classiq/open_library/functions/__init__.py +4 -1
- classiq/open_library/functions/amplitude_loading.py +66 -0
- classiq/open_library/functions/lookup_table.py +22 -9
- classiq/open_library/functions/modular_exponentiation.py +5 -8
- classiq/open_library/functions/qsvt.py +4 -4
- classiq/qmod/builtins/classical_execution_primitives.py +0 -12
- classiq/qmod/builtins/enums.py +15 -17
- classiq/qmod/builtins/functions/__init__.py +3 -5
- classiq/qmod/builtins/functions/mcx.py +7 -0
- classiq/qmod/builtins/operations.py +60 -22
- classiq/qmod/builtins/structs.py +22 -33
- classiq/qmod/semantics/annotation/call_annotation.py +3 -3
- classiq/qmod/semantics/error_manager.py +7 -8
- {classiq-0.94.1.dist-info → classiq-0.95.0.dist-info}/METADATA +1 -1
- {classiq-0.94.1.dist-info → classiq-0.95.0.dist-info}/RECORD +50 -51
- {classiq-0.94.1.dist-info → classiq-0.95.0.dist-info}/WHEEL +1 -1
- classiq/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/interface/applications/qsvm.py +0 -114
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- classiq/interface/generator/qsvm.py +0 -96
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.94.1.dist-info → classiq-0.95.0.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import sys
|
|
3
3
|
from collections.abc import Callable, Mapping
|
|
4
|
+
from functools import wraps
|
|
4
5
|
from types import FrameType
|
|
5
6
|
from typing import (
|
|
6
7
|
Any,
|
|
7
8
|
Final,
|
|
8
9
|
NoReturn,
|
|
10
|
+
ParamSpec,
|
|
11
|
+
TypeVar,
|
|
9
12
|
overload,
|
|
10
13
|
)
|
|
11
14
|
|
|
@@ -50,11 +53,25 @@ from classiq.qmod.qmod_constant import QConstant
|
|
|
50
53
|
from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum, QScalar, QVar
|
|
51
54
|
from classiq.qmod.quantum_callable import QCallable
|
|
52
55
|
from classiq.qmod.quantum_expandable import prepare_arg
|
|
56
|
+
from classiq.qmod.semantics.error_manager import ErrorManager
|
|
53
57
|
from classiq.qmod.symbolic_expr import SymbolicExpr
|
|
54
58
|
from classiq.qmod.utilities import Statements, get_source_ref, suppress_return_value
|
|
55
59
|
|
|
56
60
|
_MISSING_VALUE: Final[int] = -1
|
|
57
61
|
|
|
62
|
+
Params = ParamSpec("Params")
|
|
63
|
+
RetType = TypeVar("RetType")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def qmod_statement(func: Callable[Params, RetType]) -> Callable[Params, RetType]:
|
|
67
|
+
@wraps(func)
|
|
68
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
69
|
+
source_ref = get_source_ref(sys._getframe(1))
|
|
70
|
+
with ErrorManager().source_ref_context(source_ref):
|
|
71
|
+
return func(*args, **kwargs)
|
|
72
|
+
|
|
73
|
+
return wrapper
|
|
74
|
+
|
|
58
75
|
|
|
59
76
|
@overload
|
|
60
77
|
def allocate(num_qubits: int | SymbolicExpr, out: Output[QVar]) -> None:
|
|
@@ -77,6 +94,7 @@ def allocate(
|
|
|
77
94
|
|
|
78
95
|
|
|
79
96
|
@suppress_return_value
|
|
97
|
+
@qmod_statement
|
|
80
98
|
def allocate(*args: Any, **kwargs: Any) -> None:
|
|
81
99
|
"""
|
|
82
100
|
Initialize a quantum variable to a new quantum object in the zero state:
|
|
@@ -100,29 +118,34 @@ def allocate(*args: Any, **kwargs: Any) -> None:
|
|
|
100
118
|
2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
|
|
101
119
|
"""
|
|
102
120
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
103
|
-
source_ref = get_source_ref(sys._getframe(
|
|
121
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
104
122
|
if len(args) == 0:
|
|
105
123
|
size = kwargs.get("num_qubits", None)
|
|
106
124
|
is_signed = kwargs.get("is_signed", None)
|
|
107
125
|
fraction_digits = kwargs.get("fraction_digits", None)
|
|
108
|
-
|
|
126
|
+
out = kwargs["out"]
|
|
109
127
|
elif len(args) == 1:
|
|
110
128
|
if "out" in kwargs:
|
|
111
129
|
size = args[0]
|
|
112
130
|
is_signed = kwargs.get("is_signed", None)
|
|
113
131
|
fraction_digits = kwargs.get("fraction_digits", None)
|
|
114
|
-
|
|
132
|
+
out = kwargs["out"]
|
|
115
133
|
else:
|
|
116
134
|
size = None
|
|
117
135
|
is_signed = None
|
|
118
136
|
fraction_digits = None
|
|
119
|
-
|
|
137
|
+
out = args[0]
|
|
120
138
|
elif len(args) == 2:
|
|
121
|
-
size,
|
|
139
|
+
size, out = args
|
|
122
140
|
is_signed = kwargs.get("is_signed", None)
|
|
123
141
|
fraction_digits = kwargs.get("fraction_digits", None)
|
|
124
142
|
else:
|
|
125
|
-
size, is_signed, fraction_digits,
|
|
143
|
+
size, is_signed, fraction_digits, out = args
|
|
144
|
+
if not isinstance(out, QVar):
|
|
145
|
+
raise ClassiqValueError(
|
|
146
|
+
f"Argument 'out' of operator 'allocate' must be a quantum variable, got "
|
|
147
|
+
f"{type(out).__name__}"
|
|
148
|
+
)
|
|
126
149
|
if isinstance(size, QConstant):
|
|
127
150
|
size.add_to_model()
|
|
128
151
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
|
@@ -134,13 +157,14 @@ def allocate(*args: Any, **kwargs: Any) -> None:
|
|
|
134
157
|
if fraction_digits is None
|
|
135
158
|
else Expression(expr=str(fraction_digits))
|
|
136
159
|
),
|
|
137
|
-
target=
|
|
160
|
+
target=out.get_handle_binding(),
|
|
138
161
|
source_ref=source_ref,
|
|
139
162
|
)
|
|
140
163
|
)
|
|
141
164
|
|
|
142
165
|
|
|
143
166
|
@suppress_return_value
|
|
167
|
+
@qmod_statement
|
|
144
168
|
def bind(
|
|
145
169
|
source: Input[QVar] | list[Input[QVar]],
|
|
146
170
|
destination: Output[QVar] | list[Output[QVar]],
|
|
@@ -162,7 +186,7 @@ def bind(
|
|
|
162
186
|
For more details, see [Qmod Reference](https://docs.classiq.io/latest/qmod-reference/language-reference/statements/bind).
|
|
163
187
|
"""
|
|
164
188
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
165
|
-
source_ref = get_source_ref(sys._getframe(
|
|
189
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
166
190
|
if not isinstance(source, list):
|
|
167
191
|
source = [source]
|
|
168
192
|
if not isinstance(destination, list):
|
|
@@ -177,6 +201,7 @@ def bind(
|
|
|
177
201
|
|
|
178
202
|
|
|
179
203
|
@suppress_return_value
|
|
204
|
+
@qmod_statement
|
|
180
205
|
def if_(
|
|
181
206
|
condition: SymbolicExpr | bool,
|
|
182
207
|
then: QCallable | Callable[[], Statements],
|
|
@@ -198,7 +223,7 @@ def if_(
|
|
|
198
223
|
if else_ != _MISSING_VALUE:
|
|
199
224
|
_validate_operand(else_)
|
|
200
225
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
201
|
-
source_ref = get_source_ref(sys._getframe(
|
|
226
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
202
227
|
|
|
203
228
|
if_stmt = ClassicalIf(
|
|
204
229
|
condition=Expression(expr=str(condition)),
|
|
@@ -214,6 +239,7 @@ def if_(
|
|
|
214
239
|
|
|
215
240
|
|
|
216
241
|
@suppress_return_value
|
|
242
|
+
@qmod_statement
|
|
217
243
|
def control(
|
|
218
244
|
ctrl: SymbolicExpr | QBit | QArray[QBit] | list[QVar],
|
|
219
245
|
stmt_block: QCallable | Callable[[], Statements],
|
|
@@ -237,7 +263,7 @@ def control(
|
|
|
237
263
|
"""
|
|
238
264
|
_validate_operand(stmt_block)
|
|
239
265
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
240
|
-
source_ref = get_source_ref(sys._getframe(
|
|
266
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
241
267
|
control_stmt = Control(
|
|
242
268
|
expression=Expression(expr=str(ctrl)),
|
|
243
269
|
body=_operand_to_body(stmt_block, "stmt_block"),
|
|
@@ -252,6 +278,7 @@ def control(
|
|
|
252
278
|
|
|
253
279
|
|
|
254
280
|
@suppress_return_value
|
|
281
|
+
@qmod_statement
|
|
255
282
|
def skip_control(stmt_block: QCallable | Callable[[], Statements]) -> None:
|
|
256
283
|
"""
|
|
257
284
|
Applies quantum statements unconditionally.
|
|
@@ -263,7 +290,7 @@ def skip_control(stmt_block: QCallable | Callable[[], Statements]) -> None:
|
|
|
263
290
|
"""
|
|
264
291
|
_validate_operand(stmt_block)
|
|
265
292
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
266
|
-
source_ref = get_source_ref(sys._getframe(
|
|
293
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
267
294
|
sc_stmt = SkipControl(
|
|
268
295
|
body=_operand_to_body(stmt_block, "stmt_block"),
|
|
269
296
|
source_ref=source_ref,
|
|
@@ -274,6 +301,7 @@ def skip_control(stmt_block: QCallable | Callable[[], Statements]) -> None:
|
|
|
274
301
|
|
|
275
302
|
|
|
276
303
|
@suppress_return_value
|
|
304
|
+
@qmod_statement
|
|
277
305
|
def assign(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
278
306
|
"""
|
|
279
307
|
Initialize a scalar quantum variable using an arithmetic expression.
|
|
@@ -287,7 +315,7 @@ def assign(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
287
315
|
target_var: An uninitialized scalar quantum variable
|
|
288
316
|
"""
|
|
289
317
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
290
|
-
source_ref = get_source_ref(sys._getframe(
|
|
318
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
291
319
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
|
292
320
|
ArithmeticOperation(
|
|
293
321
|
expression=Expression(expr=str(expression)),
|
|
@@ -299,6 +327,7 @@ def assign(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
299
327
|
|
|
300
328
|
|
|
301
329
|
@suppress_return_value
|
|
330
|
+
@qmod_statement
|
|
302
331
|
def assign_amplitude(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
303
332
|
"""
|
|
304
333
|
Perform an amplitude-encoding assignment operation on a quantum variable and a
|
|
@@ -311,7 +340,7 @@ def assign_amplitude(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
311
340
|
target_var: A scalar quantum variable
|
|
312
341
|
"""
|
|
313
342
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
314
|
-
source_ref = get_source_ref(sys._getframe(
|
|
343
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
315
344
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
|
316
345
|
AmplitudeLoadingOperation(
|
|
317
346
|
expression=Expression(expr=str(expression)),
|
|
@@ -322,6 +351,7 @@ def assign_amplitude(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
322
351
|
|
|
323
352
|
|
|
324
353
|
@suppress_return_value
|
|
354
|
+
@qmod_statement
|
|
325
355
|
def inplace_add(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
326
356
|
"""
|
|
327
357
|
Add an arithmetic expression to a quantum variable.
|
|
@@ -333,7 +363,7 @@ def inplace_add(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
333
363
|
target_var: A scalar quantum variable
|
|
334
364
|
"""
|
|
335
365
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
336
|
-
source_ref = get_source_ref(sys._getframe(
|
|
366
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
337
367
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
|
338
368
|
ArithmeticOperation(
|
|
339
369
|
expression=Expression(expr=str(expression)),
|
|
@@ -345,6 +375,7 @@ def inplace_add(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
345
375
|
|
|
346
376
|
|
|
347
377
|
@suppress_return_value
|
|
378
|
+
@qmod_statement
|
|
348
379
|
def inplace_xor(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
349
380
|
"""
|
|
350
381
|
Bitwise-XOR a quantum variable with an arithmetic expression.
|
|
@@ -356,7 +387,7 @@ def inplace_xor(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
356
387
|
target_var: A scalar quantum variable
|
|
357
388
|
"""
|
|
358
389
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
359
|
-
source_ref = get_source_ref(sys._getframe(
|
|
390
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
360
391
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
|
361
392
|
ArithmeticOperation(
|
|
362
393
|
expression=Expression(expr=str(expression)),
|
|
@@ -368,6 +399,7 @@ def inplace_xor(expression: SymbolicExpr, target_var: QScalar) -> None:
|
|
|
368
399
|
|
|
369
400
|
|
|
370
401
|
@suppress_return_value
|
|
402
|
+
@qmod_statement
|
|
371
403
|
def within_apply(
|
|
372
404
|
within: Callable[[], Statements],
|
|
373
405
|
apply: Callable[[], Statements],
|
|
@@ -387,7 +419,7 @@ def within_apply(
|
|
|
387
419
|
_validate_operand(within)
|
|
388
420
|
_validate_operand(apply)
|
|
389
421
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
390
|
-
source_ref = get_source_ref(sys._getframe(
|
|
422
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
391
423
|
within_apply_stmt = WithinApply(
|
|
392
424
|
compute=_operand_to_body(within, "within"),
|
|
393
425
|
action=_operand_to_body(apply, "apply"),
|
|
@@ -400,6 +432,7 @@ def within_apply(
|
|
|
400
432
|
|
|
401
433
|
|
|
402
434
|
@suppress_return_value
|
|
435
|
+
@qmod_statement
|
|
403
436
|
def repeat(count: SymbolicExpr | int, iteration: Callable[[int], Statements]) -> None:
|
|
404
437
|
"""
|
|
405
438
|
Executes a quantum loop a specified number of times, applying a quantum operation on each iteration.
|
|
@@ -426,7 +459,7 @@ def repeat(count: SymbolicExpr | int, iteration: Callable[[int], Statements]) ->
|
|
|
426
459
|
"""
|
|
427
460
|
_validate_operand(iteration, num_params=1)
|
|
428
461
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
429
|
-
source_ref = get_source_ref(sys._getframe(
|
|
462
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
430
463
|
iteration_operand = prepare_arg(
|
|
431
464
|
QuantumOperandDeclaration(
|
|
432
465
|
name=REPEAT_OPERATOR_NAME,
|
|
@@ -455,6 +488,7 @@ def repeat(count: SymbolicExpr | int, iteration: Callable[[int], Statements]) ->
|
|
|
455
488
|
|
|
456
489
|
|
|
457
490
|
@suppress_return_value
|
|
491
|
+
@qmod_statement
|
|
458
492
|
def power(
|
|
459
493
|
exponent: SymbolicExpr | int,
|
|
460
494
|
stmt_block: QCallable | Callable[[], Statements],
|
|
@@ -489,7 +523,7 @@ def power(
|
|
|
489
523
|
"""
|
|
490
524
|
_validate_operand(stmt_block)
|
|
491
525
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
492
|
-
source_ref = get_source_ref(sys._getframe(
|
|
526
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
493
527
|
power_stmt = Power(
|
|
494
528
|
power=Expression(expr=str(exponent)),
|
|
495
529
|
body=_operand_to_body(stmt_block, "stmt_block"),
|
|
@@ -501,6 +535,7 @@ def power(
|
|
|
501
535
|
|
|
502
536
|
|
|
503
537
|
@suppress_return_value
|
|
538
|
+
@qmod_statement
|
|
504
539
|
def invert(stmt_block: QCallable | Callable[[], Statements]) -> None:
|
|
505
540
|
"""
|
|
506
541
|
Apply the inverse of a quantum gate.
|
|
@@ -525,7 +560,7 @@ def invert(stmt_block: QCallable | Callable[[], Statements]) -> None:
|
|
|
525
560
|
"""
|
|
526
561
|
_validate_operand(stmt_block)
|
|
527
562
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
528
|
-
source_ref = get_source_ref(sys._getframe(
|
|
563
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
529
564
|
invert_stmt = Invert(
|
|
530
565
|
body=_operand_to_body(stmt_block, "stmt_block"), source_ref=source_ref
|
|
531
566
|
)
|
|
@@ -535,6 +570,7 @@ def invert(stmt_block: QCallable | Callable[[], Statements]) -> None:
|
|
|
535
570
|
|
|
536
571
|
|
|
537
572
|
@suppress_return_value
|
|
573
|
+
@qmod_statement
|
|
538
574
|
def phase(
|
|
539
575
|
phase_expr: SymbolicExpr | float | None = None,
|
|
540
576
|
theta: SymbolicExpr | float = 1.0,
|
|
@@ -557,7 +593,7 @@ def phase(
|
|
|
557
593
|
they are equivalent when the phase_expr is a single-qubit variable.
|
|
558
594
|
"""
|
|
559
595
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
560
|
-
source_ref = get_source_ref(sys._getframe(
|
|
596
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
561
597
|
QCallable.CURRENT_EXPANDABLE.append_statement_to_body(
|
|
562
598
|
PhaseOperation(
|
|
563
599
|
expression=Expression(expr=str(phase_expr)),
|
|
@@ -568,12 +604,13 @@ def phase(
|
|
|
568
604
|
|
|
569
605
|
|
|
570
606
|
@suppress_return_value
|
|
607
|
+
@qmod_statement
|
|
571
608
|
def block(
|
|
572
609
|
statements: QCallable | Callable[[], Statements],
|
|
573
610
|
) -> None:
|
|
574
611
|
_validate_operand(statements)
|
|
575
612
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
576
|
-
source_ref = get_source_ref(sys._getframe(
|
|
613
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
577
614
|
|
|
578
615
|
block_stmt = Block(
|
|
579
616
|
statements=_operand_to_body(statements, "statements"),
|
|
@@ -601,13 +638,14 @@ def reset_bounds(
|
|
|
601
638
|
|
|
602
639
|
|
|
603
640
|
@suppress_return_value
|
|
641
|
+
@qmod_statement
|
|
604
642
|
def reset_bounds(
|
|
605
643
|
target_var: QNum,
|
|
606
644
|
lower_bound: float | SymbolicExpr | None = None,
|
|
607
645
|
upper_bound: float | SymbolicExpr | None = None,
|
|
608
646
|
) -> None:
|
|
609
647
|
assert QCallable.CURRENT_EXPANDABLE is not None
|
|
610
|
-
source_ref = get_source_ref(sys._getframe(
|
|
648
|
+
source_ref = get_source_ref(sys._getframe(2))
|
|
611
649
|
|
|
612
650
|
lower_bound_expr = (
|
|
613
651
|
None if lower_bound is None else Expression(expr=str(lower_bound))
|
classiq/qmod/builtins/structs.py
CHANGED
|
@@ -3,6 +3,7 @@ from typing import Union
|
|
|
3
3
|
|
|
4
4
|
from classiq.interface.exceptions import ClassiqValueError
|
|
5
5
|
from classiq.interface.generator.types.struct_declaration import StructDeclaration
|
|
6
|
+
from classiq.interface.helpers.datastructures import LenList
|
|
6
7
|
from classiq.interface.helpers.text_utils import are, readable_list, s
|
|
7
8
|
|
|
8
9
|
from classiq.qmod.builtins.enums import Pauli
|
|
@@ -69,13 +70,15 @@ class SparsePauliOp:
|
|
|
69
70
|
def __mul__(self, obj: Union[float, "SparsePauliOp"]) -> "SparsePauliOp":
|
|
70
71
|
if isinstance(obj, (int, float, complex)):
|
|
71
72
|
return SparsePauliOp(
|
|
72
|
-
terms=
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
terms=LenList(
|
|
74
|
+
[
|
|
75
|
+
SparsePauliTerm(
|
|
76
|
+
paulis=term.paulis,
|
|
77
|
+
coefficient=obj * term.coefficient, # type:ignore[arg-type]
|
|
78
|
+
)
|
|
79
|
+
for term in self.terms
|
|
80
|
+
]
|
|
81
|
+
),
|
|
79
82
|
num_qubits=self.num_qubits,
|
|
80
83
|
)
|
|
81
84
|
if len(self.terms) != 1 or len(obj.terms) != 1:
|
|
@@ -97,14 +100,17 @@ class SparsePauliOp:
|
|
|
97
100
|
f"already assigned"
|
|
98
101
|
)
|
|
99
102
|
return SparsePauliOp(
|
|
100
|
-
terms=
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
terms=LenList(
|
|
104
|
+
[
|
|
105
|
+
SparsePauliTerm(
|
|
106
|
+
paulis=LenList( # type:ignore[call-overload]
|
|
107
|
+
self.terms[0].paulis + obj.terms[0].paulis
|
|
108
|
+
),
|
|
109
|
+
coefficient=self.terms[0].coefficient
|
|
110
|
+
* obj.terms[0].coefficient, # type:ignore[arg-type]
|
|
111
|
+
)
|
|
112
|
+
]
|
|
113
|
+
),
|
|
108
114
|
num_qubits=max(self.num_qubits, obj.num_qubits),
|
|
109
115
|
)
|
|
110
116
|
|
|
@@ -113,7 +119,7 @@ class SparsePauliOp:
|
|
|
113
119
|
|
|
114
120
|
def __add__(self, other: "SparsePauliOp") -> "SparsePauliOp":
|
|
115
121
|
return SparsePauliOp(
|
|
116
|
-
terms=self.terms + other.terms,
|
|
122
|
+
terms=LenList(self.terms + other.terms),
|
|
117
123
|
num_qubits=max(self.num_qubits, other.num_qubits),
|
|
118
124
|
)
|
|
119
125
|
|
|
@@ -156,21 +162,6 @@ class LogNormalModel:
|
|
|
156
162
|
sigma: CReal
|
|
157
163
|
|
|
158
164
|
|
|
159
|
-
@dataclass
|
|
160
|
-
class QsvmResult:
|
|
161
|
-
test_score: CReal
|
|
162
|
-
predicted_labels: CArray[CReal]
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
@dataclass
|
|
166
|
-
class QSVMFeatureMapPauli:
|
|
167
|
-
feature_dimension: CInt
|
|
168
|
-
reps: CInt
|
|
169
|
-
entanglement: CInt
|
|
170
|
-
alpha: CReal
|
|
171
|
-
paulis: CArray[CArray[Pauli]]
|
|
172
|
-
|
|
173
|
-
|
|
174
165
|
BUILTIN_STRUCT_DECLARATIONS = {
|
|
175
166
|
struct_decl.__name__: StructDeclaration(
|
|
176
167
|
name=struct_decl.__name__,
|
|
@@ -190,8 +181,6 @@ __all__ = [
|
|
|
190
181
|
"IndexedPauli",
|
|
191
182
|
"LogNormalModel",
|
|
192
183
|
"PauliTerm",
|
|
193
|
-
"QSVMFeatureMapPauli",
|
|
194
|
-
"QsvmResult",
|
|
195
184
|
"SparsePauliOp",
|
|
196
185
|
"SparsePauliTerm",
|
|
197
186
|
]
|
|
@@ -4,7 +4,7 @@ from typing import Any
|
|
|
4
4
|
|
|
5
5
|
from classiq.interface.exceptions import ClassiqError
|
|
6
6
|
from classiq.interface.model.model import Model
|
|
7
|
-
from classiq.interface.model.model_visitor import
|
|
7
|
+
from classiq.interface.model.model_visitor import ModelStatementsVisitor
|
|
8
8
|
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
|
9
9
|
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
|
10
10
|
from classiq.interface.model.quantum_function_declaration import (
|
|
@@ -47,7 +47,7 @@ def _annotate_function_call_decl(
|
|
|
47
47
|
qlambda.set_op_decl(param)
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
class _CallLambdaAnnotator(
|
|
50
|
+
class _CallLambdaAnnotator(ModelStatementsVisitor):
|
|
51
51
|
def __init__(
|
|
52
52
|
self, quantum_functions: Mapping[str, QuantumFunctionDeclaration]
|
|
53
53
|
) -> None:
|
|
@@ -76,7 +76,7 @@ class _CallLambdaAnnotator(ModelVisitor):
|
|
|
76
76
|
_annotate_function_call_decl(
|
|
77
77
|
call, self._quantum_functions | self._current_operands
|
|
78
78
|
)
|
|
79
|
-
self.
|
|
79
|
+
self.visit(call.positional_args)
|
|
80
80
|
|
|
81
81
|
|
|
82
82
|
def resolve_function_calls(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from collections.abc import Iterator
|
|
2
2
|
from contextlib import contextmanager
|
|
3
3
|
|
|
4
|
-
from classiq.interface.ast_node import ASTNode
|
|
5
4
|
from classiq.interface.exceptions import CLASSIQ_SLACK_COMMUNITY_LINK
|
|
6
5
|
from classiq.interface.source_reference import SourceReference, SourceReferencedError
|
|
7
6
|
|
|
@@ -18,14 +17,14 @@ class ErrorManager:
|
|
|
18
17
|
self._instantiated = True
|
|
19
18
|
self._errors: list[SourceReferencedError] = []
|
|
20
19
|
self._warnings: list[SourceReferencedError] = []
|
|
21
|
-
self.
|
|
20
|
+
self._current_refs_stack: list[SourceReference | None] = []
|
|
22
21
|
self._call_stack: list[str] = []
|
|
23
22
|
self._ignore_errors: bool = False
|
|
24
23
|
|
|
25
24
|
@property
|
|
26
25
|
def _current_source_ref(self) -> SourceReference | None:
|
|
27
|
-
if self.
|
|
28
|
-
return self.
|
|
26
|
+
if self._current_refs_stack:
|
|
27
|
+
return self._current_refs_stack[-1]
|
|
29
28
|
return None
|
|
30
29
|
|
|
31
30
|
@contextmanager
|
|
@@ -79,7 +78,7 @@ class ErrorManager:
|
|
|
79
78
|
self.clear_warnings()
|
|
80
79
|
|
|
81
80
|
def clear_errors(self) -> None:
|
|
82
|
-
self.
|
|
81
|
+
self._current_refs_stack = []
|
|
83
82
|
self._errors = []
|
|
84
83
|
|
|
85
84
|
def clear_warnings(self) -> None:
|
|
@@ -108,10 +107,10 @@ class ErrorManager:
|
|
|
108
107
|
return self._call_stack[-1] if self._call_stack else None
|
|
109
108
|
|
|
110
109
|
@contextmanager
|
|
111
|
-
def
|
|
112
|
-
self.
|
|
110
|
+
def source_ref_context(self, ref: SourceReference | None) -> Iterator[None]:
|
|
111
|
+
self._current_refs_stack.append(ref)
|
|
113
112
|
yield
|
|
114
|
-
self.
|
|
113
|
+
self._current_refs_stack.pop()
|
|
115
114
|
|
|
116
115
|
@contextmanager
|
|
117
116
|
def call(self, func_name: str) -> Iterator[None]:
|