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,9 +1,7 @@
|
|
1
|
+
from collections.abc import Collection
|
1
2
|
from functools import reduce
|
2
3
|
from typing import (
|
3
4
|
Any,
|
4
|
-
Collection,
|
5
|
-
Dict,
|
6
|
-
List,
|
7
5
|
Optional,
|
8
6
|
Union,
|
9
7
|
cast,
|
@@ -108,7 +106,7 @@ class PauliOperator(HashablePydanticBaseModel, VersionedModel):
|
|
108
106
|
|
109
107
|
@pydantic.model_validator(mode="before")
|
110
108
|
@classmethod
|
111
|
-
def _validate_hermitianity(cls, values:
|
109
|
+
def _validate_hermitianity(cls, values: dict[str, Any]) -> dict[str, Any]:
|
112
110
|
pauli_list = values.get("pauli_list", [])
|
113
111
|
if PauliOperator.check_if_hermitian(pauli_list):
|
114
112
|
values["is_hermitian"] = all(
|
@@ -153,7 +151,7 @@ class PauliOperator(HashablePydanticBaseModel, VersionedModel):
|
|
153
151
|
)
|
154
152
|
|
155
153
|
@staticmethod
|
156
|
-
def _is_sub_pauli_commutative(qubit_pauli_string: Union[
|
154
|
+
def _is_sub_pauli_commutative(qubit_pauli_string: Union[list[str], str]) -> bool:
|
157
155
|
unique_paulis = set(qubit_pauli_string) - {"I"}
|
158
156
|
return len(unique_paulis) <= 1
|
159
157
|
|
@@ -241,8 +239,8 @@ class PauliOperator(HashablePydanticBaseModel, VersionedModel):
|
|
241
239
|
@classmethod
|
242
240
|
def from_unzipped_lists(
|
243
241
|
cls,
|
244
|
-
operators:
|
245
|
-
coefficients: Optional[
|
242
|
+
operators: list[list["Pauli"]],
|
243
|
+
coefficients: Optional[list[complex]] = None,
|
246
244
|
) -> "PauliOperator":
|
247
245
|
if coefficients is None:
|
248
246
|
coefficients = [1] * len(operators)
|
@@ -316,7 +314,7 @@ class PauliOperatorV1(HashablePydanticBaseModel):
|
|
316
314
|
|
317
315
|
@pydantic.model_validator(mode="before")
|
318
316
|
@classmethod
|
319
|
-
def _validate_hermitianity(cls, v:
|
317
|
+
def _validate_hermitianity(cls, v: dict[str, Any]) -> dict[str, Any]:
|
320
318
|
pauli_list = cast(PydanticPauliList, v.get("pauli_list"))
|
321
319
|
if all(isinstance(summand[1], complex) for summand in pauli_list):
|
322
320
|
v["is_hermitian"] = all(
|
@@ -361,7 +359,7 @@ class PauliOperatorV1(HashablePydanticBaseModel):
|
|
361
359
|
)
|
362
360
|
|
363
361
|
@staticmethod
|
364
|
-
def _is_sub_pauli_commutative(qubit_pauli_string: Union[
|
362
|
+
def _is_sub_pauli_commutative(qubit_pauli_string: Union[list[str], str]) -> bool:
|
365
363
|
unique_paulis = set(qubit_pauli_string) - {"I"}
|
366
364
|
return len(unique_paulis) <= 1
|
367
365
|
|
@@ -445,8 +443,8 @@ class PauliOperatorV1(HashablePydanticBaseModel):
|
|
445
443
|
@classmethod
|
446
444
|
def from_unzipped_lists(
|
447
445
|
cls,
|
448
|
-
operators:
|
449
|
-
coefficients: Optional[
|
446
|
+
operators: list[list["Pauli"]],
|
447
|
+
coefficients: Optional[list[complex]] = None,
|
450
448
|
) -> "PauliOperatorV1":
|
451
449
|
if coefficients is None:
|
452
450
|
coefficients = [1] * len(operators)
|
@@ -505,9 +503,9 @@ def validate_operator_has_no_complex_coefficients(
|
|
505
503
|
return pauli_operator
|
506
504
|
|
507
505
|
|
508
|
-
def pauli_integers_to_str(paulis:
|
506
|
+
def pauli_integers_to_str(paulis: list[Pauli]) -> str:
|
509
507
|
return "".join([Pauli(pauli).name for pauli in paulis])
|
510
508
|
|
511
509
|
|
512
510
|
class PauliOperators(VersionedModel):
|
513
|
-
operators:
|
511
|
+
operators: list[PauliOperator]
|
@@ -1,10 +1,8 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
1
|
import numpy as np
|
4
2
|
import pyomo.core as pyo
|
5
3
|
|
6
4
|
|
7
|
-
def ascending_sequence(coeffs:
|
5
|
+
def ascending_sequence(coeffs: list[int], bound: int) -> pyo.ConcreteModel:
|
8
6
|
model = pyo.ConcreteModel()
|
9
7
|
model.x = pyo.Var(
|
10
8
|
range(len(coeffs)), domain=pyo.NonNegativeIntegers, bounds=(0, bound)
|
@@ -1,16 +1,14 @@
|
|
1
|
-
from typing import List, Tuple
|
2
|
-
|
3
1
|
import numpy as np
|
4
2
|
import pyomo.core as pyo
|
5
3
|
|
6
4
|
|
7
5
|
def integer_portfolio_optimization(
|
8
|
-
covariances: np.ndarray, returns: np.ndarray, upper_bounds:
|
6
|
+
covariances: np.ndarray, returns: np.ndarray, upper_bounds: list[int]
|
9
7
|
) -> pyo.ConcreteModel:
|
10
8
|
model = pyo.ConcreteModel()
|
11
9
|
num_assets = len(returns)
|
12
10
|
|
13
|
-
def bounds(model: pyo.ConcreteModel, i: int) ->
|
11
|
+
def bounds(model: pyo.ConcreteModel, i: int) -> tuple[int, int]:
|
14
12
|
return 0, upper_bounds[i]
|
15
13
|
|
16
14
|
model.x = pyo.Var(range(num_assets), domain=pyo.NonNegativeIntegers, bounds=bounds)
|
@@ -1,13 +1,13 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Optional
|
2
2
|
|
3
3
|
import numpy as np
|
4
4
|
import pyomo.core as pyo
|
5
5
|
|
6
6
|
|
7
7
|
def knapsack(
|
8
|
-
values:
|
8
|
+
values: list[int],
|
9
9
|
upper_bound: int,
|
10
|
-
weights: Optional[
|
10
|
+
weights: Optional[list[int]] = None,
|
11
11
|
max_weight: Optional[int] = None,
|
12
12
|
) -> pyo.ConcreteModel:
|
13
13
|
model = pyo.ConcreteModel()
|
@@ -1,13 +1,12 @@
|
|
1
1
|
import math
|
2
|
-
from typing import Dict, Tuple
|
3
2
|
|
4
3
|
import networkx as nx
|
5
4
|
import pyomo.core as pyo
|
6
5
|
import pyomo.core.expr.numeric_expr as pyo_expr
|
7
6
|
|
8
7
|
Node = int
|
9
|
-
Edge =
|
10
|
-
Pubo =
|
8
|
+
Edge = tuple[Node, Node]
|
9
|
+
Pubo = dict[tuple[Edge, ...], float]
|
11
10
|
|
12
11
|
|
13
12
|
def build_mht_pyomo_model(
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import itertools
|
2
|
-
from typing import List
|
3
2
|
|
4
3
|
import pyomo.core as pyo
|
5
4
|
import pyomo.core.expr.numeric_expr as pyo_expr
|
6
5
|
|
7
6
|
|
8
|
-
def set_cover(sub_sets:
|
7
|
+
def set_cover(sub_sets: list[list[int]]) -> pyo.ConcreteModel:
|
9
8
|
entire_set = set(itertools.chain(*sub_sets))
|
10
9
|
n = max(entire_set)
|
11
10
|
num_sets = len(sub_sets)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
1
|
import more_itertools
|
4
2
|
import numpy as np
|
5
3
|
import pydantic
|
@@ -24,7 +22,7 @@ class MhtQaoaInput(BaseModel):
|
|
24
22
|
reps: pydantic.PositiveInt = pydantic.Field(
|
25
23
|
default=3, description="Number of QAOA layers."
|
26
24
|
)
|
27
|
-
plot_list:
|
25
|
+
plot_list: list[PlotData] = pydantic.Field(
|
28
26
|
description="The list of (x,y,t) plots of the MHT problem."
|
29
27
|
)
|
30
28
|
misdetection_maximum_time_steps: pydantic.NonNegativeInt = pydantic.Field(
|
@@ -56,8 +54,8 @@ class MhtQaoaInput(BaseModel):
|
|
56
54
|
@pydantic.field_validator("plot_list")
|
57
55
|
@classmethod
|
58
56
|
def round_plot_list_times_and_validate(
|
59
|
-
cls, plot_list:
|
60
|
-
) ->
|
57
|
+
cls, plot_list: list[PlotData]
|
58
|
+
) -> list[PlotData]:
|
61
59
|
MhtQaoaInput._check_all_ids_are_distinct(plot_list)
|
62
60
|
MhtQaoaInput._round_to_tolerance_decimals(plot_list)
|
63
61
|
|
@@ -75,11 +73,11 @@ class MhtQaoaInput(BaseModel):
|
|
75
73
|
return plot_list
|
76
74
|
|
77
75
|
@staticmethod
|
78
|
-
def _round_to_tolerance_decimals(plot_list:
|
76
|
+
def _round_to_tolerance_decimals(plot_list: list[PlotData]) -> None:
|
79
77
|
for plot in plot_list:
|
80
78
|
plot.t = np.round(plot.t, decimals=_TOLERANCE_DECIMALS)
|
81
79
|
|
82
80
|
@staticmethod
|
83
|
-
def _check_all_ids_are_distinct(plot_list:
|
81
|
+
def _check_all_ids_are_distinct(plot_list: list[PlotData]) -> None:
|
84
82
|
if not more_itertools.all_unique(plot.plot_id for plot in plot_list):
|
85
83
|
raise ClassiqValueError("Plot IDs should be unique.")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import Any
|
1
|
+
from typing import Any
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import BaseModel
|
@@ -14,4 +14,4 @@ class MaxCutProblem(BaseModel):
|
|
14
14
|
default_factory=CombinatorialOptimizer,
|
15
15
|
description="preferences for the VQE execution",
|
16
16
|
)
|
17
|
-
serialized_graph:
|
17
|
+
serialized_graph: dict[str, Any]
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import json
|
2
|
-
from
|
2
|
+
from collections.abc import Mapping
|
3
|
+
from typing import Any, Optional, Union
|
3
4
|
from uuid import UUID
|
4
5
|
|
5
6
|
from pydantic import BaseModel, Field
|
6
7
|
|
7
8
|
from classiq.interface.generator.generated_circuit_data import (
|
8
9
|
FunctionDebugInfoInterface,
|
10
|
+
OperationLevel,
|
9
11
|
)
|
10
|
-
from classiq.interface.ide.visual_model import OperationLevel
|
11
12
|
|
12
13
|
ParameterValue = Union[float, int, str, None]
|
13
14
|
|
@@ -15,11 +16,11 @@ ParameterValue = Union[float, int, str, None]
|
|
15
16
|
class FunctionDebugInfo(BaseModel):
|
16
17
|
name: str
|
17
18
|
# Parameters describe classical parameters passed to function
|
18
|
-
parameters:
|
19
|
+
parameters: dict[str, str]
|
19
20
|
level: OperationLevel
|
20
21
|
is_allocate_or_free: bool = Field(default=False)
|
21
22
|
is_inverse: bool = Field(default=False)
|
22
|
-
port_to_passed_variable_map:
|
23
|
+
port_to_passed_variable_map: dict[str, str] = Field(default_factory=dict)
|
23
24
|
|
24
25
|
@staticmethod
|
25
26
|
def param_controller(value: Any) -> str:
|
@@ -38,7 +39,7 @@ class FunctionDebugInfo(BaseModel):
|
|
38
39
|
self.port_to_passed_variable_map = new_port_to_passed_variable_map
|
39
40
|
|
40
41
|
def update_map_from_inout_port_mapping(
|
41
|
-
self, port_mapping: Mapping[str,
|
42
|
+
self, port_mapping: Mapping[str, tuple[str, str]]
|
42
43
|
) -> None:
|
43
44
|
new_port_to_passed_variable_map = self.port_to_passed_variable_map.copy()
|
44
45
|
for old_key, (new_key1, new_key2) in port_mapping.items():
|
@@ -53,8 +54,8 @@ class DebugInfoCollection(BaseModel):
|
|
53
54
|
# Pydantic only started supporting UUID as keys in Pydantic V2
|
54
55
|
# See https://github.com/pydantic/pydantic/issues/2096#issuecomment-814860206
|
55
56
|
# For now, we use strings as keys in the raw data and use UUID in the wrapper logic
|
56
|
-
data:
|
57
|
-
blackbox_data:
|
57
|
+
data: dict[str, FunctionDebugInfo] = Field(default={})
|
58
|
+
blackbox_data: dict[str, FunctionDebugInfoInterface] = Field(default={})
|
58
59
|
|
59
60
|
def __setitem__(self, key: UUID, value: FunctionDebugInfo) -> None:
|
60
61
|
self.data[str(key)] = value
|
classiq/interface/exceptions.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import logging
|
2
|
-
from
|
2
|
+
from collections.abc import Iterable
|
3
|
+
from typing import Optional
|
3
4
|
|
4
5
|
_logger = logging.getLogger(__name__)
|
5
6
|
|
@@ -26,7 +27,7 @@ class ClassiqExecutionError(ClassiqError):
|
|
26
27
|
|
27
28
|
|
28
29
|
class ClassiqMissingOutputFormatError(ClassiqError):
|
29
|
-
def __init__(self, missing_formats:
|
30
|
+
def __init__(self, missing_formats: list[str]) -> None:
|
30
31
|
msg = (
|
31
32
|
f"Cannot create program because output format is missing. "
|
32
33
|
f"Expected one of the following formats: {missing_formats}"
|
@@ -146,7 +147,7 @@ class ClassiqCombOptNoSolutionError(ClassiqError):
|
|
146
147
|
|
147
148
|
class ClassiqCombOptTrivialProblemError(ClassiqError):
|
148
149
|
|
149
|
-
def __init__(self, solution:
|
150
|
+
def __init__(self, solution: list[int]) -> None:
|
150
151
|
super().__init__(
|
151
152
|
message=f"The problem doesn't have free decision variables. "
|
152
153
|
f"The trivial solution is {solution}."
|
@@ -190,9 +191,10 @@ class ClassiqExpansionError(ClassiqError):
|
|
190
191
|
|
191
192
|
class ClassiqInternalError(ClassiqError):
|
192
193
|
def __init__(self, message: Optional[str] = None) -> None:
|
193
|
-
|
194
|
-
|
195
|
-
|
194
|
+
final_message = "Internal error occurred. Please contact Classiq support."
|
195
|
+
if message is not None:
|
196
|
+
final_message += f"\nError: {message}"
|
197
|
+
super().__init__(final_message)
|
196
198
|
|
197
199
|
|
198
200
|
class ClassiqInternalExpansionError(ClassiqInternalError):
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from datetime import datetime
|
2
|
-
from typing import
|
2
|
+
from typing import Optional
|
3
3
|
|
4
4
|
from pydantic import BaseModel
|
5
5
|
|
@@ -25,4 +25,4 @@ class ExecutionJobDetailsV1(BaseModel, extra="ignore"):
|
|
25
25
|
|
26
26
|
|
27
27
|
class ExecutionJobsQueryResultsV1(BaseModel, extra="ignore"):
|
28
|
-
results:
|
28
|
+
results: list[ExecutionJobDetailsV1]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Optional
|
2
2
|
|
3
3
|
from pydantic import BaseModel, Field
|
4
4
|
|
@@ -9,9 +9,9 @@ from classiq.interface.helpers.custom_encoders import CUSTOM_ENCODERS
|
|
9
9
|
|
10
10
|
class EstimateInput(BaseModel, json_encoders=CUSTOM_ENCODERS):
|
11
11
|
hamiltonian: PauliOperator
|
12
|
-
parameters:
|
12
|
+
parameters: list[Arguments]
|
13
13
|
|
14
14
|
|
15
15
|
class PrimitivesInput(BaseModel, json_encoders=CUSTOM_ENCODERS):
|
16
|
-
sample: Optional[
|
16
|
+
sample: Optional[list[Arguments]] = Field(default=None)
|
17
17
|
estimate: Optional[EstimateInput] = Field(default=None)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import datetime
|
2
2
|
from datetime import date
|
3
|
-
from typing import Any,
|
3
|
+
from typing import Any, Optional, Union
|
4
4
|
|
5
5
|
import pydantic
|
6
6
|
from pydantic import BaseModel, ConfigDict, Field
|
@@ -52,7 +52,7 @@ class ExecutionCostForTimePeriod(BaseModel):
|
|
52
52
|
raise ValueError('"end" date should be after "start" date')
|
53
53
|
return v
|
54
54
|
|
55
|
-
def dict(self, **kwargs: Any) ->
|
55
|
+
def dict(self, **kwargs: Any) -> dict[str, Any]:
|
56
56
|
data = super().model_dump(**kwargs)
|
57
57
|
data["start"] = self.start.strftime("%Y-%m-%d")
|
58
58
|
data["end"] = self.end.strftime("%Y-%m-%d")
|
@@ -80,11 +80,11 @@ class Total(pydantic.BaseModel):
|
|
80
80
|
class ExecutedTaskForPeriodItem(pydantic.BaseModel):
|
81
81
|
TimePeriod: TimePeriod
|
82
82
|
Total: Total
|
83
|
-
Groups: Optional[
|
83
|
+
Groups: Optional[list] = None
|
84
84
|
Estimated: Optional[bool] = None
|
85
85
|
|
86
86
|
model_config = ConfigDict(extra="forbid")
|
87
87
|
|
88
88
|
|
89
89
|
class ExecutionCostForTimePeriodResponse(pydantic.BaseModel):
|
90
|
-
executed_task_for_period:
|
90
|
+
executed_task_for_period: list[ExecutedTaskForPeriodItem]
|
@@ -1,9 +1,8 @@
|
|
1
1
|
from datetime import datetime
|
2
|
-
from typing import
|
2
|
+
from typing import Annotated, Literal, Optional, Union
|
3
3
|
|
4
4
|
import pydantic
|
5
5
|
from pydantic import BaseModel, Field
|
6
|
-
from typing_extensions import Annotated
|
7
6
|
|
8
7
|
from classiq.interface.executor.estimation import OperatorsEstimation
|
9
8
|
from classiq.interface.executor.execution_preferences import ExecutionPreferences
|
@@ -63,4 +62,4 @@ class ExecutionJobDetails(VersionedModel):
|
|
63
62
|
|
64
63
|
|
65
64
|
class ExecutionJobsQueryResults(VersionedModel):
|
66
|
-
results:
|
65
|
+
results: list[ExecutionJobDetails]
|
@@ -1,7 +1,7 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Annotated, Any, Literal, Union
|
2
2
|
|
3
3
|
from pydantic import BaseModel, ConfigDict, Field
|
4
|
-
from typing_extensions import
|
4
|
+
from typing_extensions import TypeAlias
|
5
5
|
|
6
6
|
from classiq.interface.enum_utils import StrEnum
|
7
7
|
from classiq.interface.executor.iqae_result import IQAEResult
|
@@ -104,7 +104,7 @@ SavedResult = Annotated[
|
|
104
104
|
Field(..., discriminator="value_type"),
|
105
105
|
]
|
106
106
|
|
107
|
-
ResultsCollection: TypeAlias =
|
107
|
+
ResultsCollection: TypeAlias = list[SavedResult]
|
108
108
|
|
109
109
|
|
110
110
|
class ExecuteGeneratedCircuitResults(VersionedModel):
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
1
|
from pydantic import BaseModel, Field
|
4
2
|
|
5
3
|
from classiq.interface.executor.result import ExecutionDetails
|
@@ -14,6 +12,6 @@ class IQAEIterationData(BaseModel):
|
|
14
12
|
|
15
13
|
class IQAEResult(VersionedModel, QmodPyObject):
|
16
14
|
estimation: float
|
17
|
-
confidence_interval:
|
18
|
-
iterations_data:
|
19
|
-
warnings:
|
15
|
+
confidence_interval: list[float] = Field(min_length=2, max_length=2)
|
16
|
+
iterations_data: list[IQAEIterationData]
|
17
|
+
warnings: list[str]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from typing import
|
1
|
+
from typing import Optional
|
2
2
|
|
3
3
|
import pydantic
|
4
4
|
from pydantic import BaseModel
|
@@ -45,7 +45,7 @@ class OptimizerPreferences(BaseModel):
|
|
45
45
|
default=None,
|
46
46
|
description="The random seed used for the generation",
|
47
47
|
)
|
48
|
-
initial_point: Optional[
|
48
|
+
initial_point: Optional[list[float]] = pydantic.Field(
|
49
49
|
default=None,
|
50
50
|
description="Initial values for the ansatz parameters",
|
51
51
|
)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
from pathlib import Path
|
4
|
-
from typing import Any,
|
4
|
+
from typing import Any, Optional, Union
|
5
5
|
|
6
6
|
import pydantic
|
7
7
|
from pydantic import BaseModel, ConfigDict
|
@@ -16,12 +16,12 @@ from classiq.interface.generator.synthesis_metadata.synthesis_execution_data imp
|
|
16
16
|
ExecutionData,
|
17
17
|
)
|
18
18
|
|
19
|
-
Arguments =
|
20
|
-
MultipleArguments =
|
19
|
+
Arguments = dict[PydanticArgumentNameType, Any]
|
20
|
+
MultipleArguments = tuple[Arguments, ...]
|
21
21
|
CodeType = str
|
22
|
-
RegistersInitialization =
|
23
|
-
Qubits =
|
24
|
-
OutputQubitsMap =
|
22
|
+
RegistersInitialization = dict[str, RegisterInitialization]
|
23
|
+
Qubits = tuple[int, ...]
|
24
|
+
OutputQubitsMap = dict[str, Qubits]
|
25
25
|
|
26
26
|
|
27
27
|
class QuantumBaseCode(BaseModel):
|
@@ -1,5 +1,3 @@
|
|
1
|
-
from typing import List
|
2
|
-
|
3
1
|
import pydantic
|
4
2
|
from typing_extensions import Self
|
5
3
|
|
@@ -13,7 +11,7 @@ _NON_INTEGER_INITIALIZATION_ERROR_MSG: str = (
|
|
13
11
|
|
14
12
|
class RegisterInitialization(pydantic.BaseModel):
|
15
13
|
name: str
|
16
|
-
qubits:
|
14
|
+
qubits: list[int]
|
17
15
|
initial_condition: pydantic.NonNegativeInt
|
18
16
|
|
19
17
|
@pydantic.field_validator("initial_condition", mode="before")
|
@@ -25,7 +23,7 @@ class RegisterInitialization(pydantic.BaseModel):
|
|
25
23
|
|
26
24
|
@pydantic.model_validator(mode="after")
|
27
25
|
def _validate_register_initialization(self) -> Self:
|
28
|
-
qubits:
|
26
|
+
qubits: list[int] = self.qubits or []
|
29
27
|
initial_condition: int = self.initial_condition or 0
|
30
28
|
name: str = self.name or ""
|
31
29
|
|