classiq 0.53.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 +8 -8
- classiq/_internals/async_utils.py +1 -3
- classiq/_internals/authentication/auth0.py +5 -5
- classiq/_internals/authentication/device.py +5 -4
- classiq/_internals/authentication/password_manager.py +3 -3
- classiq/_internals/authentication/token_manager.py +3 -2
- classiq/_internals/client.py +10 -12
- classiq/_internals/config.py +2 -2
- classiq/_internals/jobs.py +7 -6
- classiq/_internals/type_validation.py +9 -9
- classiq/analyzer/__init__.py +1 -3
- classiq/analyzer/analyzer.py +8 -7
- classiq/analyzer/analyzer_utilities.py +8 -8
- classiq/analyzer/rb.py +11 -11
- classiq/applications/__init__.py +1 -3
- classiq/applications/chemistry/__init__.py +1 -3
- classiq/applications/chemistry/ansatz_parameters.py +4 -4
- classiq/applications/chemistry/chemistry_model_constructor.py +10 -9
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +26 -9
- classiq/applications/combinatorial_helpers/encoding_mapping.py +10 -10
- classiq/applications/combinatorial_helpers/encoding_utils.py +4 -4
- classiq/applications/combinatorial_helpers/memory.py +5 -7
- classiq/applications/combinatorial_helpers/optimization_model.py +43 -24
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +4 -6
- classiq/applications/combinatorial_helpers/pyomo_utils.py +95 -24
- classiq/applications/combinatorial_helpers/sympy_utils.py +2 -2
- classiq/applications/combinatorial_helpers/transformations/encoding.py +8 -8
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -5
- classiq/applications/combinatorial_helpers/transformations/ising_converter.py +7 -9
- classiq/applications/combinatorial_helpers/transformations/penalty.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -2
- classiq/applications/combinatorial_helpers/transformations/slack_variables.py +1 -2
- classiq/applications/combinatorial_optimization/__init__.py +1 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
- classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
- classiq/applications/finance/__init__.py +1 -3
- classiq/applications/grover/__init__.py +1 -3
- classiq/applications/grover/grover_model_constructor.py +7 -9
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -6
- classiq/applications/qnn/__init__.py +1 -3
- classiq/applications/qnn/circuit_utils.py +5 -5
- classiq/applications/qnn/datasets/__init__.py +1 -3
- classiq/applications/qnn/datasets/dataset_base_classes.py +5 -4
- classiq/applications/qnn/datasets/dataset_parity.py +2 -2
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
- classiq/applications/qnn/qlayer.py +3 -3
- classiq/applications/qnn/torch_utils.py +2 -2
- classiq/applications/qnn/types.py +5 -5
- classiq/applications/qsvm/qsvm.py +1 -3
- classiq/applications/qsvm/qsvm_data_generation.py +3 -3
- classiq/applications/qsvm/qsvm_model_constructor.py +5 -5
- classiq/execution/__init__.py +1 -3
- classiq/execution/all_hardware_devices.py +1 -3
- classiq/execution/execution_session.py +16 -16
- classiq/execution/jobs.py +4 -4
- classiq/execution/qaoa.py +3 -3
- classiq/execution/qnn.py +3 -3
- classiq/executor.py +3 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +9 -10
- classiq/interface/analyzer/cytoscape_graph.py +5 -5
- classiq/interface/analyzer/result.py +17 -17
- classiq/interface/applications/qsvm.py +6 -10
- classiq/interface/backend/backend_preferences.py +4 -3
- classiq/interface/backend/ionq/ionq_quantum_program.py +4 -5
- classiq/interface/backend/pydantic_backend.py +1 -2
- classiq/interface/chemistry/fermionic_operator.py +5 -5
- classiq/interface/chemistry/ground_state_problem.py +7 -8
- classiq/interface/chemistry/molecule.py +4 -4
- classiq/interface/chemistry/operator.py +11 -13
- classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -3
- classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
- classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
- classiq/interface/combinatorial_optimization/examples/mht.py +2 -3
- classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
- classiq/interface/combinatorial_optimization/examples/set_cover.py +1 -2
- classiq/interface/combinatorial_optimization/mht_qaoa_input.py +5 -7
- classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
- classiq/interface/combinatorial_optimization/result.py +1 -3
- classiq/interface/debug_info/debug_info.py +8 -7
- classiq/interface/exceptions.py +8 -6
- classiq/interface/execution/jobs.py +2 -2
- classiq/interface/execution/primitives.py +3 -3
- classiq/interface/executor/aws_execution_cost.py +4 -4
- classiq/interface/executor/execution_request.py +2 -3
- classiq/interface/executor/execution_result.py +3 -3
- classiq/interface/executor/iqae_result.py +3 -5
- classiq/interface/executor/optimizer_preferences.py +2 -2
- classiq/interface/executor/quantum_code.py +6 -6
- classiq/interface/executor/register_initialization.py +2 -4
- classiq/interface/executor/result.py +23 -27
- classiq/interface/executor/vqe_result.py +8 -8
- classiq/interface/finance/function_input.py +2 -2
- classiq/interface/finance/gaussian_model_input.py +5 -5
- classiq/interface/finance/log_normal_model_input.py +2 -2
- classiq/interface/finance/model_input.py +1 -2
- classiq/interface/generator/adjacency.py +1 -3
- classiq/interface/generator/ansatz_library.py +4 -4
- classiq/interface/generator/application_apis/finance_declarations.py +1 -1
- classiq/interface/generator/arith/argument_utils.py +3 -3
- classiq/interface/generator/arith/arithmetic.py +7 -7
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +5 -5
- classiq/interface/generator/arith/arithmetic_expression_abc.py +11 -11
- classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -7
- classiq/interface/generator/arith/arithmetic_expression_validator.py +8 -8
- classiq/interface/generator/arith/arithmetic_operations.py +4 -3
- classiq/interface/generator/arith/arithmetic_param_getters.py +6 -6
- classiq/interface/generator/arith/arithmetic_result_builder.py +9 -9
- classiq/interface/generator/arith/ast_node_rewrite.py +2 -1
- classiq/interface/generator/arith/binary_ops.py +10 -13
- classiq/interface/generator/arith/extremum_operations.py +3 -2
- classiq/interface/generator/arith/logical_ops.py +7 -6
- classiq/interface/generator/arith/number_utils.py +4 -4
- classiq/interface/generator/arith/register_user_input.py +4 -4
- classiq/interface/generator/arith/unary_ops.py +2 -1
- classiq/interface/generator/builtin_api_builder.py +2 -1
- classiq/interface/generator/circuit_code/circuit_code.py +4 -4
- classiq/interface/generator/circuit_code/types_and_constants.py +3 -5
- classiq/interface/generator/complex_type.py +1 -2
- classiq/interface/generator/control_state.py +2 -2
- classiq/interface/generator/custom_ansatz.py +1 -3
- classiq/interface/generator/distance.py +3 -5
- classiq/interface/generator/excitations.py +3 -2
- classiq/interface/generator/expressions/enums/finance_functions.py +1 -3
- classiq/interface/generator/expressions/evaluated_expression.py +4 -3
- classiq/interface/generator/expressions/expression.py +4 -5
- classiq/interface/generator/expressions/expression_constants.py +4 -4
- classiq/interface/generator/expressions/qmod_qarray_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_qstruct_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_sized_proxy.py +2 -1
- classiq/interface/generator/expressions/qmod_struct_instance.py +2 -1
- classiq/interface/generator/expressions/sympy_supported_expressions.py +11 -13
- classiq/interface/generator/finance.py +2 -2
- classiq/interface/generator/function_param_library.py +6 -6
- classiq/interface/generator/function_params.py +13 -19
- classiq/interface/generator/functions/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/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 +20 -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/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 +160 -35
- 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/builtins/classical_execution_primitives.py +9 -9
- classiq/qmod/builtins/functions/__init__.py +72 -55
- classiq/qmod/builtins/functions/amplitude_estimation.py +4 -1
- classiq/qmod/builtins/functions/arithmetic.py +14 -1
- classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +86 -6
- classiq/qmod/builtins/functions/grover.py +41 -45
- classiq/qmod/builtins/functions/hea.py +60 -4
- classiq/qmod/builtins/functions/linear_pauli_rotation.py +26 -4
- classiq/qmod/builtins/functions/modular_exponentiation.py +90 -29
- classiq/qmod/builtins/functions/operators.py +1 -1
- classiq/qmod/builtins/functions/qaoa_penalty.py +14 -5
- classiq/qmod/builtins/functions/qft_functions.py +57 -0
- classiq/qmod/builtins/functions/qpe.py +20 -4
- classiq/qmod/builtins/functions/qsvt.py +49 -4
- classiq/qmod/builtins/functions/standard_gates.py +4 -4
- classiq/qmod/builtins/functions/state_preparation.py +92 -10
- classiq/qmod/builtins/functions/swap_test.py +7 -1
- classiq/qmod/builtins/functions/utility_functions.py +43 -0
- classiq/qmod/builtins/functions/variational.py +18 -2
- classiq/qmod/builtins/operations.py +4 -5
- classiq/qmod/cfunc.py +2 -2
- classiq/qmod/classical_function.py +3 -7
- classiq/qmod/create_model_function.py +7 -6
- 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_variable.py +11 -10
- classiq/qmod/quantum_expandable.py +12 -15
- classiq/qmod/quantum_function.py +10 -3
- 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-0.53.0.dist-info → classiq-0.54.0.dist-info}/METADATA +1 -1
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/RECORD +295 -292
- classiq/qmod/builtins/functions/qft.py +0 -23
- {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/WHEEL +0 -0
@@ -1,7 +1,7 @@
|
|
1
1
|
import uuid
|
2
2
|
from datetime import datetime, timezone
|
3
3
|
from pathlib import Path
|
4
|
-
from typing import
|
4
|
+
from typing import Optional, Union
|
5
5
|
|
6
6
|
import pydantic
|
7
7
|
from typing_extensions import TypeAlias
|
@@ -31,17 +31,17 @@ from classiq.interface.generator.synthesis_metadata.synthesis_duration import (
|
|
31
31
|
SynthesisStepDurations,
|
32
32
|
)
|
33
33
|
from classiq.interface.helpers.versioned_model import VersionedModel
|
34
|
-
from classiq.interface.ide.
|
34
|
+
from classiq.interface.ide.visual_model import CircuitMetrics
|
35
35
|
|
36
36
|
RegisterName: TypeAlias = str
|
37
|
-
InitialConditions: TypeAlias =
|
37
|
+
InitialConditions: TypeAlias = dict[RegisterName, int]
|
38
38
|
|
39
39
|
|
40
40
|
class TranspiledCircuitData(CircuitCodeInterface):
|
41
41
|
depth: int
|
42
|
-
count_ops:
|
43
|
-
logical_to_physical_input_qubit_map:
|
44
|
-
logical_to_physical_output_qubit_map:
|
42
|
+
count_ops: dict[str, int]
|
43
|
+
logical_to_physical_input_qubit_map: list[int]
|
44
|
+
logical_to_physical_output_qubit_map: list[int]
|
45
45
|
|
46
46
|
def get_circuit_metrics(self) -> CircuitMetrics:
|
47
47
|
return CircuitMetrics(depth=self.depth, count_ops=self.count_ops)
|
@@ -65,7 +65,7 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
|
|
65
65
|
transpiled_circuit: Optional[TranspiledCircuitData] = pydantic.Field(default=None)
|
66
66
|
creation_time: str = pydantic.Field(default_factory=_get_formatted_utc_current_time)
|
67
67
|
synthesis_duration: Optional[SynthesisStepDurations] = pydantic.Field(default=None)
|
68
|
-
debug_info: Optional[
|
68
|
+
debug_info: Optional[list[FunctionDebugInfoInterface]] = pydantic.Field(
|
69
69
|
default=None
|
70
70
|
)
|
71
71
|
program_id: str = pydantic.Field(default_factory=get_uuid_as_str)
|
@@ -123,7 +123,7 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
|
|
123
123
|
synthesis_execution_data=self.data.execution_data,
|
124
124
|
)
|
125
125
|
|
126
|
-
def _get_initialization_qubits(self, name: str) ->
|
126
|
+
def _get_initialization_qubits(self, name: str) -> tuple[int, ...]:
|
127
127
|
qubits = self.data.qubit_mapping.logical_inputs.get(name)
|
128
128
|
if qubits is None:
|
129
129
|
raise ClassiqStateInitializationError(
|
@@ -133,7 +133,7 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
|
|
133
133
|
|
134
134
|
def get_registers_initialization(
|
135
135
|
self, initial_values: InitialConditions
|
136
|
-
) ->
|
136
|
+
) -> dict[RegisterName, RegisterInitialization]:
|
137
137
|
return {
|
138
138
|
name: RegisterInitialization(
|
139
139
|
name=name,
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import Set
|
2
|
-
|
3
1
|
from classiq.interface.enum_utils import StrEnum
|
4
2
|
|
5
3
|
|
@@ -13,7 +11,7 @@ class RegisterRole(StrEnum):
|
|
13
11
|
EXPLICIT_ZERO_INPUT = "explicit_zero_input"
|
14
12
|
|
15
13
|
@staticmethod
|
16
|
-
def output_roles(include_garbage: bool = False) ->
|
14
|
+
def output_roles(include_garbage: bool = False) -> set["RegisterRole"]:
|
17
15
|
roles = {
|
18
16
|
RegisterRole.OUTPUT,
|
19
17
|
RegisterRole.ZERO_OUTPUT,
|
@@ -24,7 +22,7 @@ class RegisterRole(StrEnum):
|
|
24
22
|
return roles
|
25
23
|
|
26
24
|
@staticmethod
|
27
|
-
def input_roles() ->
|
25
|
+
def input_roles() -> set["RegisterRole"]:
|
28
26
|
return {
|
29
27
|
RegisterRole.INPUT,
|
30
28
|
RegisterRole.ZERO_INPUT,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import re
|
2
|
-
from
|
2
|
+
from re import Match
|
3
|
+
from typing import Optional
|
3
4
|
|
4
5
|
from classiq.interface.exceptions import ClassiqValueError
|
5
6
|
from classiq.interface.generator.function_params import NAME_REGEX
|
@@ -11,12 +12,12 @@ SLICING_CHARS = rf"[0-9\-{SEPARATOR}]+"
|
|
11
12
|
IO_REGEX = rf"(?P<{NAME}>{NAME_REGEX})(\[(?P<{SLICING}>{SLICING_CHARS})\])?"
|
12
13
|
|
13
14
|
|
14
|
-
def parse_io_slicing(io_str: str) ->
|
15
|
+
def parse_io_slicing(io_str: str) -> tuple[str, slice]:
|
15
16
|
name, slicing = separate_name_and_slice(io_str)
|
16
17
|
return name, get_slice(slicing)
|
17
18
|
|
18
19
|
|
19
|
-
def separate_name_and_slice(io_str: str) ->
|
20
|
+
def separate_name_and_slice(io_str: str) -> tuple[str, Optional[str]]:
|
20
21
|
match: Optional[Match] = re.fullmatch(IO_REGEX, io_str)
|
21
22
|
if match is None:
|
22
23
|
raise AssertionError("Input/output name validation error")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any,
|
1
|
+
from typing import Any, Literal, Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
@@ -13,7 +13,7 @@ To add new standard gates, refer to the following guide
|
|
13
13
|
https://docs.google.com/document/d/1Nt9frxnPkSn8swNpOQ983E95eaEiDWaiuWAKglGtUAA/edit#heading=h.e9g9309bzkxt
|
14
14
|
"""
|
15
15
|
|
16
|
-
_POSSIBLE_PARAMETERS:
|
16
|
+
_POSSIBLE_PARAMETERS: list[str] = ["theta", "phi", "lam"]
|
17
17
|
DEFAULT_STANDARD_GATE_ARG_NAME: str = "TARGET"
|
18
18
|
|
19
19
|
|
@@ -39,7 +39,7 @@ class _StandardGate(FunctionParams, metaclass=MyMetaAngledClassModel): # type:
|
|
39
39
|
return self._num_target_qubits
|
40
40
|
|
41
41
|
def __init_subclass__(
|
42
|
-
cls, angles: Optional[
|
42
|
+
cls, angles: Optional[list[str]] = None, **kwargs: Any
|
43
43
|
) -> None:
|
44
44
|
super().__init_subclass__(**kwargs)
|
45
45
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Literal
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
|
@@ -7,8 +7,8 @@ from classiq.interface.generator.state_preparation.state_preparation_abc import
|
|
7
7
|
)
|
8
8
|
|
9
9
|
BellStateName = Literal["psi+", "psi-", "phi+", "phi-"]
|
10
|
-
_ALIGNED_STATES:
|
11
|
-
_SIGNED_STATES:
|
10
|
+
_ALIGNED_STATES: frozenset[BellStateName] = frozenset({"phi+", "phi-"})
|
11
|
+
_SIGNED_STATES: frozenset[BellStateName] = frozenset({"psi-", "phi-"})
|
12
12
|
|
13
13
|
|
14
14
|
class BellStatePreparation(StatePreparationABC):
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Collection, Sequence
|
2
|
+
from typing import Union
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
from numpy.typing import ArrayLike
|
@@ -11,12 +12,12 @@ from classiq.interface.helpers.custom_pydantic_types import PydanticProbabilityF
|
|
11
12
|
|
12
13
|
|
13
14
|
class PMF(pydantic.BaseModel):
|
14
|
-
pmf:
|
15
|
+
pmf: tuple[PydanticProbabilityFloat, ...]
|
15
16
|
|
16
17
|
@pydantic.field_validator("pmf")
|
17
18
|
@classmethod
|
18
19
|
def _validate_pmf(
|
19
|
-
cls, pmf:
|
20
|
+
cls, pmf: tuple[PydanticProbabilityFloat, ...]
|
20
21
|
) -> Sequence[PydanticProbabilityFloat]:
|
21
22
|
return validate_probabilities(cls, pmf)
|
22
23
|
|
@@ -30,7 +31,7 @@ class GaussianMoments(pydantic.BaseModel):
|
|
30
31
|
|
31
32
|
|
32
33
|
class GaussianMixture(pydantic.BaseModel):
|
33
|
-
gaussian_moment_list:
|
34
|
+
gaussian_moment_list: tuple[GaussianMoments, ...]
|
34
35
|
num_qubits: pydantic.PositiveInt = pydantic.Field(
|
35
36
|
description="Number of qubits for the provided state."
|
36
37
|
)
|
@@ -39,7 +40,7 @@ class GaussianMixture(pydantic.BaseModel):
|
|
39
40
|
|
40
41
|
Probabilities = Union[PMF, GaussianMixture]
|
41
42
|
FlexibleProbabilities = Union[Probabilities, ArrayLike, dict, Collection[float]]
|
42
|
-
Amplitudes =
|
43
|
+
Amplitudes = tuple[float, ...]
|
43
44
|
FlexibleAmplitudes = Union[ArrayLike, Collection[float]]
|
44
45
|
Distribution = Union[Amplitudes, Probabilities]
|
45
46
|
|
@@ -1,16 +1,14 @@
|
|
1
|
-
from typing import FrozenSet
|
2
|
-
|
3
1
|
from classiq.interface.enum_utils import StrEnum
|
4
2
|
from classiq.interface.exceptions import ClassiqValueError
|
5
3
|
from classiq.interface.generator.preferences.optimization import (
|
6
4
|
StatePrepOptimizationMethod,
|
7
5
|
)
|
8
6
|
|
9
|
-
_AMPLITUDE_SUPPORTING_METRICS:
|
7
|
+
_AMPLITUDE_SUPPORTING_METRICS: frozenset = frozenset(
|
10
8
|
{"L2", "L1", "MAX_PROBABILITY", "TOTAL_VARIATION"}
|
11
9
|
)
|
12
10
|
|
13
|
-
_ZERO_DIVERGENT_METRICS:
|
11
|
+
_ZERO_DIVERGENT_METRICS: frozenset = frozenset({"KL", "BHATTACHARYYA"})
|
14
12
|
|
15
13
|
|
16
14
|
class Metrics(StrEnum):
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Optional, Union
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import pydantic
|
@@ -36,7 +36,7 @@ class StatePreparation(StatePreparationABC):
|
|
36
36
|
default=None,
|
37
37
|
validate_default=True,
|
38
38
|
)
|
39
|
-
error_metric:
|
39
|
+
error_metric: dict[Metrics, NonNegativeFloatRange] = pydantic.Field(
|
40
40
|
default_factory=lambda: {
|
41
41
|
Metrics.L2: NonNegativeFloatRange(lower_bound=0, upper_bound=1e-4)
|
42
42
|
}
|
@@ -80,8 +80,8 @@ class StatePreparation(StatePreparationABC):
|
|
80
80
|
@pydantic.field_validator("error_metric", mode="before")
|
81
81
|
@classmethod
|
82
82
|
def _validate_error_metric(
|
83
|
-
cls, error_metric:
|
84
|
-
) ->
|
83
|
+
cls, error_metric: dict[Metrics, NonNegativeFloatRange], info: ValidationInfo
|
84
|
+
) -> dict[Metrics, NonNegativeFloatRange]:
|
85
85
|
if not info.data.get("amplitudes"):
|
86
86
|
return error_metric
|
87
87
|
unsupported_metrics = {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
import sympy
|
@@ -24,14 +24,14 @@ class FunctionExecutionData(pydantic.BaseModel):
|
|
24
24
|
|
25
25
|
|
26
26
|
class ExecutionData(pydantic.BaseModel):
|
27
|
-
function_execution:
|
27
|
+
function_execution: dict[str, FunctionExecutionData] = pydantic.Field(
|
28
28
|
default_factory=dict
|
29
29
|
)
|
30
30
|
|
31
31
|
@property
|
32
32
|
def execution_parameters(
|
33
33
|
self,
|
34
|
-
) ->
|
34
|
+
) -> set[PydanticExecutionParameter]:
|
35
35
|
return {
|
36
36
|
function_execution_data.power_var
|
37
37
|
for function_execution_data in self.function_execution.values()
|
@@ -1,10 +1,10 @@
|
|
1
|
-
from typing import TYPE_CHECKING,
|
1
|
+
from typing import TYPE_CHECKING, Optional
|
2
2
|
|
3
3
|
from typing_extensions import TypeAlias
|
4
4
|
|
5
5
|
from classiq.interface.enum_utils import StrEnum
|
6
6
|
|
7
|
-
BasisGates: TypeAlias =
|
7
|
+
BasisGates: TypeAlias = frozenset[str]
|
8
8
|
|
9
9
|
SINGLE_QUBIT_GATES: BasisGates = frozenset(
|
10
10
|
(
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from collections import Counter
|
2
2
|
from enum import Enum, EnumMeta, IntEnum
|
3
|
-
from typing import Dict
|
4
3
|
|
5
4
|
import pydantic
|
6
5
|
|
@@ -11,14 +10,14 @@ from classiq.interface.exceptions import ClassiqValueError
|
|
11
10
|
class EnumDeclaration(HashableASTNode):
|
12
11
|
name: str
|
13
12
|
|
14
|
-
members:
|
13
|
+
members: dict[str, int] = pydantic.Field(
|
15
14
|
default_factory=dict,
|
16
15
|
description="Dictionary of member names and their values",
|
17
16
|
)
|
18
17
|
|
19
18
|
@pydantic.field_validator("members")
|
20
19
|
@classmethod
|
21
|
-
def _validate_members(cls, members:
|
20
|
+
def _validate_members(cls, members: dict[str, int]) -> dict[str, int]:
|
22
21
|
underscore_members = [
|
23
22
|
member for member in members.keys() if member.startswith("_")
|
24
23
|
]
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Mapping
|
2
|
+
from typing import Any
|
2
3
|
|
3
4
|
import pydantic
|
4
5
|
|
@@ -10,7 +11,7 @@ from classiq.interface.generator.functions.concrete_types import ConcreteClassic
|
|
10
11
|
class StructDeclaration(HashableASTNode):
|
11
12
|
name: str
|
12
13
|
|
13
|
-
variables:
|
14
|
+
variables: dict[str, ConcreteClassicalType] = pydantic.Field(
|
14
15
|
default_factory=dict,
|
15
16
|
description="Dictionary of variable names and their classical types",
|
16
17
|
)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Union
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import pydantic
|
@@ -8,7 +8,7 @@ from classiq.interface.generator import complex_type, function_params
|
|
8
8
|
from classiq.interface.generator.arith.register_user_input import RegisterArithmeticInfo
|
9
9
|
|
10
10
|
DataNumber = Union[complex_type.Complex, float, int]
|
11
|
-
DataArray =
|
11
|
+
DataArray = list[list[DataNumber]]
|
12
12
|
|
13
13
|
UNITARY_GATE_INPUT: str = "TARGET"
|
14
14
|
UNITARY_GATE_OUTPUT: str = "TARGET"
|
@@ -1,7 +1,8 @@
|
|
1
1
|
from collections import Counter, defaultdict
|
2
|
+
from collections.abc import Collection, Iterable, Mapping
|
2
3
|
from dataclasses import dataclass
|
3
4
|
from itertools import chain
|
4
|
-
from typing import
|
5
|
+
from typing import Optional, TypeVar
|
5
6
|
|
6
7
|
import networkx as nx
|
7
8
|
|
@@ -152,7 +153,7 @@ def validate_legal_wiring(
|
|
152
153
|
raise ClassiqValueError(_join_errors(error_messages))
|
153
154
|
|
154
155
|
|
155
|
-
def _join_errors(error_messages:
|
156
|
+
def _join_errors(error_messages: list[str]) -> str:
|
156
157
|
if not error_messages:
|
157
158
|
error_messages.append(f"{UNKNOWN_ERROR_MSG}")
|
158
159
|
|
@@ -162,7 +163,7 @@ def _join_errors(error_messages: List[str]) -> str:
|
|
162
163
|
T = TypeVar("T")
|
163
164
|
|
164
165
|
|
165
|
-
def _recurring_names(name_list:
|
166
|
+
def _recurring_names(name_list: list[T]) -> Iterable[T]:
|
166
167
|
name_counter = Counter(name_list)
|
167
168
|
return (name for name, appearances in name_counter.items() if appearances > 1)
|
168
169
|
|
@@ -187,11 +188,11 @@ def validate_acyclic_logic_flow(
|
|
187
188
|
|
188
189
|
|
189
190
|
def validate_acyclicity_and_topologically_sort_logic_flow(
|
190
|
-
body:
|
191
|
+
body: list[SynthesisQuantumFunctionCall],
|
191
192
|
*,
|
192
193
|
flow_input_names: Collection[str],
|
193
194
|
flow_output_names: Collection[str],
|
194
|
-
) ->
|
195
|
+
) -> list[SynthesisQuantumFunctionCall]:
|
195
196
|
graph = validate_acyclic_logic_flow(
|
196
197
|
body=body,
|
197
198
|
flow_input_names=flow_input_names,
|
@@ -1,4 +1,5 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Iterable, Sequence, Sized
|
2
|
+
from typing import TypeVar
|
2
3
|
|
3
4
|
import numpy as np
|
4
5
|
|
@@ -9,7 +10,7 @@ NOT_SUM_TO_ONE_ERROR = "Probabilities do not sum to 1"
|
|
9
10
|
|
10
11
|
SUM_TO_ONE_SENSITIVITY = 8
|
11
12
|
|
12
|
-
Amplitude = TypeVar("Amplitude",
|
13
|
+
Amplitude = TypeVar("Amplitude", tuple[float, ...], list[complex])
|
13
14
|
|
14
15
|
|
15
16
|
def _is_power_of_two(vector: Sized) -> bool:
|
@@ -1,14 +1,9 @@
|
|
1
1
|
from collections import abc
|
2
|
+
from collections.abc import Collection, Mapping, Sequence
|
2
3
|
from typing import (
|
3
4
|
TYPE_CHECKING,
|
4
5
|
Any,
|
5
|
-
Collection,
|
6
|
-
Dict,
|
7
|
-
List,
|
8
|
-
Mapping,
|
9
6
|
Optional,
|
10
|
-
Sequence,
|
11
|
-
Tuple,
|
12
7
|
TypeVar,
|
13
8
|
Union,
|
14
9
|
)
|
@@ -21,7 +16,7 @@ NodeType = Union[
|
|
21
16
|
BaseModel,
|
22
17
|
int,
|
23
18
|
bool,
|
24
|
-
|
19
|
+
tuple["NodeType", ...],
|
25
20
|
Mapping[Key, "NodeType"],
|
26
21
|
Sequence["NodeType"],
|
27
22
|
]
|
@@ -47,19 +42,19 @@ class Visitor:
|
|
47
42
|
|
48
43
|
return node
|
49
44
|
|
50
|
-
def visit_list(self, node:
|
45
|
+
def visit_list(self, node: list[NodeType]) -> Optional[RetType]:
|
51
46
|
for elem in node:
|
52
47
|
self.visit(elem)
|
53
48
|
|
54
49
|
return None
|
55
50
|
|
56
|
-
def visit_dict(self, node:
|
51
|
+
def visit_dict(self, node: dict[Key, NodeType]) -> Optional[RetType]:
|
57
52
|
for value in node.values():
|
58
53
|
self.visit(value)
|
59
54
|
|
60
55
|
return None
|
61
56
|
|
62
|
-
def visit_tuple(self, node:
|
57
|
+
def visit_tuple(self, node: tuple[NodeType, ...]) -> Optional[tuple[RetType, ...]]:
|
63
58
|
for value in node:
|
64
59
|
self.visit(value)
|
65
60
|
|
@@ -83,13 +78,13 @@ class Transformer(Visitor):
|
|
83
78
|
|
84
79
|
def visit(self, node: NodeType) -> Any: ...
|
85
80
|
|
86
|
-
def visit_list(self, node:
|
81
|
+
def visit_list(self, node: list[NodeType]) -> list[RetType]:
|
87
82
|
return [self.visit(elem) for elem in node]
|
88
83
|
|
89
|
-
def visit_dict(self, node:
|
84
|
+
def visit_dict(self, node: dict[Key, NodeType]) -> dict[Key, RetType]:
|
90
85
|
return {key: self.visit(value) for key, value in node.items()}
|
91
86
|
|
92
|
-
def visit_tuple(self, node:
|
87
|
+
def visit_tuple(self, node: tuple[NodeType, ...]) -> tuple[RetType, ...]:
|
93
88
|
return tuple(self.visit(value) for value in node)
|
94
89
|
|
95
90
|
def visit_BaseModel(
|
@@ -97,7 +92,7 @@ class Transformer(Visitor):
|
|
97
92
|
) -> RetType:
|
98
93
|
fields_to_skip = fields_to_skip or set()
|
99
94
|
|
100
|
-
result:
|
95
|
+
result: dict[str, Any] = dict()
|
101
96
|
for name, value in node:
|
102
97
|
if name not in fields_to_skip:
|
103
98
|
result[name] = self.visit(value)
|
classiq/interface/hardware.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import datetime
|
2
|
-
from typing import TYPE_CHECKING,
|
2
|
+
from typing import TYPE_CHECKING, Annotated, Optional
|
3
3
|
|
4
4
|
import pydantic
|
5
|
-
from typing_extensions import Annotated
|
6
5
|
|
7
6
|
from classiq.interface.enum_utils import StrEnum
|
8
7
|
|
@@ -75,9 +74,9 @@ class HardwareStatus(pydantic.BaseModel):
|
|
75
74
|
|
76
75
|
|
77
76
|
if TYPE_CHECKING:
|
78
|
-
ConnectivityMapEntry =
|
77
|
+
ConnectivityMapEntry = tuple[int, int]
|
79
78
|
else:
|
80
|
-
ConnectivityMapEntry =
|
79
|
+
ConnectivityMapEntry = list[int]
|
81
80
|
|
82
81
|
|
83
82
|
class HardwareInformation(pydantic.BaseModel):
|
@@ -87,8 +86,8 @@ class HardwareInformation(pydantic.BaseModel):
|
|
87
86
|
display_name: str
|
88
87
|
device_type: DeviceType
|
89
88
|
number_of_qubits: int
|
90
|
-
connectivity_map: Optional[
|
91
|
-
basis_gates:
|
89
|
+
connectivity_map: Optional[list[ConnectivityMapEntry]] = None
|
90
|
+
basis_gates: list[str]
|
92
91
|
status: HardwareStatus
|
93
92
|
|
94
93
|
def is_simulator(self) -> bool:
|
@@ -1,3 +1,3 @@
|
|
1
|
-
from typing import Any, Callable
|
1
|
+
from typing import Any, Callable
|
2
2
|
|
3
|
-
CUSTOM_ENCODERS:
|
3
|
+
CUSTOM_ENCODERS: dict[type, Callable[[Any], Any]] = {complex: str}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
from typing import TYPE_CHECKING,
|
1
|
+
from typing import TYPE_CHECKING, Annotated, Any
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import Field, StrictStr, StringConstraints
|
5
|
-
from typing_extensions import Annotated
|
6
5
|
|
7
6
|
from classiq.interface.generator.arith.number_utils import MAXIMAL_MACHINE_PRECISION
|
8
7
|
from classiq.interface.generator.parameters import ParameterComplexType
|
@@ -57,7 +56,7 @@ else:
|
|
57
56
|
if TYPE_CHECKING:
|
58
57
|
PydanticPauliMonomial = tuple
|
59
58
|
else:
|
60
|
-
PydanticPauliMonomial = Annotated[
|
59
|
+
PydanticPauliMonomial = Annotated[list[Any], Field(min_length=2, max_length=2)]
|
61
60
|
|
62
61
|
if TYPE_CHECKING:
|
63
62
|
PydanticPauliMonomialStr = str
|
@@ -68,16 +67,16 @@ else:
|
|
68
67
|
]
|
69
68
|
|
70
69
|
PydanticPauliList = Annotated[
|
71
|
-
|
70
|
+
list[tuple[PydanticPauliMonomialStr, ParameterComplexType]], Field(min_length=1)
|
72
71
|
]
|
73
72
|
|
74
73
|
if TYPE_CHECKING:
|
75
|
-
PydanticFloatTuple =
|
74
|
+
PydanticFloatTuple = tuple[float, float]
|
76
75
|
else:
|
77
|
-
PydanticFloatTuple = Annotated[
|
76
|
+
PydanticFloatTuple = Annotated[list[float], Field(min_length=2, max_length=2)]
|
78
77
|
|
79
78
|
PydanticNonNegIntTuple = Annotated[
|
80
|
-
|
79
|
+
list[pydantic.NonNegativeInt], Field(min_length=2, max_length=2)
|
81
80
|
]
|
82
81
|
|
83
82
|
if TYPE_CHECKING:
|
@@ -90,9 +89,9 @@ else:
|
|
90
89
|
),
|
91
90
|
]
|
92
91
|
if TYPE_CHECKING:
|
93
|
-
AtomType =
|
92
|
+
AtomType = tuple[str, list[float]]
|
94
93
|
else:
|
95
|
-
AtomType = Annotated[
|
94
|
+
AtomType = Annotated[list[Any], Field(min_length=2, max_length=2)]
|
96
95
|
|
97
96
|
|
98
97
|
if TYPE_CHECKING:
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import itertools
|
2
2
|
import numbers
|
3
|
+
from collections.abc import Iterator
|
3
4
|
from enum import EnumMeta
|
4
|
-
from typing import Any
|
5
|
+
from typing import Any
|
5
6
|
|
6
7
|
|
7
8
|
def immutable_version(value: Any) -> Any:
|
@@ -29,5 +30,5 @@ class HashableMixin:
|
|
29
30
|
for val in self._values_to_hash():
|
30
31
|
yield immutable_version(val)
|
31
32
|
|
32
|
-
def _value_tuple(self) ->
|
33
|
+
def _value_tuple(self) -> tuple[Any, ...]:
|
33
34
|
return tuple(itertools.chain((str(type(self))), self._immutable_fields()))
|
@@ -1,9 +1,10 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Sequence
|
2
|
+
from typing import Any, Protocol, TypeVar
|
2
3
|
|
3
4
|
|
4
5
|
def values_with_discriminator(
|
5
6
|
values: Any, discriminator: str, discriminator_value: Any
|
6
|
-
) ->
|
7
|
+
) -> dict[str, Any]:
|
7
8
|
if isinstance(values, dict):
|
8
9
|
values.setdefault(discriminator, discriminator_value)
|
9
10
|
return values
|
@@ -16,5 +17,5 @@ class Nameable(Protocol):
|
|
16
17
|
NameableType = TypeVar("NameableType", bound=Nameable)
|
17
18
|
|
18
19
|
|
19
|
-
def nameables_to_dict(nameables: Sequence[NameableType]) ->
|
20
|
+
def nameables_to_dict(nameables: Sequence[NameableType]) -> dict[str, NameableType]:
|
20
21
|
return {value.name: value for value in nameables}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
from
|
1
|
+
from collections.abc import Hashable, Mapping
|
2
2
|
|
3
3
|
from classiq.interface.exceptions import ClassiqValueError
|
4
4
|
from classiq.interface.helpers.pydantic_model_helpers import Nameable
|
5
5
|
|
6
6
|
|
7
|
-
def is_list_unique(lst:
|
7
|
+
def is_list_unique(lst: list[Hashable]) -> bool:
|
8
8
|
return len(set(lst)) == len(lst)
|
9
9
|
|
10
10
|
|