classiq 0.93.0__py3-none-any.whl → 0.99.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/__init__.py +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- 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/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- 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 +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +238 -10
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +10 -8
- classiq/evaluators/qmod_annotated_expression.py +31 -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/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -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/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- 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/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- 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 +8 -7
- classiq/interface/exceptions.py +6 -7
- 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 +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- 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 +15 -40
- 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 +3 -3
- 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 -40
- 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 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- 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 +9 -9
- 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/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- 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/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- 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 -3
- 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 +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- 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 +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- 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 +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- classiq/model_expansions/interpreters/generative_interpreter.py +5 -3
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -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 +2 -2
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +165 -79
- classiq/qmod/builtins/structs.py +24 -91
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/expression_query.py +7 -4
- 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 +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +31 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/utilities.py +13 -20
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/RECORD +271 -299
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/WHEEL +1 -1
- 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/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- 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/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- 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/hamiltonian_evolution/qdrift.py +0 -27
- 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/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- 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/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/licenses/LICENSE.txt +0 -0
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))
|
|
@@ -176,9 +176,6 @@ Input = Annotated[_Q, PortDeclarationDirection.Input]
|
|
|
176
176
|
Const = Annotated[
|
|
177
177
|
_Q, TypeModifier.Const
|
|
178
178
|
] # A constant variable, up to a phase dependent on the computational basis state
|
|
179
|
-
Permutable = Annotated[
|
|
180
|
-
_Q, TypeModifier.Permutable
|
|
181
|
-
] # A permutable ("quantum free") variable, up to a phase dependent on the computational basis state
|
|
182
179
|
|
|
183
180
|
|
|
184
181
|
class QScalar(QVar, SymbolicExpr):
|
|
@@ -186,9 +183,9 @@ class QScalar(QVar, SymbolicExpr):
|
|
|
186
183
|
|
|
187
184
|
def __init__(
|
|
188
185
|
self,
|
|
189
|
-
origin:
|
|
186
|
+
origin: None | str | HandleBinding = None,
|
|
190
187
|
*,
|
|
191
|
-
_expr_str:
|
|
188
|
+
_expr_str: str | None = None,
|
|
192
189
|
depth: int = 2,
|
|
193
190
|
) -> None:
|
|
194
191
|
origin = _infer_variable_name(origin, self.CONSTRUCTOR_DEPTH)
|
|
@@ -260,6 +257,13 @@ class QScalar(QVar, SymbolicExpr):
|
|
|
260
257
|
return self
|
|
261
258
|
|
|
262
259
|
def __imul__(self, other: Any) -> Self:
|
|
260
|
+
warnings.warn(
|
|
261
|
+
"The '*=' operator is deprecated and will no longer be supported "
|
|
262
|
+
"starting on 2025-12-03 at the earliest. Use the 'assign_amplitude_table' "
|
|
263
|
+
"function instead",
|
|
264
|
+
ClassiqDeprecationWarning,
|
|
265
|
+
stacklevel=2,
|
|
266
|
+
)
|
|
263
267
|
if not isinstance(other, SYMBOLIC_TYPES):
|
|
264
268
|
raise ClassiqValueError(
|
|
265
269
|
f"Invalid argument {str(other)!r} for out of ampltiude encoding operation"
|
|
@@ -371,9 +375,9 @@ class QBit(QScalar):
|
|
|
371
375
|
@classmethod
|
|
372
376
|
def to_qvar(
|
|
373
377
|
cls,
|
|
374
|
-
origin:
|
|
378
|
+
origin: str | HandleBinding,
|
|
375
379
|
type_hint: Any,
|
|
376
|
-
expr_str:
|
|
380
|
+
expr_str: str | None,
|
|
377
381
|
) -> "QBit":
|
|
378
382
|
return QBit(origin, _expr_str=expr_str)
|
|
379
383
|
|
|
@@ -428,11 +432,11 @@ class QNum(Generic[_P], QScalar):
|
|
|
428
432
|
|
|
429
433
|
def __init__(
|
|
430
434
|
self,
|
|
431
|
-
name:
|
|
432
|
-
size:
|
|
433
|
-
is_signed:
|
|
434
|
-
fraction_digits:
|
|
435
|
-
_expr_str:
|
|
435
|
+
name: None | str | HandleBinding = None,
|
|
436
|
+
size: int | CInt | Expression | SymbolicExpr | None = None,
|
|
437
|
+
is_signed: bool | CBool | Expression | SymbolicExpr | None = None,
|
|
438
|
+
fraction_digits: int | CInt | Expression | SymbolicExpr | None = None,
|
|
439
|
+
_expr_str: str | None = None,
|
|
436
440
|
):
|
|
437
441
|
if size is None and (is_signed is not None or fraction_digits is not None):
|
|
438
442
|
raise ClassiqValueError(
|
|
@@ -466,9 +470,9 @@ class QNum(Generic[_P], QScalar):
|
|
|
466
470
|
@classmethod
|
|
467
471
|
def to_qvar(
|
|
468
472
|
cls,
|
|
469
|
-
origin:
|
|
473
|
+
origin: str | HandleBinding,
|
|
470
474
|
type_hint: Any,
|
|
471
|
-
expr_str:
|
|
475
|
+
expr_str: str | None,
|
|
472
476
|
) -> "QNum":
|
|
473
477
|
return QNum(origin, *_get_qnum_attributes(type_hint), _expr_str=expr_str)
|
|
474
478
|
|
|
@@ -480,14 +484,14 @@ class QNum(Generic[_P], QScalar):
|
|
|
480
484
|
)
|
|
481
485
|
|
|
482
486
|
@property
|
|
483
|
-
def fraction_digits(self) ->
|
|
487
|
+
def fraction_digits(self) -> CParamScalar | int:
|
|
484
488
|
if is_generative_mode():
|
|
485
489
|
with generative_mode_context(False):
|
|
486
490
|
return interpret_expression(str(self.fraction_digits))
|
|
487
491
|
return CParamScalar(f"{self}.fraction_digits")
|
|
488
492
|
|
|
489
493
|
@property
|
|
490
|
-
def is_signed(self) ->
|
|
494
|
+
def is_signed(self) -> CParamScalar | bool:
|
|
491
495
|
if is_generative_mode():
|
|
492
496
|
with generative_mode_context(False):
|
|
493
497
|
return interpret_expression(str(self.is_signed))
|
|
@@ -510,12 +514,6 @@ class QNum(Generic[_P], QScalar):
|
|
|
510
514
|
fraction_places=self.fraction_digits,
|
|
511
515
|
)
|
|
512
516
|
|
|
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
517
|
|
|
520
518
|
class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
521
519
|
CONSTRUCTOR_DEPTH: int = 3
|
|
@@ -523,10 +521,10 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
523
521
|
# TODO [CAD-18620]: improve type hints
|
|
524
522
|
def __init__(
|
|
525
523
|
self,
|
|
526
|
-
name:
|
|
527
|
-
element_type:
|
|
528
|
-
length:
|
|
529
|
-
_expr_str:
|
|
524
|
+
name: None | str | HandleBinding = None,
|
|
525
|
+
element_type: _GenericAlias | QuantumType = QBit,
|
|
526
|
+
length: int | CInt | SymbolicExpr | Expression | None = None,
|
|
527
|
+
_expr_str: str | None = None,
|
|
530
528
|
) -> None:
|
|
531
529
|
self._element_type = element_type
|
|
532
530
|
self._length = (
|
|
@@ -536,7 +534,7 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
536
534
|
)
|
|
537
535
|
super().__init__(name, expr_str=_expr_str)
|
|
538
536
|
|
|
539
|
-
def __getitem__(self, key:
|
|
537
|
+
def __getitem__(self, key: slice | int | SymbolicExpr) -> Any:
|
|
540
538
|
return (
|
|
541
539
|
self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
|
|
542
540
|
)
|
|
@@ -544,7 +542,7 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
544
542
|
def __setitem__(self, *args: Any) -> None:
|
|
545
543
|
pass
|
|
546
544
|
|
|
547
|
-
def _get_subscript(self, index:
|
|
545
|
+
def _get_subscript(self, index: slice | int | SymbolicExpr) -> Any:
|
|
548
546
|
if isinstance(index, SymbolicExpr) and index.is_quantum:
|
|
549
547
|
raise ClassiqValueError("Non-classical parameter for slicing")
|
|
550
548
|
|
|
@@ -589,7 +587,7 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
589
587
|
else:
|
|
590
588
|
|
|
591
589
|
@property
|
|
592
|
-
def len(self) ->
|
|
590
|
+
def len(self) -> CParamScalar | int:
|
|
593
591
|
if is_generative_mode():
|
|
594
592
|
with generative_mode_context(False):
|
|
595
593
|
return interpret_expression(str(self.len))
|
|
@@ -598,9 +596,9 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
598
596
|
@classmethod
|
|
599
597
|
def to_qvar(
|
|
600
598
|
cls,
|
|
601
|
-
origin:
|
|
599
|
+
origin: str | HandleBinding,
|
|
602
600
|
type_hint: Any,
|
|
603
|
-
expr_str:
|
|
601
|
+
expr_str: str | None,
|
|
604
602
|
) -> "QArray":
|
|
605
603
|
return QArray(origin, *_get_qarray_attributes(type_hint), _expr_str=expr_str)
|
|
606
604
|
|
|
@@ -614,6 +612,9 @@ class QArray(ArrayBase[_P], QVar, NonSymbolicExpr):
|
|
|
614
612
|
length=self._length,
|
|
615
613
|
)
|
|
616
614
|
|
|
615
|
+
def __iter__(self) -> NoReturn:
|
|
616
|
+
raise TypeError(f"{type(self).__name__!r} object is not iterable")
|
|
617
|
+
|
|
617
618
|
|
|
618
619
|
class QStruct(QVar):
|
|
619
620
|
CONSTRUCTOR_DEPTH: int = 2
|
|
@@ -623,10 +624,10 @@ class QStruct(QVar):
|
|
|
623
624
|
|
|
624
625
|
def __init__(
|
|
625
626
|
self,
|
|
626
|
-
origin:
|
|
627
|
-
_struct_name:
|
|
628
|
-
_fields:
|
|
629
|
-
_expr_str:
|
|
627
|
+
origin: None | str | HandleBinding = None,
|
|
628
|
+
_struct_name: str | None = None,
|
|
629
|
+
_fields: Mapping[str, QVar] | None = None,
|
|
630
|
+
_expr_str: str | None = None,
|
|
630
631
|
) -> None:
|
|
631
632
|
_register_qstruct(type(self), qmodule=QMODULE)
|
|
632
633
|
name = _infer_variable_name(origin, self.CONSTRUCTOR_DEPTH)
|
|
@@ -654,9 +655,9 @@ class QStruct(QVar):
|
|
|
654
655
|
@classmethod
|
|
655
656
|
def to_qvar(
|
|
656
657
|
cls,
|
|
657
|
-
origin:
|
|
658
|
+
origin: str | HandleBinding,
|
|
658
659
|
type_hint: Any,
|
|
659
|
-
expr_str:
|
|
660
|
+
expr_str: str | None,
|
|
660
661
|
) -> "QStruct":
|
|
661
662
|
field_types = {
|
|
662
663
|
field_name: (_get_root_type(field_type), field_type)
|
|
@@ -699,7 +700,7 @@ def create_qvar_from_quantum_type(quantum_type: ConcreteQuantumType, name: str)
|
|
|
699
700
|
|
|
700
701
|
|
|
701
702
|
def _create_qvar_for_qtype(
|
|
702
|
-
qtype: QuantumType, origin: HandleBinding, expr_str:
|
|
703
|
+
qtype: QuantumType, origin: HandleBinding, expr_str: str | None = None
|
|
703
704
|
) -> QVar:
|
|
704
705
|
# prevent addition to local handles, since this is used for ports
|
|
705
706
|
with _no_current_expandable():
|
|
@@ -868,7 +869,7 @@ def _get_quantum_struct(type_hint: type[QStruct]) -> Struct:
|
|
|
868
869
|
|
|
869
870
|
def _register_qstruct(
|
|
870
871
|
type_hint: type[QStruct], *, qmodule: ModelStateContainer
|
|
871
|
-
) ->
|
|
872
|
+
) -> QStructDeclaration | None:
|
|
872
873
|
struct_name = type_hint.__name__
|
|
873
874
|
if type_hint is QStruct:
|
|
874
875
|
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()
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
from abc import ABC
|
|
3
|
-
from collections.abc import Generator, Iterable
|
|
3
|
+
from collections.abc import Callable, Generator, Iterable
|
|
4
4
|
from dataclasses import is_dataclass
|
|
5
5
|
from enum import Enum as PythonEnum
|
|
6
6
|
from types import TracebackType
|
|
7
7
|
from typing import (
|
|
8
8
|
TYPE_CHECKING,
|
|
9
9
|
Any,
|
|
10
|
-
Callable,
|
|
11
10
|
ClassVar,
|
|
12
|
-
Optional,
|
|
13
11
|
Union,
|
|
14
12
|
cast,
|
|
15
13
|
overload,
|
|
@@ -56,7 +54,11 @@ from classiq.interface.model.variable_declaration_statement import (
|
|
|
56
54
|
)
|
|
57
55
|
from classiq.interface.source_reference import SourceReference
|
|
58
56
|
|
|
59
|
-
from classiq.qmod.generative import
|
|
57
|
+
from classiq.qmod.generative import (
|
|
58
|
+
generative_mode_context,
|
|
59
|
+
interpret_expression,
|
|
60
|
+
is_generative_mode,
|
|
61
|
+
)
|
|
60
62
|
from classiq.qmod.global_declarative_switch import get_global_declarative_switch
|
|
61
63
|
from classiq.qmod.model_state_container import QMODULE, ModelStateContainer
|
|
62
64
|
from classiq.qmod.qmod_constant import QConstant
|
|
@@ -107,9 +109,9 @@ class QExpandable(QCallable, QExpandableInterface, ABC):
|
|
|
107
109
|
|
|
108
110
|
def __exit__(
|
|
109
111
|
self,
|
|
110
|
-
exc_type:
|
|
111
|
-
exc_val:
|
|
112
|
-
exc_tb:
|
|
112
|
+
exc_type: type[BaseException] | None,
|
|
113
|
+
exc_val: BaseException | None,
|
|
114
|
+
exc_tb: TracebackType | None,
|
|
113
115
|
) -> None:
|
|
114
116
|
assert QExpandable.STACK.pop() is self
|
|
115
117
|
QCallable.CURRENT_EXPANDABLE = (
|
|
@@ -125,14 +127,14 @@ class QExpandable(QCallable, QExpandableInterface, ABC):
|
|
|
125
127
|
with self, generative_mode_context(False):
|
|
126
128
|
self._py_callable(*self._get_positional_args())
|
|
127
129
|
|
|
128
|
-
def infer_rename_params(self) ->
|
|
130
|
+
def infer_rename_params(self) -> list[str] | None:
|
|
129
131
|
return None
|
|
130
132
|
|
|
131
133
|
def add_local_handle(
|
|
132
134
|
self,
|
|
133
135
|
name: str,
|
|
134
136
|
qtype: QuantumType,
|
|
135
|
-
source_ref:
|
|
137
|
+
source_ref: SourceReference | None = None,
|
|
136
138
|
) -> None:
|
|
137
139
|
self.append_statement_to_body(
|
|
138
140
|
VariableDeclarationStatement(
|
|
@@ -219,8 +221,8 @@ class QTerminalCallable(QCallable):
|
|
|
219
221
|
def __init__(
|
|
220
222
|
self,
|
|
221
223
|
decl: QuantumFunctionDeclaration,
|
|
222
|
-
param_idx:
|
|
223
|
-
index_:
|
|
224
|
+
param_idx: int | None = None,
|
|
225
|
+
index_: int | CParamScalar | None = None,
|
|
224
226
|
) -> None:
|
|
225
227
|
pass
|
|
226
228
|
|
|
@@ -229,22 +231,22 @@ class QTerminalCallable(QCallable):
|
|
|
229
231
|
self,
|
|
230
232
|
decl: AnonQuantumFunctionDeclaration,
|
|
231
233
|
param_idx: int,
|
|
232
|
-
index_:
|
|
234
|
+
index_: int | CParamScalar | None = None,
|
|
233
235
|
) -> None:
|
|
234
236
|
pass
|
|
235
237
|
|
|
236
238
|
def __init__(
|
|
237
239
|
self,
|
|
238
240
|
decl: AnonQuantumFunctionDeclaration,
|
|
239
|
-
param_idx:
|
|
240
|
-
index_:
|
|
241
|
+
param_idx: int | None = None,
|
|
242
|
+
index_: int | CParamScalar | None = None,
|
|
241
243
|
) -> None:
|
|
242
244
|
self._decl = self._override_decl_name(decl, param_idx)
|
|
243
245
|
self._index = index_
|
|
244
246
|
|
|
245
247
|
@staticmethod
|
|
246
248
|
def _override_decl_name(
|
|
247
|
-
decl: AnonQuantumFunctionDeclaration, param_idx:
|
|
249
|
+
decl: AnonQuantumFunctionDeclaration, param_idx: int | None
|
|
248
250
|
) -> QuantumFunctionDeclaration:
|
|
249
251
|
if (
|
|
250
252
|
not isinstance(QCallable.CURRENT_EXPANDABLE, QLambdaFunction)
|
|
@@ -260,7 +262,7 @@ class QTerminalCallable(QCallable):
|
|
|
260
262
|
isinstance(self._decl, AnonQuantumOperandDeclaration) and self._decl.is_list
|
|
261
263
|
)
|
|
262
264
|
|
|
263
|
-
def __getitem__(self, key:
|
|
265
|
+
def __getitem__(self, key: slice | int | CInt) -> "QTerminalCallable":
|
|
264
266
|
if not self.is_list:
|
|
265
267
|
raise ClassiqValueError("Cannot index a non-list operand")
|
|
266
268
|
if isinstance(key, slice):
|
|
@@ -287,6 +289,9 @@ class QTerminalCallable(QCallable):
|
|
|
287
289
|
def len(self) -> CParamScalar:
|
|
288
290
|
if not self.is_list:
|
|
289
291
|
raise ClassiqValueError("Cannot get length of a non-list operand")
|
|
292
|
+
if is_generative_mode():
|
|
293
|
+
with generative_mode_context(False):
|
|
294
|
+
return interpret_expression(str(self.len))
|
|
290
295
|
return CParamScalar(f"{self.func_decl.name}.len")
|
|
291
296
|
|
|
292
297
|
@property
|
|
@@ -315,25 +320,25 @@ class QTerminalCallable(QCallable):
|
|
|
315
320
|
@overload
|
|
316
321
|
def prepare_arg(
|
|
317
322
|
arg_decl: AnonPositionalArg,
|
|
318
|
-
val:
|
|
319
|
-
func_name:
|
|
323
|
+
val: QCallable | Callable[..., None],
|
|
324
|
+
func_name: str | None,
|
|
320
325
|
param_name: str,
|
|
321
326
|
) -> QuantumLambdaFunction: ...
|
|
322
327
|
|
|
323
328
|
|
|
324
329
|
@overload
|
|
325
330
|
def prepare_arg(
|
|
326
|
-
arg_decl: AnonPositionalArg, val: Any, func_name:
|
|
331
|
+
arg_decl: AnonPositionalArg, val: Any, func_name: str | None, param_name: str
|
|
327
332
|
) -> ArgValue: ...
|
|
328
333
|
|
|
329
334
|
|
|
330
335
|
def prepare_arg(
|
|
331
|
-
arg_decl: AnonPositionalArg, val: Any, func_name:
|
|
336
|
+
arg_decl: AnonPositionalArg, val: Any, func_name: str | None, param_name: str
|
|
332
337
|
) -> ArgValue:
|
|
333
338
|
from classiq.qmod.quantum_function import BaseQFunc, GenerativeQFunc, QFunc
|
|
334
339
|
|
|
335
340
|
if get_global_declarative_switch() and isinstance(val, GenerativeQFunc):
|
|
336
|
-
val = QFunc(val._py_callable)
|
|
341
|
+
val = QFunc(val._py_callable, permutation=val.permutation)
|
|
337
342
|
if isinstance(val, BaseQFunc):
|
|
338
343
|
val.add_function_dependencies()
|
|
339
344
|
if isinstance(val, GenerativeQFunc):
|
|
@@ -391,7 +396,7 @@ def prepare_arg(
|
|
|
391
396
|
|
|
392
397
|
|
|
393
398
|
def _validate_classical_arg(
|
|
394
|
-
arg: Any, arg_decl: AnonClassicalParameterDeclaration, func_name:
|
|
399
|
+
arg: Any, arg_decl: AnonClassicalParameterDeclaration, func_name: str | None
|
|
395
400
|
) -> None:
|
|
396
401
|
is_native_or_compatible_type = (
|
|
397
402
|
not isinstance(
|
|
@@ -504,8 +509,8 @@ def _validate_argument_names(
|
|
|
504
509
|
|
|
505
510
|
def _create_quantum_function_call(
|
|
506
511
|
decl_: QuantumFunctionDeclaration,
|
|
507
|
-
index_:
|
|
508
|
-
source_ref_:
|
|
512
|
+
index_: CParamScalar | int | None = None,
|
|
513
|
+
source_ref_: SourceReference | None = None,
|
|
509
514
|
*args: Any,
|
|
510
515
|
**kwargs: Any,
|
|
511
516
|
) -> QuantumFunctionCall:
|
|
@@ -513,7 +518,7 @@ def _create_quantum_function_call(
|
|
|
513
518
|
_validate_argument_names(decl_, arg_list, kwargs)
|
|
514
519
|
prepared_args = _prepare_args(decl_, arg_list, kwargs)
|
|
515
520
|
|
|
516
|
-
function_ident:
|
|
521
|
+
function_ident: str | OperandIdentifier = decl_.name
|
|
517
522
|
if index_ is not None:
|
|
518
523
|
function_ident = OperandIdentifier(
|
|
519
524
|
index=Expression(expr=str(index_)), name=function_ident
|
|
@@ -541,7 +546,7 @@ def _is_legal_iterable_element(arg: Any) -> bool:
|
|
|
541
546
|
return True
|
|
542
547
|
|
|
543
548
|
|
|
544
|
-
def _try_preparing_handles_list(val: Any) ->
|
|
549
|
+
def _try_preparing_handles_list(val: Any) -> HandlesList | None:
|
|
545
550
|
if not isinstance(val, list):
|
|
546
551
|
return None
|
|
547
552
|
items = [
|