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
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import
|
3
|
+
from typing import Union
|
4
4
|
|
5
5
|
import pydantic
|
6
6
|
|
@@ -90,7 +90,7 @@ class FinancePayoff(function_params.FunctionParams):
|
|
90
90
|
description="The finance function to solve the model"
|
91
91
|
)
|
92
92
|
num_qubits: pydantic.PositiveInt
|
93
|
-
distribution_range:
|
93
|
+
distribution_range: tuple[float, float]
|
94
94
|
|
95
95
|
def _create_ios(self) -> None:
|
96
96
|
self._inputs = {
|
@@ -1,19 +1,19 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Iterable
|
2
2
|
|
3
3
|
from classiq.interface.generator.function_params import FunctionParams
|
4
4
|
|
5
5
|
|
6
6
|
class FunctionParamLibrary:
|
7
|
-
def __init__(self, param_list: Iterable[
|
8
|
-
self._param_list:
|
7
|
+
def __init__(self, param_list: Iterable[type[FunctionParams]]) -> None:
|
8
|
+
self._param_list: set[type[FunctionParams]] = set(param_list)
|
9
9
|
|
10
10
|
@property
|
11
|
-
def param_list(self) ->
|
11
|
+
def param_list(self) -> set[type[FunctionParams]]:
|
12
12
|
return self._param_list.copy()
|
13
13
|
|
14
14
|
# Private methods are for tests only
|
15
|
-
def _add(self, param:
|
15
|
+
def _add(self, param: type[FunctionParams]) -> None:
|
16
16
|
self._param_list.add(param)
|
17
17
|
|
18
|
-
def _remove(self, param:
|
18
|
+
def _remove(self, param: type[FunctionParams]) -> None:
|
19
19
|
self._param_list.discard(param)
|
@@ -1,16 +1,11 @@
|
|
1
1
|
import ast
|
2
2
|
import itertools
|
3
3
|
import re
|
4
|
+
from collections.abc import Collection, Iterable, Mapping
|
4
5
|
from typing import (
|
6
|
+
Annotated,
|
5
7
|
Any,
|
6
|
-
Collection,
|
7
|
-
Dict,
|
8
|
-
Iterable,
|
9
|
-
List,
|
10
|
-
Mapping,
|
11
8
|
Optional,
|
12
|
-
Set,
|
13
|
-
Type,
|
14
9
|
Union,
|
15
10
|
get_args,
|
16
11
|
)
|
@@ -18,7 +13,6 @@ from typing import (
|
|
18
13
|
import pydantic
|
19
14
|
import sympy
|
20
15
|
from pydantic import BeforeValidator, ConfigDict
|
21
|
-
from typing_extensions import Annotated
|
22
16
|
|
23
17
|
from classiq.interface.enum_utils import StrEnum
|
24
18
|
from classiq.interface.exceptions import ClassiqValueError
|
@@ -35,7 +29,7 @@ from classiq.interface.helpers.hashable_pydantic_base_model import (
|
|
35
29
|
FunctionParamsDiscriminator = str
|
36
30
|
|
37
31
|
IOName = PydanticNonEmptyString
|
38
|
-
ArithmeticIODict =
|
32
|
+
ArithmeticIODict = dict[IOName, RegisterArithmeticInfo]
|
39
33
|
|
40
34
|
DEFAULT_ZERO_NAME = "zero"
|
41
35
|
DEFAULT_OUTPUT_NAME = "OUT"
|
@@ -114,7 +108,7 @@ GenerationExpressionSupportedNodeTypes = Union[
|
|
114
108
|
|
115
109
|
|
116
110
|
def validate_expression_str(
|
117
|
-
expr_str: str, supported_functions: Optional[
|
111
|
+
expr_str: str, supported_functions: Optional[set[str]] = None
|
118
112
|
) -> None:
|
119
113
|
# By default, no functions are allowed.
|
120
114
|
supported_functions = supported_functions or set()
|
@@ -189,11 +183,11 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
189
183
|
return sum(reg.size for reg in self.outputs.values())
|
190
184
|
|
191
185
|
@property
|
192
|
-
def _input_names(self) ->
|
186
|
+
def _input_names(self) -> list[IOName]:
|
193
187
|
return list(self._inputs.keys())
|
194
188
|
|
195
189
|
@property
|
196
|
-
def _output_names(self) ->
|
190
|
+
def _output_names(self) -> list[IOName]:
|
197
191
|
return list(self._outputs.keys())
|
198
192
|
|
199
193
|
def _create_zero_input_registers(self, names_and_sizes: Mapping[str, int]) -> None:
|
@@ -238,7 +232,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
238
232
|
return sum(reg.size if reg is not None else 0 for reg in registers)
|
239
233
|
|
240
234
|
def _validate_io_names(self) -> None:
|
241
|
-
error_msg:
|
235
|
+
error_msg: list[str] = []
|
242
236
|
error_msg += self._get_error_msg(self._inputs, BAD_INPUT_REGISTER_ERROR_MSG)
|
243
237
|
error_msg += self._get_error_msg(self._outputs, BAD_OUTPUT_REGISTER_ERROR_MSG)
|
244
238
|
if error_msg:
|
@@ -257,7 +251,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
257
251
|
if total_inputs_size != total_outputs_size:
|
258
252
|
raise ClassiqValueError(REGISTER_SIZES_MISMATCH_ERROR_MSG)
|
259
253
|
|
260
|
-
def _get_error_msg(self, names: Iterable[IOName], msg: str) ->
|
254
|
+
def _get_error_msg(self, names: Iterable[IOName], msg: str) -> list[str]:
|
261
255
|
bad_names = [name for name in names if re.fullmatch(NAME_REGEX, name) is None]
|
262
256
|
return [f"{msg}: {bad_names}"] if bad_names else []
|
263
257
|
|
@@ -272,10 +266,10 @@ def parse_function_params(
|
|
272
266
|
*,
|
273
267
|
params: Any,
|
274
268
|
discriminator: Optional[Any],
|
275
|
-
param_classes: Collection[
|
269
|
+
param_classes: Collection[type[FunctionParams]],
|
276
270
|
no_discriminator_error: Exception,
|
277
271
|
bad_function_error: Exception,
|
278
|
-
default_parser_class: Optional[
|
272
|
+
default_parser_class: Optional[type[FunctionParams]] = None,
|
279
273
|
) -> FunctionParams: # Any is for use in pydantic validators.
|
280
274
|
if not discriminator:
|
281
275
|
raise no_discriminator_error
|
@@ -299,11 +293,11 @@ def parse_function_params(
|
|
299
293
|
|
300
294
|
def parse_function_params_values(
|
301
295
|
*,
|
302
|
-
values:
|
296
|
+
values: dict[str, Any],
|
303
297
|
params_key: str,
|
304
298
|
discriminator_key: str,
|
305
|
-
param_classes: Collection[
|
306
|
-
default_parser_class:
|
299
|
+
param_classes: Collection[type[FunctionParams]],
|
300
|
+
default_parser_class: type[FunctionParams],
|
307
301
|
) -> None:
|
308
302
|
params = values.get(params_key, dict())
|
309
303
|
if isinstance(params, FunctionParams):
|
@@ -3,6 +3,14 @@ CONTROL_OPERATOR_NAME = "control"
|
|
3
3
|
INVERT_OPERATOR_NAME = "invert"
|
4
4
|
REPEAT_OPERATOR_NAME = "iteration"
|
5
5
|
POWER_OPERATOR_NAME = "power"
|
6
|
-
COMPUTE_OPERATOR_NAME = "compute"
|
7
6
|
UNCOMPUTE_OPERATOR_NAME = "uncompute"
|
8
7
|
WITHIN_APPLY_NAME = "within_apply"
|
8
|
+
|
9
|
+
All_BUILTINS_OPERATORS = {
|
10
|
+
CONTROL_OPERATOR_NAME,
|
11
|
+
INVERT_OPERATOR_NAME,
|
12
|
+
REPEAT_OPERATOR_NAME,
|
13
|
+
POWER_OPERATOR_NAME,
|
14
|
+
UNCOMPUTE_OPERATOR_NAME,
|
15
|
+
WITHIN_APPLY_NAME,
|
16
|
+
}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from typing import ClassVar, Optional
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
|
@@ -28,11 +29,11 @@ class ClassicalFunctionDeclaration(FunctionDeclaration):
|
|
28
29
|
)
|
29
30
|
|
30
31
|
BUILTIN_FUNCTION_DECLARATIONS: ClassVar[
|
31
|
-
|
32
|
+
dict[str, "ClassicalFunctionDeclaration"]
|
32
33
|
] = {}
|
33
34
|
|
34
35
|
FOREIGN_FUNCTION_DECLARATIONS: ClassVar[
|
35
|
-
|
36
|
+
dict[str, "ClassicalFunctionDeclaration"]
|
36
37
|
] = {}
|
37
38
|
|
38
39
|
@property
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import TYPE_CHECKING, Any,
|
1
|
+
from typing import TYPE_CHECKING, Any, Literal, Union
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import ConfigDict
|
@@ -19,7 +19,7 @@ NamedSymbol = Union[IndexedBase, Symbol]
|
|
19
19
|
|
20
20
|
|
21
21
|
class ClassicalType(HashableASTNode):
|
22
|
-
def as_symbolic(self, name: str) -> Union[NamedSymbol,
|
22
|
+
def as_symbolic(self, name: str) -> Union[NamedSymbol, list[NamedSymbol]]:
|
23
23
|
return Symbol(name)
|
24
24
|
|
25
25
|
model_config = ConfigDict(extra="forbid")
|
@@ -36,7 +36,7 @@ class Integer(ClassicalType):
|
|
36
36
|
|
37
37
|
@pydantic.model_validator(mode="before")
|
38
38
|
@classmethod
|
39
|
-
def _set_kind(cls, values: Any) ->
|
39
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
40
40
|
return values_with_discriminator(values, "kind", "int")
|
41
41
|
|
42
42
|
|
@@ -48,7 +48,7 @@ class Real(ClassicalType):
|
|
48
48
|
|
49
49
|
@pydantic.model_validator(mode="before")
|
50
50
|
@classmethod
|
51
|
-
def _set_kind(cls, values: Any) ->
|
51
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
52
52
|
return values_with_discriminator(values, "kind", "real")
|
53
53
|
|
54
54
|
|
@@ -57,7 +57,7 @@ class Bool(ClassicalType):
|
|
57
57
|
|
58
58
|
@pydantic.model_validator(mode="before")
|
59
59
|
@classmethod
|
60
|
-
def _set_kind(cls, values: Any) ->
|
60
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
61
61
|
return values_with_discriminator(values, "kind", "bool")
|
62
62
|
|
63
63
|
|
@@ -70,7 +70,7 @@ class ClassicalList(ClassicalType):
|
|
70
70
|
|
71
71
|
@pydantic.model_validator(mode="before")
|
72
72
|
@classmethod
|
73
|
-
def _set_kind(cls, values: Any) ->
|
73
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
74
74
|
return values_with_discriminator(values, "kind", "list")
|
75
75
|
|
76
76
|
|
@@ -79,7 +79,7 @@ class StructMetaType(ClassicalType):
|
|
79
79
|
|
80
80
|
@pydantic.model_validator(mode="before")
|
81
81
|
@classmethod
|
82
|
-
def _set_kind(cls, values: Any) ->
|
82
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
83
83
|
return values_with_discriminator(values, "kind", "type_proxy")
|
84
84
|
|
85
85
|
|
@@ -93,7 +93,7 @@ class ClassicalArray(ClassicalType):
|
|
93
93
|
|
94
94
|
@pydantic.model_validator(mode="before")
|
95
95
|
@classmethod
|
96
|
-
def _set_kind(cls, values: Any) ->
|
96
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
97
97
|
return values_with_discriminator(values, "kind", "array")
|
98
98
|
|
99
99
|
|
@@ -106,7 +106,7 @@ class VQEResult(OpaqueHandle):
|
|
106
106
|
|
107
107
|
@pydantic.model_validator(mode="before")
|
108
108
|
@classmethod
|
109
|
-
def _set_kind(cls, values: Any) ->
|
109
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
110
110
|
return values_with_discriminator(values, "kind", "vqe_result")
|
111
111
|
|
112
112
|
|
@@ -115,7 +115,7 @@ class Histogram(OpaqueHandle):
|
|
115
115
|
|
116
116
|
@pydantic.model_validator(mode="before")
|
117
117
|
@classmethod
|
118
|
-
def _set_kind(cls, values: Any) ->
|
118
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
119
119
|
return values_with_discriminator(values, "kind", "histogram")
|
120
120
|
|
121
121
|
|
@@ -124,7 +124,7 @@ class Estimation(OpaqueHandle):
|
|
124
124
|
|
125
125
|
@pydantic.model_validator(mode="before")
|
126
126
|
@classmethod
|
127
|
-
def _set_kind(cls, values: Any) ->
|
127
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
128
128
|
return values_with_discriminator(values, "kind", "estimation_result")
|
129
129
|
|
130
130
|
|
@@ -133,11 +133,11 @@ class IQAERes(OpaqueHandle):
|
|
133
133
|
|
134
134
|
@pydantic.model_validator(mode="before")
|
135
135
|
@classmethod
|
136
|
-
def _set_kind(cls, values: Any) ->
|
136
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
137
137
|
return values_with_discriminator(values, "kind", "iqae_result")
|
138
138
|
|
139
139
|
|
140
|
-
def as_symbolic(symbols:
|
140
|
+
def as_symbolic(symbols: dict[str, ClassicalType]) -> dict[str, RuntimeExpression]:
|
141
141
|
return {
|
142
142
|
param_name: param_type.as_symbolic(param_name)
|
143
143
|
for param_name, param_type in symbols.items()
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from typing import TYPE_CHECKING, Any, Literal, Optional
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
|
@@ -25,7 +26,7 @@ class TypeName(ClassicalType, QuantumType):
|
|
25
26
|
|
26
27
|
@pydantic.model_validator(mode="before")
|
27
28
|
@classmethod
|
28
|
-
def _set_kind(cls, values: Any) ->
|
29
|
+
def _set_kind(cls, values: Any) -> dict[str, Any]:
|
29
30
|
return values_with_discriminator(values, "kind", "struct_instance")
|
30
31
|
|
31
32
|
def _update_size_in_bits_from_declaration(self) -> None:
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import logging
|
2
|
-
from typing import Any,
|
2
|
+
from typing import Any, Literal, Optional, Union
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import ConfigDict
|
6
6
|
from typing_extensions import TypeAlias
|
7
7
|
|
8
|
+
from classiq.interface.enum_utils import StrEnum
|
8
9
|
from classiq.interface.generator.control_state import ControlState
|
9
10
|
from classiq.interface.generator.register_role import RegisterRole
|
10
11
|
from classiq.interface.generator.synthesis_metadata.synthesis_execution_data import (
|
11
12
|
ExecutionData,
|
12
13
|
)
|
13
|
-
from classiq.interface.ide.visual_model import OperationLevel, OperationParameter
|
14
14
|
|
15
15
|
_logger = logging.getLogger(__name__)
|
16
16
|
ParameterName = str
|
17
|
-
IOQubitMapping: TypeAlias =
|
17
|
+
IOQubitMapping: TypeAlias = dict[str, tuple[int, ...]]
|
18
18
|
|
19
19
|
CLASSIQ_HIERARCHY_SEPARATOR: Literal["."] = "."
|
20
20
|
|
@@ -42,8 +42,8 @@ class QubitMapping(pydantic.BaseModel):
|
|
42
42
|
class GeneratedRegister(pydantic.BaseModel):
|
43
43
|
name: str
|
44
44
|
role: RegisterRole
|
45
|
-
qubit_indexes_relative:
|
46
|
-
qubit_indexes_absolute:
|
45
|
+
qubit_indexes_relative: list[int]
|
46
|
+
qubit_indexes_absolute: list[int]
|
47
47
|
|
48
48
|
def __len__(self) -> int:
|
49
49
|
return self.qubit_indexes_relative.__len__()
|
@@ -55,13 +55,12 @@ class GeneratedRegister(pydantic.BaseModel):
|
|
55
55
|
|
56
56
|
class GeneratedFunction(pydantic.BaseModel):
|
57
57
|
name: str
|
58
|
-
control_states:
|
59
|
-
registers:
|
58
|
+
control_states: list[ControlState]
|
59
|
+
registers: list[GeneratedRegister] = list()
|
60
60
|
depth: Optional[int] = pydantic.Field(default=None)
|
61
61
|
width: Optional[int] = pydantic.Field(default=None)
|
62
|
-
|
63
|
-
|
64
|
-
dangling_outputs: Dict[str, GeneratedRegister] = dict()
|
62
|
+
dangling_inputs: dict[str, GeneratedRegister] = dict()
|
63
|
+
dangling_outputs: dict[str, GeneratedRegister] = dict()
|
65
64
|
|
66
65
|
def __getitem__(self, key: Union[int, str]) -> GeneratedRegister:
|
67
66
|
if isinstance(key, int):
|
@@ -88,7 +87,7 @@ class GeneratedFunction(pydantic.BaseModel):
|
|
88
87
|
|
89
88
|
class GeneratedCircuitData(pydantic.BaseModel):
|
90
89
|
width: int
|
91
|
-
circuit_parameters:
|
90
|
+
circuit_parameters: list[ParameterName] = pydantic.Field(default_factory=list)
|
92
91
|
qubit_mapping: QubitMapping = pydantic.Field(default_factory=QubitMapping)
|
93
92
|
execution_data: Optional[ExecutionData] = pydantic.Field(default=None)
|
94
93
|
|
@@ -97,17 +96,29 @@ class GeneratedCircuitData(pydantic.BaseModel):
|
|
97
96
|
return cls(width=0)
|
98
97
|
|
99
98
|
|
99
|
+
class OperationLevel(StrEnum):
|
100
|
+
QMOD_FUNCTION_CALL = "QMOD_CALL"
|
101
|
+
QMOD_STATEMENT = "QMOD_STATEMENT"
|
102
|
+
ENGINE_FUNCTION_CALL = "ENGINE_CALL"
|
103
|
+
UNKNOWN = "UNKNOWN"
|
104
|
+
|
105
|
+
|
106
|
+
class OperationParameter(pydantic.BaseModel):
|
107
|
+
label: str
|
108
|
+
value: Optional[str] = None
|
109
|
+
|
110
|
+
|
100
111
|
class FunctionDebugInfoInterface(pydantic.BaseModel):
|
101
112
|
generated_function: Optional[GeneratedFunction] = pydantic.Field(default=None)
|
102
|
-
children:
|
103
|
-
relative_qubits:
|
104
|
-
absolute_qubits: Optional[
|
113
|
+
children: list["FunctionDebugInfoInterface"]
|
114
|
+
relative_qubits: tuple[int, ...]
|
115
|
+
absolute_qubits: Optional[tuple[int, ...]] = pydantic.Field(default=None)
|
105
116
|
is_basis_gate: Optional[bool] = pydantic.Field(default=None)
|
106
117
|
is_inverse: bool = pydantic.Field(default=False)
|
107
118
|
is_allocate_or_free: bool = pydantic.Field(default=False)
|
108
119
|
level: OperationLevel = pydantic.Field(default=OperationLevel.UNKNOWN)
|
109
|
-
parameters:
|
110
|
-
port_to_passed_variable_map:
|
120
|
+
parameters: list[OperationParameter] = list()
|
121
|
+
port_to_passed_variable_map: dict[str, str] = pydantic.Field(default={})
|
111
122
|
|
112
123
|
model_config = ConfigDict(extra="allow")
|
113
124
|
# Temporary field to store the override debug info for parallel old/new visualization
|
@@ -120,7 +131,7 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
120
131
|
return self.generated_function.name
|
121
132
|
|
122
133
|
@property
|
123
|
-
def registers(self) ->
|
134
|
+
def registers(self) -> list[GeneratedRegister]:
|
124
135
|
if self.generated_function is None:
|
125
136
|
return list()
|
126
137
|
return self.generated_function.registers
|
@@ -132,15 +143,15 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
132
143
|
return len(self.generated_function.control_states) > 0
|
133
144
|
|
134
145
|
@property
|
135
|
-
def control_states(self) ->
|
146
|
+
def control_states(self) -> list[ControlState]:
|
136
147
|
if self.generated_function is None:
|
137
148
|
return list()
|
138
149
|
return self.generated_function.control_states
|
139
150
|
|
140
151
|
@staticmethod
|
141
152
|
def create_parameters_from_dict(
|
142
|
-
parameters:
|
143
|
-
) ->
|
153
|
+
parameters: dict[str, str]
|
154
|
+
) -> list[OperationParameter]:
|
144
155
|
return [
|
145
156
|
OperationParameter(label=key, value=value)
|
146
157
|
for key, value in parameters.items()
|
@@ -175,8 +186,8 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
175
186
|
|
176
187
|
|
177
188
|
def _get_absolute_from_relative(
|
178
|
-
absolute_qubits:
|
179
|
-
) ->
|
189
|
+
absolute_qubits: tuple[int, ...], relative_qubits: tuple[int, ...]
|
190
|
+
) -> tuple[int, ...]:
|
180
191
|
if max(relative_qubits) >= len(absolute_qubits):
|
181
192
|
_logger.warning(
|
182
193
|
"Invalid qubit computation (relative qubits: %s, absolute qubits: %s)",
|
@@ -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)
|