classiq 0.93.0__py3-none-any.whl → 0.94.1__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 +5 -4
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +7 -8
- 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 +2 -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 +5 -3
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -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 +2 -2
- 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 +5 -5
- 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 +35 -58
- classiq/qmod/builtins/structs.py +2 -58
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- 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 +31 -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/utilities.py +13 -10
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/RECORD +238 -260
- 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.93.0.dist-info → classiq-0.94.1.dist-info}/WHEEL +0 -0
- {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/licenses/LICENSE.txt +0 -0
|
@@ -5,7 +5,8 @@ class CompilationMetadata(BaseModel):
|
|
|
5
5
|
should_synthesize_separately: bool = Field(default=False)
|
|
6
6
|
occurrences_number: NonNegativeInt = Field(default=1)
|
|
7
7
|
_occupation_number: NonNegativeInt = PrivateAttr(default=0)
|
|
8
|
-
|
|
8
|
+
disable_perm_check: bool = Field(default=False)
|
|
9
|
+
disable_const_checks: list[str] | bool = Field(default=False)
|
|
9
10
|
|
|
10
11
|
@property
|
|
11
12
|
def occupation_number(self) -> NonNegativeInt:
|
|
@@ -14,3 +15,13 @@ class CompilationMetadata(BaseModel):
|
|
|
14
15
|
@occupation_number.setter
|
|
15
16
|
def occupation_number(self, value: NonNegativeInt) -> None:
|
|
16
17
|
self._occupation_number = value
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def has_user_directives(self) -> bool:
|
|
21
|
+
return bool(self.disable_perm_check or self.disable_const_checks)
|
|
22
|
+
|
|
23
|
+
def copy_user_directives(self) -> "CompilationMetadata":
|
|
24
|
+
return CompilationMetadata(
|
|
25
|
+
disable_perm_check=self.disable_perm_check,
|
|
26
|
+
disable_const_checks=self.disable_const_checks,
|
|
27
|
+
)
|
|
@@ -2,7 +2,7 @@ from collections import Counter, defaultdict
|
|
|
2
2
|
from collections.abc import Collection, Iterable, Mapping
|
|
3
3
|
from dataclasses import dataclass
|
|
4
4
|
from itertools import chain
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import TypeVar
|
|
6
6
|
|
|
7
7
|
import networkx as nx
|
|
8
8
|
|
|
@@ -23,8 +23,8 @@ RECURRING_NAMES_ERROR_MSG = "Recurring wire names"
|
|
|
23
23
|
|
|
24
24
|
@dataclass
|
|
25
25
|
class Wire:
|
|
26
|
-
start:
|
|
27
|
-
end:
|
|
26
|
+
start: PydanticNonEmptyString | None = None
|
|
27
|
+
end: PydanticNonEmptyString | None = None
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
def _parse_call_inputs(
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
from collections import abc, defaultdict
|
|
2
|
-
from collections.abc import Collection, Mapping, Sequence
|
|
2
|
+
from collections.abc import Callable, Collection, Mapping, Sequence
|
|
3
3
|
from functools import partial
|
|
4
4
|
from typing import (
|
|
5
5
|
TYPE_CHECKING,
|
|
6
6
|
Any,
|
|
7
|
-
Callable,
|
|
8
|
-
Optional,
|
|
9
7
|
TypeVar,
|
|
10
8
|
Union,
|
|
11
9
|
)
|
|
@@ -30,7 +28,7 @@ Ret = TypeVar("Ret", bound=RetType)
|
|
|
30
28
|
|
|
31
29
|
|
|
32
30
|
class Visitor:
|
|
33
|
-
def visit(self, node: NodeType) ->
|
|
31
|
+
def visit(self, node: NodeType) -> RetType | None:
|
|
34
32
|
for cls in type(node).__mro__:
|
|
35
33
|
method = "visit_" + cls.__name__
|
|
36
34
|
if hasattr(self, method):
|
|
@@ -38,40 +36,40 @@ class Visitor:
|
|
|
38
36
|
return visitor(node)
|
|
39
37
|
return self.generic_visit(node)
|
|
40
38
|
|
|
41
|
-
def generic_visit(self, node: NodeType) ->
|
|
39
|
+
def generic_visit(self, node: NodeType) -> RetType | None:
|
|
42
40
|
if isinstance(node, BaseModel):
|
|
43
41
|
return self.visit_BaseModel(node)
|
|
44
42
|
|
|
45
43
|
return node
|
|
46
44
|
|
|
47
|
-
def visit_list(self, node: list[NodeType]) ->
|
|
45
|
+
def visit_list(self, node: list[NodeType]) -> RetType | None:
|
|
48
46
|
for elem in node:
|
|
49
47
|
self.visit(elem)
|
|
50
48
|
|
|
51
49
|
return None
|
|
52
50
|
|
|
53
|
-
def visit_dict(self, node: dict[Key, NodeType]) ->
|
|
51
|
+
def visit_dict(self, node: dict[Key, NodeType]) -> RetType | None:
|
|
54
52
|
for value in node.values():
|
|
55
53
|
self.visit(value)
|
|
56
54
|
|
|
57
55
|
return None
|
|
58
56
|
|
|
59
|
-
def visit_tuple(self, node: tuple[NodeType, ...]) ->
|
|
57
|
+
def visit_tuple(self, node: tuple[NodeType, ...]) -> tuple[RetType, ...] | None:
|
|
60
58
|
for value in node:
|
|
61
59
|
self.visit(value)
|
|
62
60
|
|
|
63
61
|
return None
|
|
64
62
|
|
|
65
|
-
def visit_BaseModel(self, node: BaseModel) ->
|
|
63
|
+
def visit_BaseModel(self, node: BaseModel) -> RetType | None:
|
|
66
64
|
for _, value in node:
|
|
67
65
|
self.visit(value)
|
|
68
66
|
|
|
69
67
|
return None
|
|
70
68
|
|
|
71
|
-
def visit_int(self, n: int) ->
|
|
69
|
+
def visit_int(self, n: int) -> RetType | None:
|
|
72
70
|
return None
|
|
73
71
|
|
|
74
|
-
def visit_bool(self, b: bool) ->
|
|
72
|
+
def visit_bool(self, b: bool) -> RetType | None:
|
|
75
73
|
return None
|
|
76
74
|
|
|
77
75
|
|
|
@@ -103,7 +101,7 @@ class Transformer(Visitor):
|
|
|
103
101
|
return tuple(self.visit(value) for value in node)
|
|
104
102
|
|
|
105
103
|
def visit_BaseModel(
|
|
106
|
-
self, node: BaseModel, fields_to_skip:
|
|
104
|
+
self, node: BaseModel, fields_to_skip: Collection[str] | None = None
|
|
107
105
|
) -> RetType:
|
|
108
106
|
fields_to_skip = fields_to_skip or set()
|
|
109
107
|
|
classiq/interface/hardware.py
CHANGED
|
@@ -71,7 +71,7 @@ class HardwareStatus(pydantic.BaseModel):
|
|
|
71
71
|
default=None,
|
|
72
72
|
description="The estimated queue time for the hardware in seconds.",
|
|
73
73
|
)
|
|
74
|
-
pending_jobs:
|
|
74
|
+
pending_jobs: int | None = None
|
|
75
75
|
|
|
76
76
|
|
|
77
77
|
if TYPE_CHECKING:
|
|
@@ -87,7 +87,7 @@ class HardwareInformation(pydantic.BaseModel):
|
|
|
87
87
|
display_name: str
|
|
88
88
|
device_type: DeviceType
|
|
89
89
|
number_of_qubits: int
|
|
90
|
-
connectivity_map:
|
|
90
|
+
connectivity_map: list[ConnectivityMapEntry] | None = None
|
|
91
91
|
basis_gates: list[str]
|
|
92
92
|
status: HardwareStatus
|
|
93
93
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Any
|
|
1
|
+
from typing import TYPE_CHECKING, Any
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class classproperty(property): # noqa: N801
|
|
5
|
-
def __get__(self, owner_self: Any, owner_cls:
|
|
5
|
+
def __get__(self, owner_self: Any, owner_cls: type | None = None) -> Any:
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
7
|
assert self.fget is not None
|
|
8
8
|
return self.fget(owner_cls)
|
|
@@ -3,7 +3,7 @@ from collections import Counter
|
|
|
3
3
|
from collections.abc import Iterator
|
|
4
4
|
from functools import cached_property
|
|
5
5
|
from itertools import count
|
|
6
|
-
from typing import Any
|
|
6
|
+
from typing import Any
|
|
7
7
|
|
|
8
8
|
import pydantic
|
|
9
9
|
from pydantic import ConfigDict, field_validator
|
|
@@ -46,7 +46,7 @@ class OperationType(StrEnum):
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
class OperationData(pydantic.BaseModel):
|
|
49
|
-
approximated_depth:
|
|
49
|
+
approximated_depth: int | None = None
|
|
50
50
|
width: int
|
|
51
51
|
gate_count: Counter[str] = pydantic.Field(default_factory=dict)
|
|
52
52
|
|
|
@@ -65,7 +65,7 @@ class ProgramData(pydantic.BaseModel):
|
|
|
65
65
|
|
|
66
66
|
class OperationLink(pydantic.BaseModel):
|
|
67
67
|
label: str
|
|
68
|
-
inner_label:
|
|
68
|
+
inner_label: str | None = None
|
|
69
69
|
qubits: tuple[int, ...]
|
|
70
70
|
type: str
|
|
71
71
|
is_captured: bool = False
|
|
@@ -148,14 +148,14 @@ class AtomicGate(StrEnum):
|
|
|
148
148
|
|
|
149
149
|
class Operation(pydantic.BaseModel):
|
|
150
150
|
name: str
|
|
151
|
-
inner_label:
|
|
151
|
+
inner_label: str | None = None
|
|
152
152
|
_id: int = pydantic.PrivateAttr(default_factory=_operation_id_counter.next_id)
|
|
153
153
|
qasm_name: str = pydantic.Field(default="")
|
|
154
154
|
details: str = pydantic.Field(default="")
|
|
155
155
|
children: list["Operation"] = pydantic.Field(default_factory=list)
|
|
156
156
|
# children_ids is optional in order to support backwards compatibility.
|
|
157
157
|
children_ids: list[int] = pydantic.Field(default_factory=list)
|
|
158
|
-
operation_data:
|
|
158
|
+
operation_data: OperationData | None = None
|
|
159
159
|
operation_links: OperationLinks
|
|
160
160
|
control_qubits: tuple[int, ...] = pydantic.Field(default_factory=tuple)
|
|
161
161
|
auxiliary_qubits: tuple[int, ...]
|
classiq/interface/jobs.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any, Generic,
|
|
1
|
+
from typing import Any, Generic, TypeVar, Union
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
from pydantic import BaseModel
|
|
@@ -43,8 +43,8 @@ For unsuccessful jobs, we expect failure_details to be a string and result to be
|
|
|
43
43
|
|
|
44
44
|
class JobDescription(BaseModel, Generic[T], json_encoders=CUSTOM_ENCODERS):
|
|
45
45
|
status: JobStatus
|
|
46
|
-
failure_details:
|
|
47
|
-
result:
|
|
46
|
+
failure_details: str | None = pydantic.Field(default=None)
|
|
47
|
+
result: T | None = pydantic.Field(default=None)
|
|
48
48
|
|
|
49
49
|
@pydantic.model_validator(mode="after")
|
|
50
50
|
def validate_status_and_fields(self) -> Self:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Mapping
|
|
2
|
-
from typing import Literal
|
|
2
|
+
from typing import Literal
|
|
3
3
|
|
|
4
4
|
from classiq.interface.generator.expressions.expression import Expression
|
|
5
5
|
from classiq.interface.model.handle_binding import ConcreteHandleBinding, HandleBinding
|
|
@@ -8,9 +8,9 @@ from classiq.interface.model.quantum_statement import QuantumOperation
|
|
|
8
8
|
|
|
9
9
|
class Allocate(QuantumOperation):
|
|
10
10
|
kind: Literal["Allocate"]
|
|
11
|
-
size:
|
|
12
|
-
is_signed:
|
|
13
|
-
fraction_digits:
|
|
11
|
+
size: Expression | None = None
|
|
12
|
+
is_signed: Expression | None = None
|
|
13
|
+
fraction_digits: Expression | None = None
|
|
14
14
|
target: ConcreteHandleBinding
|
|
15
15
|
|
|
16
16
|
@property
|
classiq/interface/model/block.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Literal
|
|
1
|
+
from typing import TYPE_CHECKING, Literal
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
|
|
@@ -13,4 +13,4 @@ class Block(QuantumOperation):
|
|
|
13
13
|
|
|
14
14
|
statements: "StatementBlock"
|
|
15
15
|
|
|
16
|
-
label:
|
|
16
|
+
label: str | None = pydantic.Field(default=None)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Literal
|
|
1
|
+
from typing import Literal
|
|
2
2
|
|
|
3
3
|
from classiq.interface.generator.expressions.expression import Expression
|
|
4
4
|
from classiq.interface.model.handle_binding import ConcreteHandleBinding
|
|
@@ -9,8 +9,8 @@ class SetBoundsStatement(QuantumOperation):
|
|
|
9
9
|
kind: Literal["SetBoundsStatement"]
|
|
10
10
|
|
|
11
11
|
target: ConcreteHandleBinding
|
|
12
|
-
lower_bound:
|
|
13
|
-
upper_bound:
|
|
12
|
+
lower_bound: Expression | None
|
|
13
|
+
upper_bound: Expression | None
|
|
14
14
|
|
|
15
15
|
@property
|
|
16
16
|
def expressions(self) -> list[Expression]:
|
|
@@ -19,7 +19,7 @@ class Control(QuantumExpressionOperation):
|
|
|
19
19
|
else_block: Optional["StatementBlock"] = None
|
|
20
20
|
|
|
21
21
|
_ctrl_size: int = pydantic.PrivateAttr(default=0)
|
|
22
|
-
_result_type:
|
|
22
|
+
_result_type: QuantumType | None = pydantic.PrivateAttr(
|
|
23
23
|
default=None,
|
|
24
24
|
)
|
|
25
25
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Mapping, Sequence
|
|
2
|
-
from typing import Literal
|
|
2
|
+
from typing import Literal
|
|
3
3
|
|
|
4
4
|
from classiq.interface.enum_utils import StrEnum
|
|
5
5
|
from classiq.interface.generator.expressions.expression import Expression
|
|
@@ -16,7 +16,7 @@ class InplaceBinaryOperation(QuantumOperation):
|
|
|
16
16
|
kind: Literal["InplaceBinaryOperation"]
|
|
17
17
|
|
|
18
18
|
target: ConcreteHandleBinding
|
|
19
|
-
value:
|
|
19
|
+
value: ConcreteHandleBinding | Expression
|
|
20
20
|
operation: BinaryOperation
|
|
21
21
|
|
|
22
22
|
@property
|
classiq/interface/model/model.py
CHANGED
|
@@ -185,14 +185,14 @@ class Model(VersionedModel, ASTNode):
|
|
|
185
185
|
return constants
|
|
186
186
|
|
|
187
187
|
def dump_no_metadata(self) -> dict[str, Any]:
|
|
188
|
-
|
|
189
|
-
name:
|
|
188
|
+
compilation_metadata_user_directives = {
|
|
189
|
+
name: comp_metadata.copy_user_directives()
|
|
190
190
|
for name, comp_metadata in self.functions_compilation_metadata.items()
|
|
191
|
-
if
|
|
191
|
+
if comp_metadata.has_user_directives
|
|
192
192
|
}
|
|
193
193
|
model = self.model_copy(
|
|
194
194
|
update={
|
|
195
|
-
"functions_compilation_metadata":
|
|
195
|
+
"functions_compilation_metadata": compilation_metadata_user_directives,
|
|
196
196
|
}
|
|
197
197
|
)
|
|
198
198
|
return model.model_dump(
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
from classiq.interface.ast_node import ASTNode
|
|
4
2
|
from classiq.interface.exceptions import ClassiqError
|
|
5
3
|
|
|
6
4
|
|
|
7
5
|
class Parameter(ASTNode):
|
|
8
|
-
name:
|
|
6
|
+
name: str | None
|
|
9
7
|
|
|
10
8
|
def get_name(self) -> str:
|
|
11
9
|
if self.name is None:
|
|
@@ -49,7 +49,7 @@ class AnonPortDeclaration(Parameter):
|
|
|
49
49
|
def qmod_type_name(self) -> str:
|
|
50
50
|
prefix = ""
|
|
51
51
|
suffix = ""
|
|
52
|
-
if self.type_modifier
|
|
52
|
+
if self.type_modifier is TypeModifier.Const:
|
|
53
53
|
prefix += f"{self.type_modifier.name}["
|
|
54
54
|
suffix += "]"
|
|
55
55
|
if self.direction != PortDeclarationDirection.Inout:
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
from collections.abc import Mapping
|
|
3
|
-
from typing import Optional
|
|
4
3
|
|
|
5
4
|
import pydantic
|
|
6
5
|
|
|
@@ -55,7 +54,7 @@ class QuantumAssignmentOperation(QuantumExpressionOperation):
|
|
|
55
54
|
result_var: ConcreteHandleBinding = pydantic.Field(
|
|
56
55
|
description="The variable storing the expression result"
|
|
57
56
|
)
|
|
58
|
-
_result_type:
|
|
57
|
+
_result_type: QuantumType | None = pydantic.PrivateAttr(
|
|
59
58
|
default=None,
|
|
60
59
|
)
|
|
61
60
|
|
|
@@ -2,7 +2,6 @@ from collections.abc import Iterable, Mapping, Sequence
|
|
|
2
2
|
from itertools import chain
|
|
3
3
|
from typing import (
|
|
4
4
|
Literal,
|
|
5
|
-
Optional,
|
|
6
5
|
Union,
|
|
7
6
|
)
|
|
8
7
|
|
|
@@ -41,14 +40,12 @@ ArgValue = Union[
|
|
|
41
40
|
class QuantumFunctionCall(QuantumOperation):
|
|
42
41
|
kind: Literal["QuantumFunctionCall"]
|
|
43
42
|
|
|
44
|
-
function:
|
|
43
|
+
function: str | OperandIdentifier = pydantic.Field(
|
|
45
44
|
description="The function that is called"
|
|
46
45
|
)
|
|
47
46
|
positional_args: list[ArgValue] = pydantic.Field(default_factory=list)
|
|
48
47
|
|
|
49
|
-
_func_decl:
|
|
50
|
-
default=None
|
|
51
|
-
)
|
|
48
|
+
_func_decl: QuantumFunctionDeclaration | None = pydantic.PrivateAttr(default=None)
|
|
52
49
|
|
|
53
50
|
def _as_back_ref(self: ASTNodeType) -> ASTNodeType:
|
|
54
51
|
return reset_lists(self, ["positional_args"])
|
|
@@ -60,7 +57,7 @@ class QuantumFunctionCall(QuantumOperation):
|
|
|
60
57
|
|
|
61
58
|
return self._func_decl
|
|
62
59
|
|
|
63
|
-
def set_func_decl(self, fd:
|
|
60
|
+
def set_func_decl(self, fd: QuantumFunctionDeclaration | None) -> None:
|
|
64
61
|
if fd is not None and not isinstance(fd, QuantumFunctionDeclaration):
|
|
65
62
|
raise ClassiqValueError(
|
|
66
63
|
"the declaration of a quantum function call cannot be set to a non-quantum function declaration."
|
|
@@ -61,6 +61,7 @@ class AnonQuantumFunctionDeclaration(FunctionDeclaration):
|
|
|
61
61
|
positional_arg_declarations: Sequence[AnonPositionalArg] = pydantic.Field(
|
|
62
62
|
default_factory=list
|
|
63
63
|
)
|
|
64
|
+
permutation: bool = pydantic.Field(default=False)
|
|
64
65
|
|
|
65
66
|
@property
|
|
66
67
|
def port_declarations(self) -> Sequence[AnonPortDeclaration]:
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from typing import TYPE_CHECKING, Union
|
|
2
3
|
|
|
3
4
|
import pydantic
|
|
4
5
|
|
|
5
6
|
from classiq.interface.ast_node import ASTNode
|
|
6
7
|
from classiq.interface.exceptions import ClassiqError
|
|
7
8
|
from classiq.interface.generator.expressions.expression import Expression
|
|
8
|
-
from classiq.interface.helpers.backward_compatibility import zip_strict
|
|
9
9
|
from classiq.interface.model.quantum_function_declaration import (
|
|
10
10
|
AnonQuantumOperandDeclaration,
|
|
11
11
|
)
|
|
@@ -28,7 +28,7 @@ class QuantumLambdaFunction(ASTNode):
|
|
|
28
28
|
description="A list of function calls passed to the operator"
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
_func_decl:
|
|
31
|
+
_func_decl: AnonQuantumOperandDeclaration | None = pydantic.PrivateAttr(
|
|
32
32
|
default=None
|
|
33
33
|
)
|
|
34
34
|
|
|
@@ -57,7 +57,7 @@ class QuantumLambdaFunction(ASTNode):
|
|
|
57
57
|
def named_func_decl(self) -> AnonQuantumOperandDeclaration:
|
|
58
58
|
named_params = [
|
|
59
59
|
param.rename(rename)
|
|
60
|
-
for param, rename in
|
|
60
|
+
for param, rename in zip(
|
|
61
61
|
self.func_decl.positional_arg_declarations,
|
|
62
62
|
self.pos_rename_params,
|
|
63
63
|
strict=False, # strict=False enables lambda keyword args
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from collections.abc import Iterable, Mapping, Sequence
|
|
1
|
+
from collections.abc import Callable, Iterable, Mapping, Sequence
|
|
2
2
|
from dataclasses import dataclass
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any
|
|
4
4
|
from uuid import UUID, uuid4
|
|
5
5
|
|
|
6
6
|
import pydantic
|
|
@@ -27,7 +27,7 @@ class QuantumStatement(ASTNode):
|
|
|
27
27
|
def model_copy(
|
|
28
28
|
self,
|
|
29
29
|
*,
|
|
30
|
-
update:
|
|
30
|
+
update: Mapping[str, Any] | None = None,
|
|
31
31
|
deep: bool = False,
|
|
32
32
|
keep_uuid: bool = False,
|
|
33
33
|
) -> Self:
|
|
@@ -49,7 +49,7 @@ class QuantumStatement(ASTNode):
|
|
|
49
49
|
@dataclass
|
|
50
50
|
class HandleMetadata:
|
|
51
51
|
handle: HandleBinding
|
|
52
|
-
readable_location:
|
|
52
|
+
readable_location: str | None = None
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
class QuantumOperation(QuantumStatement):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Any, Literal
|
|
1
|
+
from typing import TYPE_CHECKING, Any, Literal
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
from pydantic import BaseModel, Field
|
|
@@ -23,7 +23,7 @@ if TYPE_CHECKING:
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
class QuantumType(HashableASTNode):
|
|
26
|
-
_size_in_bits:
|
|
26
|
+
_size_in_bits: int | None = pydantic.PrivateAttr(default=None)
|
|
27
27
|
|
|
28
28
|
def _update_size_in_bits_from_declaration(self) -> None:
|
|
29
29
|
pass
|
|
@@ -96,11 +96,11 @@ class QuantumScalar(QuantumType):
|
|
|
96
96
|
def fraction_digits_value(self) -> int:
|
|
97
97
|
raise NotImplementedError
|
|
98
98
|
|
|
99
|
-
def get_bounds(self) ->
|
|
99
|
+
def get_bounds(self) -> tuple[float, float] | None:
|
|
100
100
|
return None
|
|
101
101
|
|
|
102
102
|
def get_effective_bounds(
|
|
103
|
-
self, machine_precision:
|
|
103
|
+
self, machine_precision: int | None = None
|
|
104
104
|
) -> tuple[float, float]:
|
|
105
105
|
raise NotImplementedError
|
|
106
106
|
|
|
@@ -162,7 +162,7 @@ class QuantumBit(QuantumScalar):
|
|
|
162
162
|
return 0
|
|
163
163
|
|
|
164
164
|
def get_effective_bounds(
|
|
165
|
-
self, machine_precision:
|
|
165
|
+
self, machine_precision: int | None = None
|
|
166
166
|
) -> tuple[float, float]:
|
|
167
167
|
return (0, 1)
|
|
168
168
|
|
|
@@ -176,7 +176,7 @@ class QuantumBitvector(QuantumType):
|
|
|
176
176
|
discriminator="kind", default_factory=QuantumBit
|
|
177
177
|
)
|
|
178
178
|
kind: Literal["qvec"]
|
|
179
|
-
length:
|
|
179
|
+
length: Expression | None = Field(default=None)
|
|
180
180
|
|
|
181
181
|
@pydantic.model_validator(mode="before")
|
|
182
182
|
@classmethod
|
|
@@ -278,11 +278,11 @@ class QuantumBitvector(QuantumType):
|
|
|
278
278
|
class QuantumNumeric(QuantumScalar):
|
|
279
279
|
kind: Literal["qnum"]
|
|
280
280
|
|
|
281
|
-
size:
|
|
282
|
-
is_signed:
|
|
283
|
-
fraction_digits:
|
|
281
|
+
size: Expression | None = pydantic.Field(default=None)
|
|
282
|
+
is_signed: Expression | None = pydantic.Field(default=None)
|
|
283
|
+
fraction_digits: Expression | None = pydantic.Field(default=None)
|
|
284
284
|
|
|
285
|
-
_bounds:
|
|
285
|
+
_bounds: PydanticFloatTuple | None = pydantic.PrivateAttr(default=None)
|
|
286
286
|
|
|
287
287
|
@pydantic.model_validator(mode="before")
|
|
288
288
|
@classmethod
|
|
@@ -429,10 +429,10 @@ class QuantumNumeric(QuantumScalar):
|
|
|
429
429
|
exprs.append(self.fraction_digits)
|
|
430
430
|
return exprs
|
|
431
431
|
|
|
432
|
-
def get_bounds(self) ->
|
|
432
|
+
def get_bounds(self) -> tuple[float, float] | None:
|
|
433
433
|
return self._bounds
|
|
434
434
|
|
|
435
|
-
def set_bounds(self, bounds:
|
|
435
|
+
def set_bounds(self, bounds: tuple[float, float] | None) -> None:
|
|
436
436
|
self._bounds = bounds
|
|
437
437
|
|
|
438
438
|
def reset_bounds(self) -> None:
|
|
@@ -446,7 +446,7 @@ class QuantumNumeric(QuantumScalar):
|
|
|
446
446
|
)
|
|
447
447
|
|
|
448
448
|
def get_effective_bounds(
|
|
449
|
-
self, machine_precision:
|
|
449
|
+
self, machine_precision: int | None = None
|
|
450
450
|
) -> tuple[float, float]:
|
|
451
451
|
bounds = self.get_bounds() or self.get_maximal_bounds()
|
|
452
452
|
|
|
@@ -522,7 +522,7 @@ UNRESOLVED_SIZE = 1000
|
|
|
522
522
|
def quantum_var_to_register(name: str, qtype: QuantumType) -> RegisterUserInput:
|
|
523
523
|
signed: bool = False
|
|
524
524
|
fraction_places: int = 0
|
|
525
|
-
bounds:
|
|
525
|
+
bounds: tuple[float, float] | None = None
|
|
526
526
|
if isinstance(qtype, QuantumNumeric):
|
|
527
527
|
signed = qtype.sign_value
|
|
528
528
|
fraction_places = qtype.fraction_digits_value
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import dataclasses
|
|
2
2
|
from collections.abc import Mapping
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import Optional
|
|
5
4
|
|
|
6
5
|
from classiq.interface.exceptions import ClassiqError
|
|
7
6
|
from classiq.interface.model.handle_binding import HandleBinding
|
|
@@ -27,8 +26,8 @@ class ValidationHandle:
|
|
|
27
26
|
|
|
28
27
|
def __init__(
|
|
29
28
|
self,
|
|
30
|
-
initial_state:
|
|
31
|
-
errors:
|
|
29
|
+
initial_state: HandleState | None = None,
|
|
30
|
+
errors: list[str] | None = None,
|
|
32
31
|
) -> None:
|
|
33
32
|
if initial_state is None and not errors:
|
|
34
33
|
raise ClassiqError("Missing initial state for ValidationHandle")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any, Literal
|
|
1
|
+
from typing import Any, Literal
|
|
2
2
|
|
|
3
3
|
import pydantic
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ class VariableDeclarationStatement(QuantumStatement):
|
|
|
15
15
|
kind: Literal["VariableDeclarationStatement"]
|
|
16
16
|
|
|
17
17
|
name: str
|
|
18
|
-
quantum_type:
|
|
18
|
+
quantum_type: ConcreteQuantumType | None = None
|
|
19
19
|
qmod_type: ConcreteType
|
|
20
20
|
|
|
21
21
|
@pydantic.model_validator(mode="before")
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import ast
|
|
2
2
|
import re
|
|
3
|
-
from collections.abc import Mapping
|
|
3
|
+
from collections.abc import Callable, Mapping
|
|
4
4
|
from dataclasses import dataclass
|
|
5
|
-
from typing import Callable, Optional
|
|
6
5
|
|
|
7
6
|
import numpy as np
|
|
8
7
|
|
|
@@ -47,7 +46,7 @@ class PrettyPrinterError(AssertionError):
|
|
|
47
46
|
@dataclass
|
|
48
47
|
class ASTToQMODCode:
|
|
49
48
|
level: int
|
|
50
|
-
decimal_precision:
|
|
49
|
+
decimal_precision: int | None
|
|
51
50
|
indent_seq: str = " "
|
|
52
51
|
|
|
53
52
|
@property
|
|
@@ -197,7 +196,7 @@ def _remove_redundant_parentheses(expr: str) -> str:
|
|
|
197
196
|
def transform_expression(
|
|
198
197
|
expr: str,
|
|
199
198
|
level: int = 0,
|
|
200
|
-
decimal_precision:
|
|
199
|
+
decimal_precision: int | None = DEFAULT_DECIMAL_PRECISION,
|
|
201
200
|
) -> str:
|
|
202
201
|
return ASTToQMODCode(level=level, decimal_precision=decimal_precision).visit(
|
|
203
202
|
ast.parse(expr)
|