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.
- classiq/__init__.py +1 -0
- classiq/_internals/api_wrapper.py +16 -32
- classiq/analyzer/show_interactive_hack.py +26 -1
- classiq/applications/chemistry/chemistry_model_constructor.py +14 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +9 -6
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +2 -2
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +16 -8
- classiq/evaluators/classical_expression.py +63 -41
- classiq/evaluators/control.py +31 -52
- classiq/evaluators/expression_evaluator.py +31 -127
- classiq/evaluators/parameter_types.py +200 -104
- classiq/evaluators/qmod_annotated_expression.py +3 -1
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +10 -3
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +12 -37
- classiq/evaluators/qmod_node_evaluators/constant_evaluation.py +8 -17
- classiq/evaluators/qmod_node_evaluators/measurement_evaluation.py +1 -1
- classiq/evaluators/qmod_node_evaluators/min_max_evaluation.py +7 -1
- classiq/evaluators/qmod_node_evaluators/name_evaluation.py +0 -1
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +9 -1
- classiq/evaluators/qmod_node_evaluators/utils.py +33 -8
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +4 -7
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +1 -25
- classiq/interface/analyzer/result.py +4 -0
- classiq/interface/chemistry/ground_state_problem.py +16 -2
- classiq/interface/executor/optimizer_preferences.py +0 -112
- classiq/interface/executor/result.py +22 -3
- classiq/interface/generator/application_apis/chemistry_declarations.py +3 -1
- classiq/interface/generator/arith/arithmetic_expression_validator.py +2 -7
- classiq/interface/generator/expressions/evaluated_expression.py +3 -13
- classiq/interface/generator/expressions/expression_types.py +10 -22
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +3 -8
- classiq/interface/generator/expressions/proxies/classical/classical_proxy.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_struct_proxy.py +1 -2
- classiq/interface/generator/functions/classical_type.py +2 -5
- classiq/interface/generator/functions/concrete_types.py +1 -1
- classiq/interface/generator/functions/type_name.py +0 -12
- classiq/interface/generator/generated_circuit_data.py +4 -0
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +14 -0
- classiq/interface/helpers/model_normalizer.py +0 -6
- classiq/interface/ide/visual_model.py +1 -0
- classiq/interface/model/handle_binding.py +1 -1
- classiq/interface/model/port_declaration.py +2 -1
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +16 -12
- classiq/interface/model/quantum_type.py +1 -40
- classiq/interface/server/routes.py +2 -3
- classiq/model_expansions/capturing/captured_vars.py +10 -3
- classiq/model_expansions/closure.py +8 -0
- classiq/model_expansions/function_builder.py +18 -2
- classiq/model_expansions/interpreters/base_interpreter.py +84 -22
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +1 -11
- classiq/model_expansions/interpreters/generative_interpreter.py +67 -20
- classiq/model_expansions/quantum_operations/allocate.py +92 -21
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +28 -27
- classiq/model_expansions/quantum_operations/call_emitter.py +32 -26
- classiq/model_expansions/quantum_operations/classical_var_emitter.py +6 -2
- classiq/model_expansions/quantum_operations/emitter.py +50 -70
- classiq/model_expansions/quantum_operations/expression_evaluator.py +62 -7
- classiq/model_expansions/quantum_operations/quantum_function_call.py +4 -5
- classiq/model_expansions/quantum_operations/variable_decleration.py +16 -11
- classiq/model_expansions/scope.py +39 -41
- classiq/model_expansions/scope_initialization.py +3 -6
- classiq/model_expansions/transformers/model_renamer.py +35 -64
- classiq/model_expansions/transformers/type_modifier_inference.py +6 -6
- classiq/model_expansions/utils/handles_collector.py +7 -0
- classiq/model_expansions/visitors/boolean_expression_transformers.py +7 -31
- classiq/model_expansions/visitors/symbolic_param_inference.py +9 -3
- classiq/open_library/functions/state_preparation.py +3 -3
- classiq/qmod/builtins/functions/allocation.py +8 -8
- classiq/qmod/builtins/functions/arithmetic.py +1 -1
- classiq/qmod/builtins/functions/chemistry.py +64 -0
- classiq/qmod/builtins/functions/exponentiation.py +7 -13
- classiq/qmod/builtins/functions/qsvm.py +1 -1
- classiq/qmod/builtins/operations.py +42 -10
- classiq/qmod/generative.py +2 -4
- classiq/qmod/native/pretty_printer.py +1 -1
- classiq/qmod/pretty_print/pretty_printer.py +1 -1
- classiq/qmod/qmod_constant.py +1 -1
- classiq/qmod/qmod_parameter.py +2 -2
- classiq/qmod/qmod_variable.py +18 -19
- classiq/qmod/quantum_expandable.py +1 -1
- classiq/qmod/semantics/error_manager.py +34 -15
- classiq/qmod/symbolic.py +15 -4
- classiq/qmod/utilities.py +4 -1
- classiq/synthesis.py +38 -3
- classiq/visualization.py +1 -1
- {classiq-0.89.0.dist-info → classiq-0.91.0.dist-info}/METADATA +1 -1
- {classiq-0.89.0.dist-info → classiq-0.91.0.dist-info}/RECORD +89 -107
- classiq/evaluators/arg_type_match.py +0 -168
- classiq/evaluators/classical_type_inference.py +0 -121
- classiq/interface/combinatorial_optimization/optimization_problem.py +0 -17
- classiq/interface/combinatorial_optimization/result.py +0 -9
- classiq/interface/generator/expressions/handle_identifier.py +0 -6
- classiq/interface/generator/expressions/proxies/classical/any_classical_value.py +0 -41
- classiq/interface/generator/expressions/proxies/quantum/__init__.py +0 -0
- classiq/interface/generator/expressions/proxies/quantum/qmod_qarray_proxy.py +0 -80
- classiq/interface/generator/expressions/proxies/quantum/qmod_qscalar_proxy.py +0 -77
- classiq/interface/generator/expressions/proxies/quantum/qmod_qstruct_proxy.py +0 -38
- classiq/interface/generator/expressions/proxies/quantum/qmod_sized_proxy.py +0 -39
- classiq/interface/generator/expressions/type_proxy.py +0 -10
- classiq/model_expansions/atomic_expression_functions_defs.py +0 -413
- classiq/model_expansions/model_tables.py +0 -18
- classiq/model_expansions/sympy_conversion/__init__.py +0 -0
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +0 -181
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +0 -132
- classiq/model_expansions/transformers/ast_renamer.py +0 -26
- classiq/model_expansions/utils/sympy_utils.py +0 -24
- {classiq-0.89.0.dist-info → classiq-0.91.0.dist-info}/WHEEL +0 -0
|
@@ -1,132 +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 ExpressionValue
|
|
20
|
-
from classiq.interface.generator.expressions.proxies.classical.any_classical_value import (
|
|
21
|
-
AnyClassicalValue,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
from classiq.evaluators.qmod_expression_visitors.sympy_wrappers import LogicalXor
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def sympy_to_python(
|
|
28
|
-
value: Any, locals: Optional[dict[str, ExpressionValue]] = None
|
|
29
|
-
) -> ExpressionValue:
|
|
30
|
-
if isinstance(value, AnyClassicalValue):
|
|
31
|
-
pass
|
|
32
|
-
elif isinstance(value, Integer):
|
|
33
|
-
value = int(value)
|
|
34
|
-
elif isinstance(value, Float):
|
|
35
|
-
value = float(value)
|
|
36
|
-
elif isinstance(value, BooleanAtom):
|
|
37
|
-
value = bool(value)
|
|
38
|
-
elif isinstance(value, Array):
|
|
39
|
-
value = sympy_to_python(value.tolist(), locals)
|
|
40
|
-
elif isinstance(value, Rational):
|
|
41
|
-
value = float(value.evalf())
|
|
42
|
-
elif isinstance(value, list):
|
|
43
|
-
value = [sympy_to_python(element, locals) for element in value]
|
|
44
|
-
elif isinstance(value, Matrix):
|
|
45
|
-
value = [sympy_to_python(element, locals) for element in value.tolist()]
|
|
46
|
-
elif isinstance(value, Symbol) and locals is not None and value.name in locals:
|
|
47
|
-
return locals[value.name]
|
|
48
|
-
if value is None:
|
|
49
|
-
value = False
|
|
50
|
-
|
|
51
|
-
if not isinstance(value, get_args(ExpressionValue)):
|
|
52
|
-
raise ClassiqInternalExpansionError(
|
|
53
|
-
f"Invalid evaluated expression {value} of type {type(value)}"
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
return value
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def _conditional_true(*args: Any, **kwargs: Any) -> bool:
|
|
60
|
-
return True
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
class SympyToQuantumExpressionTranslator(PythonCodePrinter):
|
|
64
|
-
_operators = {**PythonCodePrinter._operators, **{"not": "~", "xor": "^"}}
|
|
65
|
-
_kf = {
|
|
66
|
-
**PythonCodePrinter._kf,
|
|
67
|
-
**{"max": "max", "min": "min", "Max": "max", "Min": "min"},
|
|
68
|
-
}
|
|
69
|
-
BINARY_BITWISE_OPERATORS_MAPPING = {
|
|
70
|
-
"BitwiseAnd": "&",
|
|
71
|
-
"BitwiseOr": "|",
|
|
72
|
-
"BitwiseXor": "^",
|
|
73
|
-
"LogicalXor": "^",
|
|
74
|
-
"RShift": ">>",
|
|
75
|
-
"LShift": "<<",
|
|
76
|
-
}
|
|
77
|
-
UNARY_BITWISE_OPERATORS_MAPPING = {"BitwiseNot": "~"}
|
|
78
|
-
|
|
79
|
-
@staticmethod
|
|
80
|
-
def _print_bitwise_binary_operator(
|
|
81
|
-
left_arg: Expr, right_arg: Expr, operator: str
|
|
82
|
-
) -> str:
|
|
83
|
-
return f"(({left_arg}) {operator} ({right_arg}))"
|
|
84
|
-
|
|
85
|
-
@staticmethod
|
|
86
|
-
def _print_bitwise_unary_operator(arg: Expr, operator: str) -> str:
|
|
87
|
-
return f"({operator} ({arg}))"
|
|
88
|
-
|
|
89
|
-
def __init__(self) -> None:
|
|
90
|
-
super().__init__(settings={"fully_qualified_modules": False})
|
|
91
|
-
for binary_operator in self.BINARY_BITWISE_OPERATORS_MAPPING:
|
|
92
|
-
self.known_functions[binary_operator] = [
|
|
93
|
-
(
|
|
94
|
-
_conditional_true,
|
|
95
|
-
functools.partial(
|
|
96
|
-
self._print_bitwise_binary_operator,
|
|
97
|
-
operator=self.BINARY_BITWISE_OPERATORS_MAPPING[binary_operator],
|
|
98
|
-
),
|
|
99
|
-
)
|
|
100
|
-
]
|
|
101
|
-
for unary_operator in self.UNARY_BITWISE_OPERATORS_MAPPING:
|
|
102
|
-
self.known_functions[unary_operator] = [
|
|
103
|
-
(
|
|
104
|
-
_conditional_true,
|
|
105
|
-
functools.partial(
|
|
106
|
-
self._print_bitwise_unary_operator,
|
|
107
|
-
operator=self.UNARY_BITWISE_OPERATORS_MAPPING[unary_operator],
|
|
108
|
-
),
|
|
109
|
-
)
|
|
110
|
-
]
|
|
111
|
-
|
|
112
|
-
def _print_Piecewise(self, expr: Piecewise) -> str: # noqa: N802
|
|
113
|
-
return str(expr)
|
|
114
|
-
|
|
115
|
-
def _print_LogicalXor(self, expr: LogicalXor) -> str: # noqa: N802
|
|
116
|
-
return f"(({self._print(expr.args[0])}) ^ ({self._print(expr.args[1])}))"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
class SympyToBoolExpressionTranslator(SympyToQuantumExpressionTranslator):
|
|
120
|
-
_operators = {
|
|
121
|
-
**SympyToQuantumExpressionTranslator._operators,
|
|
122
|
-
**{"not": "not ", "xor": "xor"},
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
def translate_sympy_quantum_expression(expr: Basic, preserve_bool_ops: bool) -> str:
|
|
127
|
-
if isinstance(expr, AnyClassicalValue):
|
|
128
|
-
return str(expr)
|
|
129
|
-
if preserve_bool_ops:
|
|
130
|
-
return SympyToBoolExpressionTranslator().doprint(expr)
|
|
131
|
-
else:
|
|
132
|
-
return SympyToQuantumExpressionTranslator().doprint(expr)
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import ast
|
|
2
|
-
|
|
3
|
-
_POSSIBLE_HANDLE_AST_TYPES = (ast.Subscript, ast.Attribute, ast.Name)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class _ASTRenamer(ast.NodeTransformer):
|
|
7
|
-
def __init__(self, sub: dict[str, str]) -> None:
|
|
8
|
-
self._sub = sub
|
|
9
|
-
|
|
10
|
-
def visit(self, node: ast.AST) -> ast.AST:
|
|
11
|
-
if isinstance(node, _POSSIBLE_HANDLE_AST_TYPES):
|
|
12
|
-
node_expr = ast.unparse(node)
|
|
13
|
-
if node_expr in self._sub:
|
|
14
|
-
return ast.Name(id=self._sub[node_expr])
|
|
15
|
-
return super().visit(node)
|
|
16
|
-
|
|
17
|
-
def visit_Call(self, node: ast.Call) -> ast.Call:
|
|
18
|
-
return ast.Call(
|
|
19
|
-
func=node.func,
|
|
20
|
-
args=[self.visit(arg) for arg in node.args],
|
|
21
|
-
keywords=[],
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def rename_variables(expr: str, sub: dict[str, str]) -> str:
|
|
26
|
-
return ast.unparse(_ASTRenamer(sub).visit(ast.parse(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
|
-
)
|
|
File without changes
|