classiq 0.66.0__py3-none-any.whl → 0.67.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/applications/finance/finance_model_constructor.py +9 -0
- classiq/applications/grover/grover_model_constructor.py +10 -0
- classiq/applications/qnn/qlayer.py +8 -2
- classiq/applications/qsvm/qsvm_model_constructor.py +9 -0
- classiq/interface/_version.py +1 -1
- classiq/interface/debug_info/debug_info.py +12 -0
- classiq/interface/exceptions.py +2 -5
- classiq/interface/generator/arith/argument_utils.py +1 -1
- classiq/interface/generator/arith/arithmetic.py +3 -1
- classiq/interface/generator/arith/binary_ops.py +3 -0
- classiq/interface/generator/function_param_list_without_self_reference.py +2 -0
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +34 -1
- classiq/interface/generator/hardware_efficient_ansatz.py +1 -1
- classiq/interface/generator/hva.py +1 -1
- classiq/interface/generator/model/preferences/preferences.py +8 -1
- classiq/interface/generator/reset.py +14 -0
- classiq/interface/generator/ucc.py +1 -1
- classiq/interface/interface_version.py +1 -1
- classiq/interface/model/quantum_statement.py +13 -0
- classiq/model_expansions/atomic_expression_functions_defs.py +2 -1
- classiq/model_expansions/capturing/captured_vars.py +184 -54
- classiq/model_expansions/closure.py +6 -3
- classiq/model_expansions/evaluators/control.py +14 -38
- classiq/model_expansions/function_builder.py +19 -14
- classiq/model_expansions/generative_functions.py +7 -11
- classiq/model_expansions/interpreters/base_interpreter.py +14 -5
- classiq/model_expansions/interpreters/generative_interpreter.py +9 -8
- classiq/model_expansions/quantum_operations/allocate.py +6 -2
- classiq/model_expansions/quantum_operations/bind.py +65 -13
- classiq/model_expansions/quantum_operations/call_emitter.py +79 -10
- classiq/model_expansions/quantum_operations/classicalif.py +5 -2
- classiq/model_expansions/quantum_operations/emitter.py +8 -1
- classiq/model_expansions/quantum_operations/repeat.py +7 -2
- classiq/model_expansions/quantum_operations/shallow_emitter.py +1 -1
- classiq/model_expansions/quantum_operations/variable_decleration.py +11 -1
- classiq/open_library/functions/__init__.py +8 -0
- classiq/open_library/functions/amplitude_amplification.py +92 -0
- classiq/open_library/functions/grover.py +5 -5
- classiq/qmod/builtins/functions/__init__.py +3 -0
- classiq/qmod/builtins/functions/mid_circuit_measurement.py +15 -0
- classiq/qmod/quantum_function.py +4 -0
- classiq/qmod/semantics/annotation/call_annotation.py +8 -2
- classiq/qmod/semantics/annotation/model_annotation.py +9 -0
- classiq/qmod/semantics/error_manager.py +0 -6
- classiq/qmod/semantics/static_semantics_visitor.py +0 -347
- {classiq-0.66.0.dist-info → classiq-0.67.0.dist-info}/METADATA +1 -1
- {classiq-0.66.0.dist-info → classiq-0.67.0.dist-info}/RECORD +49 -47
- classiq/qmod/semantics/validation/func_call_validation.py +0 -99
- classiq/qmod/semantics/validation/handle_validation.py +0 -85
- {classiq-0.66.0.dist-info → classiq-0.67.0.dist-info}/WHEEL +0 -0
@@ -1,99 +0,0 @@
|
|
1
|
-
from collections.abc import Mapping
|
2
|
-
|
3
|
-
from classiq.interface.exceptions import ClassiqError
|
4
|
-
from classiq.interface.generator.expressions.expression import Expression
|
5
|
-
from classiq.interface.model.handle_binding import HandleBinding
|
6
|
-
from classiq.interface.model.quantum_function_call import QuantumFunctionCall
|
7
|
-
from classiq.interface.model.quantum_function_declaration import (
|
8
|
-
AnonQuantumFunctionDeclaration,
|
9
|
-
AnonQuantumOperandDeclaration,
|
10
|
-
QuantumFunctionDeclaration,
|
11
|
-
)
|
12
|
-
from classiq.interface.model.quantum_lambda_function import (
|
13
|
-
OperandIdentifier,
|
14
|
-
QuantumLambdaFunction,
|
15
|
-
QuantumOperand,
|
16
|
-
)
|
17
|
-
|
18
|
-
from classiq.qmod.semantics.error_manager import ErrorManager
|
19
|
-
|
20
|
-
|
21
|
-
def validate_call_arguments(
|
22
|
-
fc: QuantumFunctionCall,
|
23
|
-
function_dict: Mapping[str, QuantumFunctionDeclaration],
|
24
|
-
) -> None:
|
25
|
-
pos_args = fc.positional_args
|
26
|
-
pos_params = fc.func_decl.positional_arg_declarations
|
27
|
-
if len(pos_args) != len(pos_params):
|
28
|
-
ErrorManager().add_error(
|
29
|
-
f"Function {fc.func_name} takes {len(pos_params)} arguments but "
|
30
|
-
f"{len(pos_args)} were given."
|
31
|
-
)
|
32
|
-
for arg, param in zip(pos_args, pos_params):
|
33
|
-
if not isinstance(arg, (Expression, HandleBinding)) and isinstance(
|
34
|
-
param, AnonQuantumOperandDeclaration
|
35
|
-
):
|
36
|
-
_check_operand_against_declaration(param, arg, function_dict, fc.func_name)
|
37
|
-
check_no_overlapping_quantum_args(fc.ports, fc.func_name)
|
38
|
-
|
39
|
-
|
40
|
-
def _check_operand_against_declaration(
|
41
|
-
operand_decl: AnonQuantumOperandDeclaration,
|
42
|
-
operand_argument: QuantumOperand,
|
43
|
-
function_dict: Mapping[str, QuantumFunctionDeclaration],
|
44
|
-
func_name: str,
|
45
|
-
in_list: bool = False,
|
46
|
-
) -> None:
|
47
|
-
if isinstance(operand_argument, list):
|
48
|
-
if in_list:
|
49
|
-
ErrorManager().add_error(
|
50
|
-
f"{str(operand_argument)!r} argument to {func_name!r} is not "
|
51
|
-
f"a valid operand. Nested operand lists are not permitted."
|
52
|
-
)
|
53
|
-
return
|
54
|
-
for arg in operand_argument:
|
55
|
-
_check_operand_against_declaration(
|
56
|
-
operand_decl, arg, function_dict, func_name, in_list=True
|
57
|
-
)
|
58
|
-
return
|
59
|
-
operand_arg_decl: AnonQuantumFunctionDeclaration
|
60
|
-
operand_argument_for_decl = operand_argument
|
61
|
-
if isinstance(operand_argument_for_decl, OperandIdentifier):
|
62
|
-
operand_argument_for_decl = operand_argument_for_decl.name
|
63
|
-
if isinstance(operand_argument_for_decl, str):
|
64
|
-
if operand_argument_for_decl not in function_dict:
|
65
|
-
ErrorManager().add_error(
|
66
|
-
f"{operand_argument!r} argument to {func_name!r} is not a "
|
67
|
-
f"registered function."
|
68
|
-
)
|
69
|
-
return
|
70
|
-
operand_arg_decl = function_dict[operand_argument_for_decl]
|
71
|
-
elif isinstance(operand_argument_for_decl, QuantumLambdaFunction):
|
72
|
-
operand_arg_decl = operand_argument_for_decl.func_decl
|
73
|
-
else:
|
74
|
-
raise ClassiqError(
|
75
|
-
f"{str(operand_argument)!r} argument to {func_name!r} is not a "
|
76
|
-
f"valid operand."
|
77
|
-
)
|
78
|
-
num_arg_parameters = len(operand_arg_decl.positional_arg_declarations)
|
79
|
-
num_decl_parameters = len(operand_decl.positional_arg_declarations)
|
80
|
-
if num_arg_parameters != num_decl_parameters:
|
81
|
-
ErrorManager().add_error(
|
82
|
-
f"Signature of argument {operand_argument!r} to {func_name!r} "
|
83
|
-
f"does not match the signature of parameter {operand_decl.name!r}. "
|
84
|
-
f"{operand_decl.name!r} accepts {num_decl_parameters} parameters but "
|
85
|
-
f"{operand_argument!r} accepts {num_arg_parameters} parameters."
|
86
|
-
)
|
87
|
-
|
88
|
-
|
89
|
-
def check_no_overlapping_quantum_args(
|
90
|
-
args: list[HandleBinding], func_name: str
|
91
|
-
) -> None:
|
92
|
-
for idx, arg in enumerate(args):
|
93
|
-
for other_arg in args[idx + 1 :]:
|
94
|
-
if arg.overlaps(other_arg):
|
95
|
-
ErrorManager().add_error(
|
96
|
-
f"Cannot use the same part of variable {arg.name!r} in multiple "
|
97
|
-
f"arguments to function {func_name!r}."
|
98
|
-
)
|
99
|
-
break
|
@@ -1,85 +0,0 @@
|
|
1
|
-
from typing import TYPE_CHECKING, Optional, Union
|
2
|
-
|
3
|
-
from classiq.interface.generator.functions.type_name import TypeName
|
4
|
-
from classiq.interface.model.handle_binding import (
|
5
|
-
ConcreteHandleBinding,
|
6
|
-
FieldHandleBinding,
|
7
|
-
HandleBinding,
|
8
|
-
NestedHandleBinding,
|
9
|
-
SlicedHandleBinding,
|
10
|
-
SubscriptHandleBinding,
|
11
|
-
)
|
12
|
-
from classiq.interface.model.quantum_type import QuantumBitvector, QuantumType
|
13
|
-
|
14
|
-
import classiq.qmod.semantics.error_manager as error_manager
|
15
|
-
from classiq.qmod.model_state_container import QMODULE
|
16
|
-
|
17
|
-
if TYPE_CHECKING:
|
18
|
-
from classiq.qmod.semantics.static_semantics_visitor import StaticScope
|
19
|
-
|
20
|
-
|
21
|
-
def resolve_handle(scope: "StaticScope", handle: HandleBinding) -> None:
|
22
|
-
if handle.name not in scope.variables_to_types:
|
23
|
-
error_manager.append_error(handle, f"Variable {handle.name!r} is undefined.")
|
24
|
-
return
|
25
|
-
_resolve_handle_recursively(scope.variables_to_types[handle.name], handle)
|
26
|
-
|
27
|
-
|
28
|
-
def _resolve_handle_recursively(
|
29
|
-
qtype: QuantumType, handle: ConcreteHandleBinding
|
30
|
-
) -> Optional[QuantumType]:
|
31
|
-
if isinstance(handle, NestedHandleBinding):
|
32
|
-
return _resolve_nested_handle(qtype, handle)
|
33
|
-
return qtype
|
34
|
-
|
35
|
-
|
36
|
-
def _resolve_nested_handle(
|
37
|
-
qtype: QuantumType, handle: NestedHandleBinding
|
38
|
-
) -> Optional[QuantumType]:
|
39
|
-
nested_qtype = _resolve_handle_recursively(qtype, handle.base_handle)
|
40
|
-
if nested_qtype is None:
|
41
|
-
return None
|
42
|
-
if isinstance(handle, (SubscriptHandleBinding, SlicedHandleBinding)):
|
43
|
-
return _resolve_subscript_sliced_handle(nested_qtype, handle)
|
44
|
-
if TYPE_CHECKING:
|
45
|
-
assert isinstance(handle, FieldHandleBinding)
|
46
|
-
return _resolve_field_handle(nested_qtype, handle)
|
47
|
-
|
48
|
-
|
49
|
-
def _resolve_subscript_sliced_handle(
|
50
|
-
qtype: QuantumType, handle: Union[SubscriptHandleBinding, SlicedHandleBinding]
|
51
|
-
) -> Optional[QuantumType]:
|
52
|
-
if not isinstance(qtype, QuantumBitvector):
|
53
|
-
error_manager.append_error(handle, f"{qtype.type_name} is not subscriptable.")
|
54
|
-
return None
|
55
|
-
return qtype.element_type if isinstance(handle, SubscriptHandleBinding) else qtype
|
56
|
-
|
57
|
-
|
58
|
-
def _validate_field_access(qtype: QuantumType, handle: FieldHandleBinding) -> bool:
|
59
|
-
if not isinstance(qtype, TypeName):
|
60
|
-
error_manager.append_error(handle, f"{qtype.type_name} has no fields.")
|
61
|
-
return False
|
62
|
-
if qtype.name not in QMODULE.qstruct_decls:
|
63
|
-
error_manager.append_error(
|
64
|
-
handle, f"{qtype.type_name} is not a quantum struct."
|
65
|
-
)
|
66
|
-
return False
|
67
|
-
if handle.field not in qtype.fields:
|
68
|
-
error_manager.append_error(
|
69
|
-
handle,
|
70
|
-
f"Struct {qtype.type_name} has no field {handle.field!r}. "
|
71
|
-
f"Available fields: {', '.join(qtype.fields.keys())}",
|
72
|
-
)
|
73
|
-
return False
|
74
|
-
|
75
|
-
return True
|
76
|
-
|
77
|
-
|
78
|
-
def _resolve_field_handle(
|
79
|
-
qtype: QuantumType, handle: FieldHandleBinding
|
80
|
-
) -> Optional[QuantumType]:
|
81
|
-
if _validate_field_access(qtype, handle):
|
82
|
-
if TYPE_CHECKING:
|
83
|
-
assert isinstance(qtype, TypeName)
|
84
|
-
return qtype.fields[handle.field]
|
85
|
-
return None
|
File without changes
|