classiq 0.90.0__py3-none-any.whl → 0.91.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.
Files changed (41) hide show
  1. classiq/evaluators/expression_evaluator.py +24 -124
  2. classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +10 -3
  3. classiq/evaluators/qmod_node_evaluators/utils.py +0 -8
  4. classiq/interface/_version.py +1 -1
  5. classiq/interface/executor/result.py +22 -3
  6. classiq/interface/generator/expressions/expression_types.py +2 -0
  7. classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +3 -8
  8. classiq/interface/generator/functions/classical_type.py +2 -5
  9. classiq/interface/generator/functions/type_name.py +0 -12
  10. classiq/interface/model/quantum_type.py +0 -39
  11. classiq/model_expansions/capturing/captured_vars.py +3 -0
  12. classiq/model_expansions/function_builder.py +18 -2
  13. classiq/model_expansions/interpreters/frontend_generative_interpreter.py +0 -10
  14. classiq/model_expansions/interpreters/generative_interpreter.py +63 -18
  15. classiq/model_expansions/quantum_operations/emitter.py +13 -3
  16. classiq/model_expansions/quantum_operations/expression_evaluator.py +49 -5
  17. classiq/model_expansions/scope.py +5 -14
  18. classiq/model_expansions/utils/handles_collector.py +7 -0
  19. classiq/qmod/builtins/operations.py +7 -3
  20. classiq/qmod/qmod_variable.py +3 -4
  21. classiq/qmod/semantics/error_manager.py +34 -15
  22. classiq/qmod/symbolic.py +15 -4
  23. classiq/qmod/utilities.py +4 -1
  24. classiq/synthesis.py +1 -2
  25. {classiq-0.90.0.dist-info → classiq-0.91.1.dist-info}/METADATA +1 -1
  26. {classiq-0.90.0.dist-info → classiq-0.91.1.dist-info}/RECORD +27 -41
  27. classiq/interface/generator/expressions/handle_identifier.py +0 -6
  28. classiq/interface/generator/expressions/proxies/classical/any_classical_value.py +0 -41
  29. classiq/interface/generator/expressions/proxies/quantum/__init__.py +0 -0
  30. classiq/interface/generator/expressions/proxies/quantum/qmod_qarray_proxy.py +0 -80
  31. classiq/interface/generator/expressions/proxies/quantum/qmod_qscalar_proxy.py +0 -77
  32. classiq/interface/generator/expressions/proxies/quantum/qmod_qstruct_proxy.py +0 -38
  33. classiq/interface/generator/expressions/proxies/quantum/qmod_sized_proxy.py +0 -39
  34. classiq/interface/generator/expressions/type_proxy.py +0 -10
  35. classiq/model_expansions/atomic_expression_functions_defs.py +0 -395
  36. classiq/model_expansions/model_tables.py +0 -18
  37. classiq/model_expansions/sympy_conversion/__init__.py +0 -0
  38. classiq/model_expansions/sympy_conversion/expression_to_sympy.py +0 -181
  39. classiq/model_expansions/sympy_conversion/sympy_to_python.py +0 -136
  40. classiq/model_expansions/utils/sympy_utils.py +0 -24
  41. {classiq-0.90.0.dist-info → classiq-0.91.1.dist-info}/WHEEL +0 -0
@@ -1,136 +0,0 @@
1
- import functools
2
- from typing import Any, Optional, get_args
3
-
4
- from sympy import (
5
- Array,
6
- Basic,
7
- Expr,
8
- Float,
9
- Integer,
10
- Matrix,
11
- Piecewise,
12
- Rational,
13
- Symbol,
14
- )
15
- from sympy.logic.boolalg import BooleanAtom
16
- from sympy.printing.pycode import PythonCodePrinter
17
-
18
- from classiq.interface.exceptions import ClassiqInternalExpansionError
19
- from classiq.interface.generator.expressions.expression_types import (
20
- ExpressionValue,
21
- RuntimeConstant,
22
- )
23
- from classiq.interface.generator.expressions.proxies.classical.any_classical_value import (
24
- AnyClassicalValue,
25
- )
26
-
27
- from classiq.evaluators.qmod_annotated_expression import QmodAnnotatedExpression
28
- from classiq.evaluators.qmod_expression_visitors.sympy_wrappers import LogicalXor
29
-
30
-
31
- def sympy_to_python(
32
- value: Any, locals: Optional[dict[str, ExpressionValue]] = None
33
- ) -> ExpressionValue:
34
- if isinstance(value, AnyClassicalValue):
35
- pass
36
- elif isinstance(value, Integer):
37
- value = int(value)
38
- elif isinstance(value, Float):
39
- value = float(value)
40
- elif isinstance(value, BooleanAtom):
41
- value = bool(value)
42
- elif isinstance(value, Array):
43
- value = sympy_to_python(value.tolist(), locals)
44
- elif isinstance(value, Rational):
45
- value = float(value.evalf())
46
- elif isinstance(value, list):
47
- value = [sympy_to_python(element, locals) for element in value]
48
- elif isinstance(value, Matrix):
49
- value = [sympy_to_python(element, locals) for element in value.tolist()]
50
- elif isinstance(value, Symbol) and locals is not None and value.name in locals:
51
- return locals[value.name]
52
- if value is None:
53
- value = False
54
-
55
- if not isinstance(value, (*get_args(RuntimeConstant), QmodAnnotatedExpression)):
56
- raise ClassiqInternalExpansionError(
57
- f"Invalid evaluated expression {value} of type {type(value)}"
58
- )
59
-
60
- return value
61
-
62
-
63
- def _conditional_true(*args: Any, **kwargs: Any) -> bool:
64
- return True
65
-
66
-
67
- class SympyToQuantumExpressionTranslator(PythonCodePrinter):
68
- _operators = {**PythonCodePrinter._operators, **{"not": "~", "xor": "^"}}
69
- _kf = {
70
- **PythonCodePrinter._kf,
71
- **{"max": "max", "min": "min", "Max": "max", "Min": "min"},
72
- }
73
- BINARY_BITWISE_OPERATORS_MAPPING = {
74
- "BitwiseAnd": "&",
75
- "BitwiseOr": "|",
76
- "BitwiseXor": "^",
77
- "LogicalXor": "^",
78
- "RShift": ">>",
79
- "LShift": "<<",
80
- }
81
- UNARY_BITWISE_OPERATORS_MAPPING = {"BitwiseNot": "~"}
82
-
83
- @staticmethod
84
- def _print_bitwise_binary_operator(
85
- left_arg: Expr, right_arg: Expr, operator: str
86
- ) -> str:
87
- return f"(({left_arg}) {operator} ({right_arg}))"
88
-
89
- @staticmethod
90
- def _print_bitwise_unary_operator(arg: Expr, operator: str) -> str:
91
- return f"({operator} ({arg}))"
92
-
93
- def __init__(self) -> None:
94
- super().__init__(settings={"fully_qualified_modules": False})
95
- for binary_operator in self.BINARY_BITWISE_OPERATORS_MAPPING:
96
- self.known_functions[binary_operator] = [
97
- (
98
- _conditional_true,
99
- functools.partial(
100
- self._print_bitwise_binary_operator,
101
- operator=self.BINARY_BITWISE_OPERATORS_MAPPING[binary_operator],
102
- ),
103
- )
104
- ]
105
- for unary_operator in self.UNARY_BITWISE_OPERATORS_MAPPING:
106
- self.known_functions[unary_operator] = [
107
- (
108
- _conditional_true,
109
- functools.partial(
110
- self._print_bitwise_unary_operator,
111
- operator=self.UNARY_BITWISE_OPERATORS_MAPPING[unary_operator],
112
- ),
113
- )
114
- ]
115
-
116
- def _print_Piecewise(self, expr: Piecewise) -> str: # noqa: N802
117
- return str(expr)
118
-
119
- def _print_LogicalXor(self, expr: LogicalXor) -> str: # noqa: N802
120
- return f"(({self._print(expr.args[0])}) ^ ({self._print(expr.args[1])}))"
121
-
122
-
123
- class SympyToBoolExpressionTranslator(SympyToQuantumExpressionTranslator):
124
- _operators = {
125
- **SympyToQuantumExpressionTranslator._operators,
126
- **{"not": "not ", "xor": "xor"},
127
- }
128
-
129
-
130
- def translate_sympy_quantum_expression(expr: Basic, preserve_bool_ops: bool) -> str:
131
- if isinstance(expr, AnyClassicalValue):
132
- return str(expr)
133
- if preserve_bool_ops:
134
- return SympyToBoolExpressionTranslator().doprint(expr)
135
- else:
136
- return SympyToQuantumExpressionTranslator().doprint(expr)
@@ -1,24 +0,0 @@
1
- from typing import Any
2
-
3
- from sympy import Number
4
-
5
-
6
- def unwrap_sympy_numeric(n: Any) -> Any:
7
- if not isinstance(n, Number) or not n.is_constant():
8
- return n
9
- if n.is_Integer:
10
- return int(n)
11
- return float(n)
12
-
13
-
14
- def is_constant_subscript(index: Any) -> bool:
15
- if not isinstance(index, slice):
16
- return isinstance(unwrap_sympy_numeric(index), int)
17
- start = unwrap_sympy_numeric(index.start)
18
- stop = unwrap_sympy_numeric(index.stop)
19
- step = unwrap_sympy_numeric(index.step)
20
- return (
21
- (start is None or isinstance(start, int))
22
- and (stop is None or isinstance(stop, int))
23
- and (step is None or isinstance(step, int))
24
- )