classiq 0.92.0__py3-none-any.whl → 0.94.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 +6 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +38 -52
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +3 -3
- classiq/_internals/authentication/device.py +4 -4
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +4 -5
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +1 -2
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +8 -8
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/qlayer.py +8 -7
- classiq/applications/qnn/torch_utils.py +3 -4
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/qsp.py +6 -5
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +17 -12
- classiq/evaluators/qmod_annotated_expression.py +24 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/execution_session.py +18 -19
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +52 -7
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/applications/qsvm.py +5 -8
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +16 -16
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +7 -7
- classiq/interface/exceptions.py +6 -3
- classiq/interface/execution/iqcc.py +1 -3
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +2 -3
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -2
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +7 -36
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +2 -2
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -20
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -14
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +12 -13
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/qsvm.py +2 -2
- classiq/interface/generator/quantum_function_call.py +8 -11
- classiq/interface/generator/quantum_program.py +12 -15
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/state_preparation/state_preparation.py +6 -8
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -136
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -2
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +5 -5
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +2 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/control.py +1 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +4 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -4
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +6 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +4 -5
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +1 -4
- classiq/model_expansions/interpreters/base_interpreter.py +2 -6
- classiq/model_expansions/interpreters/generative_interpreter.py +8 -4
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +61 -29
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +3 -3
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +317 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +6 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +19 -14
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/modular_exponentiation.py +96 -8
- classiq/qmod/__init__.py +5 -2
- classiq/qmod/builtins/classical_execution_primitives.py +4 -11
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +0 -136
- classiq/qmod/builtins/functions/__init__.py +0 -13
- classiq/qmod/builtins/functions/allocation.py +4 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/standard_gates.py +27 -27
- classiq/qmod/builtins/operations.py +43 -58
- classiq/qmod/builtins/structs.py +2 -58
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/classical_variable.py +4 -2
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +139 -16
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -43
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +33 -26
- classiq/qmod/quantum_function.py +51 -32
- classiq/qmod/semantics/annotation/call_annotation.py +2 -2
- classiq/qmod/semantics/error_manager.py +5 -6
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/symbolic_expr.py +12 -4
- classiq/qmod/utilities.py +13 -10
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/METADATA +38 -37
- {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/RECORD +240 -261
- classiq-0.94.0.dist-info/WHEEL +4 -0
- classiq-0.94.0.dist-info/licenses/LICENSE.txt +27 -0
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq-0.92.0.dist-info/WHEEL +0 -4
classiq/qmod/qfunc.py
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
from
|
|
1
|
+
import warnings
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
from typing import Literal, overload
|
|
4
|
+
|
|
5
|
+
from classiq.interface.exceptions import (
|
|
6
|
+
ClassiqDeprecationWarning,
|
|
7
|
+
ClassiqInternalError,
|
|
8
|
+
ClassiqValueError,
|
|
9
|
+
)
|
|
4
10
|
|
|
5
11
|
from classiq.qmod.global_declarative_switch import get_global_declarative_switch
|
|
6
12
|
from classiq.qmod.quantum_callable import QCallable
|
|
@@ -21,7 +27,9 @@ def qfunc(
|
|
|
21
27
|
*,
|
|
22
28
|
external: Literal[True],
|
|
23
29
|
synthesize_separately: Literal[False] = False,
|
|
24
|
-
unchecked:
|
|
30
|
+
unchecked: list[str] | None = None,
|
|
31
|
+
disable_perm_check: bool = False,
|
|
32
|
+
disable_const_checks: list[str] | bool = False,
|
|
25
33
|
) -> Callable[[Callable], ExternalQFunc]: ...
|
|
26
34
|
|
|
27
35
|
|
|
@@ -30,13 +38,19 @@ def qfunc(
|
|
|
30
38
|
*,
|
|
31
39
|
generative: Literal[False],
|
|
32
40
|
synthesize_separately: bool = False,
|
|
33
|
-
unchecked:
|
|
41
|
+
unchecked: list[str] | None = None,
|
|
42
|
+
disable_perm_check: bool = False,
|
|
43
|
+
disable_const_checks: list[str] | bool = False,
|
|
34
44
|
) -> Callable[[Callable], QFunc]: ...
|
|
35
45
|
|
|
36
46
|
|
|
37
47
|
@overload
|
|
38
48
|
def qfunc(
|
|
39
|
-
*,
|
|
49
|
+
*,
|
|
50
|
+
synthesize_separately: bool,
|
|
51
|
+
unchecked: list[str] | None = None,
|
|
52
|
+
disable_perm_check: bool = False,
|
|
53
|
+
disable_const_checks: list[str] | bool = False,
|
|
40
54
|
) -> Callable[[Callable], GenerativeQFunc]: ...
|
|
41
55
|
|
|
42
56
|
|
|
@@ -44,18 +58,113 @@ def qfunc(
|
|
|
44
58
|
def qfunc(
|
|
45
59
|
*,
|
|
46
60
|
synthesize_separately: bool = False,
|
|
47
|
-
unchecked:
|
|
61
|
+
unchecked: list[str] | None = None,
|
|
62
|
+
disable_perm_check: bool = False,
|
|
63
|
+
disable_const_checks: list[str] | bool = False,
|
|
48
64
|
) -> Callable[[Callable], GenerativeQFunc]: ...
|
|
49
65
|
|
|
50
66
|
|
|
51
67
|
def qfunc(
|
|
52
|
-
func:
|
|
68
|
+
func: Callable | None = None,
|
|
69
|
+
*,
|
|
70
|
+
external: bool = False,
|
|
71
|
+
generative: bool | None = None,
|
|
72
|
+
synthesize_separately: bool = False,
|
|
73
|
+
unchecked: list[str] | None = None,
|
|
74
|
+
disable_perm_check: bool = False,
|
|
75
|
+
disable_const_checks: list[str] | bool = False,
|
|
76
|
+
) -> Callable[[Callable], QCallable] | QCallable:
|
|
77
|
+
return _qfunc_inner(
|
|
78
|
+
func=func,
|
|
79
|
+
external=external,
|
|
80
|
+
generative=generative,
|
|
81
|
+
synthesize_separately=synthesize_separately,
|
|
82
|
+
unchecked=unchecked,
|
|
83
|
+
permutation=False,
|
|
84
|
+
disable_perm_check=disable_perm_check,
|
|
85
|
+
disable_const_checks=disable_const_checks,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
@overload
|
|
90
|
+
def qperm(func: Callable) -> GenerativeQFunc: ...
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
@overload
|
|
94
|
+
def qperm(
|
|
95
|
+
*,
|
|
96
|
+
external: Literal[True],
|
|
97
|
+
synthesize_separately: Literal[False] = False,
|
|
98
|
+
unchecked: list[str] | None = None,
|
|
99
|
+
disable_perm_check: bool = False,
|
|
100
|
+
disable_const_checks: list[str] | bool = False,
|
|
101
|
+
) -> Callable[[Callable], ExternalQFunc]: ...
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
@overload
|
|
105
|
+
def qperm(
|
|
106
|
+
*,
|
|
107
|
+
generative: Literal[False],
|
|
108
|
+
synthesize_separately: bool = False,
|
|
109
|
+
unchecked: list[str] | None = None,
|
|
110
|
+
disable_perm_check: bool = False,
|
|
111
|
+
disable_const_checks: list[str] | bool = False,
|
|
112
|
+
) -> Callable[[Callable], QFunc]: ...
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@overload
|
|
116
|
+
def qperm(
|
|
117
|
+
*,
|
|
118
|
+
synthesize_separately: bool,
|
|
119
|
+
unchecked: list[str] | None = None,
|
|
120
|
+
disable_perm_check: bool = False,
|
|
121
|
+
disable_const_checks: list[str] | bool = False,
|
|
122
|
+
) -> Callable[[Callable], GenerativeQFunc]: ...
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
@overload
|
|
126
|
+
def qperm(
|
|
127
|
+
*,
|
|
128
|
+
synthesize_separately: bool = False,
|
|
129
|
+
unchecked: list[str] | None = None,
|
|
130
|
+
disable_perm_check: bool = False,
|
|
131
|
+
disable_const_checks: list[str] | bool = False,
|
|
132
|
+
) -> Callable[[Callable], GenerativeQFunc]: ...
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def qperm(
|
|
136
|
+
func: Callable | None = None,
|
|
137
|
+
*,
|
|
138
|
+
external: bool = False,
|
|
139
|
+
generative: bool | None = None,
|
|
140
|
+
synthesize_separately: bool = False,
|
|
141
|
+
unchecked: list[str] | None = None,
|
|
142
|
+
disable_perm_check: bool = False,
|
|
143
|
+
disable_const_checks: list[str] | bool = False,
|
|
144
|
+
) -> Callable[[Callable], QCallable] | QCallable:
|
|
145
|
+
return _qfunc_inner(
|
|
146
|
+
func=func,
|
|
147
|
+
external=external,
|
|
148
|
+
generative=generative,
|
|
149
|
+
synthesize_separately=synthesize_separately,
|
|
150
|
+
unchecked=unchecked,
|
|
151
|
+
permutation=True,
|
|
152
|
+
disable_perm_check=disable_perm_check,
|
|
153
|
+
disable_const_checks=disable_const_checks,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _qfunc_inner(
|
|
53
158
|
*,
|
|
159
|
+
func: Callable | None = None,
|
|
54
160
|
external: bool = False,
|
|
55
|
-
generative:
|
|
161
|
+
generative: bool | None = None,
|
|
56
162
|
synthesize_separately: bool = False,
|
|
57
|
-
unchecked:
|
|
58
|
-
|
|
163
|
+
unchecked: list[str] | None = None,
|
|
164
|
+
permutation: bool = False,
|
|
165
|
+
disable_perm_check: bool = False,
|
|
166
|
+
disable_const_checks: list[str] | bool = False,
|
|
167
|
+
) -> Callable[[Callable], QCallable] | QCallable:
|
|
59
168
|
if generative is None:
|
|
60
169
|
generative = True
|
|
61
170
|
if get_global_declarative_switch():
|
|
@@ -66,16 +175,30 @@ def qfunc(
|
|
|
66
175
|
|
|
67
176
|
if external:
|
|
68
177
|
_validate_directives(synthesize_separately, unchecked)
|
|
69
|
-
return ExternalQFunc(func)
|
|
178
|
+
return ExternalQFunc(func, permutation=permutation)
|
|
70
179
|
|
|
71
180
|
if generative:
|
|
72
|
-
qfunc = GenerativeQFunc(func)
|
|
181
|
+
qfunc = GenerativeQFunc(func, permutation=permutation)
|
|
73
182
|
else:
|
|
74
|
-
qfunc = QFunc(func)
|
|
183
|
+
qfunc = QFunc(func, permutation=permutation)
|
|
75
184
|
if synthesize_separately:
|
|
76
185
|
qfunc.update_compilation_metadata(should_synthesize_separately=True)
|
|
77
186
|
if unchecked is not None and len(unchecked) > 0:
|
|
78
|
-
|
|
187
|
+
nonlocal disable_const_checks
|
|
188
|
+
if disable_const_checks:
|
|
189
|
+
raise ClassiqValueError(
|
|
190
|
+
"The 'unchecked' parameter is deprecated, please use 'disable_const_checks' only."
|
|
191
|
+
)
|
|
192
|
+
warnings.warn(
|
|
193
|
+
"The 'unchecked' parameter is deprecated and will no longer be supported starting on 2025-10-30 at the earliest. Please use the 'disable_const_checks' instead.",
|
|
194
|
+
ClassiqDeprecationWarning,
|
|
195
|
+
stacklevel=2,
|
|
196
|
+
)
|
|
197
|
+
disable_const_checks = unchecked
|
|
198
|
+
if disable_perm_check:
|
|
199
|
+
qfunc.update_compilation_metadata(disable_perm_check=disable_perm_check)
|
|
200
|
+
if disable_const_checks:
|
|
201
|
+
qfunc.update_compilation_metadata(disable_const_checks=disable_const_checks)
|
|
79
202
|
return qfunc
|
|
80
203
|
|
|
81
204
|
if func is not None:
|
|
@@ -84,7 +207,7 @@ def qfunc(
|
|
|
84
207
|
|
|
85
208
|
|
|
86
209
|
def _validate_directives(
|
|
87
|
-
synthesize_separately: bool, unchecked:
|
|
210
|
+
synthesize_separately: bool, unchecked: list[str] | None = None
|
|
88
211
|
) -> None:
|
|
89
212
|
error_msg = ""
|
|
90
213
|
if synthesize_separately:
|
classiq/qmod/qmod_constant.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
from dataclasses import is_dataclass
|
|
3
|
-
from typing import TYPE_CHECKING, Any,
|
|
3
|
+
from typing import TYPE_CHECKING, Any, cast, get_origin
|
|
4
4
|
|
|
5
5
|
from classiq.interface.exceptions import ClassiqError, ClassiqValueError
|
|
6
6
|
from classiq.interface.generator.constant import Constant
|
|
@@ -25,7 +25,7 @@ QMODULE_ERROR_MESSAGE = (
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class QConstant(SymbolicExpr):
|
|
28
|
-
CURRENT_QMODULE:
|
|
28
|
+
CURRENT_QMODULE: ModelStateContainer | None = None
|
|
29
29
|
|
|
30
30
|
def __init__(self, name: str, py_type: type, value: Any) -> None:
|
|
31
31
|
super().__init__(name, False)
|
classiq/qmod/qmod_parameter.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Any,
|
|
1
|
+
from typing import TYPE_CHECKING, Any, NoReturn
|
|
2
2
|
|
|
3
3
|
from classiq.interface.exceptions import ClassiqInternalError, ClassiqValueError
|
|
4
4
|
from classiq.interface.generator.functions.classical_type import (
|
|
@@ -41,7 +41,7 @@ class CParamList(CParam):
|
|
|
41
41
|
def __init__(
|
|
42
42
|
self,
|
|
43
43
|
expr: str,
|
|
44
|
-
list_type:
|
|
44
|
+
list_type: ClassicalArray | ClassicalTuple,
|
|
45
45
|
qmodule: ModelStateContainer,
|
|
46
46
|
) -> None:
|
|
47
47
|
super().__init__(expr)
|
|
@@ -102,6 +102,9 @@ class CParamList(CParam):
|
|
|
102
102
|
return interpret_expression(str(self.len))
|
|
103
103
|
return CParamScalar(f"{self}.len")
|
|
104
104
|
|
|
105
|
+
def __iter__(self) -> NoReturn:
|
|
106
|
+
raise TypeError(f"{type(self).__name__!r} object is not iterable")
|
|
107
|
+
|
|
105
108
|
|
|
106
109
|
class CParamStruct(CParam):
|
|
107
110
|
def __init__(
|
classiq/qmod/qmod_variable.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
import sys
|
|
3
|
+
import warnings
|
|
3
4
|
from collections.abc import Iterator, Mapping
|
|
4
5
|
from contextlib import contextmanager
|
|
5
6
|
from typing import ( # type: ignore[attr-defined]
|
|
@@ -10,10 +11,8 @@ from typing import ( # type: ignore[attr-defined]
|
|
|
10
11
|
Generic,
|
|
11
12
|
Literal,
|
|
12
13
|
NoReturn,
|
|
13
|
-
Optional,
|
|
14
14
|
Protocol,
|
|
15
15
|
TypeVar,
|
|
16
|
-
Union,
|
|
17
16
|
_GenericAlias,
|
|
18
17
|
cast,
|
|
19
18
|
get_args,
|
|
@@ -24,6 +23,7 @@ from typing import ( # type: ignore[attr-defined]
|
|
|
24
23
|
from typing_extensions import ParamSpec, Self, _AnnotatedAlias
|
|
25
24
|
|
|
26
25
|
from classiq.interface.exceptions import (
|
|
26
|
+
ClassiqDeprecationWarning,
|
|
27
27
|
ClassiqInternalError,
|
|
28
28
|
ClassiqNotImplementedError,
|
|
29
29
|
ClassiqValueError,
|
|
@@ -109,9 +109,9 @@ class QVar(Symbolic):
|
|
|
109
109
|
|
|
110
110
|
def __init__(
|
|
111
111
|
self,
|
|
112
|
-
origin:
|
|
112
|
+
origin: None | str | HandleBinding = None,
|
|
113
113
|
*,
|
|
114
|
-
expr_str:
|
|
114
|
+
expr_str: str | None = None,
|
|
115
115
|
depth: int = 2,
|
|
116
116
|
) -> None:
|
|
117
117
|
name = _infer_variable_name(origin, self.CONSTRUCTOR_DEPTH)
|
|
@@ -141,9 +141,9 @@ class QVar(Symbolic):
|
|
|
141
141
|
@abc.abstractmethod
|
|
142
142
|
def to_qvar(
|
|
143
143
|
cls,
|
|
144
|
-
origin:
|
|
144
|
+
origin: str | HandleBinding,
|
|
145
145
|
type_hint: Any,
|
|
146
|
-
expr_str:
|
|
146
|
+
expr_str: str | None,
|
|
147
147
|
) -> Self:
|
|
148
148
|
raise NotImplementedError()
|
|
149
149
|
|
|
@@ -151,7 +151,7 @@ class QVar(Symbolic):
|
|
|
151
151
|
return self._expr_str
|
|
152
152
|
|
|
153
153
|
@property
|
|
154
|
-
def size(self) ->
|
|
154
|
+
def size(self) -> CParamScalar | int:
|
|
155
155
|
if is_generative_mode():
|
|
156
156
|
with generative_mode_context(False):
|
|
157
157
|
return interpret_expression(str(self.size))
|
|
@@ -186,9 +186,9 @@ class QScalar(QVar, SymbolicExpr):
|
|
|
186
186
|
|
|
187
187
|
def __init__(
|
|
188
188
|
self,
|
|
189
|
-
origin:
|
|
189
|
+
origin: None | str | HandleBinding = None,
|
|
190
190
|
*,
|
|
191
|
-
_expr_str:
|
|
191
|
+
_expr_str: str | None = None,
|
|
192
192
|
depth: int = 2,
|
|
193
193
|
) -> None:
|
|
194
194
|
origin = _infer_variable_name(origin, self.CONSTRUCTOR_DEPTH)
|
|
@@ -371,9 +371,9 @@ class QBit(QScalar):
|
|
|
371
371
|
@classmethod
|
|
372
372
|
def to_qvar(
|
|
373
373
|
cls,
|
|
374
|
-
origin:
|
|
374
|
+
origin: str | HandleBinding,
|
|
375
375
|
type_hint: Any,
|
|
376
|
-
expr_str:
|
|
376
|
+
expr_str: str | None,
|
|
377
377
|
) -> "QBit":
|
|
378
378
|
return QBit(origin, _expr_str=expr_str)
|
|
379
379
|
|
|
@@ -428,11 +428,11 @@ class QNum(Generic[_P], QScalar):
|
|
|
428
428
|
|
|
429
429
|
def __init__(
|
|
430
430
|
self,
|
|
431
|
-
name:
|
|
432
|
-
size:
|
|
433
|
-
is_signed:
|
|
434
|
-
fraction_digits:
|
|
435
|
-
_expr_str:
|
|
431
|
+
name: None | str | HandleBinding = None,
|
|
432
|
+
size: int | CInt | Expression | SymbolicExpr | None = None,
|
|
433
|
+
is_signed: bool | CBool | Expression | SymbolicExpr | None = None,
|
|
434
|
+
fraction_digits: int | CInt | Expression | SymbolicExpr | None = None,
|
|
435
|
+
_expr_str: str | None = None,
|
|
436
436
|
):
|
|
437
437
|
if size is None and (is_signed is not None or fraction_digits is not None):
|
|
438
438
|
raise ClassiqValueError(
|
|
@@ -466,9 +466,9 @@ class QNum(Generic[_P], QScalar):
|
|
|
466
466
|
@classmethod
|
|
467
467
|
def to_qvar(
|
|
468
468
|
cls,
|
|
469
|
-
origin:
|
|
469
|
+
origin: str | HandleBinding,
|
|
470
470
|
type_hint: Any,
|
|
471
|
-
expr_str:
|
|
471
|
+
expr_str: str | None,
|
|
472
472
|
) -> "QNum":
|
|
473
473
|
return QNum(origin, *_get_qnum_attributes(type_hint), _expr_str=expr_str)
|
|
474
474
|
|
|
@@ -480,14 +480,14 @@ class QNum(Generic[_P], QScalar):
|
|
|
480
480
|
)
|
|
481
481
|
|
|
482
482
|
@property
|
|
483
|
-
def fraction_digits(self) ->
|
|
483
|
+
def fraction_digits(self) -> CParamScalar | int:
|
|
484
484
|
if is_generative_mode():
|
|
485
485
|
with generative_mode_context(False):
|
|
486
486
|
return interpret_expression(str(self.fraction_digits))
|
|
487
487
|
return CParamScalar(f"{self}.fraction_digits")
|
|
488
488
|
|
|
489
489
|
@property
|
|
490
|
-
def is_signed(self) ->
|
|
490
|
+
def is_signed(self) -> CParamScalar | bool:
|
|
491
491
|
if is_generative_mode():
|
|
492
492
|
with generative_mode_context(False):
|
|
493
493
|
return interpret_expression(str(self.is_signed))
|
|
@@ -510,12 +510,6 @@ class QNum(Generic[_P], QScalar):
|
|
|
510
510
|
fraction_places=self.fraction_digits,
|
|
511
511
|
)
|
|
512
512
|
|
|
513
|
-
# Support comma-separated generic args in older Python versions
|
|
514
|
-
if sys.version_info[0:2] < (3, 10):
|
|
515
|
-
|
|
516
|
-
def __class_getitem__(cls, args) -> _GenericAlias:
|
|
517
|
-
return _GenericAlias(cls, args)
|
|
518
|
-
|
|
519
513
|
|
|
520
514
|
class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
521
515
|
CONSTRUCTOR_DEPTH: int = 3
|
|
@@ -523,10 +517,10 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
523
517
|
# TODO [CAD-18620]: improve type hints
|
|
524
518
|
def __init__(
|
|
525
519
|
self,
|
|
526
|
-
name:
|
|
527
|
-
element_type:
|
|
528
|
-
length:
|
|
529
|
-
_expr_str:
|
|
520
|
+
name: None | str | HandleBinding = None,
|
|
521
|
+
element_type: _GenericAlias | QuantumType = QBit,
|
|
522
|
+
length: int | CInt | SymbolicExpr | Expression | None = None,
|
|
523
|
+
_expr_str: str | None = None,
|
|
530
524
|
) -> None:
|
|
531
525
|
self._element_type = element_type
|
|
532
526
|
self._length = (
|
|
@@ -536,7 +530,7 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
536
530
|
)
|
|
537
531
|
super().__init__(name, expr_str=_expr_str)
|
|
538
532
|
|
|
539
|
-
def __getitem__(self, key:
|
|
533
|
+
def __getitem__(self, key: slice | int | SymbolicExpr) -> Any:
|
|
540
534
|
return (
|
|
541
535
|
self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
|
|
542
536
|
)
|
|
@@ -544,7 +538,7 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
544
538
|
def __setitem__(self, *args: Any) -> None:
|
|
545
539
|
pass
|
|
546
540
|
|
|
547
|
-
def _get_subscript(self, index:
|
|
541
|
+
def _get_subscript(self, index: slice | int | SymbolicExpr) -> Any:
|
|
548
542
|
if isinstance(index, SymbolicExpr) and index.is_quantum:
|
|
549
543
|
raise ClassiqValueError("Non-classical parameter for slicing")
|
|
550
544
|
|
|
@@ -589,7 +583,7 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
589
583
|
else:
|
|
590
584
|
|
|
591
585
|
@property
|
|
592
|
-
def len(self) ->
|
|
586
|
+
def len(self) -> CParamScalar | int:
|
|
593
587
|
if is_generative_mode():
|
|
594
588
|
with generative_mode_context(False):
|
|
595
589
|
return interpret_expression(str(self.len))
|
|
@@ -598,9 +592,9 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
598
592
|
@classmethod
|
|
599
593
|
def to_qvar(
|
|
600
594
|
cls,
|
|
601
|
-
origin:
|
|
595
|
+
origin: str | HandleBinding,
|
|
602
596
|
type_hint: Any,
|
|
603
|
-
expr_str:
|
|
597
|
+
expr_str: str | None,
|
|
604
598
|
) -> "QArray":
|
|
605
599
|
return QArray(origin, *_get_qarray_attributes(type_hint), _expr_str=expr_str)
|
|
606
600
|
|
|
@@ -614,6 +608,9 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
614
608
|
length=self._length,
|
|
615
609
|
)
|
|
616
610
|
|
|
611
|
+
def __iter__(self) -> NoReturn:
|
|
612
|
+
raise TypeError(f"{type(self).__name__!r} object is not iterable")
|
|
613
|
+
|
|
617
614
|
|
|
618
615
|
class QStruct(QVar):
|
|
619
616
|
CONSTRUCTOR_DEPTH: int = 2
|
|
@@ -623,10 +620,10 @@ class QStruct(QVar):
|
|
|
623
620
|
|
|
624
621
|
def __init__(
|
|
625
622
|
self,
|
|
626
|
-
origin:
|
|
627
|
-
_struct_name:
|
|
628
|
-
_fields:
|
|
629
|
-
_expr_str:
|
|
623
|
+
origin: None | str | HandleBinding = None,
|
|
624
|
+
_struct_name: str | None = None,
|
|
625
|
+
_fields: Mapping[str, QVar] | None = None,
|
|
626
|
+
_expr_str: str | None = None,
|
|
630
627
|
) -> None:
|
|
631
628
|
_register_qstruct(type(self), qmodule=QMODULE)
|
|
632
629
|
name = _infer_variable_name(origin, self.CONSTRUCTOR_DEPTH)
|
|
@@ -654,9 +651,9 @@ class QStruct(QVar):
|
|
|
654
651
|
@classmethod
|
|
655
652
|
def to_qvar(
|
|
656
653
|
cls,
|
|
657
|
-
origin:
|
|
654
|
+
origin: str | HandleBinding,
|
|
658
655
|
type_hint: Any,
|
|
659
|
-
expr_str:
|
|
656
|
+
expr_str: str | None,
|
|
660
657
|
) -> "QStruct":
|
|
661
658
|
field_types = {
|
|
662
659
|
field_name: (_get_root_type(field_type), field_type)
|
|
@@ -699,7 +696,7 @@ def create_qvar_from_quantum_type(quantum_type: ConcreteQuantumType, name: str)
|
|
|
699
696
|
|
|
700
697
|
|
|
701
698
|
def _create_qvar_for_qtype(
|
|
702
|
-
qtype: QuantumType, origin: HandleBinding, expr_str:
|
|
699
|
+
qtype: QuantumType, origin: HandleBinding, expr_str: str | None = None
|
|
703
700
|
) -> QVar:
|
|
704
701
|
# prevent addition to local handles, since this is used for ports
|
|
705
702
|
with _no_current_expandable():
|
|
@@ -770,6 +767,13 @@ def get_port_from_type_hint(
|
|
|
770
767
|
else:
|
|
771
768
|
quantum_type = _to_quantum_type(py_type)
|
|
772
769
|
|
|
770
|
+
if modifier is TypeModifier.Permutable:
|
|
771
|
+
warnings.warn(
|
|
772
|
+
"The `Permutable` type modifier is deprecated and will no longer be supported starting on 2025-10-30 at the earliest. If the function as a whole is a permutation, use `qperm` instead.",
|
|
773
|
+
ClassiqDeprecationWarning,
|
|
774
|
+
stacklevel=1,
|
|
775
|
+
)
|
|
776
|
+
|
|
773
777
|
return quantum_type, direction, modifier
|
|
774
778
|
|
|
775
779
|
|
|
@@ -868,7 +872,7 @@ def _get_quantum_struct(type_hint: type[QStruct]) -> Struct:
|
|
|
868
872
|
|
|
869
873
|
def _register_qstruct(
|
|
870
874
|
type_hint: type[QStruct], *, qmodule: ModelStateContainer
|
|
871
|
-
) ->
|
|
875
|
+
) -> QStructDeclaration | None:
|
|
872
876
|
struct_name = type_hint.__name__
|
|
873
877
|
if type_hint is QStruct:
|
|
874
878
|
return None
|
classiq/qmod/quantum_callable.py
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import sys
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
|
-
from typing import (
|
|
3
|
+
from typing import (
|
|
4
4
|
TYPE_CHECKING,
|
|
5
5
|
Any,
|
|
6
6
|
ClassVar,
|
|
7
7
|
Generic,
|
|
8
|
-
Optional,
|
|
9
|
-
Union,
|
|
10
|
-
_GenericAlias,
|
|
11
8
|
)
|
|
12
9
|
|
|
13
10
|
from typing_extensions import ParamSpec
|
|
@@ -39,13 +36,13 @@ class QExpandableInterface(ABC):
|
|
|
39
36
|
self,
|
|
40
37
|
name: str,
|
|
41
38
|
qtype: QuantumType,
|
|
42
|
-
source_ref:
|
|
39
|
+
source_ref: SourceReference | None = None,
|
|
43
40
|
) -> None:
|
|
44
41
|
raise NotImplementedError()
|
|
45
42
|
|
|
46
43
|
|
|
47
44
|
class QCallable(Generic[P], ABC):
|
|
48
|
-
CURRENT_EXPANDABLE: ClassVar[
|
|
45
|
+
CURRENT_EXPANDABLE: ClassVar[QExpandableInterface | None] = None
|
|
49
46
|
FRAME_DEPTH = 1
|
|
50
47
|
|
|
51
48
|
@suppress_return_value
|
|
@@ -62,12 +59,6 @@ class QCallable(Generic[P], ABC):
|
|
|
62
59
|
def func_decl(self) -> AnonQuantumFunctionDeclaration:
|
|
63
60
|
raise NotImplementedError
|
|
64
61
|
|
|
65
|
-
# Support comma-separated generic args in older Python versions
|
|
66
|
-
if sys.version_info[0:2] < (3, 10):
|
|
67
|
-
|
|
68
|
-
def __class_getitem__(cls, args) -> _GenericAlias:
|
|
69
|
-
return _GenericAlias(cls, args)
|
|
70
|
-
|
|
71
62
|
@abstractmethod
|
|
72
63
|
def create_quantum_function_call(
|
|
73
64
|
self, source_ref_: SourceReference, *args: Any, **kwargs: Any
|
|
@@ -81,5 +72,19 @@ class QCallableList(QCallable, Generic[P], ABC):
|
|
|
81
72
|
@property
|
|
82
73
|
def len(self) -> int: ...
|
|
83
74
|
|
|
84
|
-
def __getitem__(self, key:
|
|
75
|
+
def __getitem__(self, key: slice | int | CInt) -> "QTerminalCallable":
|
|
76
|
+
raise NotImplementedError()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class QPerm(QCallable, Generic[P], ABC):
|
|
80
|
+
pass
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class QPermList(QCallable, Generic[P], ABC):
|
|
84
|
+
if TYPE_CHECKING:
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def len(self) -> int: ...
|
|
88
|
+
|
|
89
|
+
def __getitem__(self, key: slice | int | CInt) -> "QTerminalCallable":
|
|
85
90
|
raise NotImplementedError()
|