classiq 0.93.0__py3-none-any.whl → 0.99.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 +11 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +31 -142
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +41 -15
- classiq/_internals/authentication/authorization_code.py +9 -0
- classiq/_internals/authentication/authorization_flow.py +41 -0
- classiq/_internals/authentication/device.py +33 -52
- classiq/_internals/authentication/hybrid_flow.py +19 -0
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +9 -9
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +19 -5
- 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/analyzer/show_interactive_hack.py +1 -1
- classiq/applications/__init__.py +2 -2
- 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 +14 -11
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
- classiq/applications/qnn/qlayer.py +9 -8
- classiq/applications/qnn/torch_utils.py +5 -6
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/__init__.py +20 -2
- classiq/applications/qsp/qsp.py +238 -10
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +10 -8
- classiq/evaluators/qmod_annotated_expression.py +31 -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/binary_op_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -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/__init__.py +0 -3
- classiq/execution/execution_session.py +28 -21
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +71 -37
- 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/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +26 -50
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/backend/provider_config/__init__.py +0 -0
- classiq/interface/backend/provider_config/provider_config.py +8 -0
- classiq/interface/backend/provider_config/providers/__init__.py +0 -0
- classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
- classiq/interface/backend/provider_config/providers/aqt.py +16 -0
- classiq/interface/backend/provider_config/providers/azure.py +37 -0
- classiq/interface/backend/provider_config/providers/braket.py +39 -0
- classiq/interface/backend/provider_config/providers/ibm.py +26 -0
- classiq/interface/backend/provider_config/providers/ionq.py +22 -0
- classiq/interface/backend/quantum_backend_providers.py +20 -2
- 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 +8 -7
- classiq/interface/exceptions.py +6 -7
- 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 +25 -17
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -3
- 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 +15 -40
- 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 +3 -3
- 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 -40
- 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 -15
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +14 -18
- 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 +9 -9
- 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/quantum_function_call.py +9 -12
- classiq/interface/generator/quantum_program.py +10 -23
- 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/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +12 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
- 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 -3
- 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 +6 -5
- classiq/interface/interface_version.py +1 -1
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +6 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/classical_if.py +4 -0
- classiq/interface/model/control.py +8 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/invert.py +4 -0
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/model_visitor.py +40 -1
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/power.py +4 -0
- 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 +11 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/repeat.py +4 -0
- classiq/interface/model/skip_control.py +4 -0
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/model/within_apply_operation.py +4 -0
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -16
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +11 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +30 -27
- 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 +7 -12
- classiq/model_expansions/interpreters/base_interpreter.py +3 -7
- classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
- 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 +6 -6
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +28 -11
- classiq/open_library/functions/amplitude_loading.py +81 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/lcu.py +47 -18
- classiq/open_library/functions/modular_exponentiation.py +93 -8
- classiq/open_library/functions/qsvt.py +66 -79
- classiq/open_library/functions/qsvt_temp.py +536 -0
- classiq/open_library/functions/state_preparation.py +130 -27
- classiq/qmod/__init__.py +6 -4
- classiq/qmod/builtins/classical_execution_primitives.py +4 -23
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +15 -153
- classiq/qmod/builtins/functions/__init__.py +9 -18
- classiq/qmod/builtins/functions/allocation.py +25 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/exponentiation.py +51 -2
- classiq/qmod/builtins/functions/mcx_func.py +7 -0
- classiq/qmod/builtins/functions/standard_gates.py +46 -27
- classiq/qmod/builtins/operations.py +165 -79
- classiq/qmod/builtins/structs.py +24 -91
- 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/expression_query.py +7 -4
- 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 +124 -19
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -46
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +31 -26
- classiq/qmod/quantum_function.py +84 -36
- classiq/qmod/semantics/annotation/call_annotation.py +5 -5
- classiq/qmod/semantics/error_manager.py +12 -14
- 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 -20
- 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.99.0.dist-info}/METADATA +2 -3
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/RECORD +271 -299
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/WHEEL +1 -1
- 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/applications/qsvm/__init__.py +0 -8
- classiq/applications/qsvm/qsvm.py +0 -11
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/execution/iqcc.py +0 -128
- classiq/interface/applications/qsvm.py +0 -117
- 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/execution/iqcc.py +0 -44
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
- 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/hamiltonian_evolution/qdrift.py +0 -27
- 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/qsvm.py +0 -96
- classiq/interface/generator/state_preparation/__init__.py +0 -14
- classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
- classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
- classiq/interface/generator/state_preparation/distributions.py +0 -53
- classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
- classiq/interface/generator/state_preparation/metrics.py +0 -41
- classiq/interface/generator/state_preparation/state_preparation.py +0 -113
- classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
- classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
- classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
- 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/open_library/functions/lookup_table.py +0 -58
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq/qmod/builtins/functions/qsvm.py +0 -24
- {classiq-0.93.0.dist-info → classiq-0.99.0.dist-info}/licenses/LICENSE.txt +0 -0
classiq/_internals/jobs.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import logging
|
|
3
|
-
from collections.abc import Iterable
|
|
4
|
-
from typing import
|
|
3
|
+
from collections.abc import Callable, Iterable
|
|
4
|
+
from typing import TypeVar
|
|
5
5
|
|
|
6
6
|
import httpx
|
|
7
7
|
import pydantic
|
|
@@ -37,7 +37,7 @@ def _join_url_path(*parts: str) -> str:
|
|
|
37
37
|
|
|
38
38
|
def _general_job_description_parser(
|
|
39
39
|
json_response: JSONObject,
|
|
40
|
-
) ->
|
|
40
|
+
) -> GeneralJobDescription | None:
|
|
41
41
|
job_description = GeneralJobDescription.model_validate(json_response)
|
|
42
42
|
if job_description.status.is_final():
|
|
43
43
|
return job_description
|
|
@@ -54,7 +54,7 @@ class JobPoller:
|
|
|
54
54
|
self,
|
|
55
55
|
base_url: str,
|
|
56
56
|
use_versioned_url: bool = True,
|
|
57
|
-
additional_headers:
|
|
57
|
+
additional_headers: dict[str, str] | None = None,
|
|
58
58
|
) -> None:
|
|
59
59
|
self._additional_headers = additional_headers
|
|
60
60
|
client_instance = client()
|
|
@@ -80,7 +80,7 @@ class JobPoller:
|
|
|
80
80
|
http_client: httpx.AsyncClient,
|
|
81
81
|
http_method: str,
|
|
82
82
|
url: str,
|
|
83
|
-
body:
|
|
83
|
+
body: dict | None = None,
|
|
84
84
|
) -> httpx.Response:
|
|
85
85
|
return await client().request(
|
|
86
86
|
http_client=http_client,
|
|
@@ -111,8 +111,8 @@ class JobPoller:
|
|
|
111
111
|
self,
|
|
112
112
|
http_client: httpx.AsyncClient,
|
|
113
113
|
poll_url: str,
|
|
114
|
-
timeout_sec:
|
|
115
|
-
response_parser: Callable[[JSONObject],
|
|
114
|
+
timeout_sec: float | None,
|
|
115
|
+
response_parser: Callable[[JSONObject], T | None] = _general_job_description_parser, # type: ignore[assignment]
|
|
116
116
|
) -> T:
|
|
117
117
|
async def poller() -> JSONObject:
|
|
118
118
|
nonlocal self, poll_url
|
|
@@ -132,9 +132,9 @@ class JobPoller:
|
|
|
132
132
|
async def poll(
|
|
133
133
|
self,
|
|
134
134
|
job_id: JobID,
|
|
135
|
-
timeout_sec:
|
|
136
|
-
response_parser: Callable[[JSONObject],
|
|
137
|
-
http_client:
|
|
135
|
+
timeout_sec: float | None,
|
|
136
|
+
response_parser: Callable[[JSONObject], T | None] = _general_job_description_parser, # type: ignore[assignment]
|
|
137
|
+
http_client: httpx.AsyncClient | None = None,
|
|
138
138
|
) -> T:
|
|
139
139
|
poll_url = self._make_poll_url(job_id=job_id)
|
|
140
140
|
async with client().use_client_or_create(http_client) as async_client:
|
|
@@ -153,8 +153,8 @@ class JobPoller:
|
|
|
153
153
|
async def run(
|
|
154
154
|
self,
|
|
155
155
|
body: dict,
|
|
156
|
-
timeout_sec:
|
|
157
|
-
http_client:
|
|
156
|
+
timeout_sec: float | None,
|
|
157
|
+
http_client: httpx.AsyncClient | None = None,
|
|
158
158
|
) -> GeneralJobDescription:
|
|
159
159
|
async with client().use_client_or_create(http_client) as async_client:
|
|
160
160
|
submit_response = await self._submit(http_client=async_client, body=body)
|
|
@@ -173,8 +173,8 @@ class JobPoller:
|
|
|
173
173
|
async def run_pydantic(
|
|
174
174
|
self,
|
|
175
175
|
model: pydantic.BaseModel,
|
|
176
|
-
timeout_sec:
|
|
177
|
-
http_client:
|
|
176
|
+
timeout_sec: float | None,
|
|
177
|
+
http_client: httpx.AsyncClient | None = None,
|
|
178
178
|
) -> GeneralJobDescription:
|
|
179
179
|
# TODO: we can't use model.dict() - it doesn't serialize complex class.
|
|
180
180
|
# This was added because JSON serializer doesn't serialize complex and UUID,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any, TypeVar,
|
|
1
|
+
from typing import Any, TypeVar, overload
|
|
2
2
|
|
|
3
3
|
T = TypeVar("T")
|
|
4
4
|
U = TypeVar("U")
|
|
@@ -20,7 +20,7 @@ def validate_type(
|
|
|
20
20
|
expected_type: tuple[type[T], type[U]],
|
|
21
21
|
operation: str,
|
|
22
22
|
exception_type: type[Exception],
|
|
23
|
-
) ->
|
|
23
|
+
) -> T | U: ...
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
@overload
|
|
@@ -34,7 +34,7 @@ def validate_type(
|
|
|
34
34
|
|
|
35
35
|
def validate_type(
|
|
36
36
|
obj: Any,
|
|
37
|
-
expected_type:
|
|
37
|
+
expected_type: tuple[type, ...] | type,
|
|
38
38
|
operation: str,
|
|
39
39
|
exception_type: type[Exception],
|
|
40
40
|
) -> Any:
|
classiq/analyzer/analyzer.py
CHANGED
|
@@ -4,9 +4,7 @@ import json
|
|
|
4
4
|
import webbrowser
|
|
5
5
|
from collections.abc import Sequence
|
|
6
6
|
from importlib.util import find_spec
|
|
7
|
-
from typing import
|
|
8
|
-
|
|
9
|
-
import plotly.graph_objects as go
|
|
7
|
+
from typing import TYPE_CHECKING, Optional
|
|
10
8
|
|
|
11
9
|
from classiq.interface.analyzer import analysis_params
|
|
12
10
|
from classiq.interface.backend.quantum_backend_providers import AnalyzerProviderVendor
|
|
@@ -21,12 +19,12 @@ from classiq.analyzer.analyzer_utilities import (
|
|
|
21
19
|
ProviderNameEnum,
|
|
22
20
|
)
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
import plotly.graph_objects as go
|
|
24
|
+
from ipywidgets import VBox # type: ignore[import]
|
|
26
25
|
|
|
26
|
+
find_ipywidgets = find_spec("ipywidgets")
|
|
27
27
|
if find_ipywidgets is not None:
|
|
28
|
-
from ipywidgets import VBox # type: ignore[import, no-redef]
|
|
29
|
-
|
|
30
28
|
from classiq._analyzer_extras.interactive_hardware import InteractiveHardware
|
|
31
29
|
|
|
32
30
|
|
|
@@ -53,7 +51,7 @@ class Analyzer(AnalyzerUtilities):
|
|
|
53
51
|
hardware_graphs=dict(),
|
|
54
52
|
)
|
|
55
53
|
|
|
56
|
-
self.hardware_comparison_table: Optional[go.Figure] = None
|
|
54
|
+
self.hardware_comparison_table: Optional["go.Figure"] = None
|
|
57
55
|
|
|
58
56
|
self.transpilation_params = analysis_params.AnalysisHardwareTranspilationParams(
|
|
59
57
|
hardware_data=self.circuit.hardware_data,
|
|
@@ -62,7 +60,7 @@ class Analyzer(AnalyzerUtilities):
|
|
|
62
60
|
)
|
|
63
61
|
|
|
64
62
|
def get_available_devices(
|
|
65
|
-
self, providers:
|
|
63
|
+
self, providers: list[ProviderNameEnum] | None = None
|
|
66
64
|
) -> dict[ProviderNameEnum, list[DeviceName]]:
|
|
67
65
|
"""Deprecated. Use get_all_hardware_devices instead.
|
|
68
66
|
|
|
@@ -85,9 +83,9 @@ class Analyzer(AnalyzerUtilities):
|
|
|
85
83
|
|
|
86
84
|
def plot_hardware_connectivity(
|
|
87
85
|
self,
|
|
88
|
-
provider:
|
|
89
|
-
device:
|
|
90
|
-
) -> VBox:
|
|
86
|
+
provider: ProviderNameEnum | None = None,
|
|
87
|
+
device: DeviceName | None = None,
|
|
88
|
+
) -> "VBox":
|
|
91
89
|
"""plot the hardware_connectivity graph. It is required to required install the
|
|
92
90
|
analyzer_sdk extra.
|
|
93
91
|
|
|
@@ -115,8 +113,8 @@ class Analyzer(AnalyzerUtilities):
|
|
|
115
113
|
|
|
116
114
|
def get_hardware_comparison_table(
|
|
117
115
|
self,
|
|
118
|
-
providers:
|
|
119
|
-
devices:
|
|
116
|
+
providers: Sequence[str | AnalyzerProviderVendor] | None = None,
|
|
117
|
+
devices: list[str] | None = None,
|
|
120
118
|
) -> None:
|
|
121
119
|
"""create a comparison table between the transpiled circuits result on different hardware.
|
|
122
120
|
The comparison table included the depth, multi qubit gates count,and total gates count of the circuits.
|
|
@@ -129,6 +127,8 @@ class Analyzer(AnalyzerUtilities):
|
|
|
129
127
|
Returns:
|
|
130
128
|
None.
|
|
131
129
|
"""
|
|
130
|
+
import plotly.graph_objects as go
|
|
131
|
+
|
|
132
132
|
if providers is None:
|
|
133
133
|
providers = list(AnalyzerProviderVendor)
|
|
134
134
|
params = analysis_params.AnalysisHardwareListParams(
|
|
@@ -142,8 +142,8 @@ class Analyzer(AnalyzerUtilities):
|
|
|
142
142
|
|
|
143
143
|
def plot_hardware_comparison_table(
|
|
144
144
|
self,
|
|
145
|
-
providers:
|
|
146
|
-
devices:
|
|
145
|
+
providers: list[str | AnalyzerProviderVendor] | None = None,
|
|
146
|
+
devices: list[str] | None = None,
|
|
147
147
|
) -> None:
|
|
148
148
|
"""plot the comparison table. if it has not been created it, it first creates the table using all the
|
|
149
149
|
available hardware.
|
|
@@ -156,8 +156,8 @@ class Analyzer(AnalyzerUtilities):
|
|
|
156
156
|
|
|
157
157
|
def _hardware_comparison_condition(
|
|
158
158
|
self,
|
|
159
|
-
providers:
|
|
160
|
-
devices:
|
|
159
|
+
providers: Sequence[str | AnalyzerProviderVendor] | None = None,
|
|
160
|
+
devices: list[str] | None = None,
|
|
161
161
|
) -> None:
|
|
162
162
|
if (
|
|
163
163
|
providers is not None
|
classiq/analyzer/rb.py
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
from enum import Enum as PythonEnum
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import TYPE_CHECKING, Optional
|
|
3
3
|
|
|
4
|
-
import matplotlib.pyplot as plt
|
|
5
4
|
import numpy as np
|
|
6
|
-
import pandas as pd
|
|
7
|
-
import plotly.graph_objects as go
|
|
8
5
|
|
|
9
6
|
from classiq.interface.analyzer.analysis_params import AnalysisRBParams
|
|
10
7
|
from classiq.interface.analyzer.result import RbResults
|
|
@@ -13,6 +10,11 @@ from classiq.interface.exceptions import ClassiqAnalyzerError
|
|
|
13
10
|
from classiq._internals.api_wrapper import ApiWrapper
|
|
14
11
|
from classiq.executor import BackendPreferencesAndResult
|
|
15
12
|
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
import matplotlib.pyplot as plt
|
|
15
|
+
import pandas as pd
|
|
16
|
+
import plotly.graph_objects as go
|
|
17
|
+
|
|
16
18
|
|
|
17
19
|
class RBAnalysis:
|
|
18
20
|
def __init__(self, experiments_data: list[AnalysisRBParams]) -> None:
|
|
@@ -21,6 +23,7 @@ class RBAnalysis:
|
|
|
21
23
|
Args:
|
|
22
24
|
experiments_data: List of results from varius RB experiments.
|
|
23
25
|
"""
|
|
26
|
+
import pandas as pd
|
|
24
27
|
|
|
25
28
|
self.experiments_data = experiments_data
|
|
26
29
|
self._total_results: pd.DataFrame = pd.DataFrame()
|
|
@@ -43,12 +46,14 @@ class RBAnalysis:
|
|
|
43
46
|
_, rb_result_keys = temp_res.popitem()
|
|
44
47
|
return list(rb_result_keys.__dict__.keys())
|
|
45
48
|
|
|
46
|
-
async def show_multiple_hardware_data_async(self) -> pd.DataFrame:
|
|
49
|
+
async def show_multiple_hardware_data_async(self) -> "pd.DataFrame":
|
|
47
50
|
"""Run the RB analysis.
|
|
48
51
|
|
|
49
52
|
Returns:
|
|
50
53
|
The RB result.
|
|
51
54
|
"""
|
|
55
|
+
import pandas as pd
|
|
56
|
+
|
|
52
57
|
results = await self._get_multiple_hardware_results_async()
|
|
53
58
|
indices = RBAnalysis._get_df_indices(results)
|
|
54
59
|
result_df = pd.DataFrame(index=indices)
|
|
@@ -57,12 +62,14 @@ class RBAnalysis:
|
|
|
57
62
|
self._total_results = result_df
|
|
58
63
|
return result_df
|
|
59
64
|
|
|
60
|
-
def plot_multiple_hardware_results(self) -> go.Figure:
|
|
65
|
+
def plot_multiple_hardware_results(self) -> "go.Figure":
|
|
61
66
|
"""Plot Bar graph of the results.
|
|
62
67
|
|
|
63
68
|
Returns:
|
|
64
69
|
None.
|
|
65
70
|
"""
|
|
71
|
+
import plotly.graph_objects as go
|
|
72
|
+
|
|
66
73
|
df = self._total_results.loc[["mean_fidelity", "average_error"]].transpose()
|
|
67
74
|
hardware = list(df.index)
|
|
68
75
|
params = list(df.columns)
|
|
@@ -78,7 +85,7 @@ class RBAnalysis:
|
|
|
78
85
|
return fig
|
|
79
86
|
|
|
80
87
|
|
|
81
|
-
def _strict_string(arg:
|
|
88
|
+
def _strict_string(arg: PythonEnum | str) -> str:
|
|
82
89
|
if isinstance(arg, PythonEnum):
|
|
83
90
|
return arg.value
|
|
84
91
|
return arg
|
|
@@ -110,8 +117,10 @@ def order_executor_data_by_hardware(
|
|
|
110
117
|
|
|
111
118
|
|
|
112
119
|
def fit_to_exponential_function(
|
|
113
|
-
result: RbResults, num_clifford: list[int], ax: Optional[plt.Axes] = None
|
|
120
|
+
result: RbResults, num_clifford: list[int], ax: Optional["plt.Axes"] = None
|
|
114
121
|
) -> None:
|
|
122
|
+
import matplotlib.pyplot as plt
|
|
123
|
+
|
|
115
124
|
if ax is None:
|
|
116
125
|
plt.figure()
|
|
117
126
|
ax = plt.gca()
|
|
@@ -122,7 +122,7 @@ async def handle_remote_app(circuit: QuantumProgram, display_url: bool = True) -
|
|
|
122
122
|
"for QASM programs. Try adding QASM to the output formats "
|
|
123
123
|
"synthesis preferences"
|
|
124
124
|
)
|
|
125
|
-
circuit_dataid =
|
|
125
|
+
circuit_dataid = DataID(id=circuit.program_id)
|
|
126
126
|
|
|
127
127
|
renderer = get_visualization_renderer()
|
|
128
128
|
if display_url:
|
classiq/applications/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from classiq.applications import chemistry, combinatorial_optimization, qsp
|
|
1
|
+
from classiq.applications import chemistry, combinatorial_optimization, qsp
|
|
2
2
|
|
|
3
|
-
__all__ = ["chemistry", "combinatorial_optimization", "qsp"
|
|
3
|
+
__all__ = ["chemistry", "combinatorial_optimization", "qsp"]
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
_NON_IMPORTED_PUBLIC_SUBMODULES = ["qnn"]
|
|
@@ -1,38 +1,8 @@
|
|
|
1
|
-
from classiq.interface.chemistry.fermionic_operator import (
|
|
2
|
-
FermionicOperator,
|
|
3
|
-
SummedFermionicOperator,
|
|
4
|
-
)
|
|
5
|
-
from classiq.interface.chemistry.ground_state_problem import (
|
|
6
|
-
GroundStateProblem,
|
|
7
|
-
HamiltonianProblem,
|
|
8
|
-
MoleculeProblem,
|
|
9
|
-
)
|
|
10
|
-
from classiq.interface.chemistry.molecule import Molecule
|
|
11
1
|
from classiq.interface.chemistry.operator import PauliOperator, PauliOperators
|
|
12
2
|
|
|
13
|
-
from . import ground_state_problem
|
|
14
|
-
from .ansatz_parameters import HEAParameters, HVAParameters, UCCParameters
|
|
15
|
-
from .chemistry_execution_parameters import ChemistryExecutionParameters
|
|
16
|
-
from .chemistry_model_constructor import (
|
|
17
|
-
construct_chemistry_model,
|
|
18
|
-
molecule_problem_to_qmod,
|
|
19
|
-
)
|
|
20
|
-
|
|
21
3
|
__all__ = [
|
|
22
|
-
"ChemistryExecutionParameters",
|
|
23
|
-
"FermionicOperator",
|
|
24
|
-
"GroundStateProblem",
|
|
25
|
-
"HEAParameters",
|
|
26
|
-
"HVAParameters",
|
|
27
|
-
"HamiltonianProblem",
|
|
28
|
-
"Molecule",
|
|
29
|
-
"MoleculeProblem",
|
|
30
4
|
"PauliOperator",
|
|
31
5
|
"PauliOperators",
|
|
32
|
-
"SummedFermionicOperator",
|
|
33
|
-
"UCCParameters",
|
|
34
|
-
"construct_chemistry_model",
|
|
35
|
-
"molecule_problem_to_qmod",
|
|
36
6
|
]
|
|
37
7
|
|
|
38
8
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import cast
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
from openfermion.ops.operators.qubit_operator import QubitOperator
|
|
@@ -10,7 +10,7 @@ from classiq.qmod.builtins.enums import Pauli
|
|
|
10
10
|
from classiq.qmod.builtins.structs import IndexedPauli, SparsePauliOp, SparsePauliTerm
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
def _get_n_qubits(qubit_op: QubitOperator, n_qubits:
|
|
13
|
+
def _get_n_qubits(qubit_op: QubitOperator, n_qubits: int | None) -> int:
|
|
14
14
|
min_n_qubits = cast(int, count_qubits(qubit_op))
|
|
15
15
|
if n_qubits is None:
|
|
16
16
|
return min_n_qubits
|
|
@@ -23,7 +23,7 @@ def _get_n_qubits(qubit_op: QubitOperator, n_qubits: Optional[int]) -> int:
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def qubit_op_to_pauli_terms(
|
|
26
|
-
qubit_op: QubitOperator, n_qubits:
|
|
26
|
+
qubit_op: QubitOperator, n_qubits: int | None = None
|
|
27
27
|
) -> SparsePauliOp:
|
|
28
28
|
n_qubits = _get_n_qubits(qubit_op, n_qubits)
|
|
29
29
|
return SparsePauliOp(
|
|
@@ -49,7 +49,7 @@ _XZ_TO_PAULIS = {(0, 0): "I", (1, 0): "X", (0, 1): "Z", (1, 1): "Y"}
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def qubit_op_to_xz_matrix(
|
|
52
|
-
qubit_op: QubitOperator, n_qubits:
|
|
52
|
+
qubit_op: QubitOperator, n_qubits: int | None = None
|
|
53
53
|
) -> np.ndarray:
|
|
54
54
|
n_qubits = _get_n_qubits(qubit_op, n_qubits)
|
|
55
55
|
xz_mat = np.zeros((len(qubit_op.terms), 2 * n_qubits), dtype=np.int8)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import cast
|
|
3
3
|
|
|
4
4
|
from openfermion import MolecularData
|
|
5
5
|
from openfermion.ops import FermionOperator
|
|
@@ -31,7 +31,7 @@ class FermionHamiltonianProblem:
|
|
|
31
31
|
self,
|
|
32
32
|
fermion_hamiltonian: FermionOperator,
|
|
33
33
|
n_particles: tuple[int, int],
|
|
34
|
-
n_orbitals:
|
|
34
|
+
n_orbitals: int | None = None,
|
|
35
35
|
) -> None:
|
|
36
36
|
"""
|
|
37
37
|
Initializes a `FermionHamiltonianProblem` from the fermion hamiltonian, number
|
|
@@ -115,7 +115,7 @@ class FermionHamiltonianProblem:
|
|
|
115
115
|
cls,
|
|
116
116
|
molecule: MolecularData,
|
|
117
117
|
first_active_index: int = 0,
|
|
118
|
-
remove_orbitlas:
|
|
118
|
+
remove_orbitlas: Sequence[int] | None = None,
|
|
119
119
|
op_compression_tol: float = 1e-13,
|
|
120
120
|
) -> "FermionHamiltonianProblem":
|
|
121
121
|
"""
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
2
|
from itertools import chain, combinations, product
|
|
3
3
|
from math import factorial
|
|
4
|
-
from typing import Union
|
|
5
4
|
|
|
6
5
|
from openfermion.ops.operators.fermion_operator import FermionOperator
|
|
7
6
|
from openfermion.ops.operators.qubit_operator import QubitOperator
|
|
@@ -17,7 +16,7 @@ from classiq.qmod.builtins.structs import (
|
|
|
17
16
|
def get_ucc_hamiltonians(
|
|
18
17
|
problem: FermionHamiltonianProblem,
|
|
19
18
|
mapper: FermionToQubitMapper,
|
|
20
|
-
excitations:
|
|
19
|
+
excitations: int | Sequence[int],
|
|
21
20
|
) -> list[SparsePauliOp]:
|
|
22
21
|
"""
|
|
23
22
|
Computes the UCC hamiltonians of the given problem in the desired excitations,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
2
|
from functools import cached_property
|
|
3
|
-
from typing import TYPE_CHECKING, Any
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
from openfermion.ops.operators.fermion_operator import FermionOperator
|
|
@@ -38,7 +38,7 @@ class Z2SymTaperMapper(FermionToQubitMapper):
|
|
|
38
38
|
generators: Sequence[QubitOperator],
|
|
39
39
|
x_ops: Sequence[QubitOperator],
|
|
40
40
|
method: MappingMethod = MappingMethod.JORDAN_WIGNER,
|
|
41
|
-
sector:
|
|
41
|
+
sector: Sequence[int] | None = None,
|
|
42
42
|
tol: float = 1e-14,
|
|
43
43
|
) -> None:
|
|
44
44
|
"""
|
|
@@ -192,7 +192,7 @@ class Z2SymTaperMapper(FermionToQubitMapper):
|
|
|
192
192
|
generators = _get_z2_symmetries_generators(qubit_op, n_qubits)
|
|
193
193
|
x_ops = _get_x_ops_for_generators(generators, n_qubits)
|
|
194
194
|
|
|
195
|
-
sector:
|
|
195
|
+
sector: list[int] | None = None
|
|
196
196
|
if sector_from_hartree_fock:
|
|
197
197
|
from classiq.applications.chemistry.hartree_fock import get_hf_state
|
|
198
198
|
|
|
@@ -252,7 +252,7 @@ def _get_x_ops_for_generators(
|
|
|
252
252
|
# we look for a column in the Z-part of the matrix which is populated only with
|
|
253
253
|
# 0s except for a 1 in the current generator: a X operation in this column's
|
|
254
254
|
# qubit will anti-commute with the current generator and commute with all others
|
|
255
|
-
found_col:
|
|
255
|
+
found_col: int | None = None
|
|
256
256
|
for col in range(n_qubits):
|
|
257
257
|
if (
|
|
258
258
|
generators[row, n_qubits + col] == 1
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
from sympy import Add, Expr, LessThan, Symbol
|
|
4
2
|
|
|
5
3
|
from classiq.interface.combinatorial_optimization.encoding_types import EncodingType
|
|
@@ -8,7 +6,7 @@ _INEQUALITY_UPPER_LIMIT = 1
|
|
|
8
6
|
|
|
9
7
|
|
|
10
8
|
def is_constraint_sum_less_than_one(
|
|
11
|
-
expression: Expr, encoding_type:
|
|
9
|
+
expression: Expr, encoding_type: EncodingType | None = None
|
|
12
10
|
) -> bool:
|
|
13
11
|
# tests the case: x_1 + ... + x_n <= 1
|
|
14
12
|
return (
|
|
@@ -2,7 +2,6 @@ from typing import Any
|
|
|
2
2
|
|
|
3
3
|
import sympy
|
|
4
4
|
from pyomo.core.expr.sympy_tools import PyomoSympyBimap
|
|
5
|
-
from scipy.optimize import differential_evolution
|
|
6
5
|
from sympy import Expr
|
|
7
6
|
|
|
8
7
|
from classiq.applications.combinatorial_helpers import encoding_utils
|
|
@@ -17,6 +16,8 @@ def sympy_lambdify(*args: Any, **kwargs: Any) -> Any:
|
|
|
17
16
|
def multivariate_extremum(
|
|
18
17
|
expr: Expr, symbols_map: PyomoSympyBimap, is_min: bool
|
|
19
18
|
) -> float:
|
|
19
|
+
from scipy.optimize import differential_evolution
|
|
20
|
+
|
|
20
21
|
if expr.is_number:
|
|
21
22
|
return float(expr)
|
|
22
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import itertools
|
|
2
|
+
from collections.abc import Callable
|
|
2
3
|
from functools import partial
|
|
3
|
-
from typing import Callable, Union
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import pyomo.environ as pyo
|
|
@@ -96,7 +96,7 @@ def _decode_vector_str(
|
|
|
96
96
|
) # reverse qubit order
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
def _evaluate_operator(operator: SparsePauliOp, state:
|
|
99
|
+
def _evaluate_operator(operator: SparsePauliOp, state: list[int] | str) -> float:
|
|
100
100
|
if isinstance(state, list):
|
|
101
101
|
state = "".join([str(x) for x in state])
|
|
102
102
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import itertools
|
|
2
2
|
from dataclasses import dataclass, field
|
|
3
|
-
from typing import Optional, Union
|
|
4
3
|
|
|
5
4
|
import pyomo.environ as pyo
|
|
6
5
|
from pyomo.core.base.var import VarData
|
|
@@ -47,7 +46,7 @@ class EncodingMapping:
|
|
|
47
46
|
self,
|
|
48
47
|
original_var: VarData,
|
|
49
48
|
encoding_expr: pyo.Expression,
|
|
50
|
-
encodings_vars:
|
|
49
|
+
encodings_vars: list[VarData] | None = None,
|
|
51
50
|
) -> None:
|
|
52
51
|
if encodings_vars is None:
|
|
53
52
|
encodings_vars = list(identify_variables(encoding_expr))
|
|
@@ -73,7 +72,7 @@ class EncodingMapping:
|
|
|
73
72
|
def get_encoding_vars(self, original_var: VarData) -> list[VarData]:
|
|
74
73
|
return self.get_var_expr_mapping(original_var).encodings_vars
|
|
75
74
|
|
|
76
|
-
def get_original_var(self, encoding_var: VarData) ->
|
|
75
|
+
def get_original_var(self, encoding_var: VarData) -> VarData | None:
|
|
77
76
|
for original_var in self.original_vars:
|
|
78
77
|
if pyomo_utils.contains(encoding_var, self.get_encoding_vars(original_var)):
|
|
79
78
|
return original_var
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import math
|
|
2
2
|
from itertools import filterfalse
|
|
3
|
-
from typing import Any,
|
|
3
|
+
from typing import Any, cast
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import pyomo.environ as pyo
|
|
@@ -97,7 +97,7 @@ def encode_constraints(
|
|
|
97
97
|
|
|
98
98
|
def deal_with_trivial_boolean_constraint(
|
|
99
99
|
constraint: _ComponentBase,
|
|
100
|
-
constraint_expression:
|
|
100
|
+
constraint_expression: bool | Expr,
|
|
101
101
|
model: pyo.ConcreteModel,
|
|
102
102
|
) -> None:
|
|
103
103
|
# using '==' on purpose since comparing against sympy's True
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
from functools import cached_property
|
|
3
3
|
from itertools import filterfalse
|
|
4
|
-
from typing import Optional, Union
|
|
5
4
|
|
|
6
5
|
import pyomo.environ as pyo
|
|
7
6
|
import sympy
|
|
@@ -49,8 +48,8 @@ class OptimizationModel:
|
|
|
49
48
|
self,
|
|
50
49
|
model: ConcreteModel,
|
|
51
50
|
qsolver: QSolver,
|
|
52
|
-
penalty_energy:
|
|
53
|
-
encoding_type:
|
|
51
|
+
penalty_energy: float | None,
|
|
52
|
+
encoding_type: EncodingType | None = None,
|
|
54
53
|
) -> None:
|
|
55
54
|
assert model.nobjectives() == 1, "model must have a single objective"
|
|
56
55
|
model_copy = copy.deepcopy(model)
|
|
@@ -130,7 +129,7 @@ class OptimizationModel:
|
|
|
130
129
|
|
|
131
130
|
def _get_penalty_term(
|
|
132
131
|
self, constraints: list[_GeneralConstraintData]
|
|
133
|
-
) ->
|
|
132
|
+
) -> int | Expression:
|
|
134
133
|
normalized_penalty_term = penalty.get_penalty_expression(constraints)
|
|
135
134
|
return self.penalty_energy * normalized_penalty_term * self.sign
|
|
136
135
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Any
|
|
1
|
+
from typing import Any
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
|
|
@@ -23,7 +23,7 @@ class SparsePauliOp:
|
|
|
23
23
|
new_coeffs = np.concatenate([self.coeffs, other.coeffs])
|
|
24
24
|
return SparsePauliOp(new_paulis, new_coeffs)
|
|
25
25
|
|
|
26
|
-
def __mul__(self, other:
|
|
26
|
+
def __mul__(self, other: int | float | complex) -> "SparsePauliOp":
|
|
27
27
|
"""Scalar multiplication of a SparsePauliOp."""
|
|
28
28
|
if not isinstance(other, (int, float, complex)):
|
|
29
29
|
raise ValueError("Can only multiply by scalar values.")
|
|
@@ -8,7 +8,7 @@ from enum import Enum
|
|
|
8
8
|
from functools import reduce
|
|
9
9
|
from operator import mul
|
|
10
10
|
from types import CodeType
|
|
11
|
-
from typing import Any,
|
|
11
|
+
from typing import Any, TypeVar
|
|
12
12
|
|
|
13
13
|
import pydantic
|
|
14
14
|
import pyomo.core.expr.numeric_expr as pyo_expr
|
|
@@ -132,7 +132,7 @@ def _delete_element_by_value(dict_: dict, value: Any) -> None:
|
|
|
132
132
|
del dict_[k]
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
def get_name(component:
|
|
135
|
+
def get_name(component: IndexedComponent | ComponentData) -> str:
|
|
136
136
|
if isinstance(component, IndexedComponent):
|
|
137
137
|
return component._name # constraint.name returns "'{name}'"
|
|
138
138
|
else:
|
|
@@ -141,8 +141,8 @@ def get_name(component: Union[IndexedComponent, ComponentData]) -> str:
|
|
|
141
141
|
|
|
142
142
|
class FixedSympy2PyomoVisitor(Sympy2PyomoVisitor):
|
|
143
143
|
def beforeChild( # noqa: N802
|
|
144
|
-
self, node:
|
|
145
|
-
) -> tuple[bool,
|
|
144
|
+
self, node: sympy.Expr | None, child: sympy.Expr, child_idx: int | None
|
|
145
|
+
) -> tuple[bool, int | float | None]:
|
|
146
146
|
if not child._args:
|
|
147
147
|
item = self.object_map.getPyomoSymbol(child, None)
|
|
148
148
|
if item is None:
|
|
@@ -300,7 +300,7 @@ def _get_array_sizes(vars: list[VarData]) -> dict[str, tuple[int, ...]]:
|
|
|
300
300
|
|
|
301
301
|
def _get_indices_dimensions(
|
|
302
302
|
indices: set[tuple[int, ...]], *, strict: bool
|
|
303
|
-
) ->
|
|
303
|
+
) -> tuple[int, ...] | None:
|
|
304
304
|
indices_list = list(indices)
|
|
305
305
|
if len(indices) == 0:
|
|
306
306
|
return None
|
|
@@ -365,7 +365,7 @@ def _get_qmod_field_type(var_name: str, var_data: VarData) -> type[QVar]:
|
|
|
365
365
|
|
|
366
366
|
|
|
367
367
|
def evaluate_objective(
|
|
368
|
-
var_mapping: dict[Any,
|
|
368
|
+
var_mapping: dict[Any, str | tuple[str, tuple[int, ...]]],
|
|
369
369
|
sympy_expr: sympy.Expr,
|
|
370
370
|
code_expr: CodeType,
|
|
371
371
|
struct_obj: Any,
|
|
@@ -411,7 +411,7 @@ def is_index_var(var: VarData) -> bool:
|
|
|
411
411
|
)
|
|
412
412
|
|
|
413
413
|
|
|
414
|
-
def index_as_tuple(index:
|
|
414
|
+
def index_as_tuple(index: int | tuple[int, ...]) -> tuple[int, ...]:
|
|
415
415
|
if isinstance(index, int):
|
|
416
416
|
return (index,)
|
|
417
417
|
return index
|
|
@@ -435,7 +435,7 @@ def add_var_domain_constraints(model: ConcreteModel) -> Iterator[None]:
|
|
|
435
435
|
model.del_component("var_domain_constraints")
|
|
436
436
|
|
|
437
437
|
|
|
438
|
-
def _get_var_domain_constraint(var: VarData) ->
|
|
438
|
+
def _get_var_domain_constraint(var: VarData) -> ExpressionBase | None:
|
|
439
439
|
bounds = var.bounds
|
|
440
440
|
if (
|
|
441
441
|
type(bounds) is not tuple
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Optional
|
|
2
|
-
|
|
3
1
|
import pyomo.core as pyo
|
|
4
2
|
from pyomo.core.base.var import VarData
|
|
5
3
|
from pyomo.core.expr.sympy_tools import Pyomo2SympyVisitor, PyomoSympyBimap
|
|
@@ -14,7 +12,7 @@ def sympyify_vars(variables: list[VarData]) -> PyomoSympyBimap:
|
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
def sympyify_expression(
|
|
17
|
-
expression: pyo.Expression, symbols_map:
|
|
15
|
+
expression: pyo.Expression, symbols_map: PyomoSympyBimap | None = None
|
|
18
16
|
) -> Expr:
|
|
19
17
|
if symbols_map is None:
|
|
20
18
|
symbols_map = PyomoSympyBimap()
|