classiq 0.89.0__py3-none-any.whl → 0.91.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.

Files changed (108) hide show
  1. classiq/__init__.py +1 -0
  2. classiq/_internals/api_wrapper.py +16 -32
  3. classiq/analyzer/show_interactive_hack.py +26 -1
  4. classiq/applications/chemistry/chemistry_model_constructor.py +14 -2
  5. classiq/applications/combinatorial_helpers/pyomo_utils.py +9 -6
  6. classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +2 -2
  7. classiq/applications/combinatorial_optimization/combinatorial_problem.py +16 -8
  8. classiq/evaluators/classical_expression.py +63 -41
  9. classiq/evaluators/control.py +31 -52
  10. classiq/evaluators/expression_evaluator.py +31 -127
  11. classiq/evaluators/parameter_types.py +200 -104
  12. classiq/evaluators/qmod_annotated_expression.py +3 -1
  13. classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +10 -3
  14. classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +12 -37
  15. classiq/evaluators/qmod_node_evaluators/constant_evaluation.py +8 -17
  16. classiq/evaluators/qmod_node_evaluators/measurement_evaluation.py +1 -1
  17. classiq/evaluators/qmod_node_evaluators/min_max_evaluation.py +7 -1
  18. classiq/evaluators/qmod_node_evaluators/name_evaluation.py +0 -1
  19. classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +9 -1
  20. classiq/evaluators/qmod_node_evaluators/utils.py +33 -8
  21. classiq/evaluators/qmod_type_inference/classical_type_inference.py +4 -7
  22. classiq/interface/_version.py +1 -1
  23. classiq/interface/analyzer/analysis_params.py +1 -25
  24. classiq/interface/analyzer/result.py +4 -0
  25. classiq/interface/chemistry/ground_state_problem.py +16 -2
  26. classiq/interface/executor/optimizer_preferences.py +0 -112
  27. classiq/interface/executor/result.py +22 -3
  28. classiq/interface/generator/application_apis/chemistry_declarations.py +3 -1
  29. classiq/interface/generator/arith/arithmetic_expression_validator.py +2 -7
  30. classiq/interface/generator/expressions/evaluated_expression.py +3 -13
  31. classiq/interface/generator/expressions/expression_types.py +10 -22
  32. classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +3 -8
  33. classiq/interface/generator/expressions/proxies/classical/classical_proxy.py +2 -2
  34. classiq/interface/generator/expressions/proxies/classical/classical_struct_proxy.py +1 -2
  35. classiq/interface/generator/functions/classical_type.py +2 -5
  36. classiq/interface/generator/functions/concrete_types.py +1 -1
  37. classiq/interface/generator/functions/type_name.py +0 -12
  38. classiq/interface/generator/generated_circuit_data.py +4 -0
  39. classiq/interface/generator/preferences/qasm_to_qmod_params.py +14 -0
  40. classiq/interface/helpers/model_normalizer.py +0 -6
  41. classiq/interface/ide/visual_model.py +1 -0
  42. classiq/interface/model/handle_binding.py +1 -1
  43. classiq/interface/model/port_declaration.py +2 -1
  44. classiq/interface/model/quantum_expressions/arithmetic_operation.py +16 -12
  45. classiq/interface/model/quantum_type.py +1 -40
  46. classiq/interface/server/routes.py +2 -3
  47. classiq/model_expansions/capturing/captured_vars.py +10 -3
  48. classiq/model_expansions/closure.py +8 -0
  49. classiq/model_expansions/function_builder.py +18 -2
  50. classiq/model_expansions/interpreters/base_interpreter.py +84 -22
  51. classiq/model_expansions/interpreters/frontend_generative_interpreter.py +1 -11
  52. classiq/model_expansions/interpreters/generative_interpreter.py +67 -20
  53. classiq/model_expansions/quantum_operations/allocate.py +92 -21
  54. classiq/model_expansions/quantum_operations/assignment_result_processor.py +28 -27
  55. classiq/model_expansions/quantum_operations/call_emitter.py +32 -26
  56. classiq/model_expansions/quantum_operations/classical_var_emitter.py +6 -2
  57. classiq/model_expansions/quantum_operations/emitter.py +50 -70
  58. classiq/model_expansions/quantum_operations/expression_evaluator.py +62 -7
  59. classiq/model_expansions/quantum_operations/quantum_function_call.py +4 -5
  60. classiq/model_expansions/quantum_operations/variable_decleration.py +16 -11
  61. classiq/model_expansions/scope.py +39 -41
  62. classiq/model_expansions/scope_initialization.py +3 -6
  63. classiq/model_expansions/transformers/model_renamer.py +35 -64
  64. classiq/model_expansions/transformers/type_modifier_inference.py +6 -6
  65. classiq/model_expansions/utils/handles_collector.py +7 -0
  66. classiq/model_expansions/visitors/boolean_expression_transformers.py +7 -31
  67. classiq/model_expansions/visitors/symbolic_param_inference.py +9 -3
  68. classiq/open_library/functions/state_preparation.py +3 -3
  69. classiq/qmod/builtins/functions/allocation.py +8 -8
  70. classiq/qmod/builtins/functions/arithmetic.py +1 -1
  71. classiq/qmod/builtins/functions/chemistry.py +64 -0
  72. classiq/qmod/builtins/functions/exponentiation.py +7 -13
  73. classiq/qmod/builtins/functions/qsvm.py +1 -1
  74. classiq/qmod/builtins/operations.py +42 -10
  75. classiq/qmod/generative.py +2 -4
  76. classiq/qmod/native/pretty_printer.py +1 -1
  77. classiq/qmod/pretty_print/pretty_printer.py +1 -1
  78. classiq/qmod/qmod_constant.py +1 -1
  79. classiq/qmod/qmod_parameter.py +2 -2
  80. classiq/qmod/qmod_variable.py +18 -19
  81. classiq/qmod/quantum_expandable.py +1 -1
  82. classiq/qmod/semantics/error_manager.py +34 -15
  83. classiq/qmod/symbolic.py +15 -4
  84. classiq/qmod/utilities.py +4 -1
  85. classiq/synthesis.py +38 -3
  86. classiq/visualization.py +1 -1
  87. {classiq-0.89.0.dist-info → classiq-0.91.0.dist-info}/METADATA +1 -1
  88. {classiq-0.89.0.dist-info → classiq-0.91.0.dist-info}/RECORD +89 -107
  89. classiq/evaluators/arg_type_match.py +0 -168
  90. classiq/evaluators/classical_type_inference.py +0 -121
  91. classiq/interface/combinatorial_optimization/optimization_problem.py +0 -17
  92. classiq/interface/combinatorial_optimization/result.py +0 -9
  93. classiq/interface/generator/expressions/handle_identifier.py +0 -6
  94. classiq/interface/generator/expressions/proxies/classical/any_classical_value.py +0 -41
  95. classiq/interface/generator/expressions/proxies/quantum/__init__.py +0 -0
  96. classiq/interface/generator/expressions/proxies/quantum/qmod_qarray_proxy.py +0 -80
  97. classiq/interface/generator/expressions/proxies/quantum/qmod_qscalar_proxy.py +0 -77
  98. classiq/interface/generator/expressions/proxies/quantum/qmod_qstruct_proxy.py +0 -38
  99. classiq/interface/generator/expressions/proxies/quantum/qmod_sized_proxy.py +0 -39
  100. classiq/interface/generator/expressions/type_proxy.py +0 -10
  101. classiq/model_expansions/atomic_expression_functions_defs.py +0 -413
  102. classiq/model_expansions/model_tables.py +0 -18
  103. classiq/model_expansions/sympy_conversion/__init__.py +0 -0
  104. classiq/model_expansions/sympy_conversion/expression_to_sympy.py +0 -181
  105. classiq/model_expansions/sympy_conversion/sympy_to_python.py +0 -132
  106. classiq/model_expansions/transformers/ast_renamer.py +0 -26
  107. classiq/model_expansions/utils/sympy_utils.py +0 -24
  108. {classiq-0.89.0.dist-info → classiq-0.91.0.dist-info}/WHEEL +0 -0
@@ -1,168 +0,0 @@
1
- from collections.abc import Sequence
2
- from enum import Enum
3
- from typing import Any
4
-
5
- from classiq.interface.exceptions import ClassiqExpansionError
6
- from classiq.interface.generator.expressions.proxies.classical.qmod_struct_instance import (
7
- QmodStructInstance,
8
- )
9
- from classiq.interface.generator.expressions.proxies.quantum.qmod_sized_proxy import (
10
- QmodSizedProxy,
11
- )
12
- from classiq.interface.generator.functions.classical_type import (
13
- StructMetaType,
14
- )
15
- from classiq.interface.generator.functions.concrete_types import ConcreteClassicalType
16
- from classiq.interface.generator.functions.type_name import (
17
- TypeName,
18
- )
19
- from classiq.interface.model.classical_parameter_declaration import (
20
- AnonClassicalParameterDeclaration,
21
- )
22
- from classiq.interface.model.port_declaration import AnonPortDeclaration
23
- from classiq.interface.model.quantum_function_declaration import (
24
- AnonPositionalArg,
25
- AnonQuantumOperandDeclaration,
26
- )
27
-
28
- from classiq.evaluators.type_type_match import check_signature_match
29
- from classiq.model_expansions.closure import FunctionClosure
30
- from classiq.model_expansions.scope import Evaluated, QuantumVariable
31
- from classiq.qmod.model_state_container import QMODULE
32
- from classiq.qmod.qmod_parameter import CInt, get_qmod_type
33
-
34
-
35
- def check_type_match(
36
- parameters: Sequence[AnonPositionalArg],
37
- arguments: list[Evaluated],
38
- function_name: str,
39
- ) -> None:
40
- if len(parameters) != len(arguments):
41
- raise ClassiqExpansionError(
42
- f"Function {function_name!r} takes {len(parameters)} arguments but "
43
- f"{len(arguments)} were given"
44
- )
45
- for parameter, evaluated_arg in zip(parameters, arguments):
46
- check_arg_type_match(evaluated_arg.value, parameter, function_name)
47
-
48
-
49
- def check_arg_type_match(
50
- argument: Any, parameter: AnonPositionalArg, function_name: str
51
- ) -> None:
52
- message_prefix = (
53
- f"Argument {str(argument)!r} to parameter {parameter.name!r} of function "
54
- f"{function_name!r} has incompatible type; "
55
- )
56
- if isinstance(parameter, AnonPortDeclaration):
57
- error_message = message_prefix + "expected quantum variable"
58
- _check_qvar_type_match(argument, error_message)
59
- elif isinstance(parameter, AnonQuantumOperandDeclaration):
60
- if parameter.is_list:
61
- error_message = message_prefix + "expected list of operands"
62
- _check_operand_list_type_match(
63
- argument, parameter, function_name, error_message
64
- )
65
- else:
66
- error_message = message_prefix + "expected operand"
67
- _check_operand_type_match(argument, parameter, function_name, error_message)
68
- elif isinstance(parameter, AnonClassicalParameterDeclaration):
69
- error_message = (
70
- message_prefix + f"expected {_resolve_type_name(parameter.classical_type)}"
71
- )
72
- _check_classical_type_match(argument, parameter, error_message, function_name)
73
- else:
74
- raise ClassiqExpansionError(
75
- f"unexpected parameter declaration type: {type(parameter).__name__}"
76
- )
77
-
78
-
79
- def _check_qvar_type_match(argument: Any, error_message: str) -> None:
80
- if not isinstance(argument, QuantumVariable):
81
- raise ClassiqExpansionError(error_message)
82
-
83
-
84
- def _check_operand_list_type_match(
85
- argument: Any,
86
- parameter: AnonQuantumOperandDeclaration,
87
- function_name: str,
88
- error_message: str,
89
- ) -> None:
90
- if not isinstance(argument, list) or any(
91
- not isinstance(op, FunctionClosure) for op in argument
92
- ):
93
- raise ClassiqExpansionError(error_message)
94
- for idx, operand in enumerate(argument):
95
- if operand.positional_arg_declarations is not None:
96
- check_signature_match(
97
- parameter.positional_arg_declarations,
98
- operand.positional_arg_declarations,
99
- f"operand #{idx + 1} in parameter {parameter.name!r} "
100
- f"in function {function_name!r}",
101
- )
102
-
103
-
104
- def _check_operand_type_match(
105
- argument: Any,
106
- parameter: AnonQuantumOperandDeclaration,
107
- function_name: str,
108
- error_message: str,
109
- ) -> None:
110
- if not isinstance(argument, FunctionClosure):
111
- raise ClassiqExpansionError(error_message)
112
- if argument.positional_arg_declarations is not None:
113
- check_signature_match(
114
- parameter.positional_arg_declarations,
115
- argument.positional_arg_declarations,
116
- f"operand {parameter.name!r} in function {function_name!r}",
117
- )
118
-
119
-
120
- def _check_classical_type_match(
121
- argument: Any,
122
- parameter: AnonClassicalParameterDeclaration,
123
- error_message: str,
124
- function_name: str,
125
- ) -> None:
126
- classical_type = parameter.classical_type
127
- type_name = _resolve_type_name(classical_type)
128
- type_is_struct = (
129
- isinstance(classical_type, TypeName)
130
- and classical_type.name in QMODULE.type_decls
131
- )
132
- type_is_enum = (
133
- isinstance(classical_type, TypeName)
134
- and classical_type.name in QMODULE.enum_decls
135
- )
136
- arg_is_qvar = isinstance(argument, QmodSizedProxy)
137
- arg_is_builtin = argument.__class__.__module__ == "builtins"
138
- arg_is_int = isinstance(argument, int)
139
- arg_is_enum = isinstance(argument, Enum)
140
- arg_is_struct = isinstance(argument, QmodStructInstance)
141
- arg_struct_name = None if not arg_is_struct else argument.struct_declaration.name
142
- # FIXME: Remove suzuki_trotter overloading (CLS-2912)
143
- if function_name == "suzuki_trotter" and parameter.name == "pauli_operator":
144
- return
145
- if (
146
- arg_is_qvar
147
- or (arg_is_builtin and type_is_struct)
148
- or (arg_is_builtin and not arg_is_int and type_is_enum)
149
- or (arg_is_struct and (not type_is_struct or arg_struct_name != type_name))
150
- or (
151
- arg_is_enum
152
- and get_qmod_type(classical_type) != CInt
153
- and (not type_is_enum or type(argument).__name__ != type_name)
154
- )
155
- ):
156
- raise ClassiqExpansionError(error_message)
157
-
158
-
159
- def _resolve_type_name(classical_type: ConcreteClassicalType) -> str:
160
- if isinstance(classical_type, StructMetaType):
161
- type_name = "Struct"
162
- else:
163
- type_name = get_qmod_type(classical_type).__name__
164
- if not isinstance(classical_type, TypeName):
165
- return type_name
166
- if type_name not in QMODULE.type_decls and type_name not in QMODULE.enum_decls:
167
- raise ClassiqExpansionError(f"Undefined type {type_name}")
168
- return type_name
@@ -1,121 +0,0 @@
1
- from typing import TYPE_CHECKING, Any, Union
2
-
3
- from classiq.interface.exceptions import ClassiqExpansionError
4
- from classiq.interface.generator.expressions.expression import Expression
5
- from classiq.interface.generator.expressions.proxies.classical.any_classical_value import (
6
- AnyClassicalValue,
7
- )
8
- from classiq.interface.generator.expressions.proxies.classical.classical_array_proxy import (
9
- ClassicalSequenceProxy,
10
- _is_int,
11
- )
12
- from classiq.interface.generator.expressions.proxies.classical.classical_struct_proxy import (
13
- ClassicalStructProxy,
14
- )
15
- from classiq.interface.generator.expressions.proxies.classical.qmod_struct_instance import (
16
- QmodStructInstance,
17
- )
18
- from classiq.interface.generator.functions.classical_type import (
19
- ClassicalArray,
20
- ClassicalTuple,
21
- ClassicalType,
22
- )
23
- from classiq.interface.generator.functions.type_name import TypeName
24
- from classiq.interface.generator.types.struct_declaration import StructDeclaration
25
- from classiq.interface.helpers.backward_compatibility import zip_strict
26
-
27
-
28
- def infer_classical_type(val: Any, classical_type: ClassicalType) -> ClassicalType:
29
- if isinstance(classical_type, TypeName):
30
- return _infer_classical_struct_type(val, classical_type)
31
- if isinstance(classical_type, (ClassicalArray, ClassicalTuple)):
32
- return _infer_classical_array_type(val, classical_type)
33
- return classical_type
34
-
35
-
36
- def _infer_classical_struct_type(val: Any, classical_type: TypeName) -> ClassicalType:
37
- if not isinstance(val, (QmodStructInstance, ClassicalStructProxy)):
38
- return classical_type
39
- if classical_type.is_enum:
40
- raise ClassiqExpansionError(
41
- f"{classical_type.type_name!r} expected, got {str(val)!r}"
42
- )
43
- decl = classical_type.classical_struct_decl
44
- new_fields = {
45
- field_name: infer_classical_type(field_val, field_type)
46
- for (field_name, field_val), field_type in zip_strict(
47
- val.fields.items(),
48
- decl.variables.values(),
49
- strict=True,
50
- )
51
- }
52
- new_classical_type = TypeName(name=decl.name)
53
- new_classical_type.set_classical_struct_decl(
54
- StructDeclaration(name=decl.name, variables=new_fields)
55
- )
56
- return new_classical_type
57
-
58
-
59
- def _infer_classical_array_type(
60
- val: Any, classical_type: Union[ClassicalArray, ClassicalTuple]
61
- ) -> ClassicalType:
62
- if isinstance(val, ClassicalSequenceProxy):
63
- val_length = val.length
64
- elif isinstance(val, list):
65
- val_length = len(val)
66
- elif isinstance(val, AnyClassicalValue):
67
- return classical_type
68
- else:
69
- raise ClassiqExpansionError(f"Array expected, got {str(val)!r}")
70
- if isinstance(val_length, int) and (
71
- (
72
- isinstance(classical_type, ClassicalArray)
73
- and classical_type.length is not None
74
- and classical_type.length.is_evaluated()
75
- and _is_int(classical_type.length.value.value)
76
- and val_length != (type_length := int(classical_type.length.value.value))
77
- )
78
- or (
79
- isinstance(classical_type, ClassicalTuple)
80
- and val_length != (type_length := classical_type.length)
81
- )
82
- ):
83
- raise ClassiqExpansionError(
84
- f"Type mismatch: Argument has {val_length} items but "
85
- f"{type_length} expected"
86
- )
87
- new_classical_type = _infer_inner_array_types(classical_type, val, val_length)
88
- if classical_type.is_generative:
89
- new_classical_type.set_generative()
90
- return new_classical_type
91
-
92
-
93
- def _infer_inner_array_types(
94
- classical_type: ClassicalType, val: Any, val_length: Any
95
- ) -> ClassicalType:
96
- if isinstance(classical_type, ClassicalTuple):
97
- return ClassicalTuple(
98
- element_types=(
99
- infer_classical_type(val[idx], element_type)
100
- for idx, element_type in enumerate(classical_type.element_types)
101
- ),
102
- )
103
- if TYPE_CHECKING:
104
- assert isinstance(classical_type, ClassicalArray)
105
- if _is_int(val_length) and val_length != 0:
106
- return ClassicalTuple(
107
- element_types=(
108
- infer_classical_type(val[i], classical_type.element_type)
109
- for i in range(int(val_length))
110
- ),
111
- )
112
- element_type: ClassicalType
113
- if val_length == 0:
114
- element_type = classical_type.element_type
115
- else:
116
- element_type = infer_classical_type(val[0], classical_type.element_type)
117
- if _is_int(val_length):
118
- length = Expression(expr=str(int(val_length)))
119
- else:
120
- length = None
121
- return ClassicalArray(element_type=element_type, length=length)
@@ -1,17 +0,0 @@
1
- from typing import Any
2
-
3
- import pydantic
4
- from pydantic import BaseModel
5
-
6
- from classiq.interface.executor.optimizer_preferences import CombinatorialOptimizer
7
-
8
-
9
- class MaxCutProblem(BaseModel):
10
- qaoa_reps: pydantic.PositiveInt = pydantic.Field(
11
- default=1, description="Number of layers in qaoa ansatz."
12
- )
13
- optimizer_preferences: CombinatorialOptimizer = pydantic.Field(
14
- default_factory=CombinatorialOptimizer,
15
- description="preferences for the VQE execution",
16
- )
17
- serialized_graph: dict[str, Any]
@@ -1,9 +0,0 @@
1
- from classiq.interface.helpers.versioned_model import VersionedModel
2
-
3
-
4
- class AnglesResult(VersionedModel):
5
- initial_point: list[float]
6
-
7
-
8
- class PyomoObjectResult(VersionedModel):
9
- details: str
@@ -1,6 +0,0 @@
1
- import dataclasses
2
-
3
-
4
- @dataclasses.dataclass(frozen=True)
5
- class HandleIdentifier:
6
- id: int
@@ -1,41 +0,0 @@
1
- import inspect
2
- from typing import Any, NoReturn
3
-
4
- import sympy
5
-
6
- _SYMPY_MEMBERS = [name for name, _ in inspect.getmembers(sympy.Symbol)] + ["precedence"]
7
-
8
-
9
- def subscript_to_str(index: Any) -> str:
10
- if not isinstance(index, slice):
11
- return str(index)
12
- expr = ""
13
- if index.start is not None:
14
- expr += str(index.start)
15
- expr += ":"
16
- if index.stop is not None:
17
- expr += str(index.stop)
18
- if index.step is not None:
19
- expr += f":{index.step}"
20
- return expr
21
-
22
-
23
- class AnyClassicalValue(sympy.Symbol):
24
- def __getitem__(self, item: Any) -> "AnyClassicalValue":
25
- if isinstance(item, slice):
26
- return AnyClassicalValue(f"{self}[{subscript_to_str(item)}]")
27
- return AnyClassicalValue(f"do_subscript({self}, {item})")
28
-
29
- def __getattribute__(self, attr: str) -> Any:
30
- if attr.startswith("_") or attr in _SYMPY_MEMBERS:
31
- return super().__getattribute__(attr)
32
- return AnyClassicalValue(f"get_field({self}, '{attr}')")
33
-
34
- def __len__(self) -> NoReturn:
35
- raise TypeError("object of type 'AnyClassicalValue' has no len()")
36
-
37
- def __iter__(self) -> NoReturn:
38
- raise TypeError("'AnyClassicalValue' object is not iterable")
39
-
40
- def __bool__(self) -> bool:
41
- return True
@@ -1,80 +0,0 @@
1
- from collections.abc import Mapping
2
- from typing import TYPE_CHECKING, Any, Union
3
-
4
- import sympy
5
-
6
- from classiq.interface.exceptions import ClassiqValueError
7
- from classiq.interface.generator.expressions.expression import Expression
8
- from classiq.interface.generator.expressions.non_symbolic_expr import NonSymbolicExpr
9
- from classiq.interface.generator.expressions.proxies.quantum.qmod_sized_proxy import (
10
- QmodSizedProxy,
11
- )
12
- from classiq.interface.model.handle_binding import (
13
- HandleBinding,
14
- SlicedHandleBinding,
15
- SubscriptHandleBinding,
16
- )
17
-
18
- if TYPE_CHECKING:
19
- from classiq.interface.model.quantum_type import QuantumType
20
-
21
-
22
- ILLEGAL_SLICING_STEP_MSG = "Slicing with a step of a quantum variable is not supported"
23
- ILLEGAL_SLICE_MSG = "Quantum array slice must be of the form [<int-value>:<int-value>]."
24
-
25
-
26
- class QmodQArrayProxy(NonSymbolicExpr, QmodSizedProxy):
27
- def __init__(
28
- self,
29
- handle: HandleBinding,
30
- element_type: "QuantumType",
31
- element_size: Union[int, sympy.Basic],
32
- length: Union[int, sympy.Basic],
33
- ) -> None:
34
- super().__init__(handle, element_size * length)
35
- self._length = length
36
- self._element_type = element_type
37
- self._element_size = element_size
38
-
39
- def __getitem__(self, key: Any) -> "QmodSizedProxy":
40
- return (
41
- self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
42
- )
43
-
44
- def _get_subscript(self, index: Any) -> "QmodSizedProxy":
45
- return self._element_type.get_proxy(
46
- SubscriptHandleBinding(
47
- base_handle=self.handle,
48
- index=Expression(expr=str(index)),
49
- )
50
- )
51
-
52
- def _get_slice(self, slice_: slice) -> "QmodSizedProxy":
53
- if slice_.step is not None:
54
- raise ClassiqValueError(ILLEGAL_SLICING_STEP_MSG)
55
- return QmodQArrayProxy(
56
- SlicedHandleBinding(
57
- base_handle=self.handle,
58
- start=Expression(expr=str(slice_.start)),
59
- end=Expression(expr=str(slice_.stop)),
60
- ),
61
- self._element_type,
62
- self._element_size,
63
- slice_.stop - slice_.start,
64
- )
65
-
66
- @property
67
- def type_name(self) -> str:
68
- return "Quantum array"
69
-
70
- @property
71
- def len(self) -> Union[int, sympy.Basic]:
72
- return self._length
73
-
74
- @property
75
- def fields(self) -> Mapping[str, Any]:
76
- return {**super().fields, "len": self.len}
77
-
78
- @property
79
- def size(self) -> int:
80
- return self.len * self._element_size
@@ -1,77 +0,0 @@
1
- from collections.abc import Mapping
2
- from typing import Any, Optional, Union
3
-
4
- import sympy
5
- from sympy import Symbol
6
- from typing_extensions import Self
7
-
8
- from classiq.interface.exceptions import ClassiqValueError
9
- from classiq.interface.generator.expressions.proxies.quantum.qmod_sized_proxy import (
10
- QmodSizedProxy,
11
- )
12
- from classiq.interface.model.handle_binding import HandleBinding
13
-
14
-
15
- class QmodQScalarProxy(Symbol, QmodSizedProxy):
16
- def __new__(cls, handle: HandleBinding, **assumptions: bool) -> "QmodQScalarProxy":
17
- return super().__new__(cls, handle.qmod_expr, **assumptions)
18
-
19
- def __init__(self, handle: HandleBinding, size: int) -> None:
20
- super().__init__(handle, size)
21
-
22
- def __copy__(self) -> Self:
23
- return self
24
-
25
- def __deepcopy__(self, memo: Optional[dict]) -> Self:
26
- return self
27
-
28
-
29
- class QmodQBitProxy(QmodQScalarProxy):
30
- def __init__(self, handle: HandleBinding) -> None:
31
- super().__init__(handle, 1)
32
-
33
- @property
34
- def type_name(self) -> str:
35
- return "Quantum bit"
36
-
37
-
38
- class QmodQNumProxy(QmodQScalarProxy):
39
- def __init__(
40
- self,
41
- handle: HandleBinding,
42
- size: Union[int, sympy.Basic],
43
- fraction_digits: Union[int, sympy.Basic],
44
- is_signed: Union[bool, sympy.Basic],
45
- ) -> None:
46
- super().__init__(handle, size)
47
- if (
48
- isinstance(fraction_digits, int)
49
- and isinstance(size, int)
50
- and fraction_digits > size
51
- ):
52
- raise ClassiqValueError(
53
- f"Quantum numeric of size {size} cannot have {fraction_digits} "
54
- f"fraction digits"
55
- )
56
- self._fraction_digits = fraction_digits
57
- self._is_signed = is_signed
58
-
59
- @property
60
- def type_name(self) -> str:
61
- return "Quantum numeric"
62
-
63
- @property
64
- def fraction_digits(self) -> Union[int, sympy.Basic]:
65
- return self._fraction_digits
66
-
67
- @property
68
- def is_signed(self) -> Union[bool, sympy.Basic]:
69
- return self._is_signed
70
-
71
- @property
72
- def fields(self) -> Mapping[str, Any]:
73
- return {
74
- **super().fields,
75
- "is_signed": self.is_signed,
76
- "fraction_digits": self.fraction_digits,
77
- }
@@ -1,38 +0,0 @@
1
- from collections.abc import Mapping
2
- from typing import TYPE_CHECKING
3
-
4
- from classiq.interface.generator.expressions.non_symbolic_expr import NonSymbolicExpr
5
- from classiq.interface.generator.expressions.proxies.quantum.qmod_sized_proxy import (
6
- QmodSizedProxy,
7
- )
8
- from classiq.interface.model.handle_binding import (
9
- FieldHandleBinding,
10
- HandleBinding,
11
- )
12
-
13
- if TYPE_CHECKING:
14
- from classiq.interface.model.quantum_type import QuantumType
15
-
16
-
17
- class QmodQStructProxy(NonSymbolicExpr, QmodSizedProxy):
18
- def __init__(
19
- self,
20
- handle: HandleBinding,
21
- struct_name: str,
22
- fields: Mapping[str, "QuantumType"],
23
- ) -> None:
24
- self._fields = {
25
- name: type_.get_proxy(FieldHandleBinding(base_handle=handle, field=name))
26
- for name, type_ in fields.items()
27
- }
28
- size = sum(proxy.size for proxy in self._fields.values())
29
- super().__init__(handle, size)
30
- self._struct_name = struct_name
31
-
32
- @property
33
- def type_name(self) -> str:
34
- return self._struct_name
35
-
36
- @property
37
- def fields(self) -> Mapping[str, QmodSizedProxy]:
38
- return {**super().fields, **self._fields}
@@ -1,39 +0,0 @@
1
- from collections.abc import Mapping
2
- from typing import TYPE_CHECKING, Any, Union
3
-
4
- import sympy
5
-
6
- if TYPE_CHECKING:
7
- from classiq.interface.model.handle_binding import HandleBinding
8
-
9
-
10
- class QmodSizedProxy:
11
- def __init__(self, handle: "HandleBinding", size: Union[int, sympy.Basic]) -> None:
12
- self._handle = handle
13
- self._size = size
14
-
15
- @property
16
- def size(self) -> Union[int, sympy.Basic]:
17
- return self._size
18
-
19
- def __str__(self) -> str:
20
- return self.handle.qmod_expr
21
-
22
- def __repr__(self) -> str:
23
- return str(self)
24
-
25
- @property
26
- def type_name(self) -> str:
27
- raise NotImplementedError
28
-
29
- @property
30
- def handle(self) -> "HandleBinding":
31
- return self._handle
32
-
33
- @property
34
- def len(self) -> int:
35
- return self._size
36
-
37
- @property
38
- def fields(self) -> Mapping[str, Any]:
39
- return {"size": self._size}
@@ -1,10 +0,0 @@
1
- from typing import TYPE_CHECKING
2
-
3
- if TYPE_CHECKING:
4
- from classiq.interface.generator.types.struct_declaration import StructDeclaration
5
-
6
-
7
- class TypeProxy:
8
- def __init__(self, struct_declaration: "StructDeclaration") -> None:
9
- super().__init__()
10
- self.struct_declaration = struct_declaration