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,7 +1,7 @@
|
|
1
1
|
import abc
|
2
2
|
import ast
|
3
3
|
import re
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional, Union
|
5
5
|
|
6
6
|
import networkx as nx
|
7
7
|
import pydantic
|
@@ -41,16 +41,16 @@ class ArithmeticExpressionABC(abc.ABC, FunctionParams):
|
|
41
41
|
uncomputation_method: UncomputationMethods = UncomputationMethods.optimized
|
42
42
|
machine_precision: pydantic.NonNegativeInt = DEFAULT_MACHINE_PRECISION
|
43
43
|
expression: PydanticExpressionStr
|
44
|
-
definitions:
|
44
|
+
definitions: dict[str, ValidDefinitions]
|
45
45
|
qubit_count: Optional[pydantic.NonNegativeInt] = None
|
46
46
|
|
47
|
-
def _get_literal_set(self) ->
|
47
|
+
def _get_literal_set(self) -> set[str]:
|
48
48
|
return _extract_literals(self.expression)
|
49
49
|
|
50
50
|
@classmethod
|
51
51
|
def _validate_expression_literals_and_definitions(
|
52
|
-
cls, definitions:
|
53
|
-
) ->
|
52
|
+
cls, definitions: dict[str, ValidDefinitions], expression: PydanticExpressionStr
|
53
|
+
) -> dict[str, ValidDefinitions]:
|
54
54
|
literals = _extract_literals(expression)
|
55
55
|
|
56
56
|
forbidden = literals.intersection(FORBIDDEN_LITERALS)
|
@@ -69,13 +69,13 @@ class ArithmeticExpressionABC(abc.ABC, FunctionParams):
|
|
69
69
|
|
70
70
|
@pydantic.model_validator(mode="before")
|
71
71
|
@classmethod
|
72
|
-
def _validate_expression(cls, values: Any) ->
|
72
|
+
def _validate_expression(cls, values: Any) -> dict[str, Any]:
|
73
73
|
if not isinstance(values, dict):
|
74
74
|
return values
|
75
75
|
expression_adapter: TypeAdapter = TypeAdapter(Optional[PydanticExpressionStr])
|
76
76
|
expression = expression_adapter.validate_python(values.get("expression"))
|
77
77
|
definitions_adapter: TypeAdapter = TypeAdapter(
|
78
|
-
Optional[
|
78
|
+
Optional[dict[str, ValidDefinitions]]
|
79
79
|
)
|
80
80
|
definition_dict = values.get("definitions")
|
81
81
|
if (
|
@@ -148,16 +148,16 @@ class ArithmeticExpressionABC(abc.ABC, FunctionParams):
|
|
148
148
|
pass
|
149
149
|
|
150
150
|
@staticmethod
|
151
|
-
def _validate_expression_graph(graph: nx.DiGraph, values:
|
151
|
+
def _validate_expression_graph(graph: nx.DiGraph, values: dict[str, Any]) -> None:
|
152
152
|
pass
|
153
153
|
|
154
154
|
@classmethod
|
155
155
|
def _replace_const_definitions_in_expression(
|
156
156
|
cls,
|
157
157
|
expression: str,
|
158
|
-
definitions:
|
158
|
+
definitions: dict[str, ValidDefinitions],
|
159
159
|
machine_precision: int,
|
160
|
-
) ->
|
160
|
+
) -> tuple[str, dict[str, RegisterArithmeticInfo]]:
|
161
161
|
new_definitions = dict()
|
162
162
|
for var_name, value in definitions.items():
|
163
163
|
if isinstance(value, RegisterArithmeticInfo):
|
@@ -182,5 +182,5 @@ class ArithmeticExpressionABC(abc.ABC, FunctionParams):
|
|
182
182
|
return re.sub(r"\b" + var + r"\b", str(value), expression)
|
183
183
|
|
184
184
|
|
185
|
-
def _extract_literals(expression: str) ->
|
185
|
+
def _extract_literals(expression: str) -> set[str]:
|
186
186
|
return set(re.findall(SUPPORTED_VAR_NAMES_REG, expression)) - SUPPORTED_FUNC_NAMES
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import ast
|
2
2
|
from _ast import AST
|
3
|
-
from
|
3
|
+
from collections.abc import Collection
|
4
|
+
from typing import Optional, Union, cast
|
4
5
|
|
5
6
|
import networkx as nx
|
6
7
|
|
@@ -28,9 +29,9 @@ Node = Union[str, float, int]
|
|
28
29
|
class ExpressionVisitor(ExpressionValidator):
|
29
30
|
def __init__(
|
30
31
|
self,
|
31
|
-
supported_nodes:
|
32
|
+
supported_nodes: tuple[type[AST], ...],
|
32
33
|
expression_type: str = DEFAULT_EXPRESSION_TYPE,
|
33
|
-
supported_functions: Optional[
|
34
|
+
supported_functions: Optional[set[str]] = None,
|
34
35
|
) -> None:
|
35
36
|
super().__init__(supported_nodes, expression_type, supported_functions)
|
36
37
|
self.graph = nx.DiGraph()
|
@@ -90,8 +91,8 @@ class ExpressionVisitor(ExpressionValidator):
|
|
90
91
|
class InDegreeLimiter:
|
91
92
|
@staticmethod
|
92
93
|
def _sort_in_edges(
|
93
|
-
in_edges: Collection[
|
94
|
-
) ->
|
94
|
+
in_edges: Collection[tuple[Node, str]]
|
95
|
+
) -> list[tuple[Node, str]]:
|
95
96
|
return sorted(
|
96
97
|
in_edges,
|
97
98
|
key=lambda edge_tuple: isinstance(edge_tuple[0], str), # vars before consts
|
@@ -134,9 +135,9 @@ class InDegreeLimiter:
|
|
134
135
|
def parse_expression(
|
135
136
|
expression: str,
|
136
137
|
*,
|
137
|
-
supported_nodes:
|
138
|
+
supported_nodes: tuple[type[AST], ...] = DEFAULT_SUPPORTED_NODE_TYPES,
|
138
139
|
expression_type: str = DEFAULT_EXPRESSION_TYPE,
|
139
|
-
supported_functions: Optional[
|
140
|
+
supported_functions: Optional[set[str]] = None,
|
140
141
|
) -> nx.DiGraph:
|
141
142
|
supported_functions = supported_functions or DEFAULT_SUPPORTED_FUNC_NAMES
|
142
143
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import ast
|
2
2
|
import re
|
3
3
|
from _ast import AST
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional, Union
|
5
5
|
|
6
6
|
from typing_extensions import TypeAlias, get_args
|
7
7
|
|
@@ -11,7 +11,7 @@ from classiq.interface.generator.expressions.sympy_supported_expressions import
|
|
11
11
|
SYMPY_SUPPORTED_EXPRESSIONS,
|
12
12
|
)
|
13
13
|
|
14
|
-
DEFAULT_SUPPORTED_FUNC_NAMES:
|
14
|
+
DEFAULT_SUPPORTED_FUNC_NAMES: set[str] = {"CLShift", "CRShift", "min", "max"}
|
15
15
|
|
16
16
|
DEFAULT_EXPRESSION_TYPE = "arithmetic"
|
17
17
|
IDENITIFIER_REGEX = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*")
|
@@ -19,7 +19,7 @@ IDENITIFIER_REGEX = re.compile(r"[a-zA-Z_][a-zA-Z0-9_]*")
|
|
19
19
|
_REPEATED_VARIABLES_ERROR_MESSAGE: str = (
|
20
20
|
"Repeated variables in the beginning of an arithmetic expression are not allowed."
|
21
21
|
)
|
22
|
-
ValidKeyValuePairs: TypeAlias =
|
22
|
+
ValidKeyValuePairs: TypeAlias = dict[str, set[str]]
|
23
23
|
|
24
24
|
SupportedNodesTypes = Union[
|
25
25
|
ast.Expression,
|
@@ -68,9 +68,9 @@ def _is_constant(expr: str) -> bool:
|
|
68
68
|
class ExpressionValidator(ast.NodeVisitor):
|
69
69
|
def __init__(
|
70
70
|
self,
|
71
|
-
supported_nodes:
|
71
|
+
supported_nodes: tuple[type[AST], ...],
|
72
72
|
expression_type: str = DEFAULT_EXPRESSION_TYPE,
|
73
|
-
supported_functions: Optional[
|
73
|
+
supported_functions: Optional[set[str]] = None,
|
74
74
|
mode: str = "eval",
|
75
75
|
) -> None:
|
76
76
|
super().__init__()
|
@@ -108,7 +108,7 @@ class ExpressionValidator(ast.NodeVisitor):
|
|
108
108
|
return self._ast_obj
|
109
109
|
|
110
110
|
@staticmethod
|
111
|
-
def _check_repeated_variables(variables:
|
111
|
+
def _check_repeated_variables(variables: tuple[Any, Any]) -> None:
|
112
112
|
if (
|
113
113
|
all(isinstance(var, ast.Name) for var in variables)
|
114
114
|
and variables[0].id == variables[1].id
|
@@ -186,9 +186,9 @@ class ExpressionValidator(ast.NodeVisitor):
|
|
186
186
|
def validate_expression(
|
187
187
|
expression: str,
|
188
188
|
*,
|
189
|
-
supported_nodes:
|
189
|
+
supported_nodes: tuple[type[AST], ...] = DEFAULT_SUPPORTED_NODE_TYPES,
|
190
190
|
expression_type: str = DEFAULT_EXPRESSION_TYPE,
|
191
|
-
supported_functions: Optional[
|
191
|
+
supported_functions: Optional[set[str]] = None,
|
192
192
|
mode: str = "eval",
|
193
193
|
) -> ast.AST:
|
194
194
|
supported_functions = supported_functions or set(SYMPY_SUPPORTED_EXPRESSIONS).union(
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import abc
|
2
|
-
from
|
2
|
+
from collections.abc import Iterable
|
3
|
+
from typing import ClassVar, Final, Optional
|
3
4
|
|
4
5
|
import pydantic
|
5
6
|
|
@@ -43,8 +44,8 @@ class ArithmeticOperationParams(FunctionParams):
|
|
43
44
|
return self.output_size is None
|
44
45
|
|
45
46
|
def _legal_bounds(
|
46
|
-
self, suggested_bounds:
|
47
|
-
) -> Optional[
|
47
|
+
self, suggested_bounds: tuple[float, float], max_bounds: tuple[float, float]
|
48
|
+
) -> Optional[tuple[float, float]]:
|
48
49
|
if self.output_size is None or (
|
49
50
|
suggested_bounds[0] >= max_bounds[0]
|
50
51
|
and suggested_bounds[1] <= max_bounds[1]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Callable,
|
1
|
+
from typing import Callable, Optional
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqArithmeticError
|
4
4
|
from classiq.interface.generator.arith.argument_utils import (
|
@@ -39,7 +39,7 @@ from classiq.interface.generator.arith.unary_ops import BitwiseInvert, Negation
|
|
39
39
|
ParamsGetter = Callable[..., ArithmeticOperationParams] # Argument vary
|
40
40
|
|
41
41
|
_TARGET_ERROR_MESSAGE: str = "Target unavailable for the requested operation"
|
42
|
-
_OPERATIONS_ALLOWING_TARGET:
|
42
|
+
_OPERATIONS_ALLOWING_TARGET: frozenset = frozenset(
|
43
43
|
{"And", "Or", "Eq", "NotEq", "Lt", "Gt", "LtE", "GtE"}
|
44
44
|
)
|
45
45
|
|
@@ -55,7 +55,7 @@ def operation_allows_target(operation: str) -> bool:
|
|
55
55
|
def get_params(
|
56
56
|
*,
|
57
57
|
node_id: str,
|
58
|
-
args:
|
58
|
+
args: list[RegisterOrFloat],
|
59
59
|
machine_precision: int,
|
60
60
|
output_size: Optional[int] = None,
|
61
61
|
inplace_arg: Optional[str] = None,
|
@@ -330,7 +330,7 @@ def less_equal_params_getter(
|
|
330
330
|
|
331
331
|
|
332
332
|
def logical_and_params_getter(
|
333
|
-
*arg:
|
333
|
+
*arg: list[RegisterOrFloat],
|
334
334
|
machine_precision: int,
|
335
335
|
output_size: Optional[int] = None,
|
336
336
|
inplace_arg: Optional[str] = None,
|
@@ -340,7 +340,7 @@ def logical_and_params_getter(
|
|
340
340
|
|
341
341
|
|
342
342
|
def logical_or_params_getter(
|
343
|
-
*arg:
|
343
|
+
*arg: list[RegisterOrFloat],
|
344
344
|
machine_precision: int,
|
345
345
|
output_size: Optional[int] = None,
|
346
346
|
inplace_arg: Optional[str] = None,
|
@@ -434,7 +434,7 @@ def modulo_params_getter(
|
|
434
434
|
)
|
435
435
|
|
436
436
|
|
437
|
-
params_getter_map:
|
437
|
+
params_getter_map: dict[str, ParamsGetter] = dict(
|
438
438
|
BitOr=or_params_getter,
|
439
439
|
BitAnd=and_params_getter,
|
440
440
|
BitXor=xor_params_getter,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Optional
|
2
2
|
|
3
3
|
import networkx as nx
|
4
4
|
|
@@ -8,7 +8,7 @@ from classiq.interface.generator.arith.argument_utils import RegisterOrConst
|
|
8
8
|
from classiq.interface.generator.arith.ast_node_rewrite import OUTPUT_SIZE
|
9
9
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
10
10
|
|
11
|
-
ArithmeticDefinitions =
|
11
|
+
ArithmeticDefinitions = dict[str, RegisterOrConst]
|
12
12
|
|
13
13
|
|
14
14
|
class ArithmeticResultBuilder:
|
@@ -43,10 +43,10 @@ class ArithmeticResultBuilder:
|
|
43
43
|
def _compute_inputs_data(
|
44
44
|
cls,
|
45
45
|
*,
|
46
|
-
inputs_node_set:
|
46
|
+
inputs_node_set: set[Any],
|
47
47
|
result_definitions: ArithmeticDefinitions,
|
48
48
|
machine_precision: int,
|
49
|
-
) ->
|
49
|
+
) -> dict[str, RegisterOrConst]:
|
50
50
|
return {
|
51
51
|
cls._convert_int_to_float_str(node): cls.convert_result_definition(
|
52
52
|
node, result_definitions.get(node), machine_precision
|
@@ -61,11 +61,11 @@ class ArithmeticResultBuilder:
|
|
61
61
|
graph: nx.DiGraph,
|
62
62
|
result_definitions: ArithmeticDefinitions,
|
63
63
|
machine_precision: int,
|
64
|
-
) ->
|
65
|
-
inputs_node_set:
|
64
|
+
) -> tuple[RegisterArithmeticInfo, Optional[RegisterArithmeticInfo]]:
|
65
|
+
inputs_node_set: set[str] = {
|
66
66
|
vertex for vertex, deg in graph.in_degree if deg == 0
|
67
67
|
}
|
68
|
-
node_results:
|
68
|
+
node_results: dict[str, RegisterOrConst] = cls._compute_inputs_data(
|
69
69
|
inputs_node_set=inputs_node_set,
|
70
70
|
result_definitions=result_definitions,
|
71
71
|
machine_precision=machine_precision,
|
@@ -91,11 +91,11 @@ class ArithmeticResultBuilder:
|
|
91
91
|
def _get_node_result_and_garbage(
|
92
92
|
cls,
|
93
93
|
graph: nx.DiGraph,
|
94
|
-
args:
|
94
|
+
args: list[RegisterOrConst],
|
95
95
|
node: str,
|
96
96
|
*,
|
97
97
|
machine_precision: int,
|
98
|
-
) ->
|
98
|
+
) -> tuple[RegisterArithmeticInfo, Optional[RegisterArithmeticInfo]]:
|
99
99
|
node_params = arithmetic_param_getters.get_params(
|
100
100
|
node_id=node,
|
101
101
|
args=args,
|
@@ -1,14 +1,11 @@
|
|
1
1
|
import math
|
2
|
+
from collections.abc import Iterable
|
2
3
|
from typing import (
|
3
4
|
Any,
|
4
5
|
ClassVar,
|
5
|
-
Dict,
|
6
6
|
Generic,
|
7
|
-
Iterable,
|
8
7
|
Literal,
|
9
8
|
Optional,
|
10
|
-
Tuple,
|
11
|
-
Type,
|
12
9
|
TypeVar,
|
13
10
|
Union,
|
14
11
|
)
|
@@ -65,7 +62,7 @@ class BinaryOpParams(
|
|
65
62
|
|
66
63
|
@pydantic.model_validator(mode="before")
|
67
64
|
@classmethod
|
68
|
-
def _clone_repeated_arg(cls, values: Any) ->
|
65
|
+
def _clone_repeated_arg(cls, values: Any) -> dict[str, Any]:
|
69
66
|
if isinstance(values, dict):
|
70
67
|
left_arg = values.get("left_arg")
|
71
68
|
right_arg = values.get("right_arg")
|
@@ -113,7 +110,7 @@ class InplacableBinaryOpParams(
|
|
113
110
|
|
114
111
|
@pydantic.model_validator(mode="before")
|
115
112
|
@classmethod
|
116
|
-
def _validate_inplace_arg(cls, values: Any) ->
|
113
|
+
def _validate_inplace_arg(cls, values: Any) -> dict[str, Any]:
|
117
114
|
if isinstance(values, dict):
|
118
115
|
left_arg = values.get("left_arg")
|
119
116
|
right_arg = values.get("right_arg")
|
@@ -168,7 +165,7 @@ class InplacableBinaryOpParams(
|
|
168
165
|
0, arg.fraction_places - self.result_register.fraction_places # type: ignore[attr-defined]
|
169
166
|
)
|
170
167
|
|
171
|
-
def _carried_arguments(self) ->
|
168
|
+
def _carried_arguments(self) -> tuple[Optional[LeftDataT], Optional[RightDataT]]:
|
172
169
|
if self.inplace_arg == ArgToInplace.RIGHT and isinstance(
|
173
170
|
self.left_arg, RegisterArithmeticInfo
|
174
171
|
):
|
@@ -366,7 +363,7 @@ class Subtractor(InplacableBinaryOpParams[RegisterOrConst, RegisterOrConst]):
|
|
366
363
|
)
|
367
364
|
|
368
365
|
def _get_output_size(
|
369
|
-
self, bounds:
|
366
|
+
self, bounds: tuple[float, float], fraction_places: int
|
370
367
|
) -> int:
|
371
368
|
if isinstance(self.right_arg, float) and self.effective_right_arg == 0:
|
372
369
|
assert isinstance(self.effective_left_arg, RegisterArithmeticInfo)
|
@@ -477,8 +474,8 @@ class Multiplier(BinaryOpWithFloatInputs):
|
|
477
474
|
|
478
475
|
@staticmethod
|
479
476
|
def _get_bounds(
|
480
|
-
args:
|
481
|
-
) ->
|
477
|
+
args: tuple[RegisterOrConst, RegisterOrConst], machine_precision: int
|
478
|
+
) -> tuple[float, float]:
|
482
479
|
extremal_values = [
|
483
480
|
left * right
|
484
481
|
for left in argument_utils.bounds(args[0])
|
@@ -524,7 +521,7 @@ class Multiplier(BinaryOpWithFloatInputs):
|
|
524
521
|
|
525
522
|
@staticmethod
|
526
523
|
def _get_output_size(
|
527
|
-
bounds:
|
524
|
+
bounds: tuple[float, float],
|
528
525
|
fraction_places: int,
|
529
526
|
left_arg: Union[RegisterArithmeticInfo, float],
|
530
527
|
right_arg: Union[RegisterArithmeticInfo, float],
|
@@ -603,7 +600,7 @@ class Power(BinaryOpParams[RegisterArithmeticInfo, pydantic.PositiveInt]):
|
|
603
600
|
* self.right_arg
|
604
601
|
)
|
605
602
|
|
606
|
-
def _get_result_bounds(self) ->
|
603
|
+
def _get_result_bounds(self) -> tuple[float, float]:
|
607
604
|
bounds = [
|
608
605
|
number_utils.limit_fraction_places(
|
609
606
|
bound, machine_precision=self.machine_precision
|
@@ -644,7 +641,7 @@ class Power(BinaryOpParams[RegisterArithmeticInfo, pydantic.PositiveInt]):
|
|
644
641
|
|
645
642
|
def _get_inner_action_garbage_size(
|
646
643
|
self,
|
647
|
-
action_type: Union[
|
644
|
+
action_type: Union[type["Power"], type[Multiplier]],
|
648
645
|
*,
|
649
646
|
arg: RegisterArithmeticInfo,
|
650
647
|
action_right_arg: RegisterOrConst,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import abc
|
2
|
-
from
|
2
|
+
from collections.abc import Iterable
|
3
|
+
from typing import Any
|
3
4
|
|
4
5
|
import pydantic
|
5
6
|
|
@@ -26,7 +27,7 @@ class Extremum(ArithmeticOperationParams):
|
|
26
27
|
|
27
28
|
@pydantic.model_validator(mode="before")
|
28
29
|
@classmethod
|
29
|
-
def _validate_one_is_register(cls, values: Any) ->
|
30
|
+
def _validate_one_is_register(cls, values: Any) -> dict[str, Any]:
|
30
31
|
if isinstance(values, dict):
|
31
32
|
left_arg = values.get("left_arg")
|
32
33
|
right_arg = values.get("right_arg")
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Iterable
|
2
|
+
from typing import Optional
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
from pydantic import ConfigDict
|
@@ -17,11 +18,11 @@ def get_arg_name(idx: int) -> str:
|
|
17
18
|
|
18
19
|
|
19
20
|
class LogicalOps(ArithmeticOperationParams):
|
20
|
-
args:
|
21
|
+
args: list[RegisterOrConst]
|
21
22
|
target: Optional[RegisterArithmeticInfo]
|
22
|
-
_should_invert_node_list:
|
23
|
+
_should_invert_node_list: list[str] = pydantic.PrivateAttr(default_factory=list)
|
23
24
|
|
24
|
-
def update_should_invert_node_list(self, invert_args:
|
25
|
+
def update_should_invert_node_list(self, invert_args: list[str]) -> None:
|
25
26
|
self._should_invert_node_list.extend(invert_args)
|
26
27
|
|
27
28
|
@pydantic.field_validator("output_size")
|
@@ -34,8 +35,8 @@ class LogicalOps(ArithmeticOperationParams):
|
|
34
35
|
@pydantic.field_validator("args")
|
35
36
|
@classmethod
|
36
37
|
def _validate_inputs_sizes(
|
37
|
-
cls, arguments:
|
38
|
-
) ->
|
38
|
+
cls, arguments: list[RegisterOrConst]
|
39
|
+
) -> list[RegisterOrConst]:
|
39
40
|
for arg_idx, arg in enumerate(arguments):
|
40
41
|
if isinstance(arg, RegisterArithmeticInfo) and not arg.is_boolean_register:
|
41
42
|
raise ClassiqValueError(
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Final,
|
1
|
+
from typing import Final, Union
|
2
2
|
|
3
3
|
MAXIMAL_MACHINE_PRECISION: Final[int] = 20
|
4
4
|
|
@@ -40,7 +40,7 @@ def _get_fraction_places(*, binary_value: str) -> int:
|
|
40
40
|
return fraction_places
|
41
41
|
|
42
42
|
|
43
|
-
def get_int_representation_and_fraction_places(float_value: float) ->
|
43
|
+
def get_int_representation_and_fraction_places(float_value: float) -> tuple[int, int]:
|
44
44
|
int_val = signed_int_to_unsigned(int(float_value * 2**MAXIMAL_MACHINE_PRECISION))
|
45
45
|
if int_val == 0:
|
46
46
|
return 0, 0
|
@@ -113,6 +113,6 @@ def limit_fraction_places(number: float, machine_precision: int) -> float:
|
|
113
113
|
|
114
114
|
|
115
115
|
def bounds_cut(
|
116
|
-
bounds1:
|
117
|
-
) ->
|
116
|
+
bounds1: tuple[float, float], bounds2: tuple[float, float]
|
117
|
+
) -> tuple[float, float]:
|
118
118
|
return max(min(bounds1), min(bounds2)), min(max(bounds1), max(bounds2))
|
@@ -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
|
@@ -24,7 +24,7 @@ class RegisterArithmeticInfo(HashablePydanticBaseModel):
|
|
24
24
|
|
25
25
|
@pydantic.model_validator(mode="before")
|
26
26
|
@classmethod
|
27
|
-
def _remove_name(cls, values: Any, info: ValidationInfo) ->
|
27
|
+
def _remove_name(cls, values: Any, info: ValidationInfo) -> dict[str, Any]:
|
28
28
|
if isinstance(values, dict):
|
29
29
|
values = values.copy()
|
30
30
|
elif hasattr(values, "__dict__"):
|
@@ -40,7 +40,7 @@ class RegisterArithmeticInfo(HashablePydanticBaseModel):
|
|
40
40
|
@staticmethod
|
41
41
|
def get_maximal_bounds(
|
42
42
|
*, size: int, is_signed: bool, fraction_places: int
|
43
|
-
) ->
|
43
|
+
) -> tuple[float, float]:
|
44
44
|
lb = 0 if not is_signed else -(2 ** (size - 1))
|
45
45
|
ub = 2**size - 1 if not is_signed else 2 ** (size - 1) - 1
|
46
46
|
fraction_factor = float(2**-fraction_places)
|
@@ -106,7 +106,7 @@ class RegisterUserInput(RegisterArithmeticInfo):
|
|
106
106
|
|
107
107
|
@pydantic.model_validator(mode="before")
|
108
108
|
@classmethod
|
109
|
-
def _remove_name(cls, values: Any, info: ValidationInfo) ->
|
109
|
+
def _remove_name(cls, values: Any, info: ValidationInfo) -> dict[str, Any]:
|
110
110
|
return values
|
111
111
|
|
112
112
|
def revalued(self, **kwargs: Any) -> "RegisterUserInput":
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
@@ -15,14 +15,14 @@ from classiq.interface.generator.model.preferences.preferences import QuantumFor
|
|
15
15
|
|
16
16
|
|
17
17
|
class CircuitCodeInterface(pydantic.BaseModel):
|
18
|
-
outputs:
|
18
|
+
outputs: dict[QuantumFormat, Code]
|
19
19
|
qasm_version: QasmVersion
|
20
20
|
|
21
21
|
@pydantic.field_validator("outputs")
|
22
22
|
@classmethod
|
23
23
|
def reformat_long_string_output_formats(
|
24
|
-
cls, outputs:
|
25
|
-
) ->
|
24
|
+
cls, outputs: dict[QuantumFormat, str]
|
25
|
+
) -> dict[QuantumFormat, LongStr]:
|
26
26
|
return {key: LongStr(value) for key, value in outputs.items()}
|
27
27
|
|
28
28
|
@property
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import Dict, Tuple
|
2
|
-
|
3
1
|
from typing_extensions import TypeAlias
|
4
2
|
|
5
3
|
from classiq.interface.enum_utils import StrEnum
|
@@ -8,14 +6,14 @@ from classiq.interface.generator.model.preferences.preferences import QuantumFor
|
|
8
6
|
from classiq.interface.hardware import Provider
|
9
7
|
|
10
8
|
Code: TypeAlias = str
|
11
|
-
CodeAndSyntax: TypeAlias =
|
9
|
+
CodeAndSyntax: TypeAlias = tuple[Code, QuantumInstructionSet]
|
12
10
|
|
13
|
-
INSTRUCTION_SET_TO_FORMAT:
|
11
|
+
INSTRUCTION_SET_TO_FORMAT: dict[QuantumInstructionSet, QuantumFormat] = {
|
14
12
|
QuantumInstructionSet.QASM: QuantumFormat.QASM,
|
15
13
|
QuantumInstructionSet.QSHARP: QuantumFormat.QSHARP,
|
16
14
|
QuantumInstructionSet.IONQ: QuantumFormat.IONQ,
|
17
15
|
}
|
18
|
-
VENDOR_TO_INSTRUCTION_SET:
|
16
|
+
VENDOR_TO_INSTRUCTION_SET: dict[Provider, QuantumInstructionSet] = {
|
19
17
|
Provider.CLASSIQ: QuantumInstructionSet.QASM,
|
20
18
|
Provider.IONQ: QuantumInstructionSet.IONQ,
|
21
19
|
Provider.AZURE_QUANTUM: QuantumInstructionSet.QSHARP,
|
@@ -1,8 +1,7 @@
|
|
1
|
-
from typing import Union
|
1
|
+
from typing import Annotated, Union
|
2
2
|
|
3
3
|
from pydantic import PlainSerializer, PlainValidator
|
4
4
|
from pydantic.json_schema import WithJsonSchema
|
5
|
-
from typing_extensions import Annotated
|
6
5
|
|
7
6
|
|
8
7
|
def validate_complex(v: Union[complex, str]) -> complex:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from typing import Any
|
3
|
+
from typing import Any
|
4
4
|
|
5
5
|
import pydantic
|
6
6
|
from pydantic import BaseModel, ConfigDict
|
@@ -28,7 +28,7 @@ class ControlState(BaseModel):
|
|
28
28
|
|
29
29
|
@pydantic.model_validator(mode="before")
|
30
30
|
@classmethod
|
31
|
-
def _validate_control(cls, values: Any) ->
|
31
|
+
def _validate_control(cls, values: Any) -> dict[str, Any]:
|
32
32
|
if isinstance(values, dict):
|
33
33
|
num_ctrl_qubits: int = (
|
34
34
|
values.get("num_ctrl_qubits", _DEFAULT_NUM_CONTROL_QUBITS) or 0
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import Dict, Type
|
2
|
-
|
3
1
|
import pydantic
|
4
2
|
|
5
3
|
from classiq.interface.enum_utils import StrEnum
|
@@ -22,7 +20,7 @@ class CustomAnsatzType(StrEnum):
|
|
22
20
|
RandomTwoQubitGates = "RandomTwoQubitGates"
|
23
21
|
|
24
22
|
|
25
|
-
CUSTOM_ANSATZ_ARGS_MAPPING:
|
23
|
+
CUSTOM_ANSATZ_ARGS_MAPPING: dict[CustomAnsatzType, type[pydantic.BaseModel]] = {
|
26
24
|
CustomAnsatzType.TwoLocal: TwoLocalArgs,
|
27
25
|
CustomAnsatzType.SeparateU3: SeparateU3Args,
|
28
26
|
CustomAnsatzType.Hypercube: HypercubeArgs,
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
1
|
import numpy as np
|
4
2
|
|
5
3
|
# Taken and modified from quantum_tsp_tutorials repository of mstechly in github.
|
@@ -10,7 +8,7 @@ def _distance_between_points(point_1: np.ndarray, point_2: np.ndarray) -> float:
|
|
10
8
|
return float(np.linalg.norm(point_1 - point_2))
|
11
9
|
|
12
10
|
|
13
|
-
def get_distance_matrix(cities: np.ndarray) ->
|
11
|
+
def get_distance_matrix(cities: np.ndarray) -> list[list[float]]:
|
14
12
|
number_of_cities = len(cities)
|
15
13
|
matrix = np.zeros((number_of_cities, number_of_cities))
|
16
14
|
for i in range(number_of_cities):
|
@@ -20,14 +18,14 @@ def get_distance_matrix(cities: np.ndarray) -> List[List[float]]:
|
|
20
18
|
return matrix.tolist()
|
21
19
|
|
22
20
|
|
23
|
-
def get_rand_euclidean_distance_matrix(num_points: int) ->
|
21
|
+
def get_rand_euclidean_distance_matrix(num_points: int) -> list[list[float]]:
|
24
22
|
_points_array_dim = 2
|
25
23
|
points = np.random.rand(num_points, _points_array_dim)
|
26
24
|
distance_matrix = get_distance_matrix(points)
|
27
25
|
return distance_matrix
|
28
26
|
|
29
27
|
|
30
|
-
def get_rand_distance_matrix(num_points: int) ->
|
28
|
+
def get_rand_distance_matrix(num_points: int) -> list[list[float]]:
|
31
29
|
distance_matrix = np.random.rand(num_points, num_points)
|
32
30
|
distance_matrix *= 0.5
|
33
31
|
distance_matrix += distance_matrix.T
|