classiq 0.53.0__py3-none-any.whl → 0.54.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/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 +34 -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 +7 -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/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 +20 -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/handle_binding.py +3 -2
- classiq/interface/model/inplace_binary_operation.py +2 -1
- classiq/interface/model/model.py +12 -11
- 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 +3 -2
- 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 +4 -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/call_to_model_converter.py +190 -0
- 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 +17 -9
- 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 +19 -12
- classiq/model_expansions/generative_functions.py +3 -2
- classiq/model_expansions/interpreter.py +31 -19
- 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 +2 -4
- classiq/model_expansions/quantum_operations/emitter.py +10 -13
- classiq/model_expansions/quantum_operations/expression_operation.py +23 -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 +25 -5
- classiq/model_expansions/quantum_operations/quantum_function_call.py +41 -2
- classiq/model_expansions/quantum_operations/repeat.py +1 -3
- classiq/model_expansions/scope.py +11 -10
- classiq/model_expansions/scope_initialization.py +6 -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 +4 -5
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +3 -7
- classiq/qmod/create_model_function.py +7 -6
- 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 +5 -7
- classiq/qmod/native/__init__.py +1 -3
- classiq/qmod/native/expression_to_qmod.py +9 -8
- classiq/qmod/native/pretty_printer.py +6 -5
- 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 +13 -12
- 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 +10 -3
- 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-0.53.0.dist-info → classiq-0.54.0.dist-info}/METADATA +1 -1
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/RECORD +295 -292
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/WHEEL +0 -0
@@ -1,8 +1,8 @@
|
|
1
|
-
from typing import TYPE_CHECKING,
|
1
|
+
from typing import TYPE_CHECKING, Annotated, Any
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import StringConstraints
|
5
|
-
from typing_extensions import
|
5
|
+
from typing_extensions import Self
|
6
6
|
|
7
7
|
from classiq.interface.exceptions import ClassiqValueError
|
8
8
|
from classiq.interface.generator import function_params
|
@@ -51,19 +51,19 @@ class LinearPauliRotations(function_params.FunctionParams):
|
|
51
51
|
num_state_qubits: pydantic.PositiveInt = pydantic.Field(
|
52
52
|
description="The number of input qubits"
|
53
53
|
)
|
54
|
-
bases:
|
54
|
+
bases: list[PydanticPauliBasisStr] = pydantic.Field(
|
55
55
|
description="The types of Pauli rotations ('X', 'Y', 'Z')."
|
56
56
|
)
|
57
|
-
slopes:
|
57
|
+
slopes: list[float] = pydantic.Field(
|
58
58
|
description="The slopes of the controlled rotations."
|
59
59
|
)
|
60
|
-
offsets:
|
60
|
+
offsets: list[float] = pydantic.Field(
|
61
61
|
description="The offsets of the controlled rotations."
|
62
62
|
)
|
63
63
|
|
64
64
|
@pydantic.field_validator("bases", "slopes", "offsets", mode="before")
|
65
65
|
@classmethod
|
66
|
-
def as_list(cls, v: Any) ->
|
66
|
+
def as_list(cls, v: Any) -> list[Any]:
|
67
67
|
if not isinstance(v, list):
|
68
68
|
v = [v]
|
69
69
|
res = []
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Optional, cast
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
@@ -53,7 +53,7 @@ class Mcu(FunctionParams):
|
|
53
53
|
|
54
54
|
@pydantic.model_validator(mode="before")
|
55
55
|
@classmethod
|
56
|
-
def _validate_control(cls, values: Any) ->
|
56
|
+
def _validate_control(cls, values: Any) -> dict[str, Any]:
|
57
57
|
num_ctrl_qubits = values.get("num_ctrl_qubits")
|
58
58
|
ctrl_state = values.get("ctrl_state")
|
59
59
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic_core.core_schema import ValidationInfo
|
@@ -17,7 +17,7 @@ class Mcx(FunctionParams):
|
|
17
17
|
multi-controlled x-gate
|
18
18
|
"""
|
19
19
|
|
20
|
-
arguments:
|
20
|
+
arguments: list[RegisterUserInput] = pydantic.Field(
|
21
21
|
default_factory=list, description="registers describing the state (ordered)"
|
22
22
|
)
|
23
23
|
num_ctrl_qubits: Optional[pydantic.PositiveInt] = pydantic.Field(
|
@@ -31,9 +31,9 @@ class Mcx(FunctionParams):
|
|
31
31
|
@pydantic.field_validator("arguments")
|
32
32
|
@classmethod
|
33
33
|
def _validate_argument_names(
|
34
|
-
cls, arguments:
|
35
|
-
) ->
|
36
|
-
register_name_list:
|
34
|
+
cls, arguments: list[RegisterUserInput]
|
35
|
+
) -> list[RegisterUserInput]:
|
36
|
+
register_name_list: list[Optional[str]] = [arg.name for arg in arguments]
|
37
37
|
if None in register_name_list:
|
38
38
|
raise ClassiqValueError("All registers must be named")
|
39
39
|
if len(set(register_name_list)) != len(register_name_list):
|
@@ -42,7 +42,7 @@ class Mcx(FunctionParams):
|
|
42
42
|
|
43
43
|
@pydantic.model_validator(mode="before")
|
44
44
|
@classmethod
|
45
|
-
def _validate_sizes(cls, values:
|
45
|
+
def _validate_sizes(cls, values: dict[str, Any]) -> dict[str, Any]:
|
46
46
|
arguments_size = sum(arg.size for arg in values.get("arguments", list()))
|
47
47
|
num_ctrl_qubits = values.get("num_ctrl_qubits")
|
48
48
|
if not num_ctrl_qubits:
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
1
|
from classiq.interface.generator.model.constraints import (
|
4
2
|
Constraints,
|
5
3
|
OptimizationParameter,
|
@@ -10,7 +8,7 @@ from classiq.interface.generator.model.preferences import (
|
|
10
8
|
Preferences,
|
11
9
|
)
|
12
10
|
|
13
|
-
__all__:
|
11
|
+
__all__: list[str] = [
|
14
12
|
"Constraints",
|
15
13
|
"Preferences",
|
16
14
|
"CustomHardwareSettings",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from collections import defaultdict
|
2
|
-
from typing import
|
2
|
+
from typing import Optional, Union
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import BaseModel, ConfigDict
|
@@ -59,7 +59,7 @@ class Constraints(BaseModel):
|
|
59
59
|
)
|
60
60
|
max_depth: Optional[pydantic.PositiveInt] = None
|
61
61
|
|
62
|
-
max_gate_count:
|
62
|
+
max_gate_count: dict[TranspilerBasisGates, pydantic.NonNegativeInt] = (
|
63
63
|
pydantic.Field(default_factory=lambda: defaultdict(int))
|
64
64
|
)
|
65
65
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
from abc import ABC
|
2
|
-
from typing import List
|
3
2
|
|
4
3
|
import pydantic
|
5
4
|
|
@@ -24,22 +23,22 @@ class ClassiqBaseModel(VersionedModel, ABC):
|
|
24
23
|
All the relevant data for evaluating execution in one place.
|
25
24
|
"""
|
26
25
|
|
27
|
-
enums:
|
26
|
+
enums: list[EnumDeclaration] = pydantic.Field(
|
28
27
|
default_factory=list,
|
29
28
|
description="user-defined enums",
|
30
29
|
)
|
31
30
|
|
32
|
-
types:
|
31
|
+
types: list[StructDeclaration] = pydantic.Field(
|
33
32
|
default_factory=list,
|
34
33
|
description="user-defined structs",
|
35
34
|
)
|
36
35
|
|
37
|
-
qstructs:
|
36
|
+
qstructs: list[QStructDeclaration] = pydantic.Field(
|
38
37
|
default_factory=list,
|
39
38
|
description="user-defined quantum structs",
|
40
39
|
)
|
41
40
|
|
42
|
-
constants:
|
41
|
+
constants: list[Constant] = pydantic.Field(
|
43
42
|
default_factory=list,
|
44
43
|
)
|
45
44
|
|
@@ -53,7 +52,7 @@ class ClassiqBaseModel(VersionedModel, ABC):
|
|
53
52
|
|
54
53
|
@pydantic.field_validator("types")
|
55
54
|
@classmethod
|
56
|
-
def types_validator(cls, types:
|
55
|
+
def types_validator(cls, types: list[StructDeclaration]) -> list[StructDeclaration]:
|
57
56
|
if not is_list_unique([struct_type.name for struct_type in types]):
|
58
57
|
raise ClassiqValueError(TYPE_LIBRARY_DUPLICATED_TYPE_NAMES)
|
59
58
|
|
@@ -1,9 +1,10 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from typing import TYPE_CHECKING, Annotated, Any, Optional, Union
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
from pydantic import Field
|
5
6
|
from pydantic_core.core_schema import ValidationInfo
|
6
|
-
from typing_extensions import
|
7
|
+
from typing_extensions import Self, TypeAlias
|
7
8
|
|
8
9
|
from classiq.interface.backend.backend_preferences import (
|
9
10
|
BackendPreferences,
|
@@ -47,7 +48,7 @@ class QuantumFormat(StrEnum):
|
|
47
48
|
QASM_CIRQ_COMPATIBLE = "qasm_cirq_compatible"
|
48
49
|
|
49
50
|
|
50
|
-
_SERVICE_PROVIDER_TO_FORMAT:
|
51
|
+
_SERVICE_PROVIDER_TO_FORMAT: dict[Provider, QuantumFormat] = {
|
51
52
|
Provider.CLASSIQ: QuantumFormat.QASM,
|
52
53
|
Provider.IONQ: QuantumFormat.IONQ,
|
53
54
|
Provider.AZURE_QUANTUM: QuantumFormat.QSHARP,
|
@@ -56,10 +57,10 @@ _SERVICE_PROVIDER_TO_FORMAT: Dict[Provider, QuantumFormat] = {
|
|
56
57
|
}
|
57
58
|
|
58
59
|
if TYPE_CHECKING:
|
59
|
-
PydanticConstrainedQuantumFormatList =
|
60
|
+
PydanticConstrainedQuantumFormatList = list[QuantumFormat]
|
60
61
|
else:
|
61
62
|
PydanticConstrainedQuantumFormatList = Annotated[
|
62
|
-
|
63
|
+
list[QuantumFormat], Field(min_length=1, max_length=len(QuantumFormat))
|
63
64
|
]
|
64
65
|
|
65
66
|
|
@@ -215,7 +216,7 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
|
|
215
216
|
|
216
217
|
@pydantic.field_validator("output_format", mode="before")
|
217
218
|
@classmethod
|
218
|
-
def make_output_format_list(cls, output_format: Any) ->
|
219
|
+
def make_output_format_list(cls, output_format: Any) -> list:
|
219
220
|
if not isinstance(output_format, Sequence) or isinstance(output_format, str):
|
220
221
|
output_format = [output_format]
|
221
222
|
|
@@ -1,12 +1,10 @@
|
|
1
1
|
import itertools
|
2
2
|
import sys
|
3
|
+
from collections.abc import Iterator
|
4
|
+
from types import GenericAlias as TypesGenericAlias
|
3
5
|
from typing import ( # type: ignore[attr-defined]
|
4
6
|
Any,
|
5
|
-
Dict,
|
6
|
-
Iterator,
|
7
|
-
List,
|
8
7
|
Optional,
|
9
|
-
Type,
|
10
8
|
Union,
|
11
9
|
_GenericAlias,
|
12
10
|
)
|
@@ -19,9 +17,6 @@ from classiq.interface.generator.arith.register_user_input import (
|
|
19
17
|
from classiq.interface.generator.function_params import ArithmeticIODict, IOName
|
20
18
|
from classiq.interface.generator.register_role import RegisterRole
|
21
19
|
|
22
|
-
if sys.version_info >= (3, 9):
|
23
|
-
from types import GenericAlias as TypesGenericAlias
|
24
|
-
|
25
20
|
|
26
21
|
# This class is used for QReg, to support type-hint initialization
|
27
22
|
# Due to the `size` property of QReg
|
@@ -90,7 +85,7 @@ class QReg:
|
|
90
85
|
return super.__hash__(self)
|
91
86
|
|
92
87
|
@classmethod
|
93
|
-
def _from_qubits(cls, qubits:
|
88
|
+
def _from_qubits(cls, qubits: list[Qubit]) -> "QReg":
|
94
89
|
if (
|
95
90
|
not isinstance(qubits, list)
|
96
91
|
or not all(isinstance(qubit, Qubit) for qubit in qubits)
|
@@ -141,7 +136,7 @@ class QReg:
|
|
141
136
|
return len(self._qubits)
|
142
137
|
|
143
138
|
@property
|
144
|
-
def qubits(self) ->
|
139
|
+
def qubits(self) -> list[Qubit]:
|
145
140
|
return self._qubits
|
146
141
|
|
147
142
|
def __class_getitem__(cls, params: Any) -> QRegGenericAlias:
|
@@ -231,7 +226,7 @@ _PROP_TO_QREG_TYPE = {
|
|
231
226
|
}
|
232
227
|
|
233
228
|
|
234
|
-
def _get_qreg_type_from_arithmetic_info(info: RegisterArithmeticInfo) ->
|
229
|
+
def _get_qreg_type_from_arithmetic_info(info: RegisterArithmeticInfo) -> type["QReg"]:
|
235
230
|
return _PROP_TO_QREG_TYPE[(info.is_signed, info.is_frac)]
|
236
231
|
|
237
232
|
|
@@ -247,7 +242,7 @@ def _get_qreg_generic_alias_from_arithmetic_info(
|
|
247
242
|
|
248
243
|
def get_type_and_size_dict(
|
249
244
|
arithmetic_info_dict: ArithmeticIODict,
|
250
|
-
) ->
|
245
|
+
) -> dict[IOName, QRegGenericAlias]:
|
251
246
|
return {
|
252
247
|
io_name: _get_qreg_generic_alias_from_arithmetic_info(info)
|
253
248
|
for io_name, info in arithmetic_info_dict.items()
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import ast
|
2
2
|
import re
|
3
|
-
from typing import Dict
|
4
3
|
|
5
4
|
import numexpr # type: ignore[import]
|
6
5
|
|
@@ -61,7 +60,7 @@ class ArithmeticOracle(OracleABC[float], ArithmeticExpressionABC):
|
|
61
60
|
|
62
61
|
@staticmethod
|
63
62
|
def _simplify_negations_of_boolean_variables(
|
64
|
-
expression: str, input_definitions:
|
63
|
+
expression: str, input_definitions: dict[str, RegisterArithmeticInfo]
|
65
64
|
) -> str:
|
66
65
|
for var_name in input_definitions:
|
67
66
|
if getattr(input_definitions[var_name], "size", 0) == 1:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any
|
1
|
+
from typing import Any
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
@@ -24,7 +24,7 @@ class CustomOracle(OracleABC[QubitState]):
|
|
24
24
|
|
25
25
|
@pydantic.model_validator(mode="before")
|
26
26
|
@classmethod
|
27
|
-
def _parse_oracle(cls, values: Any) ->
|
27
|
+
def _parse_oracle(cls, values: Any) -> dict[str, Any]:
|
28
28
|
if isinstance(values, dict):
|
29
29
|
parse_function_params_values(
|
30
30
|
values=values,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import abc
|
2
|
-
from
|
2
|
+
from collections.abc import Sequence
|
3
|
+
from typing import Generic, Optional, TypeVar
|
3
4
|
|
4
5
|
import numpy as np
|
5
6
|
|
@@ -11,8 +12,8 @@ from classiq.interface.generator.generated_circuit_data import IOQubitMapping
|
|
11
12
|
|
12
13
|
ProblemResultType = TypeVar("ProblemResultType")
|
13
14
|
|
14
|
-
VariableBinResultMap =
|
15
|
-
VariableTypedResultMap =
|
15
|
+
VariableBinResultMap = dict[str, State]
|
16
|
+
VariableTypedResultMap = dict[str, ProblemResultType]
|
16
17
|
|
17
18
|
|
18
19
|
class OracleABC(abc.ABC, FunctionParams, Generic[ProblemResultType]):
|
@@ -58,7 +59,7 @@ class OracleABC(abc.ABC, FunctionParams, Generic[ProblemResultType]):
|
|
58
59
|
) -> bool:
|
59
60
|
pass
|
60
61
|
|
61
|
-
def variables(self) ->
|
62
|
+
def variables(self) -> list[RegisterUserInput]:
|
62
63
|
return [
|
63
64
|
RegisterUserInput.from_arithmetic_info(info=info, name=name)
|
64
65
|
for name, info in self._inputs.items()
|
@@ -71,5 +72,5 @@ class OracleABC(abc.ABC, FunctionParams, Generic[ProblemResultType]):
|
|
71
72
|
)
|
72
73
|
|
73
74
|
|
74
|
-
def _reverse_endianness(indices: Sequence[int], state_length: int) ->
|
75
|
+
def _reverse_endianness(indices: Sequence[int], state_length: int) -> list[int]:
|
75
76
|
return [state_length - 1 - index for index in indices]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import itertools
|
2
|
+
from collections.abc import Iterator
|
2
3
|
from dataclasses import dataclass
|
3
|
-
from typing import
|
4
|
+
from typing import Optional
|
4
5
|
|
5
6
|
from classiq.interface.exceptions import ClassiqValueError
|
6
7
|
from classiq.interface.generator.slice_parsing_utils import parse_io_slicing
|
@@ -12,7 +13,7 @@ class PartitionedRegister:
|
|
12
13
|
|
13
14
|
# There are up to num_qubits qubits within the partitions, with unique values from 0 to num_qubits-1
|
14
15
|
num_qubits: int
|
15
|
-
partitions:
|
16
|
+
partitions: tuple[tuple[int, ...], ...]
|
16
17
|
|
17
18
|
def __post_init__(self) -> None:
|
18
19
|
if not self.partitions:
|
@@ -47,7 +48,7 @@ class PartitionedRegister:
|
|
47
48
|
return RegisterPartition(self, _index=None)
|
48
49
|
|
49
50
|
@property
|
50
|
-
def _leftover_qubits(self) ->
|
51
|
+
def _leftover_qubits(self) -> tuple[int, ...]:
|
51
52
|
total_qubits = set(itertools.chain.from_iterable(self.partitions))
|
52
53
|
return tuple(
|
53
54
|
qubit for qubit in range(self.num_qubits) if qubit not in total_qubits
|
@@ -59,7 +60,7 @@ class PartitionedRegister:
|
|
59
60
|
|
60
61
|
def all_register_partitions(
|
61
62
|
self, include_leftover_partition: bool = False
|
62
|
-
) ->
|
63
|
+
) -> list["RegisterPartition"]:
|
63
64
|
all_partitions = [self.get_partition(i) for i in range(len(self.partitions))]
|
64
65
|
if include_leftover_partition:
|
65
66
|
all_partitions.append(self.leftover_partition)
|
@@ -82,7 +83,7 @@ class RegisterPartition:
|
|
82
83
|
raise ClassiqValueError(message)
|
83
84
|
|
84
85
|
@property
|
85
|
-
def qubits(self) ->
|
86
|
+
def qubits(self) -> tuple[int, ...]:
|
86
87
|
if self._index is None:
|
87
88
|
return self.partitioned_register._leftover_qubits
|
88
89
|
return self.partitioned_register.partitions[self._index]
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import math
|
2
|
-
from
|
2
|
+
from collections.abc import Sequence
|
3
|
+
from typing import Any, Generic, TypeVar
|
3
4
|
|
4
5
|
import pydantic
|
5
6
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
@@ -26,7 +27,7 @@ class AffineMap(HashablePydanticBaseModel):
|
|
26
27
|
def evaluate(self, x: float) -> float:
|
27
28
|
return self.offset + self.slope * x
|
28
29
|
|
29
|
-
def image_bounds(self, domain_bounds:
|
30
|
+
def image_bounds(self, domain_bounds: tuple[float, float]) -> tuple[float, float]:
|
30
31
|
return self.evaluate(domain_bounds[0]), self.evaluate(domain_bounds[1])
|
31
32
|
|
32
33
|
model_config = ConfigDict(frozen=True)
|
@@ -50,8 +51,8 @@ class PiecewiseLinearAmplitudeLoadingABC(
|
|
50
51
|
def _max_index(self) -> int:
|
51
52
|
return 2**self.num_qubits - 1
|
52
53
|
|
53
|
-
def _get_image_bounds(self) ->
|
54
|
-
piece_bounds: Sequence[
|
54
|
+
def _get_image_bounds(self) -> tuple[float, float]:
|
55
|
+
piece_bounds: Sequence[tuple[float, float]] = [
|
55
56
|
affine_map.image_bounds((self.breakpoints[idx], self.breakpoints[idx + 1]))
|
56
57
|
for idx, affine_map in enumerate(self.affine_maps)
|
57
58
|
]
|
@@ -74,7 +75,7 @@ class PiecewiseLinearAmplitudeLoadingABC(
|
|
74
75
|
|
75
76
|
@pydantic.model_validator(mode="before")
|
76
77
|
@classmethod
|
77
|
-
def _validate_lengths(cls, values: Any) ->
|
78
|
+
def _validate_lengths(cls, values: Any) -> dict[str, Any]:
|
78
79
|
breakpoints = values.get("breakpoints", list())
|
79
80
|
affine_maps = values.get("affine_maps", list())
|
80
81
|
num_qubits = values.get("num_qubits", int)
|
@@ -126,11 +127,11 @@ class PiecewiseLinearAmplitudeLoading(PiecewiseLinearAmplitudeLoadingABC[float])
|
|
126
127
|
|
127
128
|
a, b = self.breakpoints[0], self.breakpoints[-1]
|
128
129
|
|
129
|
-
normalized_breakpoints:
|
130
|
+
normalized_breakpoints: list[int] = [
|
130
131
|
round(self._max_index * (point - a) / (b - a)) for point in self.breakpoints
|
131
132
|
]
|
132
133
|
|
133
|
-
normalized_affine_maps:
|
134
|
+
normalized_affine_maps: list[AffineMap] = list()
|
134
135
|
for affine_map in self.affine_maps:
|
135
136
|
normalized_slope = (
|
136
137
|
2 * affine_map.slope * self.rescaling_factor * (b - a)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import ConfigDict
|
@@ -52,7 +52,7 @@ class ExponentiationSpecification(pydantic.BaseModel):
|
|
52
52
|
default=None,
|
53
53
|
description="The scaling of the exponentiation functions.",
|
54
54
|
)
|
55
|
-
max_depths: Optional[
|
55
|
+
max_depths: Optional[tuple[pydantic.NonNegativeInt, ...]] = pydantic.Field(
|
56
56
|
default=None,
|
57
57
|
description="The max_depth of each exponentiation function; overrides scaling.",
|
58
58
|
)
|
@@ -103,7 +103,7 @@ class PhaseEstimation(FunctionParams):
|
|
103
103
|
|
104
104
|
@pydantic.model_validator(mode="before")
|
105
105
|
@classmethod
|
106
|
-
def _validate_composite_name(cls, values: Any) ->
|
106
|
+
def _validate_composite_name(cls, values: Any) -> dict[str, Any]:
|
107
107
|
if not isinstance(values, dict):
|
108
108
|
return values
|
109
109
|
unitary_params = values.get("unitary_params")
|
@@ -119,7 +119,7 @@ class PhaseEstimation(FunctionParams):
|
|
119
119
|
@classmethod
|
120
120
|
def _parse_function_params(
|
121
121
|
cls, values: Any, info: ValidationInfo
|
122
|
-
) ->
|
122
|
+
) -> dict[str, Any]:
|
123
123
|
vals = info.data.copy() if info.data else {}
|
124
124
|
if isinstance(values, dict):
|
125
125
|
vals = values
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Literal, Optional, Union
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import pydantic
|
@@ -37,13 +37,13 @@ class QSVMFeatureMapPauli(QSVMFeatureMapDimensional):
|
|
37
37
|
reps: int = 2
|
38
38
|
entanglement: QSVMFeatureMapEntanglement = QSVMFeatureMapEntanglement.LINEAR
|
39
39
|
alpha: float = 2.0
|
40
|
-
paulis:
|
40
|
+
paulis: list[str] = ["Z", "ZZ"]
|
41
41
|
parameter_prefix: str = "x"
|
42
42
|
name: str = "PauliFeatureMap"
|
43
43
|
|
44
44
|
@pydantic.field_validator("paulis", mode="before")
|
45
45
|
@classmethod
|
46
|
-
def set_paulis(cls, paulis:
|
46
|
+
def set_paulis(cls, paulis: list[str]) -> list[str]:
|
47
47
|
# iterate every letter in every string in the list of paulis
|
48
48
|
for s in paulis:
|
49
49
|
if not all(map(VALID_PAULI_LETTERS.__contains__, s.upper())):
|
@@ -6,16 +6,11 @@ import random
|
|
6
6
|
import re
|
7
7
|
import string
|
8
8
|
from collections import defaultdict
|
9
|
+
from collections.abc import Iterable, Mapping, Sequence
|
10
|
+
from re import Match
|
9
11
|
from typing import (
|
10
12
|
Any,
|
11
|
-
Dict,
|
12
|
-
Iterable,
|
13
|
-
List,
|
14
|
-
Mapping,
|
15
|
-
Match,
|
16
13
|
Optional,
|
17
|
-
Sequence,
|
18
|
-
Tuple,
|
19
14
|
Union,
|
20
15
|
)
|
21
16
|
from uuid import UUID, uuid4
|
@@ -64,7 +59,7 @@ LEGAL_SLICING = rf"(\-?\d+)?({SEPARATOR}(\-?\d+)?)?({SEPARATOR}(\-?\d+)?)?"
|
|
64
59
|
|
65
60
|
_ALPHANUM_CHARACTERS = string.ascii_letters + string.digits
|
66
61
|
|
67
|
-
RegNameAndSlice =
|
62
|
+
RegNameAndSlice = tuple[str, slice]
|
68
63
|
|
69
64
|
ZERO_INDICATOR = "0"
|
70
65
|
INVERSE_SUFFIX = "_qinverse"
|
@@ -86,7 +81,7 @@ SUFFIX_RANDOMIZER = random.Random() # noqa: S311
|
|
86
81
|
|
87
82
|
def split_wire_pair_to_wires(
|
88
83
|
inout: WirePair,
|
89
|
-
) ->
|
84
|
+
) -> tuple[WireName, WireName]:
|
90
85
|
return inout.in_wire, inout.out_wire
|
91
86
|
|
92
87
|
|
@@ -98,7 +93,7 @@ def randomize_suffix(suffix_len: int = DEFAULT_SUFFIX_LEN) -> str:
|
|
98
93
|
|
99
94
|
def get_non_zero_wires(
|
100
95
|
wires: Iterable[WireName],
|
101
|
-
) ->
|
96
|
+
) -> list[WireName]:
|
102
97
|
return [wire for wire in wires if wire != ZERO_INDICATOR]
|
103
98
|
|
104
99
|
|
@@ -122,7 +117,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
122
117
|
release_by_inverse: bool = pydantic.Field(
|
123
118
|
default=False, description="Release zero inputs in inverse call."
|
124
119
|
)
|
125
|
-
control_states:
|
120
|
+
control_states: list[ControlState] = pydantic.Field(
|
126
121
|
default_factory=list,
|
127
122
|
description="Call the controlled function with the given controlled states.",
|
128
123
|
)
|
@@ -166,14 +161,14 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
166
161
|
return hash(self.name)
|
167
162
|
|
168
163
|
@property
|
169
|
-
def non_zero_input_wires(self) ->
|
164
|
+
def non_zero_input_wires(self) -> list[WireName]:
|
170
165
|
in_out_input_wires = [
|
171
166
|
split_wire_pair_to_wires(inout)[0] for inout in self.inouts.values()
|
172
167
|
]
|
173
168
|
return get_non_zero_wires(self.inputs_dict.values()) + in_out_input_wires
|
174
169
|
|
175
170
|
@property
|
176
|
-
def non_zero_output_wires(self) ->
|
171
|
+
def non_zero_output_wires(self) -> list[WireName]:
|
177
172
|
in_out_output_wires = [
|
178
173
|
split_wire_pair_to_wires(inout)[1] for inout in self.inouts.values()
|
179
174
|
]
|
@@ -246,7 +241,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
246
241
|
|
247
242
|
@pydantic.model_validator(mode="before")
|
248
243
|
@classmethod
|
249
|
-
def validate_composite_name(cls, values: Any) ->
|
244
|
+
def validate_composite_name(cls, values: Any) -> dict[str, Any]:
|
250
245
|
if (
|
251
246
|
isinstance(values, dict)
|
252
247
|
and isinstance(values.get("unitary_params"), CustomFunction)
|
@@ -259,7 +254,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
259
254
|
|
260
255
|
@pydantic.model_validator(mode="before")
|
261
256
|
@classmethod
|
262
|
-
def _parse_function_params(cls, values: Any) ->
|
257
|
+
def _parse_function_params(cls, values: Any) -> dict[str, Any]:
|
263
258
|
if isinstance(values, dict):
|
264
259
|
f_params.parse_function_params_values(
|
265
260
|
values=values,
|
@@ -279,7 +274,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
279
274
|
params: f_params.FunctionParams,
|
280
275
|
inputs: WireDict,
|
281
276
|
is_inverse: bool,
|
282
|
-
control_states:
|
277
|
+
control_states: list[ControlState],
|
283
278
|
strict_zero_ios: bool,
|
284
279
|
) -> None:
|
285
280
|
(
|
@@ -317,8 +312,8 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
317
312
|
@pydantic.field_validator("control_states")
|
318
313
|
@classmethod
|
319
314
|
def _validate_control_states(
|
320
|
-
cls, control_states:
|
321
|
-
) ->
|
315
|
+
cls, control_states: list[ControlState], info: ValidationInfo
|
316
|
+
) -> list[ControlState]:
|
322
317
|
control_names = [ctrl_state.name for ctrl_state in control_states]
|
323
318
|
function_params = info.data.get("function_params")
|
324
319
|
strict_zero_ios = info.data.get("strict_zero_ios")
|
@@ -349,10 +344,10 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
349
344
|
inputs: IOType,
|
350
345
|
fp: FunctionParams,
|
351
346
|
strict_zero_ios: bool,
|
352
|
-
control_states:
|
347
|
+
control_states: list[ControlState],
|
353
348
|
) -> None:
|
354
349
|
name_slice_pairs = [parse_io_slicing(input) for input in inputs]
|
355
|
-
slices_dict:
|
350
|
+
slices_dict: dict[str, list[slice]] = defaultdict(list)
|
356
351
|
for name, slice in name_slice_pairs:
|
357
352
|
slices_dict[name].append(slice)
|
358
353
|
|
@@ -374,7 +369,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
374
369
|
raise ClassiqValueError(BAD_INPUT_SLICING_MSG)
|
375
370
|
|
376
371
|
@staticmethod
|
377
|
-
def _register_validate_slices(slices:
|
372
|
+
def _register_validate_slices(slices: list[slice], reg_width: int) -> bool:
|
378
373
|
widths_separated = [len(range(reg_width)[reg_slice]) for reg_slice in slices]
|
379
374
|
# examples: slice(0), slice(5,None) when width <= 5, slice(5,3)
|
380
375
|
empty_slices = 0 in widths_separated
|
@@ -399,7 +394,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
399
394
|
params: Optional[FunctionParams] = info.data.get("function_params")
|
400
395
|
is_inverse: bool = info.data.get("is_inverse", False)
|
401
396
|
strict_zero_ios: bool = info.data.get("strict_zero_ios", True)
|
402
|
-
control_states:
|
397
|
+
control_states: list[ControlState] = info.data.get("control_states", list())
|
403
398
|
if params is None:
|
404
399
|
return dict()
|
405
400
|
if isinstance(params, CustomFunction):
|
@@ -440,7 +435,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
440
435
|
params: f_params.FunctionParams,
|
441
436
|
outputs: WireDict,
|
442
437
|
is_inverse: bool,
|
443
|
-
control_states:
|
438
|
+
control_states: list[ControlState],
|
444
439
|
strict_zero_ios: bool,
|
445
440
|
) -> None:
|
446
441
|
(
|
@@ -549,15 +544,15 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
549
544
|
expressions: Iterable[str],
|
550
545
|
params: f_params.FunctionParams,
|
551
546
|
io: f_params.PortDirection,
|
552
|
-
control_states:
|
547
|
+
control_states: list[ControlState],
|
553
548
|
strict_zero_ios: bool,
|
554
|
-
) ->
|
549
|
+
) -> tuple[list[str], list[str], list[str]]:
|
555
550
|
expression_matches: Iterable[Optional[Match]] = map(
|
556
551
|
functools.partial(re.fullmatch, IO_REGEX), expressions
|
557
552
|
)
|
558
553
|
|
559
|
-
valid_matches:
|
560
|
-
invalid_expressions:
|
554
|
+
valid_matches: list[Match] = []
|
555
|
+
invalid_expressions: list[str] = []
|
561
556
|
for expression, expression_match in zip(expressions, expression_matches):
|
562
557
|
(
|
563
558
|
invalid_expressions.append(expression)
|
@@ -565,8 +560,8 @@ class SynthesisQuantumFunctionCall(BaseModel):
|
|
565
560
|
else valid_matches.append(expression_match)
|
566
561
|
)
|
567
562
|
|
568
|
-
invalid_slicings:
|
569
|
-
invalid_names:
|
563
|
+
invalid_slicings: list[str] = []
|
564
|
+
invalid_names: list[str] = []
|
570
565
|
valid_names = frozenset(
|
571
566
|
params.inputs_full(strict_zero_ios)
|
572
567
|
if io == PortDirection.Input
|