classiq 0.52.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 +23 -17
- 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 +11 -13
- 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 +25 -6
- 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 +3 -3
- classiq/execution/all_hardware_devices.py +1 -3
- classiq/execution/execution_session.py +57 -16
- classiq/execution/iqcc.py +1 -1
- classiq/execution/jobs.py +4 -4
- classiq/execution/qaoa.py +84 -0
- classiq/execution/qnn.py +3 -3
- classiq/executor.py +4 -4
- 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 +11 -7
- classiq/interface/execution/iqcc.py +1 -3
- 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 +35 -28
- 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/dotdict.py +18 -0
- 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 +33 -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/native_function_definition.py +10 -0
- 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 +164 -38
- 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/__init__.py +2 -0
- classiq/qmod/builtins/classical_execution_primitives.py +9 -9
- classiq/qmod/builtins/functions/__init__.py +75 -53
- 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 +18 -18
- 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 +53 -0
- 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 +19 -8
- 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_parameter.py +3 -1
- classiq/qmod/qmod_variable.py +11 -10
- classiq/qmod/quantum_expandable.py +32 -15
- classiq/qmod/quantum_function.py +34 -5
- 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 +16 -0
- {classiq-0.52.0.dist-info → classiq-0.54.0.dist-info}/METADATA +1 -1
- {classiq-0.52.0.dist-info → classiq-0.54.0.dist-info}/RECORD +302 -295
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.52.0.dist-info → classiq-0.54.0.dist-info}/WHEEL +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Union
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic_core.core_schema import ValidationInfo
|
@@ -17,7 +17,7 @@ GroverStatePreparation = Union[StatePreparation, CustomFunction]
|
|
17
17
|
|
18
18
|
|
19
19
|
class GroverDiffuser(FunctionParams):
|
20
|
-
variables:
|
20
|
+
variables: list[RegisterUserInput]
|
21
21
|
state_preparation: str = pydantic.Field(
|
22
22
|
default="", description="State preparation function"
|
23
23
|
)
|
@@ -32,7 +32,7 @@ class GroverDiffuser(FunctionParams):
|
|
32
32
|
|
33
33
|
@pydantic.model_validator(mode="before")
|
34
34
|
@classmethod
|
35
|
-
def _validate_state_preparation_name(cls, values: Any) ->
|
35
|
+
def _validate_state_preparation_name(cls, values: Any) -> dict[str, Any]:
|
36
36
|
if (
|
37
37
|
isinstance(values, dict)
|
38
38
|
and isinstance(values.get("state_preparation_params"), CustomFunction)
|
@@ -45,7 +45,7 @@ class GroverDiffuser(FunctionParams):
|
|
45
45
|
|
46
46
|
@pydantic.model_validator(mode="before")
|
47
47
|
@classmethod
|
48
|
-
def _parse_state_preparation(cls, values: Any) ->
|
48
|
+
def _parse_state_preparation(cls, values: Any) -> dict[str, Any]:
|
49
49
|
if isinstance(values, dict):
|
50
50
|
parse_function_params_values(
|
51
51
|
values=values,
|
@@ -59,8 +59,8 @@ class GroverDiffuser(FunctionParams):
|
|
59
59
|
@pydantic.field_validator("variables")
|
60
60
|
@classmethod
|
61
61
|
def _validate_variables(
|
62
|
-
cls, variables:
|
63
|
-
) ->
|
62
|
+
cls, variables: list[RegisterUserInput]
|
63
|
+
) -> list[RegisterUserInput]:
|
64
64
|
names = {reg.name for reg in variables}
|
65
65
|
assert len(variables) == len(names), "Repeating names not allowed"
|
66
66
|
return variables
|
@@ -89,5 +89,5 @@ class GroverDiffuser(FunctionParams):
|
|
89
89
|
return state_preparation_params
|
90
90
|
|
91
91
|
@staticmethod
|
92
|
-
def _names_and_sizes(transputs: ArithmeticIODict) ->
|
92
|
+
def _names_and_sizes(transputs: ArithmeticIODict) -> set[tuple[str, int]]:
|
93
93
|
return {(name, reg.size) for name, reg in transputs.items()}
|
@@ -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
|
@@ -49,7 +49,7 @@ class GroverOperator(FunctionParams):
|
|
49
49
|
|
50
50
|
@pydantic.model_validator(mode="before")
|
51
51
|
@classmethod
|
52
|
-
def _parse_oracle(cls, values: Any) ->
|
52
|
+
def _parse_oracle(cls, values: Any) -> dict[str, Any]:
|
53
53
|
if isinstance(values, dict):
|
54
54
|
oracle_params = values.get("oracle_params")
|
55
55
|
if isinstance(oracle_params, dict):
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import itertools
|
2
2
|
from collections import defaultdict
|
3
|
-
from
|
3
|
+
from collections.abc import MutableSet
|
4
|
+
from typing import Any, Optional
|
4
5
|
|
5
6
|
import pydantic
|
6
7
|
from typing_extensions import Self
|
@@ -16,7 +17,7 @@ from classiq.interface.generator.transpiler_basis_gates import (
|
|
16
17
|
)
|
17
18
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonNegIntTuple
|
18
19
|
|
19
|
-
ConnectivityMap =
|
20
|
+
ConnectivityMap = list[PydanticNonNegIntTuple]
|
20
21
|
BACKEND_VALIDATION_ERROR_MESSAGE = (
|
21
22
|
"Backend service provider and backend name should be specified together."
|
22
23
|
)
|
@@ -41,7 +42,7 @@ class HardwareData(pydantic.BaseModel):
|
|
41
42
|
that both qubits in each pair can act as control and target. Defaults to True.
|
42
43
|
"""
|
43
44
|
|
44
|
-
basis_gates:
|
45
|
+
basis_gates: list[str] = pydantic.Field(
|
45
46
|
default=list(),
|
46
47
|
description="The basis gates of the hardware. "
|
47
48
|
"This set will be used during the model optimization. "
|
@@ -129,7 +130,7 @@ class CustomHardwareSettings(HardwareData):
|
|
129
130
|
|
130
131
|
@pydantic.field_validator("basis_gates", mode="after")
|
131
132
|
@classmethod
|
132
|
-
def validate_basis_gates(cls, basis_gates:
|
133
|
+
def validate_basis_gates(cls, basis_gates: list[str]) -> list[TranspilerBasisGates]:
|
133
134
|
valid_gates = list(TranspilerBasisGates)
|
134
135
|
invalid_gates = [gate for gate in basis_gates if gate not in valid_gates]
|
135
136
|
if invalid_gates:
|
@@ -154,7 +155,7 @@ class CustomHardwareSettings(HardwareData):
|
|
154
155
|
|
155
156
|
def _is_connected_map(connectivity_map: ConnectivityMap) -> bool:
|
156
157
|
nodes: MutableSet[int] = set()
|
157
|
-
node_to_neighbors:
|
158
|
+
node_to_neighbors: dict[int, MutableSet[int]] = defaultdict(set)
|
158
159
|
for edge in connectivity_map:
|
159
160
|
nodes.add(edge[0])
|
160
161
|
nodes.add(edge[1])
|
@@ -167,7 +168,7 @@ def _is_connected_map(connectivity_map: ConnectivityMap) -> bool:
|
|
167
168
|
|
168
169
|
|
169
170
|
def _node_dfs(
|
170
|
-
node: int, node_to_neighbors:
|
171
|
+
node: int, node_to_neighbors: dict[int, MutableSet[int]], visited: MutableSet[int]
|
171
172
|
) -> None:
|
172
173
|
visited.add(node)
|
173
174
|
neighbors = node_to_neighbors[node]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import itertools
|
2
|
-
from typing import TYPE_CHECKING,
|
2
|
+
from typing import TYPE_CHECKING, Optional, Union
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic_core.core_schema import ValidationInfo
|
@@ -18,7 +18,7 @@ from classiq.interface.generator.transpiler_basis_gates import (
|
|
18
18
|
)
|
19
19
|
from classiq.interface.helpers.custom_pydantic_types import PydanticNonNegIntTuple
|
20
20
|
|
21
|
-
ConnectivityMap =
|
21
|
+
ConnectivityMap = list[PydanticNonNegIntTuple]
|
22
22
|
|
23
23
|
|
24
24
|
class SupportedConnectivityMaps(StrEnum):
|
@@ -51,11 +51,11 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
51
51
|
default=1, description="Number of layers in the Ansatz"
|
52
52
|
)
|
53
53
|
|
54
|
-
one_qubit_gates: Union[str,
|
54
|
+
one_qubit_gates: Union[str, list[str]] = pydantic.Field(
|
55
55
|
default=["x", "ry"],
|
56
56
|
description='List of gates for the one qubit gates layer, e.g. ["x", "ry"]',
|
57
57
|
)
|
58
|
-
two_qubit_gates: Union[str,
|
58
|
+
two_qubit_gates: Union[str, list[str]] = pydantic.Field(
|
59
59
|
default=["cx"],
|
60
60
|
description='List of gates for the two qubit gates entangling layer, e.g. ["cx", "cry"]',
|
61
61
|
)
|
@@ -107,8 +107,8 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
107
107
|
@pydantic.field_validator("one_qubit_gates")
|
108
108
|
@classmethod
|
109
109
|
def validate_one_qubit_gates(
|
110
|
-
cls, one_qubit_gates: Union[str,
|
111
|
-
) -> Union[str,
|
110
|
+
cls, one_qubit_gates: Union[str, list[str]]
|
111
|
+
) -> Union[str, list[str]]:
|
112
112
|
one_qubit_gates_list = (
|
113
113
|
[one_qubit_gates] if isinstance(one_qubit_gates, str) else one_qubit_gates
|
114
114
|
)
|
@@ -120,8 +120,8 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
120
120
|
@pydantic.field_validator("two_qubit_gates")
|
121
121
|
@classmethod
|
122
122
|
def validate_two_qubit_gates(
|
123
|
-
cls, two_qubit_gates: Union[str,
|
124
|
-
) -> Union[str,
|
123
|
+
cls, two_qubit_gates: Union[str, list[str]]
|
124
|
+
) -> Union[str, list[str]]:
|
125
125
|
two_qubit_gates_list = (
|
126
126
|
[two_qubit_gates] if isinstance(two_qubit_gates, str) else two_qubit_gates
|
127
127
|
)
|
@@ -1,17 +1,16 @@
|
|
1
|
-
from typing import TYPE_CHECKING,
|
1
|
+
from typing import TYPE_CHECKING, Annotated
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import Field
|
5
|
-
from typing_extensions import Annotated
|
6
5
|
|
7
6
|
from classiq.interface.generator.arith.register_user_input import RegisterUserInput
|
8
7
|
from classiq.interface.generator.function_params import FunctionParams
|
9
8
|
|
10
9
|
if TYPE_CHECKING:
|
11
|
-
NonEmptyRegisterUserInputList =
|
10
|
+
NonEmptyRegisterUserInputList = list[RegisterUserInput]
|
12
11
|
else:
|
13
12
|
NonEmptyRegisterUserInputList = Annotated[
|
14
|
-
|
13
|
+
list[RegisterUserInput], Field(min_length=1)
|
15
14
|
]
|
16
15
|
|
17
16
|
|
@@ -23,8 +22,8 @@ class Identity(FunctionParams):
|
|
23
22
|
@pydantic.field_validator("arguments")
|
24
23
|
@classmethod
|
25
24
|
def _validate_argument_names(
|
26
|
-
cls, arguments:
|
27
|
-
) ->
|
25
|
+
cls, arguments: list[RegisterUserInput]
|
26
|
+
) -> list[RegisterUserInput]:
|
28
27
|
return [
|
29
28
|
arg if arg.name else arg.revalued(name=cls._get_default_arg_name(index))
|
30
29
|
for index, arg in enumerate(arguments)
|
@@ -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
|