classiq 0.92.0__py3-none-any.whl → 0.94.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.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/__init__.py +6 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +38 -52
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +3 -3
- classiq/_internals/authentication/device.py +4 -4
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +4 -5
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +1 -2
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +8 -8
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/qlayer.py +8 -7
- classiq/applications/qnn/torch_utils.py +3 -4
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/qsp.py +6 -5
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +17 -12
- classiq/evaluators/qmod_annotated_expression.py +24 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/execution_session.py +18 -19
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +52 -7
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/applications/qsvm.py +5 -8
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +16 -16
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +7 -7
- classiq/interface/exceptions.py +6 -3
- classiq/interface/execution/iqcc.py +1 -3
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +2 -3
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -2
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +7 -36
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +2 -2
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -20
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -14
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +12 -13
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/qsvm.py +2 -2
- classiq/interface/generator/quantum_function_call.py +8 -11
- classiq/interface/generator/quantum_program.py +12 -15
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/state_preparation/state_preparation.py +6 -8
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -136
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -2
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +5 -5
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +2 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/control.py +1 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +4 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -4
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +6 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +4 -5
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +1 -4
- classiq/model_expansions/interpreters/base_interpreter.py +2 -6
- classiq/model_expansions/interpreters/generative_interpreter.py +8 -4
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +61 -29
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +3 -3
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +317 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +6 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +19 -14
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/modular_exponentiation.py +96 -8
- classiq/qmod/__init__.py +5 -2
- classiq/qmod/builtins/classical_execution_primitives.py +4 -11
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +0 -136
- classiq/qmod/builtins/functions/__init__.py +0 -13
- classiq/qmod/builtins/functions/allocation.py +4 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/standard_gates.py +27 -27
- classiq/qmod/builtins/operations.py +43 -58
- classiq/qmod/builtins/structs.py +2 -58
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/classical_variable.py +4 -2
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +139 -16
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -43
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +33 -26
- classiq/qmod/quantum_function.py +51 -32
- classiq/qmod/semantics/annotation/call_annotation.py +2 -2
- classiq/qmod/semantics/error_manager.py +5 -6
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/symbolic_expr.py +12 -4
- classiq/qmod/utilities.py +13 -10
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/METADATA +38 -37
- {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/RECORD +240 -261
- classiq-0.94.0.dist-info/WHEEL +4 -0
- classiq-0.94.0.dist-info/licenses/LICENSE.txt +27 -0
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq-0.92.0.dist-info/WHEEL +0 -4
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
SUPPORTED_PYTHON_BUILTIN_FUNCTIONS = {"len", "sum", "print"}
|
|
2
2
|
|
|
3
3
|
CLASSIQ_BUILTIN_CLASSICAL_FUNCTIONS = {
|
|
4
|
-
"hypercube_entangler_graph",
|
|
5
|
-
"grid_entangler_graph",
|
|
6
4
|
"qft_const_adder_phase",
|
|
7
|
-
"molecule_problem_to_hamiltonian",
|
|
8
|
-
"fock_hamiltonian_problem_to_hamiltonian",
|
|
9
|
-
"molecule_ground_state_solution_post_process",
|
|
10
5
|
}
|
|
11
6
|
|
|
12
7
|
CLASSIQ_EXPR_FUNCTIONS = {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import re
|
|
2
2
|
from collections.abc import Mapping
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from typing import Any,
|
|
4
|
+
from typing import Any, get_args
|
|
5
5
|
|
|
6
6
|
from sympy import Expr
|
|
7
|
-
from typing_extensions import get_args
|
|
8
7
|
|
|
9
8
|
from classiq.interface.backend.pydantic_backend import EXECUTION_PARAMETER_PATTERN
|
|
10
9
|
from classiq.interface.exceptions import ClassiqValueError
|
|
@@ -21,7 +20,7 @@ from classiq.interface.generator.expressions.proxies.classical.qmod_struct_insta
|
|
|
21
20
|
class EvaluatedExpression:
|
|
22
21
|
value: ExpressionValue
|
|
23
22
|
|
|
24
|
-
def is_constant(self, constant_type:
|
|
23
|
+
def is_constant(self, constant_type: type | None = None) -> bool:
|
|
25
24
|
return isinstance(
|
|
26
25
|
self.value,
|
|
27
26
|
get_args(RuntimeConstant) if constant_type is None else constant_type,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ast
|
|
2
2
|
from collections.abc import Mapping
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any
|
|
4
4
|
|
|
5
5
|
import pydantic
|
|
6
6
|
from pydantic import ConfigDict, PrivateAttr
|
|
@@ -24,7 +24,7 @@ from classiq.interface.generator.function_params import validate_expression_str
|
|
|
24
24
|
|
|
25
25
|
class Expression(HashableASTNode):
|
|
26
26
|
expr: str
|
|
27
|
-
_evaluated_expr:
|
|
27
|
+
_evaluated_expr: EvaluatedExpression | None = PrivateAttr(default=None)
|
|
28
28
|
|
|
29
29
|
def __init__(self, **kwargs: Any) -> None:
|
|
30
30
|
super().__init__(**kwargs)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from collections.abc import Mapping
|
|
2
|
-
from typing import TYPE_CHECKING, Any, Optional,
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Optional, TypeGuard
|
|
3
3
|
|
|
4
4
|
import sympy
|
|
5
5
|
from sympy import Integer
|
|
6
|
-
from typing_extensions import TypeGuard
|
|
7
6
|
|
|
8
7
|
from classiq.interface.exceptions import ClassiqIndexError
|
|
9
8
|
from classiq.interface.generator.expressions.expression import Expression
|
|
@@ -24,7 +23,7 @@ if TYPE_CHECKING:
|
|
|
24
23
|
)
|
|
25
24
|
|
|
26
25
|
|
|
27
|
-
def _is_int(val: Any) -> TypeGuard[
|
|
26
|
+
def _is_int(val: Any) -> TypeGuard[int | sympy.Basic]:
|
|
28
27
|
if isinstance(val, sympy.Basic):
|
|
29
28
|
return val.is_Number
|
|
30
29
|
return isinstance(val, int)
|
|
@@ -47,7 +46,7 @@ class ClassicalSequenceProxy(NonSymbolicExpr, ClassicalProxy):
|
|
|
47
46
|
raise NotImplementedError
|
|
48
47
|
|
|
49
48
|
def __getitem__(
|
|
50
|
-
self, key:
|
|
49
|
+
self, key: slice | int | Integer | ClassicalProxy
|
|
51
50
|
) -> ClassicalProxy:
|
|
52
51
|
return (
|
|
53
52
|
self._get_slice(key) if isinstance(key, slice) else self._get_subscript(key)
|
|
@@ -68,9 +67,7 @@ class ClassicalSequenceProxy(NonSymbolicExpr, ClassicalProxy):
|
|
|
68
67
|
def get_slice_at(self, start: Any, stop: Any) -> ClassicalProxy:
|
|
69
68
|
raise NotImplementedError
|
|
70
69
|
|
|
71
|
-
def _get_subscript(
|
|
72
|
-
self, index_: Union[int, Integer, ClassicalProxy]
|
|
73
|
-
) -> ClassicalProxy:
|
|
70
|
+
def _get_subscript(self, index_: int | Integer | ClassicalProxy) -> ClassicalProxy:
|
|
74
71
|
if _is_int(index_):
|
|
75
72
|
index = int(index_)
|
|
76
73
|
if index < 0:
|
|
@@ -7,7 +7,6 @@ from classiq.interface.generator.arith.binary_ops import (
|
|
|
7
7
|
BitwiseAnd,
|
|
8
8
|
BitwiseOr,
|
|
9
9
|
BitwiseXor,
|
|
10
|
-
CyclicShift,
|
|
11
10
|
Equal,
|
|
12
11
|
GreaterEqual,
|
|
13
12
|
GreaterThan,
|
|
@@ -28,11 +27,6 @@ from classiq.interface.generator.commuting_pauli_exponentiation import (
|
|
|
28
27
|
CommutingPauliExponentiation,
|
|
29
28
|
)
|
|
30
29
|
from classiq.interface.generator.copy import Copy
|
|
31
|
-
from classiq.interface.generator.entangler_params import (
|
|
32
|
-
GridEntangler,
|
|
33
|
-
HypercubeEntangler,
|
|
34
|
-
TwoDimensionalEntangler,
|
|
35
|
-
)
|
|
36
30
|
from classiq.interface.generator.function_param_library import FunctionParamLibrary
|
|
37
31
|
from classiq.interface.generator.hadamard_transform import HadamardTransform
|
|
38
32
|
from classiq.interface.generator.hamiltonian_evolution.exponentiation import (
|
|
@@ -45,13 +39,9 @@ from classiq.interface.generator.hamiltonian_evolution.suzuki_trotter import (
|
|
|
45
39
|
from classiq.interface.generator.hardware_efficient_ansatz import (
|
|
46
40
|
HardwareEfficientAnsatz,
|
|
47
41
|
)
|
|
48
|
-
from classiq.interface.generator.hartree_fock import HartreeFock
|
|
49
|
-
from classiq.interface.generator.hva import HVA
|
|
50
42
|
from classiq.interface.generator.identity import Identity
|
|
51
|
-
from classiq.interface.generator.linear_pauli_rotations import LinearPauliRotations
|
|
52
43
|
from classiq.interface.generator.mcu import Mcu
|
|
53
44
|
from classiq.interface.generator.mcx import Mcx
|
|
54
|
-
from classiq.interface.generator.qft import QFT
|
|
55
45
|
from classiq.interface.generator.qsvm import QSVMFeatureMap
|
|
56
46
|
from classiq.interface.generator.randomized_benchmarking import RandomizedBenchmarking
|
|
57
47
|
from classiq.interface.generator.reset import Reset
|
|
@@ -68,7 +58,6 @@ from classiq.interface.generator.state_preparation import (
|
|
|
68
58
|
UniformDistributionStatePreparation,
|
|
69
59
|
WStatePreparation,
|
|
70
60
|
)
|
|
71
|
-
from classiq.interface.generator.ucc import UCC
|
|
72
61
|
from classiq.interface.generator.unitary_gate import UnitaryGate
|
|
73
62
|
from classiq.interface.generator.user_defined_function_params import CustomFunction
|
|
74
63
|
|
|
@@ -82,7 +71,6 @@ function_param_library: FunctionParamLibrary = FunctionParamLibrary(
|
|
|
82
71
|
GHZStatePreparation,
|
|
83
72
|
WStatePreparation,
|
|
84
73
|
ExponentialStatePreparation,
|
|
85
|
-
QFT,
|
|
86
74
|
BitwiseAnd,
|
|
87
75
|
BitwiseOr,
|
|
88
76
|
BitwiseXor,
|
|
@@ -102,21 +90,14 @@ function_param_library: FunctionParamLibrary = FunctionParamLibrary(
|
|
|
102
90
|
Subtractor,
|
|
103
91
|
RShift,
|
|
104
92
|
LShift,
|
|
105
|
-
CyclicShift,
|
|
106
93
|
Modulo,
|
|
107
|
-
TwoDimensionalEntangler,
|
|
108
|
-
HypercubeEntangler,
|
|
109
|
-
GridEntangler,
|
|
110
94
|
Mcx,
|
|
111
95
|
Mcu,
|
|
112
96
|
CustomFunction,
|
|
113
97
|
HardwareEfficientAnsatz,
|
|
114
98
|
UnitaryGate,
|
|
115
|
-
LinearPauliRotations,
|
|
116
99
|
Multiplier,
|
|
117
100
|
Power,
|
|
118
|
-
HartreeFock,
|
|
119
|
-
UCC,
|
|
120
101
|
Min,
|
|
121
102
|
Max,
|
|
122
103
|
Exponentiation,
|
|
@@ -125,7 +106,6 @@ function_param_library: FunctionParamLibrary = FunctionParamLibrary(
|
|
|
125
106
|
QDrift,
|
|
126
107
|
Identity,
|
|
127
108
|
RandomizedBenchmarking,
|
|
128
|
-
HVA,
|
|
129
109
|
UGate,
|
|
130
110
|
AmplitudeLoading,
|
|
131
111
|
QSVMFeatureMap,
|
|
@@ -5,7 +5,6 @@ from collections.abc import Collection, Iterable, Mapping
|
|
|
5
5
|
from typing import (
|
|
6
6
|
Annotated,
|
|
7
7
|
Any,
|
|
8
|
-
Optional,
|
|
9
8
|
Union,
|
|
10
9
|
get_args,
|
|
11
10
|
)
|
|
@@ -108,7 +107,7 @@ GenerationExpressionSupportedNodeTypes = Union[
|
|
|
108
107
|
|
|
109
108
|
|
|
110
109
|
def validate_expression_str(
|
|
111
|
-
expr_str: str, supported_functions:
|
|
110
|
+
expr_str: str, supported_functions: set[str] | None = None
|
|
112
111
|
) -> None:
|
|
113
112
|
# By default, no functions are allowed.
|
|
114
113
|
supported_functions = supported_functions or set()
|
|
@@ -219,7 +218,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
|
219
218
|
and (len(output_names - input_names) <= 1)
|
|
220
219
|
)
|
|
221
220
|
|
|
222
|
-
def get_power_order(self) ->
|
|
221
|
+
def get_power_order(self) -> int | None:
|
|
223
222
|
return None
|
|
224
223
|
|
|
225
224
|
def _create_ios(self) -> None:
|
|
@@ -227,7 +226,7 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
|
227
226
|
|
|
228
227
|
@staticmethod
|
|
229
228
|
def _get_size_of_ios(
|
|
230
|
-
registers: Collection[
|
|
229
|
+
registers: Collection[RegisterArithmeticInfo | None],
|
|
231
230
|
) -> int:
|
|
232
231
|
return sum(reg.size if reg is not None else 0 for reg in registers)
|
|
233
232
|
|
|
@@ -265,11 +264,11 @@ class FunctionParams(HashablePydanticBaseModel):
|
|
|
265
264
|
def parse_function_params(
|
|
266
265
|
*,
|
|
267
266
|
params: Any,
|
|
268
|
-
discriminator:
|
|
267
|
+
discriminator: Any | None,
|
|
269
268
|
param_classes: Collection[type[FunctionParams]],
|
|
270
269
|
no_discriminator_error: Exception,
|
|
271
270
|
bad_function_error: Exception,
|
|
272
|
-
default_parser_class:
|
|
271
|
+
default_parser_class: type[FunctionParams] | None = None,
|
|
273
272
|
) -> FunctionParams: # Any is for use in pydantic validators.
|
|
274
273
|
if not discriminator:
|
|
275
274
|
raise no_discriminator_error
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
|
-
from typing import ClassVar
|
|
2
|
+
from typing import ClassVar
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
|
|
@@ -23,7 +23,7 @@ class ClassicalFunctionDeclaration(FunctionDeclaration):
|
|
|
23
23
|
default_factory=list,
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
return_type:
|
|
26
|
+
return_type: ConcreteClassicalType | None = pydantic.Field(
|
|
27
27
|
description="The type of the classical value that is returned by the function (for classical functions)",
|
|
28
28
|
default=None,
|
|
29
29
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from itertools import chain
|
|
2
|
-
from typing import TYPE_CHECKING, Any, Literal
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
from pydantic import PrivateAttr
|
|
@@ -131,7 +131,7 @@ class StructMetaType(ClassicalType):
|
|
|
131
131
|
class ClassicalArray(ClassicalType):
|
|
132
132
|
kind: Literal["array"]
|
|
133
133
|
element_type: "ConcreteClassicalType"
|
|
134
|
-
length:
|
|
134
|
+
length: Expression | None = None
|
|
135
135
|
|
|
136
136
|
@pydantic.model_validator(mode="before")
|
|
137
137
|
@classmethod
|
|
@@ -160,7 +160,7 @@ class ClassicalArray(ClassicalType):
|
|
|
160
160
|
return self.length.to_int_value()
|
|
161
161
|
|
|
162
162
|
def get_classical_proxy(self, handle: HandleBinding) -> ClassicalProxy:
|
|
163
|
-
length:
|
|
163
|
+
length: ExpressionValue | None
|
|
164
164
|
if self.length is None:
|
|
165
165
|
length = None
|
|
166
166
|
elif not self.length.is_evaluated():
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from classiq.interface.enum_utils import StrEnum
|
|
2
|
-
from classiq.interface.exceptions import ClassiqInternalExpansionError
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
class TypeModifier(StrEnum):
|
|
@@ -7,16 +6,3 @@ class TypeModifier(StrEnum):
|
|
|
7
6
|
Permutable = "permutable"
|
|
8
7
|
Mutable = "mutable"
|
|
9
8
|
Inferred = "inferred"
|
|
10
|
-
|
|
11
|
-
@staticmethod
|
|
12
|
-
def and_(first: "TypeModifier", second: "TypeModifier") -> "TypeModifier":
|
|
13
|
-
if second is TypeModifier.Inferred:
|
|
14
|
-
raise ClassiqInternalExpansionError
|
|
15
|
-
if first is TypeModifier.Mutable or second is TypeModifier.Mutable:
|
|
16
|
-
return TypeModifier.Mutable
|
|
17
|
-
elif first is TypeModifier.Permutable or second is TypeModifier.Permutable:
|
|
18
|
-
return TypeModifier.Permutable
|
|
19
|
-
else:
|
|
20
|
-
if first is not TypeModifier.Const and second is not TypeModifier.Const:
|
|
21
|
-
raise ClassiqInternalExpansionError("Unexpected type modifiers")
|
|
22
|
-
return TypeModifier.Const
|
|
@@ -35,8 +35,8 @@ if TYPE_CHECKING:
|
|
|
35
35
|
class TypeName(ClassicalType, QuantumType):
|
|
36
36
|
kind: Literal["struct_instance"]
|
|
37
37
|
name: str = pydantic.Field(description="The type name of the instance")
|
|
38
|
-
_assigned_fields:
|
|
39
|
-
|
|
38
|
+
_assigned_fields: Mapping[str, "ConcreteQuantumType"] | None = pydantic.PrivateAttr(
|
|
39
|
+
default=None
|
|
40
40
|
)
|
|
41
41
|
_classical_struct_decl: Optional["StructDeclaration"] = pydantic.PrivateAttr(
|
|
42
42
|
default=None
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import re
|
|
3
|
-
from typing import Literal, Optional,
|
|
3
|
+
from typing import Literal, Optional, TypeAlias
|
|
4
4
|
from uuid import UUID
|
|
5
5
|
|
|
6
6
|
import pydantic
|
|
7
7
|
from pydantic import ConfigDict, Field
|
|
8
|
-
from typing_extensions import TypeAlias
|
|
9
8
|
|
|
10
9
|
from classiq.interface.debug_info.back_ref_util import is_allocate_or_free_by_backref
|
|
11
10
|
from classiq.interface.enum_utils import StrEnum
|
|
@@ -87,12 +86,12 @@ class GeneratedFunction(pydantic.BaseModel):
|
|
|
87
86
|
name: str
|
|
88
87
|
control_states: list[ControlState]
|
|
89
88
|
registers: list[GeneratedRegister] = list()
|
|
90
|
-
depth:
|
|
91
|
-
width:
|
|
89
|
+
depth: int | None = pydantic.Field(default=None)
|
|
90
|
+
width: int | None = pydantic.Field(default=None)
|
|
92
91
|
dangling_inputs: dict[str, GeneratedRegister] = dict()
|
|
93
92
|
dangling_outputs: dict[str, GeneratedRegister] = dict()
|
|
94
93
|
|
|
95
|
-
def __getitem__(self, key:
|
|
94
|
+
def __getitem__(self, key: int | str) -> GeneratedRegister:
|
|
96
95
|
if isinstance(key, int):
|
|
97
96
|
return self.registers[key]
|
|
98
97
|
if isinstance(key, str):
|
|
@@ -101,7 +100,7 @@ class GeneratedFunction(pydantic.BaseModel):
|
|
|
101
100
|
return register
|
|
102
101
|
raise KeyError(key)
|
|
103
102
|
|
|
104
|
-
def get(self, key:
|
|
103
|
+
def get(self, key: int | str) -> GeneratedRegister | None:
|
|
105
104
|
try:
|
|
106
105
|
return self.__getitem__(key)
|
|
107
106
|
except KeyError:
|
|
@@ -119,7 +118,7 @@ class GeneratedCircuitData(pydantic.BaseModel):
|
|
|
119
118
|
width: int
|
|
120
119
|
circuit_parameters: list[ParameterName] = pydantic.Field(default_factory=list)
|
|
121
120
|
qubit_mapping: QubitMapping = pydantic.Field(default_factory=QubitMapping)
|
|
122
|
-
execution_data:
|
|
121
|
+
execution_data: ExecutionData | None = pydantic.Field(default=None)
|
|
123
122
|
|
|
124
123
|
@classmethod
|
|
125
124
|
def from_empty_logic_flow(cls) -> "GeneratedCircuitData":
|
|
@@ -176,15 +175,15 @@ STATEMENTS_NAME: dict[str, StatementType] = {
|
|
|
176
175
|
|
|
177
176
|
|
|
178
177
|
class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
179
|
-
generated_function:
|
|
178
|
+
generated_function: GeneratedFunction | None = Field(default=None)
|
|
180
179
|
children: list["FunctionDebugInfoInterface"]
|
|
181
180
|
relative_qubits: tuple[int, ...]
|
|
182
|
-
absolute_qubits:
|
|
183
|
-
control_variable:
|
|
184
|
-
is_basis_gate:
|
|
181
|
+
absolute_qubits: tuple[int, ...] | None = Field(default=None)
|
|
182
|
+
control_variable: str | None = Field(default=None)
|
|
183
|
+
is_basis_gate: bool | None = Field(default=None)
|
|
185
184
|
is_inverse: bool = Field(default=False)
|
|
186
185
|
is_unitary: bool = Field(default=True, exclude=True)
|
|
187
|
-
uuid:
|
|
186
|
+
uuid: UUID | None = Field(default=None, exclude=True)
|
|
188
187
|
port_to_passed_variable_map: dict[str, str] = Field(default={})
|
|
189
188
|
back_refs: StatementBlock = Field(default_factory=list)
|
|
190
189
|
|
|
@@ -229,7 +228,7 @@ class FunctionDebugInfoInterface(pydantic.BaseModel):
|
|
|
229
228
|
return f"{name}{suffix}"
|
|
230
229
|
|
|
231
230
|
@property
|
|
232
|
-
def first_back_ref(self) ->
|
|
231
|
+
def first_back_ref(self) -> ConcreteQuantumStatement | None:
|
|
233
232
|
return self.back_refs[0] if self.back_refs else None
|
|
234
233
|
|
|
235
234
|
@property
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
import pydantic
|
|
4
2
|
|
|
5
3
|
from classiq.interface.chemistry import operator
|
|
@@ -16,10 +14,10 @@ class ExponentiationOptimization(StrEnum):
|
|
|
16
14
|
|
|
17
15
|
|
|
18
16
|
class ExponentiationConstraints(pydantic.BaseModel):
|
|
19
|
-
max_depth:
|
|
17
|
+
max_depth: pydantic.PositiveInt | None = pydantic.Field(
|
|
20
18
|
default=None, description="Maximum depth of the exponentiation circuit."
|
|
21
19
|
)
|
|
22
|
-
max_error:
|
|
20
|
+
max_error: pydantic.PositiveFloat | None = pydantic.Field(
|
|
23
21
|
default=None,
|
|
24
22
|
description="Maximum approximation error of the exponentiation circuit.",
|
|
25
23
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import itertools
|
|
2
2
|
from collections import defaultdict
|
|
3
3
|
from collections.abc import MutableSet
|
|
4
|
-
from typing import Any
|
|
4
|
+
from typing import Any
|
|
5
5
|
|
|
6
6
|
import pydantic
|
|
7
7
|
from typing_extensions import Self
|
|
@@ -50,7 +50,7 @@ class HardwareData(pydantic.BaseModel):
|
|
|
50
50
|
f"If no connectivity map is given or the connectivity map is symmetric - {sorted(DEFAULT_BASIS_GATES)}. "
|
|
51
51
|
f"If a non-symmetric connectivity map is given - {sorted(DEFAULT_ROUTING_BASIS_GATES)}. ",
|
|
52
52
|
)
|
|
53
|
-
connectivity_map:
|
|
53
|
+
connectivity_map: ConnectivityMap | None = pydantic.Field(
|
|
54
54
|
default=None,
|
|
55
55
|
description="Qubit connectivity map, in the form [ [q0, q1], [q1, q2],...]. "
|
|
56
56
|
"If none given, assume the hardware is fully connected",
|
|
@@ -65,8 +65,8 @@ class HardwareData(pydantic.BaseModel):
|
|
|
65
65
|
@pydantic.field_validator("connectivity_map")
|
|
66
66
|
@classmethod
|
|
67
67
|
def _validate_connectivity_map(
|
|
68
|
-
cls, connectivity_map:
|
|
69
|
-
) ->
|
|
68
|
+
cls, connectivity_map: ConnectivityMap | None
|
|
69
|
+
) -> ConnectivityMap | None:
|
|
70
70
|
if connectivity_map is None:
|
|
71
71
|
return connectivity_map
|
|
72
72
|
if not connectivity_map:
|
|
@@ -128,7 +128,7 @@ class CustomHardwareSettings(HardwareData):
|
|
|
128
128
|
|
|
129
129
|
"""
|
|
130
130
|
|
|
131
|
-
_width:
|
|
131
|
+
_width: int | None = pydantic.PrivateAttr(default=None)
|
|
132
132
|
|
|
133
133
|
@pydantic.field_validator("basis_gates", mode="after")
|
|
134
134
|
@classmethod
|
|
@@ -144,14 +144,14 @@ class CustomHardwareSettings(HardwareData):
|
|
|
144
144
|
|
|
145
145
|
def __init__(self, **kwargs: Any) -> None:
|
|
146
146
|
super().__init__(**kwargs)
|
|
147
|
-
self._width:
|
|
147
|
+
self._width: int | None = (
|
|
148
148
|
len(set(itertools.chain.from_iterable(self.connectivity_map)))
|
|
149
149
|
if self.connectivity_map
|
|
150
150
|
else None
|
|
151
151
|
)
|
|
152
152
|
|
|
153
153
|
@property
|
|
154
|
-
def width(self) ->
|
|
154
|
+
def width(self) -> int | None:
|
|
155
155
|
return self._width
|
|
156
156
|
|
|
157
157
|
|
|
@@ -221,4 +221,4 @@ class SynthesisHardwareData(HardwareData):
|
|
|
221
221
|
Defaults to `None`.
|
|
222
222
|
"""
|
|
223
223
|
|
|
224
|
-
backend_data:
|
|
224
|
+
backend_data: BackendPreferences | None = pydantic.Field(default=None)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import itertools
|
|
2
|
-
from typing import TYPE_CHECKING,
|
|
2
|
+
from typing import TYPE_CHECKING, Union
|
|
3
3
|
|
|
4
4
|
import pydantic
|
|
5
5
|
from pydantic_core.core_schema import ValidationInfo
|
|
@@ -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:
|
|
54
|
+
one_qubit_gates: 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:
|
|
58
|
+
two_qubit_gates: 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
|
)
|
|
@@ -67,7 +67,7 @@ class HardwareEfficientAnsatz(function_params.FunctionParams):
|
|
|
67
67
|
@pydantic.field_validator("num_qubits", mode="before")
|
|
68
68
|
@classmethod
|
|
69
69
|
def validate_num_qubits(
|
|
70
|
-
cls, num_qubits:
|
|
70
|
+
cls, num_qubits: pydantic.PositiveInt | None, info: ValidationInfo
|
|
71
71
|
) -> pydantic.PositiveInt:
|
|
72
72
|
connectivity_map = info.data.get("connectivity_map")
|
|
73
73
|
conn_map_is_not_list = (
|
|
@@ -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:
|
|
111
|
-
) ->
|
|
110
|
+
cls, one_qubit_gates: str | list[str]
|
|
111
|
+
) -> 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:
|
|
124
|
-
) ->
|
|
123
|
+
cls, two_qubit_gates: str | list[str]
|
|
124
|
+
) -> 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,4 +1,4 @@
|
|
|
1
|
-
from typing import Any,
|
|
1
|
+
from typing import Any, cast
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
|
|
@@ -44,10 +44,10 @@ class Mcu(FunctionParams):
|
|
|
44
44
|
default=0, description="gam radian angle."
|
|
45
45
|
)
|
|
46
46
|
|
|
47
|
-
num_ctrl_qubits:
|
|
47
|
+
num_ctrl_qubits: pydantic.PositiveInt | None = pydantic.Field(
|
|
48
48
|
default=None, description="The number of control qubits."
|
|
49
49
|
)
|
|
50
|
-
ctrl_state:
|
|
50
|
+
ctrl_state: str | None = pydantic.Field(
|
|
51
51
|
default=None, description="string of the control state"
|
|
52
52
|
)
|
|
53
53
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
from pydantic_core.core_schema import ValidationInfo
|
|
@@ -20,7 +20,7 @@ class Mcx(FunctionParams):
|
|
|
20
20
|
arguments: list[RegisterUserInput] = pydantic.Field(
|
|
21
21
|
default_factory=list, description="registers describing the state (ordered)"
|
|
22
22
|
)
|
|
23
|
-
num_ctrl_qubits:
|
|
23
|
+
num_ctrl_qubits: pydantic.PositiveInt | None = pydantic.Field(
|
|
24
24
|
description="number of control qubits",
|
|
25
25
|
default=None,
|
|
26
26
|
)
|
|
@@ -33,7 +33,7 @@ class Mcx(FunctionParams):
|
|
|
33
33
|
def _validate_argument_names(
|
|
34
34
|
cls, arguments: list[RegisterUserInput]
|
|
35
35
|
) -> list[RegisterUserInput]:
|
|
36
|
-
register_name_list: list[
|
|
36
|
+
register_name_list: list[str | None] = [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):
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import warnings
|
|
1
2
|
from collections import defaultdict
|
|
2
|
-
from typing import
|
|
3
|
+
from typing import TypeVar, Union
|
|
3
4
|
|
|
4
5
|
import pydantic
|
|
5
6
|
from pydantic import BaseModel, ConfigDict
|
|
6
7
|
|
|
7
8
|
from classiq.interface.enum_utils import StrEnum
|
|
8
|
-
from classiq.interface.exceptions import ClassiqValueError
|
|
9
|
+
from classiq.interface.exceptions import ClassiqDeprecationWarning, ClassiqValueError
|
|
9
10
|
from classiq.interface.generator.transpiler_basis_gates import TranspilerBasisGates
|
|
10
11
|
|
|
11
12
|
UNCONSTRAINED = -1
|
|
@@ -19,6 +20,8 @@ class OptimizationParameter(StrEnum):
|
|
|
19
20
|
|
|
20
21
|
OptimizationParameterType = Union[OptimizationParameter, TranspilerBasisGates]
|
|
21
22
|
|
|
23
|
+
T = TypeVar("T")
|
|
24
|
+
|
|
22
25
|
|
|
23
26
|
def optimization_parameter_type_from_string(param: str) -> OptimizationParameterType:
|
|
24
27
|
for enum_ in (OptimizationParameter, TranspilerBasisGates):
|
|
@@ -53,14 +56,18 @@ class Constraints(BaseModel):
|
|
|
53
56
|
|
|
54
57
|
model_config = ConfigDict(extra="forbid")
|
|
55
58
|
|
|
56
|
-
max_width:
|
|
59
|
+
max_width: pydantic.PositiveInt | None = pydantic.Field(
|
|
57
60
|
default=None,
|
|
58
61
|
description="Maximum number of qubits in generated quantum circuit",
|
|
59
62
|
)
|
|
60
|
-
max_depth:
|
|
63
|
+
max_depth: pydantic.PositiveInt | None = pydantic.Field(
|
|
64
|
+
default=None,
|
|
65
|
+
)
|
|
61
66
|
|
|
62
67
|
max_gate_count: dict[TranspilerBasisGates, pydantic.NonNegativeInt] = (
|
|
63
|
-
pydantic.Field(
|
|
68
|
+
pydantic.Field(
|
|
69
|
+
default_factory=lambda: defaultdict(int),
|
|
70
|
+
)
|
|
64
71
|
)
|
|
65
72
|
|
|
66
73
|
optimization_parameter: OptimizationParameterType = pydantic.Field(
|
|
@@ -68,3 +75,25 @@ class Constraints(BaseModel):
|
|
|
68
75
|
description="If set, the synthesis engine optimizes the solution"
|
|
69
76
|
" according to that chosen parameter",
|
|
70
77
|
)
|
|
78
|
+
|
|
79
|
+
@pydantic.field_validator("max_depth", mode="before")
|
|
80
|
+
@classmethod
|
|
81
|
+
def deprecate_max_depth(cls, value: T) -> T:
|
|
82
|
+
if value is not None:
|
|
83
|
+
warnings.warn(
|
|
84
|
+
"max_depth is deprecated and will no longer be supported starting on 2025-10-27 at the earliest.",
|
|
85
|
+
ClassiqDeprecationWarning,
|
|
86
|
+
stacklevel=1,
|
|
87
|
+
)
|
|
88
|
+
return value
|
|
89
|
+
|
|
90
|
+
@pydantic.field_validator("max_gate_count", mode="before")
|
|
91
|
+
@classmethod
|
|
92
|
+
def deprecate_max_gate_count(cls, value: T) -> T:
|
|
93
|
+
if value:
|
|
94
|
+
warnings.warn(
|
|
95
|
+
"max_gate_count is deprecated and will no longer be supported starting on 2025-10-27 at the earliest.",
|
|
96
|
+
ClassiqDeprecationWarning,
|
|
97
|
+
stacklevel=1,
|
|
98
|
+
)
|
|
99
|
+
return value
|