classiq 0.53.0__py3-none-any.whl → 0.55.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 +1 -3
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +2 -1
- classiq/_internals/__init__.py +0 -20
- classiq/_internals/api_wrapper.py +8 -8
- classiq/_internals/async_utils.py +1 -3
- classiq/_internals/authentication/auth0.py +5 -5
- classiq/_internals/authentication/device.py +5 -4
- classiq/_internals/authentication/password_manager.py +3 -3
- classiq/_internals/authentication/token_manager.py +3 -2
- classiq/_internals/client.py +10 -12
- classiq/_internals/config.py +2 -2
- classiq/_internals/jobs.py +7 -6
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +8 -7
- classiq/analyzer/analyzer_utilities.py +8 -8
- classiq/analyzer/rb.py +11 -11
- classiq/applications/__init__.py +1 -3
- classiq/applications/chemistry/__init__.py +1 -3
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/applications/chemistry/chemistry_model_constructor.py +10 -9
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +26 -9
- classiq/applications/combinatorial_helpers/encoding_mapping.py +10 -10
- classiq/applications/combinatorial_helpers/encoding_utils.py +4 -4
- classiq/applications/combinatorial_helpers/memory.py +5 -7
- classiq/applications/combinatorial_helpers/optimization_model.py +43 -24
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +4 -6
- classiq/applications/combinatorial_helpers/pyomo_utils.py +95 -24
- classiq/applications/combinatorial_helpers/sympy_utils.py +2 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +8 -8
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -5
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +7 -9
- classiq/applications/combinatorial_helpers/transformations/penalty.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +1 -2
- classiq/applications/combinatorial_optimization/__init__.py +1 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +1 -3
- classiq/applications/grover/__init__.py +1 -3
- classiq/applications/grover/grover_model_constructor.py +7 -9
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -6
- classiq/applications/qnn/__init__.py +1 -3
- classiq/applications/qnn/circuit_utils.py +5 -5
- classiq/applications/qnn/datasets/__init__.py +1 -3
- classiq/applications/qnn/datasets/dataset_base_classes.py +5 -4
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +3 -3
- classiq/applications/qnn/torch_utils.py +2 -2
- classiq/applications/qnn/types.py +5 -5
- classiq/applications/qsvm/qsvm.py +1 -3
- classiq/applications/qsvm/qsvm_data_generation.py +3 -3
- classiq/applications/qsvm/qsvm_model_constructor.py +5 -5
- classiq/execution/__init__.py +1 -3
- classiq/execution/all_hardware_devices.py +1 -3
- classiq/execution/execution_session.py +16 -16
- classiq/execution/jobs.py +4 -4
- classiq/execution/qaoa.py +3 -3
- classiq/execution/qnn.py +3 -3
- classiq/executor.py +3 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +9 -10
- classiq/interface/analyzer/cytoscape_graph.py +5 -5
- classiq/interface/analyzer/result.py +17 -17
- classiq/interface/applications/qsvm.py +6 -10
- classiq/interface/backend/backend_preferences.py +4 -3
- classiq/interface/backend/ionq/ionq_quantum_program.py +4 -5
- classiq/interface/backend/pydantic_backend.py +1 -2
- classiq/interface/chemistry/fermionic_operator.py +5 -5
- classiq/interface/chemistry/ground_state_problem.py +7 -8
- classiq/interface/chemistry/molecule.py +4 -4
- classiq/interface/chemistry/operator.py +11 -13
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -3
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mht.py +2 -3
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +1 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +5 -7
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +8 -6
- classiq/interface/execution/jobs.py +2 -2
- classiq/interface/execution/primitives.py +3 -3
- classiq/interface/executor/aws_execution_cost.py +4 -4
- classiq/interface/executor/execution_request.py +2 -3
- classiq/interface/executor/execution_result.py +3 -3
- classiq/interface/executor/iqae_result.py +3 -5
- classiq/interface/executor/optimizer_preferences.py +2 -2
- classiq/interface/executor/quantum_code.py +6 -6
- classiq/interface/executor/register_initialization.py +2 -4
- classiq/interface/executor/result.py +23 -27
- classiq/interface/executor/vqe_result.py +8 -8
- classiq/interface/finance/function_input.py +2 -2
- classiq/interface/finance/gaussian_model_input.py +5 -5
- classiq/interface/finance/log_normal_model_input.py +2 -2
- classiq/interface/finance/model_input.py +1 -2
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/ansatz_library.py +4 -4
- classiq/interface/generator/application_apis/finance_declarations.py +1 -1
- classiq/interface/generator/arith/argument_utils.py +3 -3
- classiq/interface/generator/arith/arithmetic.py +7 -7
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +5 -5
- classiq/interface/generator/arith/arithmetic_expression_abc.py +11 -11
- classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -7
- classiq/interface/generator/arith/arithmetic_expression_validator.py +8 -8
- classiq/interface/generator/arith/arithmetic_operations.py +4 -3
- classiq/interface/generator/arith/arithmetic_param_getters.py +6 -6
- classiq/interface/generator/arith/arithmetic_result_builder.py +9 -9
- classiq/interface/generator/arith/ast_node_rewrite.py +2 -1
- classiq/interface/generator/arith/binary_ops.py +10 -13
- classiq/interface/generator/arith/extremum_operations.py +3 -2
- classiq/interface/generator/arith/logical_ops.py +7 -6
- classiq/interface/generator/arith/number_utils.py +4 -4
- classiq/interface/generator/arith/register_user_input.py +4 -4
- classiq/interface/generator/arith/unary_ops.py +2 -1
- classiq/interface/generator/builtin_api_builder.py +2 -1
- classiq/interface/generator/circuit_code/circuit_code.py +4 -4
- classiq/interface/generator/circuit_code/types_and_constants.py +3 -5
- classiq/interface/generator/complex_type.py +1 -2
- classiq/interface/generator/control_state.py +2 -2
- classiq/interface/generator/custom_ansatz.py +1 -3
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/enums/finance_functions.py +1 -3
- classiq/interface/generator/expressions/evaluated_expression.py +4 -3
- classiq/interface/generator/expressions/expression.py +4 -5
- classiq/interface/generator/expressions/expression_constants.py +4 -4
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_sized_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_struct_instance.py +2 -1
- classiq/interface/generator/expressions/sympy_supported_expressions.py +11 -13
- classiq/interface/generator/finance.py +2 -2
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_params.py +13 -19
- classiq/interface/generator/functions/builtins/internal_operators.py +9 -1
- classiq/interface/generator/functions/classical_function_declaration.py +4 -3
- classiq/interface/generator/functions/classical_type.py +13 -13
- classiq/interface/generator/functions/concrete_types.py +1 -2
- classiq/interface/generator/functions/function_declaration.py +1 -1
- classiq/interface/generator/functions/qmod_python_interface.py +2 -1
- classiq/interface/generator/functions/type_name.py +3 -2
- classiq/interface/generator/generated_circuit_data.py +33 -22
- classiq/interface/generator/grover_diffuser.py +7 -7
- classiq/interface/generator/grover_operator.py +2 -2
- classiq/interface/generator/hardware/hardware_data.py +7 -6
- classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
- classiq/interface/generator/identity.py +5 -6
- classiq/interface/generator/linear_pauli_rotations.py +6 -6
- classiq/interface/generator/mcu.py +2 -2
- classiq/interface/generator/mcx.py +6 -6
- classiq/interface/generator/model/__init__.py +1 -3
- classiq/interface/generator/model/constraints.py +2 -2
- classiq/interface/generator/model/model.py +5 -6
- classiq/interface/generator/model/preferences/preferences.py +11 -6
- classiq/interface/generator/model/quantum_register.py +6 -11
- classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
- classiq/interface/generator/oracles/custom_oracle.py +2 -2
- classiq/interface/generator/oracles/oracle_abc.py +6 -5
- classiq/interface/generator/partitioned_register.py +6 -5
- classiq/interface/generator/piecewise_linear_amplitude_loading.py +8 -7
- classiq/interface/generator/qpe.py +4 -4
- classiq/interface/generator/qsvm.py +3 -3
- classiq/interface/generator/quantum_function_call.py +24 -29
- classiq/interface/generator/quantum_program.py +9 -9
- classiq/interface/generator/register_role.py +2 -4
- classiq/interface/generator/slice_parsing_utils.py +4 -3
- classiq/interface/generator/standard_gates/standard_gates.py +3 -3
- classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
- classiq/interface/generator/state_preparation/distributions.py +6 -5
- classiq/interface/generator/state_preparation/metrics.py +2 -4
- classiq/interface/generator/state_preparation/state_preparation.py +4 -4
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +3 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -2
- classiq/interface/generator/types/compilation_metadata.py +5 -0
- classiq/interface/generator/types/enum_declaration.py +2 -3
- classiq/interface/generator/types/qstruct_declaration.py +2 -1
- classiq/interface/generator/types/struct_declaration.py +3 -2
- classiq/interface/generator/ucc.py +2 -1
- classiq/interface/generator/unitary_gate.py +2 -2
- classiq/interface/generator/user_defined_function_params.py +1 -1
- classiq/interface/generator/validations/flow_graph.py +6 -5
- classiq/interface/generator/validations/validator_functions.py +3 -2
- classiq/interface/generator/visitor.py +9 -14
- classiq/interface/hardware.py +5 -6
- classiq/interface/helpers/custom_encoders.py +2 -2
- classiq/interface/helpers/custom_pydantic_types.py +8 -9
- classiq/interface/helpers/hashable_mixin.py +3 -2
- classiq/interface/helpers/hashable_pydantic_base_model.py +2 -1
- classiq/interface/helpers/pydantic_model_helpers.py +4 -3
- classiq/interface/helpers/validation_helpers.py +2 -2
- classiq/interface/ide/ide_data.py +11 -15
- classiq/interface/ide/visual_model.py +22 -22
- classiq/interface/jobs.py +2 -2
- classiq/interface/model/bind_operation.py +5 -4
- classiq/interface/model/classical_parameter_declaration.py +2 -2
- classiq/interface/model/control.py +22 -1
- classiq/interface/model/handle_binding.py +3 -2
- classiq/interface/model/inplace_binary_operation.py +2 -1
- classiq/interface/model/model.py +16 -11
- classiq/interface/model/native_function_definition.py +1 -1
- classiq/interface/model/port_declaration.py +2 -2
- classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +3 -2
- classiq/interface/model/quantum_expressions/arithmetic_operation.py +4 -27
- classiq/interface/model/quantum_expressions/quantum_expression.py +8 -7
- classiq/interface/model/quantum_function_call.py +9 -14
- classiq/interface/model/quantum_function_declaration.py +10 -12
- classiq/interface/model/quantum_lambda_function.py +3 -16
- classiq/interface/model/quantum_statement.py +7 -3
- classiq/interface/model/quantum_type.py +5 -5
- classiq/interface/model/statement_block.py +2 -3
- classiq/interface/model/validation_handle.py +5 -4
- classiq/interface/server/global_versions.py +3 -3
- classiq/model_expansions/atomic_expression_functions_defs.py +3 -2
- classiq/model_expansions/capturing/captured_var_manager.py +4 -6
- classiq/model_expansions/capturing/propagated_var_stack.py +7 -7
- classiq/model_expansions/closure.py +83 -12
- classiq/model_expansions/evaluators/arg_type_match.py +3 -2
- classiq/model_expansions/evaluators/argument_types.py +3 -3
- classiq/model_expansions/evaluators/control.py +3 -3
- classiq/model_expansions/evaluators/parameter_types.py +7 -7
- classiq/model_expansions/evaluators/quantum_type_utils.py +2 -1
- classiq/model_expansions/evaluators/type_type_match.py +1 -1
- classiq/model_expansions/expression_evaluator.py +10 -9
- classiq/model_expansions/expression_renamer.py +6 -6
- classiq/model_expansions/function_builder.py +13 -12
- classiq/model_expansions/generative_functions.py +5 -4
- classiq/model_expansions/interpreter.py +20 -11
- classiq/model_expansions/model_tables.py +14 -14
- classiq/model_expansions/quantum_operations/bind.py +2 -4
- classiq/model_expansions/quantum_operations/classicalif.py +1 -1
- classiq/model_expansions/quantum_operations/control.py +81 -24
- classiq/model_expansions/quantum_operations/emitter.py +33 -20
- classiq/model_expansions/quantum_operations/expression_operation.py +47 -16
- classiq/model_expansions/quantum_operations/inplace_binary_operation.py +160 -35
- classiq/model_expansions/quantum_operations/phase.py +6 -6
- classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +28 -31
- classiq/model_expansions/quantum_operations/quantum_function_call.py +9 -0
- classiq/model_expansions/quantum_operations/repeat.py +1 -3
- classiq/model_expansions/quantum_operations/within_apply.py +0 -16
- classiq/model_expansions/scope.py +11 -10
- classiq/model_expansions/scope_initialization.py +5 -5
- classiq/model_expansions/sympy_conversion/expression_to_sympy.py +6 -6
- classiq/model_expansions/sympy_conversion/sympy_to_python.py +2 -2
- classiq/model_expansions/visitors/variable_references.py +5 -4
- classiq/qmod/builtins/classical_execution_primitives.py +9 -9
- classiq/qmod/builtins/functions/__init__.py +72 -55
- classiq/qmod/builtins/functions/amplitude_estimation.py +4 -1
- classiq/qmod/builtins/functions/arithmetic.py +14 -1
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +86 -6
- classiq/qmod/builtins/functions/grover.py +41 -45
- classiq/qmod/builtins/functions/hea.py +60 -4
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +26 -4
- classiq/qmod/builtins/functions/modular_exponentiation.py +90 -29
- classiq/qmod/builtins/functions/operators.py +1 -1
- classiq/qmod/builtins/functions/qaoa_penalty.py +14 -5
- classiq/qmod/builtins/functions/qft_functions.py +57 -0
- classiq/qmod/builtins/functions/qpe.py +20 -4
- classiq/qmod/builtins/functions/qsvt.py +49 -4
- classiq/qmod/builtins/functions/standard_gates.py +4 -4
- classiq/qmod/builtins/functions/state_preparation.py +92 -10
- classiq/qmod/builtins/functions/swap_test.py +7 -1
- classiq/qmod/builtins/functions/utility_functions.py +43 -0
- classiq/qmod/builtins/functions/variational.py +18 -2
- classiq/qmod/builtins/operations.py +117 -22
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +3 -7
- classiq/qmod/create_model_function.py +16 -17
- classiq/qmod/declaration_inferrer.py +7 -10
- classiq/qmod/expression_query.py +3 -3
- classiq/qmod/generative.py +2 -1
- classiq/qmod/model_state_container.py +10 -8
- classiq/qmod/native/__init__.py +1 -3
- classiq/qmod/native/expression_to_qmod.py +9 -8
- classiq/qmod/native/pretty_printer.py +12 -6
- classiq/qmod/pretty_print/__init__.py +1 -3
- classiq/qmod/pretty_print/expression_to_python.py +13 -12
- classiq/qmod/pretty_print/pretty_printer.py +38 -23
- classiq/qmod/python_classical_type.py +8 -4
- classiq/qmod/qfunc.py +4 -4
- classiq/qmod/qmod_variable.py +11 -10
- classiq/qmod/quantum_expandable.py +12 -15
- classiq/qmod/quantum_function.py +35 -22
- classiq/qmod/semantics/annotation.py +1 -1
- classiq/qmod/semantics/error_manager.py +8 -7
- classiq/qmod/semantics/static_semantics_visitor.py +19 -24
- classiq/qmod/semantics/validation/constants_validation.py +1 -1
- classiq/qmod/semantics/validation/func_call_validation.py +2 -2
- classiq/qmod/semantics/validation/main_validation.py +33 -0
- classiq/qmod/semantics/validation/types_validation.py +2 -1
- classiq/qmod/symbolic.py +5 -8
- classiq/qmod/symbolic_type.py +2 -2
- classiq/qmod/synthesize_separately.py +1 -2
- {classiq-0.53.0.dist-info → classiq-0.55.0.dist-info}/METADATA +1 -1
- {classiq-0.53.0.dist-info → classiq-0.55.0.dist-info}/RECORD +300 -297
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.53.0.dist-info → classiq-0.55.0.dist-info}/WHEEL +0 -0
classiq/qmod/qmod_variable.py
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
import abc
|
2
2
|
import sys
|
3
|
+
from collections.abc import Iterator, Mapping
|
3
4
|
from contextlib import contextmanager
|
4
5
|
from typing import ( # type: ignore[attr-defined]
|
5
6
|
TYPE_CHECKING,
|
7
|
+
Annotated,
|
6
8
|
Any,
|
7
9
|
ForwardRef,
|
8
10
|
Generic,
|
9
|
-
Iterator,
|
10
11
|
Literal,
|
11
|
-
Mapping,
|
12
12
|
Optional,
|
13
|
-
Tuple,
|
14
|
-
Type,
|
15
13
|
TypeVar,
|
16
14
|
Union,
|
17
15
|
_GenericAlias,
|
@@ -20,7 +18,7 @@ from typing import ( # type: ignore[attr-defined]
|
|
20
18
|
get_origin,
|
21
19
|
)
|
22
20
|
|
23
|
-
from typing_extensions import
|
21
|
+
from typing_extensions import ParamSpec, Self, _AnnotatedAlias
|
24
22
|
|
25
23
|
from classiq.interface.exceptions import ClassiqValueError
|
26
24
|
from classiq.interface.generator.expressions.expression import Expression
|
@@ -127,7 +125,7 @@ class QVar(Symbolic):
|
|
127
125
|
raise NotImplementedError()
|
128
126
|
|
129
127
|
@staticmethod
|
130
|
-
def from_type_hint(type_hint: Any) -> Optional[
|
128
|
+
def from_type_hint(type_hint: Any) -> Optional[type["QVar"]]:
|
131
129
|
if _is_input_output_typehint(type_hint):
|
132
130
|
return QVar.from_type_hint(type_hint.__args__[0])
|
133
131
|
type_ = get_origin(type_hint) or type_hint
|
@@ -322,7 +320,7 @@ class QNum(Generic[_P], QScalar):
|
|
322
320
|
super().__init__(name, _expr_str=_expr_str, depth=3)
|
323
321
|
|
324
322
|
@classmethod
|
325
|
-
def _get_attributes(cls, type_hint: Any) ->
|
323
|
+
def _get_attributes(cls, type_hint: Any) -> tuple[Any, Any, Any]:
|
326
324
|
type_args = version_portable_get_args(type_hint)
|
327
325
|
if len(type_args) == 0:
|
328
326
|
return None, None, None
|
@@ -413,6 +411,9 @@ class QArray(ArrayBase[_P], QVar):
|
|
413
411
|
self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
|
414
412
|
)
|
415
413
|
|
414
|
+
def __setitem__(self, *args: Any) -> None:
|
415
|
+
pass
|
416
|
+
|
416
417
|
def _get_subscript(self, index: Union[slice, int, SymbolicExpr]) -> Any:
|
417
418
|
if isinstance(index, SymbolicExpr) and index.is_quantum:
|
418
419
|
raise ClassiqValueError("Non-classical parameter for slicing")
|
@@ -492,7 +493,7 @@ class QArray(ArrayBase[_P], QVar):
|
|
492
493
|
return CParamScalar(f"get_field({self}, 'len')")
|
493
494
|
|
494
495
|
@classmethod
|
495
|
-
def _get_attributes(cls, type_hint: Any) ->
|
496
|
+
def _get_attributes(cls, type_hint: Any) -> tuple[type[QVar], Any]:
|
496
497
|
type_args = version_portable_get_args(type_hint)
|
497
498
|
if len(type_args) == 0:
|
498
499
|
return QBit, None
|
@@ -505,7 +506,7 @@ class QArray(ArrayBase[_P], QVar):
|
|
505
506
|
"QArray receives two type arguments: QArray[element_type: QVar, "
|
506
507
|
"length: int | CInt]"
|
507
508
|
)
|
508
|
-
return cast(
|
509
|
+
return cast(tuple[type[QVar], Any], type_args)
|
509
510
|
|
510
511
|
@classmethod
|
511
512
|
def to_qmod_quantum_type(cls, type_hint: Any) -> QuantumType:
|
@@ -597,7 +598,7 @@ class QStruct(QVar):
|
|
597
598
|
base_handle = HandleBinding(name=origin) if isinstance(origin, str) else origin
|
598
599
|
with _no_current_expandable():
|
599
600
|
field_vars = {
|
600
|
-
field_name: cast(
|
601
|
+
field_name: cast(type[QVar], field_class).to_qvar(
|
601
602
|
FieldHandleBinding(base_handle=base_handle, field=field_name),
|
602
603
|
field_type,
|
603
604
|
f"get_field({expr_str if expr_str is not None else str(origin)}, '{field_name}')",
|
@@ -9,10 +9,7 @@ from typing import (
|
|
9
9
|
Any,
|
10
10
|
Callable,
|
11
11
|
ClassVar,
|
12
|
-
Dict,
|
13
|
-
List,
|
14
12
|
Optional,
|
15
|
-
Type,
|
16
13
|
Union,
|
17
14
|
cast,
|
18
15
|
overload,
|
@@ -74,15 +71,15 @@ ArgType = Union[CParam, QVar, QCallable]
|
|
74
71
|
|
75
72
|
|
76
73
|
class QExpandable(QCallable, QExpandableInterface, ABC):
|
77
|
-
STACK: ClassVar[
|
74
|
+
STACK: ClassVar[list["QExpandable"]] = list()
|
78
75
|
|
79
76
|
def __init__(self, py_callable: Callable) -> None:
|
80
77
|
self._qmodule: ModelStateContainer = QMODULE
|
81
78
|
self._py_callable: Callable = py_callable
|
82
|
-
self._body:
|
79
|
+
self._body: list[QuantumStatement] = list()
|
83
80
|
|
84
81
|
@property
|
85
|
-
def body(self) ->
|
82
|
+
def body(self) -> list[QuantumStatement]:
|
86
83
|
return self._body
|
87
84
|
|
88
85
|
def __enter__(self) -> Self:
|
@@ -93,7 +90,7 @@ class QExpandable(QCallable, QExpandableInterface, ABC):
|
|
93
90
|
|
94
91
|
def __exit__(
|
95
92
|
self,
|
96
|
-
exc_type: Optional[
|
93
|
+
exc_type: Optional[type[BaseException]],
|
97
94
|
exc_val: Optional[BaseException],
|
98
95
|
exc_tb: Optional[TracebackType],
|
99
96
|
) -> None:
|
@@ -107,7 +104,7 @@ class QExpandable(QCallable, QExpandableInterface, ABC):
|
|
107
104
|
with self, generative_mode_context(False):
|
108
105
|
self._py_callable(*self._get_positional_args())
|
109
106
|
|
110
|
-
def infer_rename_params(self) -> Optional[
|
107
|
+
def infer_rename_params(self) -> Optional[list[str]]:
|
111
108
|
return None
|
112
109
|
|
113
110
|
def add_local_handle(
|
@@ -125,8 +122,8 @@ class QExpandable(QCallable, QExpandableInterface, ABC):
|
|
125
122
|
def append_statement_to_body(self, stmt: QuantumStatement) -> None:
|
126
123
|
self._body.append(stmt)
|
127
124
|
|
128
|
-
def _get_positional_args(self) ->
|
129
|
-
result:
|
125
|
+
def _get_positional_args(self) -> list[ArgType]:
|
126
|
+
result: list[ArgType] = []
|
130
127
|
rename_params = self.infer_rename_params()
|
131
128
|
if rename_params is not None and len(rename_params) != len(
|
132
129
|
self.func_decl.positional_arg_declarations
|
@@ -179,7 +176,7 @@ class QLambdaFunction(QExpandable):
|
|
179
176
|
if not is_generative_mode():
|
180
177
|
super().expand()
|
181
178
|
|
182
|
-
def infer_rename_params(self) ->
|
179
|
+
def infer_rename_params(self) -> list[str]:
|
183
180
|
return inspect.getfullargspec(self._py_callable).args
|
184
181
|
|
185
182
|
|
@@ -313,7 +310,7 @@ def prepare_arg(
|
|
313
310
|
f"Quantum operand {param_name!r} cannot be initialized with a "
|
314
311
|
f"list of non-callables"
|
315
312
|
)
|
316
|
-
val = cast(
|
313
|
+
val = cast(list[Union[QCallable, Callable[[Any], None]]], val)
|
317
314
|
return [prepare_arg(arg_decl, v, func_name, param_name) for v in val]
|
318
315
|
|
319
316
|
if not isinstance(val, QCallable):
|
@@ -391,8 +388,8 @@ def _get_operand_hint(
|
|
391
388
|
|
392
389
|
|
393
390
|
def _prepare_args(
|
394
|
-
decl: AnonQuantumFunctionDeclaration, arg_list:
|
395
|
-
) ->
|
391
|
+
decl: AnonQuantumFunctionDeclaration, arg_list: list[Any], kwargs: dict[str, Any]
|
392
|
+
) -> list[ArgValue]:
|
396
393
|
_apply_control_backward_compatibility(decl, kwargs)
|
397
394
|
result = []
|
398
395
|
for idx, arg_decl in enumerate(decl.positional_arg_declarations):
|
@@ -417,7 +414,7 @@ def _prepare_args(
|
|
417
414
|
|
418
415
|
|
419
416
|
def _apply_control_backward_compatibility(
|
420
|
-
decl: AnonQuantumFunctionDeclaration, kwargs:
|
417
|
+
decl: AnonQuantumFunctionDeclaration, kwargs: dict[str, Any]
|
421
418
|
) -> None:
|
422
419
|
from classiq.qmod.builtins.functions import __all__ as builtin_functions
|
423
420
|
|
classiq/qmod/quantum_function.py
CHANGED
@@ -3,15 +3,15 @@ import functools
|
|
3
3
|
from dataclasses import is_dataclass
|
4
4
|
from enum import EnumMeta
|
5
5
|
from inspect import isclass
|
6
|
-
from typing import Any, Callable,
|
6
|
+
from typing import Any, Callable, Optional, get_origin
|
7
7
|
|
8
8
|
from classiq.interface.exceptions import ClassiqError
|
9
9
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
10
10
|
from classiq.interface.generator.model.constraints import Constraints
|
11
11
|
from classiq.interface.generator.model.preferences.preferences import Preferences
|
12
|
+
from classiq.interface.generator.types.compilation_metadata import CompilationMetadata
|
12
13
|
from classiq.interface.model.model import Model
|
13
14
|
from classiq.interface.model.native_function_definition import (
|
14
|
-
FunctionSynthesisData,
|
15
15
|
NativeFunctionDefinition,
|
16
16
|
)
|
17
17
|
from classiq.interface.model.quantum_function_declaration import (
|
@@ -35,7 +35,7 @@ class QFunc(QExpandable):
|
|
35
35
|
_validate_no_gen_params(py_callable.__annotations__)
|
36
36
|
super().__init__(py_callable)
|
37
37
|
functools.update_wrapper(self, py_callable)
|
38
|
-
self.
|
38
|
+
self.compilation_metadata: Optional[CompilationMetadata] = None
|
39
39
|
|
40
40
|
@property
|
41
41
|
def func_decl(self) -> NamedParamsQuantumFunctionDeclaration:
|
@@ -45,12 +45,19 @@ class QFunc(QExpandable):
|
|
45
45
|
)
|
46
46
|
|
47
47
|
@property
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
def should_synthesize_separately(self) -> bool:
|
49
|
+
if self.compilation_metadata is None:
|
50
|
+
return False
|
51
|
+
return self.compilation_metadata.should_synthesize_separately
|
52
|
+
|
53
|
+
@should_synthesize_separately.setter
|
54
|
+
def should_synthesize_separately(self, value: bool) -> None:
|
55
|
+
if self.compilation_metadata is None:
|
56
|
+
self.compilation_metadata = CompilationMetadata(
|
57
|
+
should_synthesize_separately=value
|
58
|
+
)
|
59
|
+
else:
|
60
|
+
self.compilation_metadata.should_synthesize_separately = value
|
54
61
|
|
55
62
|
def __call__(self, *args: Any, **kwargs: Any) -> None:
|
56
63
|
super().__call__(*args, **kwargs)
|
@@ -62,15 +69,19 @@ class QFunc(QExpandable):
|
|
62
69
|
execution_preferences: Optional[ExecutionPreferences] = None,
|
63
70
|
preferences: Optional[Preferences] = None,
|
64
71
|
classical_execution_function: Optional[CFunc] = None,
|
72
|
+
functions_compilation_metadata: Optional[dict[str, CompilationMetadata]] = None,
|
65
73
|
) -> Model:
|
74
|
+
if functions_compilation_metadata is None:
|
75
|
+
functions_compilation_metadata = dict()
|
66
76
|
self._qmodule.enum_decls = dict()
|
67
77
|
self._qmodule.type_decls = dict()
|
68
78
|
self._qmodule.qstruct_decls = dict()
|
69
79
|
self._qmodule.native_defs = dict()
|
70
80
|
self._qmodule.constants = dict()
|
81
|
+
self._qmodule.functions_compilation_metadata = functions_compilation_metadata
|
71
82
|
QConstant.set_current_model(self._qmodule)
|
72
83
|
self.expand()
|
73
|
-
model_extra_settings:
|
84
|
+
model_extra_settings: list[tuple[str, Any]] = [
|
74
85
|
("constraints", constraints),
|
75
86
|
("execution_preferences", execution_preferences),
|
76
87
|
("preferences", preferences),
|
@@ -86,6 +97,7 @@ class QFunc(QExpandable):
|
|
86
97
|
enums=list(self._qmodule.enum_decls.values()),
|
87
98
|
types=list(self._qmodule.type_decls.values()),
|
88
99
|
qstructs=list(self._qmodule.qstruct_decls.values()),
|
100
|
+
functions_compilation_metadata=self._qmodule.functions_compilation_metadata,
|
89
101
|
**{key: value for key, value in model_extra_settings if value},
|
90
102
|
)
|
91
103
|
|
@@ -94,18 +106,12 @@ class QFunc(QExpandable):
|
|
94
106
|
return
|
95
107
|
super().expand()
|
96
108
|
self._qmodule.native_defs[self.func_decl.name] = NativeFunctionDefinition(
|
97
|
-
**{
|
98
|
-
**self.func_decl.model_dump(),
|
99
|
-
**{
|
100
|
-
"body": self.body,
|
101
|
-
"synthesis_data": (
|
102
|
-
self.synthesis_data
|
103
|
-
if self.synthesis_data is not None
|
104
|
-
else FunctionSynthesisData()
|
105
|
-
),
|
106
|
-
},
|
107
|
-
},
|
109
|
+
**{**self.func_decl.model_dump(), **{"body": self.body}}
|
108
110
|
)
|
111
|
+
if self.compilation_metadata is not None:
|
112
|
+
self._qmodule.functions_compilation_metadata[self.func_decl.name] = (
|
113
|
+
self.compilation_metadata
|
114
|
+
)
|
109
115
|
|
110
116
|
def _add_constants_from_classical_code(
|
111
117
|
self, classical_execution_function: CFunc
|
@@ -137,6 +143,7 @@ class ExternalQFunc(QTerminalCallable):
|
|
137
143
|
_decl: NamedParamsQuantumFunctionDeclaration
|
138
144
|
|
139
145
|
def __init__(self, py_callable: Callable) -> None:
|
146
|
+
self._py_callable = py_callable
|
140
147
|
decl = infer_func_decl(py_callable)
|
141
148
|
|
142
149
|
py_callable.__annotations__.pop("return", None)
|
@@ -153,6 +160,12 @@ class ExternalQFunc(QTerminalCallable):
|
|
153
160
|
def func_decl(self) -> NamedParamsQuantumFunctionDeclaration:
|
154
161
|
return self._decl
|
155
162
|
|
163
|
+
def get_implementation(self) -> NativeFunctionDefinition:
|
164
|
+
model = QFunc(self._py_callable).create_model()
|
165
|
+
return [
|
166
|
+
func for func in model.functions if func.name == self._py_callable.__name__
|
167
|
+
][0]
|
168
|
+
|
156
169
|
|
157
170
|
class GenerativeQFunc(QExpandable):
|
158
171
|
def __init__(
|
@@ -183,7 +196,7 @@ class IllegalParamsError(ClassiqError):
|
|
183
196
|
super().__init__(message + self._HINT)
|
184
197
|
|
185
198
|
|
186
|
-
def _validate_no_gen_params(annotations:
|
199
|
+
def _validate_no_gen_params(annotations: dict[str, Any]) -> None:
|
187
200
|
_illegal_params = {
|
188
201
|
name: annotation
|
189
202
|
for name, annotation in annotations.items()
|
@@ -1,5 +1,6 @@
|
|
1
|
+
from collections.abc import Iterator
|
1
2
|
from contextlib import contextmanager
|
2
|
-
from typing import
|
3
|
+
from typing import Optional
|
3
4
|
|
4
5
|
from classiq.interface.ast_node import ASTNode
|
5
6
|
from classiq.interface.exceptions import CLASSIQ_SLACK_COMMUNITY_LINK
|
@@ -16,9 +17,9 @@ class ErrorManager:
|
|
16
17
|
if hasattr(self, "_instantiated"):
|
17
18
|
return
|
18
19
|
self._instantiated = True
|
19
|
-
self._errors:
|
20
|
-
self._current_nodes_stack:
|
21
|
-
self._call_stack:
|
20
|
+
self._errors: list[SourceReferencedError] = []
|
21
|
+
self._current_nodes_stack: list[ASTNode] = []
|
22
|
+
self._call_stack: list[str] = []
|
22
23
|
self._ignore_errors: bool = False
|
23
24
|
|
24
25
|
@contextmanager
|
@@ -31,7 +32,7 @@ class ErrorManager:
|
|
31
32
|
self._ignore_errors = previous
|
32
33
|
|
33
34
|
@property
|
34
|
-
def annotated_errors(self) ->
|
35
|
+
def annotated_errors(self) -> list[str]:
|
35
36
|
return [str(error) for error in self._errors]
|
36
37
|
|
37
38
|
def add_error(self, error: str) -> None:
|
@@ -48,7 +49,7 @@ class ErrorManager:
|
|
48
49
|
)
|
49
50
|
)
|
50
51
|
|
51
|
-
def get_errors(self) ->
|
52
|
+
def get_errors(self) -> list[SourceReferencedError]:
|
52
53
|
return self._errors
|
53
54
|
|
54
55
|
def clear(self) -> None:
|
@@ -58,7 +59,7 @@ class ErrorManager:
|
|
58
59
|
def has_errors(self) -> bool:
|
59
60
|
return len(self._errors) > 0
|
60
61
|
|
61
|
-
def report_errors(self, error_type:
|
62
|
+
def report_errors(self, error_type: type[Exception]) -> None:
|
62
63
|
if self.has_errors():
|
63
64
|
errors = self.annotated_errors
|
64
65
|
self.clear()
|
@@ -1,15 +1,8 @@
|
|
1
|
+
from collections.abc import Iterator, Mapping, Sequence
|
1
2
|
from contextlib import contextmanager
|
2
3
|
from typing import (
|
3
4
|
Any,
|
4
|
-
Dict,
|
5
|
-
Iterator,
|
6
|
-
List,
|
7
|
-
Mapping,
|
8
5
|
Optional,
|
9
|
-
Sequence,
|
10
|
-
Set,
|
11
|
-
Tuple,
|
12
|
-
Type,
|
13
6
|
)
|
14
7
|
|
15
8
|
from classiq.interface.exceptions import ClassiqSemanticError
|
@@ -59,6 +52,7 @@ from classiq.qmod.semantics.validation.func_call_validation import (
|
|
59
52
|
validate_call_arguments,
|
60
53
|
)
|
61
54
|
from classiq.qmod.semantics.validation.handle_validation import resolve_handle
|
55
|
+
from classiq.qmod.semantics.validation.main_validation import validate_main_function
|
62
56
|
from classiq.qmod.semantics.validation.types_validation import (
|
63
57
|
check_cstruct_has_fields,
|
64
58
|
check_duplicate_types,
|
@@ -79,10 +73,10 @@ class StaticScope:
|
|
79
73
|
|
80
74
|
def __init__(
|
81
75
|
self,
|
82
|
-
parameters:
|
83
|
-
operands:
|
84
|
-
variables_to_states:
|
85
|
-
variables_to_types:
|
76
|
+
parameters: list[str],
|
77
|
+
operands: dict[str, QuantumOperandDeclaration],
|
78
|
+
variables_to_states: dict[str, HandleState],
|
79
|
+
variables_to_types: dict[str, ConcreteQuantumType],
|
86
80
|
) -> None:
|
87
81
|
self.parameters = parameters
|
88
82
|
self.operands = operands
|
@@ -94,9 +88,9 @@ class StaticSemanticsVisitor(Visitor):
|
|
94
88
|
def __init__(
|
95
89
|
self,
|
96
90
|
functions_dict: Mapping[str, QuantumFunctionDeclaration],
|
97
|
-
constants:
|
91
|
+
constants: list[str],
|
98
92
|
) -> None:
|
99
|
-
self._scope:
|
93
|
+
self._scope: list[StaticScope] = []
|
100
94
|
self._error_manager = ErrorManager()
|
101
95
|
self._functions_dict = functions_dict
|
102
96
|
self._constants = constants
|
@@ -122,6 +116,7 @@ class StaticSemanticsVisitor(Visitor):
|
|
122
116
|
check_qstruct_flexibility(qstruct)
|
123
117
|
for cstruct in model.types:
|
124
118
|
check_cstruct_has_fields(cstruct)
|
119
|
+
validate_main_function(model.main_func)
|
125
120
|
self.visit_BaseModel(model)
|
126
121
|
|
127
122
|
def visit_NativeFunctionDefinition(
|
@@ -141,7 +136,7 @@ class StaticSemanticsVisitor(Visitor):
|
|
141
136
|
parameter_declaration_names = [
|
142
137
|
decl.name for decl in func_def.positional_arg_declarations
|
143
138
|
]
|
144
|
-
seen_names:
|
139
|
+
seen_names: set[str] = set()
|
145
140
|
for name in parameter_declaration_names:
|
146
141
|
if name in seen_names:
|
147
142
|
self._error_manager.add_error(
|
@@ -254,12 +249,12 @@ class StaticSemanticsVisitor(Visitor):
|
|
254
249
|
|
255
250
|
def _get_renamed_parameters(
|
256
251
|
self, lambda_func: QuantumLambdaFunction
|
257
|
-
) ->
|
258
|
-
renamed_parameters:
|
259
|
-
renamed_operands:
|
260
|
-
renamed_ports:
|
252
|
+
) -> tuple[list[str], dict[str, QuantumOperandDeclaration], list[PortDeclaration]]:
|
253
|
+
renamed_parameters: list[str] = []
|
254
|
+
renamed_operands: dict[str, QuantumOperandDeclaration] = {}
|
255
|
+
renamed_ports: list[PortDeclaration] = []
|
261
256
|
for idx, param in enumerate(lambda_func.func_decl.positional_arg_declarations):
|
262
|
-
param_name = lambda_func.
|
257
|
+
param_name = lambda_func.pos_rename_params[idx]
|
263
258
|
if isinstance(param, AnonClassicalParameterDeclaration):
|
264
259
|
renamed_parameters.append(param_name)
|
265
260
|
elif isinstance(param, AnonQuantumOperandDeclaration):
|
@@ -375,7 +370,7 @@ def resolve_function_calls(
|
|
375
370
|
|
376
371
|
|
377
372
|
def static_semantics_analysis_pass(
|
378
|
-
model: Model, error_type: Optional[
|
373
|
+
model: Model, error_type: Optional[type[Exception]] = ClassiqSemanticError
|
379
374
|
) -> None:
|
380
375
|
StaticSemanticsVisitor(
|
381
376
|
{**BUILTIN_FUNCTION_DECLARATIONS, **model.function_dict},
|
@@ -385,7 +380,7 @@ def static_semantics_analysis_pass(
|
|
385
380
|
ErrorManager().report_errors(error_type)
|
386
381
|
|
387
382
|
|
388
|
-
EXPECTED_TERMINAL_STATES:
|
383
|
+
EXPECTED_TERMINAL_STATES: dict[PortDeclarationDirection, HandleState] = {
|
389
384
|
PortDeclarationDirection.Output: HandleState.INITIALIZED,
|
390
385
|
PortDeclarationDirection.Inout: HandleState.INITIALIZED,
|
391
386
|
}
|
@@ -393,8 +388,8 @@ EXPECTED_TERMINAL_STATES: Dict[PortDeclarationDirection, HandleState] = {
|
|
393
388
|
|
394
389
|
def initialize_variables_to_state(
|
395
390
|
port_declarations: Sequence[PortDeclaration],
|
396
|
-
) ->
|
397
|
-
variables_to_state:
|
391
|
+
) -> dict[str, HandleState]:
|
392
|
+
variables_to_state: dict[str, HandleState] = dict()
|
398
393
|
|
399
394
|
for port_decl in port_declarations:
|
400
395
|
variables_to_state[port_decl.name] = (
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Mapping
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqError
|
4
4
|
from classiq.interface.generator.expressions.expression import Expression
|
@@ -83,7 +83,7 @@ def _check_operand_against_declaration(
|
|
83
83
|
|
84
84
|
|
85
85
|
def check_no_overlapping_quantum_args(
|
86
|
-
args:
|
86
|
+
args: list[HandleBinding], func_name: str
|
87
87
|
) -> None:
|
88
88
|
for idx, arg in enumerate(args):
|
89
89
|
for other_arg in args[idx + 1 :]:
|
@@ -0,0 +1,33 @@
|
|
1
|
+
from classiq.interface.generator.functions.classical_type import (
|
2
|
+
ClassicalArray,
|
3
|
+
ClassicalList,
|
4
|
+
)
|
5
|
+
from classiq.interface.generator.functions.concrete_types import ConcreteClassicalType
|
6
|
+
from classiq.interface.model.native_function_definition import NativeFunctionDefinition
|
7
|
+
from classiq.interface.model.quantum_function_declaration import PositionalArg
|
8
|
+
|
9
|
+
from classiq import ClassicalParameterDeclaration
|
10
|
+
from classiq.qmod.semantics.error_manager import append_error
|
11
|
+
|
12
|
+
|
13
|
+
def validate_main_function(func: NativeFunctionDefinition) -> None:
|
14
|
+
for param in func.positional_arg_declarations:
|
15
|
+
_validate_main_param(param)
|
16
|
+
|
17
|
+
|
18
|
+
def _validate_main_param(param: PositionalArg) -> None:
|
19
|
+
if isinstance(param, ClassicalParameterDeclaration):
|
20
|
+
_validate_main_classical_param_type(param.classical_type, param.name)
|
21
|
+
|
22
|
+
|
23
|
+
def _validate_main_classical_param_type(
|
24
|
+
param: ConcreteClassicalType, param_name: str
|
25
|
+
) -> None:
|
26
|
+
if isinstance(param, ClassicalList):
|
27
|
+
append_error(
|
28
|
+
param,
|
29
|
+
f"Classical array parameter {param_name!r} of function 'main' must must "
|
30
|
+
f"specify array length",
|
31
|
+
)
|
32
|
+
if isinstance(param, ClassicalArray):
|
33
|
+
_validate_main_classical_param_type(param.element_type, param_name)
|
classiq/qmod/symbolic.py
CHANGED
@@ -2,10 +2,7 @@ import sys
|
|
2
2
|
from typing import (
|
3
3
|
TYPE_CHECKING,
|
4
4
|
Any,
|
5
|
-
List,
|
6
5
|
Optional,
|
7
|
-
Tuple,
|
8
|
-
Type,
|
9
6
|
TypeVar,
|
10
7
|
Union,
|
11
8
|
overload,
|
@@ -41,10 +38,10 @@ def symbolic_function(*args: Any, return_type: None = None) -> CParamScalar: ...
|
|
41
38
|
|
42
39
|
|
43
40
|
@overload
|
44
|
-
def symbolic_function(*args: Any, return_type:
|
41
|
+
def symbolic_function(*args: Any, return_type: type[T]) -> T: ...
|
45
42
|
|
46
43
|
|
47
|
-
def symbolic_function(*args: Any, return_type: Optional[
|
44
|
+
def symbolic_function(*args: Any, return_type: Optional[type[T]] = None) -> CParam:
|
48
45
|
qmodule = (
|
49
46
|
model_state_container.QMODULE
|
50
47
|
) # FIXME: https://classiq.atlassian.net/browse/CAD-15126
|
@@ -266,7 +263,7 @@ def catalan(x: SymbolicTypes) -> CParamScalar:
|
|
266
263
|
return symbolic_function(x)
|
267
264
|
|
268
265
|
|
269
|
-
def Piecewise(*args:
|
266
|
+
def Piecewise(*args: tuple[SymbolicTypes, SymbolicTypes]) -> CParamScalar: # noqa: N802
|
270
267
|
return symbolic_function(*args)
|
271
268
|
|
272
269
|
|
@@ -299,7 +296,7 @@ def sum(arr: SymbolicTypes) -> CParamScalar:
|
|
299
296
|
|
300
297
|
|
301
298
|
def subscript(
|
302
|
-
amplitudes: Union[
|
299
|
+
amplitudes: Union[list[float], list[CReal], list[CParamScalar], CArray[CReal]],
|
303
300
|
index: QNum,
|
304
301
|
) -> CParamScalar:
|
305
302
|
return CParamScalar(expr=f"{amplitudes}[{index}]")
|
@@ -373,5 +370,5 @@ __all__ = [
|
|
373
370
|
]
|
374
371
|
|
375
372
|
|
376
|
-
def __dir__() ->
|
373
|
+
def __dir__() -> list[str]:
|
377
374
|
return __all__
|
classiq/qmod/symbolic_type.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Union
|
2
2
|
|
3
3
|
from classiq.qmod.symbolic_expr import SymbolicExpr
|
4
4
|
|
5
|
-
SymbolicTypes = Union[SymbolicExpr, int, float, bool,
|
5
|
+
SymbolicTypes = Union[SymbolicExpr, int, float, bool, tuple["SymbolicTypes", ...]]
|
@@ -1,14 +1,13 @@
|
|
1
1
|
from typing import Union
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqError
|
4
|
-
from classiq.interface.model.native_function_definition import FunctionSynthesisData
|
5
4
|
|
6
5
|
from classiq.qmod.quantum_function import ExternalQFunc, GenerativeQFunc, QFunc
|
7
6
|
|
8
7
|
|
9
8
|
def synthesize_separately(qfunc: Union[QFunc, GenerativeQFunc, ExternalQFunc]) -> QFunc:
|
10
9
|
if isinstance(qfunc, QFunc):
|
11
|
-
qfunc.
|
10
|
+
qfunc.should_synthesize_separately = True
|
12
11
|
return qfunc
|
13
12
|
if isinstance(qfunc, GenerativeQFunc):
|
14
13
|
raise ClassiqError("Generative functions can not be synthesized separately")
|