classiq 0.92.0__py3-none-any.whl → 0.94.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of classiq might be problematic. Click here for more details.
- classiq/__init__.py +6 -19
- classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
- classiq/_analyzer_extras/interactive_hardware.py +19 -12
- classiq/_internals/api_wrapper.py +38 -52
- classiq/_internals/async_utils.py +4 -7
- classiq/_internals/authentication/auth0.py +3 -3
- classiq/_internals/authentication/device.py +4 -4
- classiq/_internals/authentication/password_manager.py +13 -13
- classiq/_internals/authentication/token_manager.py +4 -5
- classiq/_internals/client.py +17 -44
- classiq/_internals/config.py +1 -2
- classiq/_internals/help.py +1 -2
- classiq/_internals/host_checker.py +3 -3
- classiq/_internals/jobs.py +14 -14
- classiq/_internals/type_validation.py +3 -3
- classiq/analyzer/analyzer.py +18 -18
- classiq/analyzer/rb.py +17 -8
- classiq/applications/chemistry/__init__.py +0 -30
- classiq/applications/chemistry/op_utils.py +4 -4
- classiq/applications/chemistry/problems.py +3 -3
- classiq/applications/chemistry/ucc.py +1 -2
- classiq/applications/chemistry/z2_symmetries.py +4 -4
- classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
- classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
- classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
- classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
- classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
- classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
- classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
- classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
- classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
- classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
- classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
- classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
- classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
- classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
- classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
- classiq/applications/iqae/iqae.py +8 -8
- classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
- classiq/applications/qnn/datasets/dataset_parity.py +6 -6
- classiq/applications/qnn/qlayer.py +8 -7
- classiq/applications/qnn/torch_utils.py +3 -4
- classiq/applications/qnn/types.py +2 -1
- classiq/applications/qsp/qsp.py +6 -5
- classiq/applications/qsvm/qsvm_data_generation.py +1 -2
- classiq/evaluators/classical_expression.py +0 -4
- classiq/evaluators/parameter_types.py +17 -12
- classiq/evaluators/qmod_annotated_expression.py +24 -26
- classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
- classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
- classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
- classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +4 -4
- classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
- classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
- classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
- classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
- classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
- classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
- classiq/execution/execution_session.py +18 -19
- classiq/execution/jobs.py +26 -26
- classiq/execution/qnn.py +1 -2
- classiq/execution/user_budgets.py +52 -7
- classiq/executor.py +1 -3
- classiq/interface/_version.py +1 -1
- classiq/interface/analyzer/analysis_params.py +4 -4
- classiq/interface/analyzer/cytoscape_graph.py +3 -3
- classiq/interface/analyzer/result.py +4 -4
- classiq/interface/applications/qsvm.py +5 -8
- classiq/interface/ast_node.py +3 -3
- classiq/interface/backend/backend_preferences.py +16 -16
- classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
- classiq/interface/chemistry/ansatz_library.py +3 -5
- classiq/interface/chemistry/operator.py +3 -3
- classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
- classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
- classiq/interface/compression_utils.py +2 -3
- classiq/interface/debug_info/debug_info.py +7 -7
- classiq/interface/exceptions.py +6 -3
- classiq/interface/execution/iqcc.py +1 -3
- classiq/interface/execution/primitives.py +6 -6
- classiq/interface/executor/estimate_cost.py +1 -1
- classiq/interface/executor/execution_preferences.py +3 -5
- classiq/interface/executor/execution_request.py +10 -10
- classiq/interface/executor/execution_result.py +1 -2
- classiq/interface/executor/quantum_code.py +8 -8
- classiq/interface/executor/result.py +28 -18
- classiq/interface/executor/user_budget.py +2 -3
- classiq/interface/executor/vqe_result.py +5 -6
- classiq/interface/generator/ansatz_library.py +6 -8
- classiq/interface/generator/application_apis/__init__.py +0 -2
- classiq/interface/generator/arith/arithmetic.py +2 -2
- classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
- classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
- classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
- classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
- classiq/interface/generator/arith/arithmetic_operations.py +4 -6
- classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
- classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
- classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
- classiq/interface/generator/arith/binary_ops.py +7 -36
- classiq/interface/generator/arith/logical_ops.py +2 -3
- classiq/interface/generator/arith/number_utils.py +2 -2
- classiq/interface/generator/arith/register_user_input.py +2 -2
- classiq/interface/generator/arith/unary_ops.py +2 -2
- classiq/interface/generator/circuit_code/circuit_code.py +8 -10
- classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
- classiq/interface/generator/complex_type.py +2 -2
- classiq/interface/generator/copy.py +1 -3
- classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
- classiq/interface/generator/expressions/evaluated_expression.py +2 -3
- classiq/interface/generator/expressions/expression.py +2 -2
- classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
- classiq/interface/generator/function_param_list.py +0 -20
- classiq/interface/generator/function_params.py +5 -6
- classiq/interface/generator/functions/classical_function_declaration.py +2 -2
- classiq/interface/generator/functions/classical_type.py +3 -3
- classiq/interface/generator/functions/type_modifier.py +0 -14
- classiq/interface/generator/functions/type_name.py +2 -2
- classiq/interface/generator/generated_circuit_data.py +12 -13
- classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
- classiq/interface/generator/hardware/hardware_data.py +8 -8
- classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
- classiq/interface/generator/mcu.py +3 -3
- classiq/interface/generator/mcx.py +3 -3
- classiq/interface/generator/model/constraints.py +34 -5
- classiq/interface/generator/model/preferences/preferences.py +15 -21
- classiq/interface/generator/model/quantum_register.py +7 -10
- classiq/interface/generator/noise_properties.py +3 -7
- classiq/interface/generator/parameters.py +1 -1
- classiq/interface/generator/partitioned_register.py +1 -2
- classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
- classiq/interface/generator/qsvm.py +2 -2
- classiq/interface/generator/quantum_function_call.py +8 -11
- classiq/interface/generator/quantum_program.py +12 -15
- classiq/interface/generator/range_types.py +3 -3
- classiq/interface/generator/slice_parsing_utils.py +4 -5
- classiq/interface/generator/standard_gates/standard_gates.py +2 -4
- classiq/interface/generator/state_preparation/state_preparation.py +6 -8
- classiq/interface/generator/synthesis_execution_parameter.py +1 -3
- classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
- classiq/interface/generator/transpiler_basis_gates.py +2 -4
- classiq/interface/generator/types/builtin_enum_declarations.py +0 -136
- classiq/interface/generator/types/compilation_metadata.py +12 -1
- classiq/interface/generator/types/enum_declaration.py +2 -1
- classiq/interface/generator/validations/flow_graph.py +3 -3
- classiq/interface/generator/visitor.py +10 -12
- classiq/interface/hardware.py +2 -2
- classiq/interface/helpers/classproperty.py +2 -2
- classiq/interface/helpers/custom_encoders.py +2 -1
- classiq/interface/helpers/custom_pydantic_types.py +1 -1
- classiq/interface/helpers/text_utils.py +1 -4
- classiq/interface/ide/visual_model.py +5 -5
- classiq/interface/jobs.py +3 -3
- classiq/interface/model/allocate.py +4 -4
- classiq/interface/model/block.py +2 -2
- classiq/interface/model/bounds.py +3 -3
- classiq/interface/model/control.py +1 -1
- classiq/interface/model/inplace_binary_operation.py +2 -2
- classiq/interface/model/model.py +4 -4
- classiq/interface/model/parameter.py +1 -3
- classiq/interface/model/port_declaration.py +1 -1
- classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
- classiq/interface/model/quantum_function_call.py +3 -6
- classiq/interface/model/quantum_function_declaration.py +1 -0
- classiq/interface/model/quantum_lambda_function.py +4 -4
- classiq/interface/model/quantum_statement.py +4 -4
- classiq/interface/model/quantum_type.py +14 -14
- classiq/interface/model/validation_handle.py +2 -3
- classiq/interface/model/variable_declaration_statement.py +2 -2
- classiq/interface/pretty_print/expression_to_qmod.py +3 -4
- classiq/interface/server/routes.py +0 -4
- classiq/interface/source_reference.py +3 -4
- classiq/model_expansions/arithmetic.py +6 -7
- classiq/model_expansions/arithmetic_compute_result_attrs.py +4 -5
- classiq/model_expansions/capturing/captured_vars.py +3 -3
- classiq/model_expansions/capturing/mangling_utils.py +1 -2
- classiq/model_expansions/closure.py +12 -11
- classiq/model_expansions/function_builder.py +14 -6
- classiq/model_expansions/generative_functions.py +1 -4
- classiq/model_expansions/interpreters/base_interpreter.py +2 -6
- classiq/model_expansions/interpreters/generative_interpreter.py +8 -4
- classiq/model_expansions/quantum_operations/allocate.py +4 -4
- classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -4
- classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
- classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
- classiq/model_expansions/quantum_operations/emitter.py +3 -5
- classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
- classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
- classiq/model_expansions/quantum_operations/variable_decleration.py +61 -29
- classiq/model_expansions/scope.py +7 -7
- classiq/model_expansions/scope_initialization.py +4 -0
- classiq/model_expansions/visitors/symbolic_param_inference.py +3 -3
- classiq/model_expansions/visitors/uncomputation_signature_inference.py +317 -0
- classiq/model_expansions/visitors/variable_references.py +15 -14
- classiq/open_library/functions/__init__.py +6 -0
- classiq/open_library/functions/discrete_sine_cosine_transform.py +19 -14
- classiq/open_library/functions/grover.py +8 -10
- classiq/open_library/functions/modular_exponentiation.py +96 -8
- classiq/qmod/__init__.py +5 -2
- classiq/qmod/builtins/classical_execution_primitives.py +4 -11
- classiq/qmod/builtins/classical_functions.py +1 -42
- classiq/qmod/builtins/enums.py +0 -136
- classiq/qmod/builtins/functions/__init__.py +0 -13
- classiq/qmod/builtins/functions/allocation.py +4 -4
- classiq/qmod/builtins/functions/arithmetic.py +22 -27
- classiq/qmod/builtins/functions/standard_gates.py +27 -27
- classiq/qmod/builtins/operations.py +43 -58
- classiq/qmod/builtins/structs.py +2 -58
- classiq/qmod/cfunc.py +3 -2
- classiq/qmod/classical_function.py +2 -1
- classiq/qmod/classical_variable.py +4 -2
- classiq/qmod/cparam.py +2 -8
- classiq/qmod/create_model_function.py +7 -7
- classiq/qmod/declaration_inferrer.py +33 -30
- classiq/qmod/model_state_container.py +2 -2
- classiq/qmod/native/pretty_printer.py +25 -14
- classiq/qmod/pretty_print/expression_to_python.py +5 -3
- classiq/qmod/pretty_print/pretty_printer.py +39 -17
- classiq/qmod/python_classical_type.py +40 -13
- classiq/qmod/qfunc.py +139 -16
- classiq/qmod/qmod_constant.py +2 -2
- classiq/qmod/qmod_parameter.py +5 -2
- classiq/qmod/qmod_variable.py +47 -43
- classiq/qmod/quantum_callable.py +18 -13
- classiq/qmod/quantum_expandable.py +33 -26
- classiq/qmod/quantum_function.py +51 -32
- classiq/qmod/semantics/annotation/call_annotation.py +2 -2
- classiq/qmod/semantics/error_manager.py +5 -6
- classiq/qmod/semantics/lambdas.py +1 -2
- classiq/qmod/semantics/validation/types_validation.py +1 -2
- classiq/qmod/symbolic.py +2 -4
- classiq/qmod/symbolic_expr.py +12 -4
- classiq/qmod/utilities.py +13 -10
- classiq/qmod/write_qmod.py +3 -4
- classiq/quantum_program.py +1 -3
- classiq/synthesis.py +11 -7
- {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/METADATA +38 -37
- {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/RECORD +240 -261
- classiq-0.94.0.dist-info/WHEEL +4 -0
- classiq-0.94.0.dist-info/licenses/LICENSE.txt +27 -0
- classiq/applications/chemistry/ansatz_parameters.py +0 -29
- classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
- classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
- classiq/applications/chemistry/ground_state_problem.py +0 -42
- classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
- classiq/interface/chemistry/elements.py +0 -120
- classiq/interface/chemistry/fermionic_operator.py +0 -208
- classiq/interface/chemistry/ground_state_problem.py +0 -132
- classiq/interface/chemistry/ground_state_result.py +0 -8
- classiq/interface/chemistry/molecule.py +0 -71
- classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
- classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
- classiq/interface/generator/chemistry_function_params.py +0 -50
- classiq/interface/generator/entangler_params.py +0 -72
- classiq/interface/generator/entanglers.py +0 -14
- classiq/interface/generator/hartree_fock.py +0 -26
- classiq/interface/generator/hva.py +0 -22
- classiq/interface/generator/linear_pauli_rotations.py +0 -92
- classiq/interface/generator/qft.py +0 -37
- classiq/interface/generator/ucc.py +0 -74
- classiq/interface/helpers/backward_compatibility.py +0 -9
- classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
- classiq/qmod/builtins/functions/chemistry.py +0 -123
- classiq-0.92.0.dist-info/WHEEL +0 -4
|
@@ -5,7 +5,7 @@ import os
|
|
|
5
5
|
import pathlib
|
|
6
6
|
import platform
|
|
7
7
|
import stat
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
9
|
|
|
10
10
|
import keyring
|
|
11
11
|
from keyring.backends import fail
|
|
@@ -42,27 +42,27 @@ class PasswordManager(abc.ABC):
|
|
|
42
42
|
self._settings = PasswordManagerSettings()
|
|
43
43
|
|
|
44
44
|
@property
|
|
45
|
-
def access_token(self) ->
|
|
45
|
+
def access_token(self) -> str | None:
|
|
46
46
|
return self._get(key=self._settings.ACCESS_TOKEN_KEY)
|
|
47
47
|
|
|
48
48
|
@access_token.setter
|
|
49
|
-
def access_token(self, access_token:
|
|
49
|
+
def access_token(self, access_token: str | None) -> None:
|
|
50
50
|
self._set(key=self._settings.ACCESS_TOKEN_KEY, value=access_token)
|
|
51
51
|
|
|
52
52
|
@property
|
|
53
|
-
def refresh_token(self) ->
|
|
53
|
+
def refresh_token(self) -> str | None:
|
|
54
54
|
return self._get(key=self._settings.REFRESH_TOKEN_KEY)
|
|
55
55
|
|
|
56
56
|
@refresh_token.setter
|
|
57
|
-
def refresh_token(self, refresh_token:
|
|
57
|
+
def refresh_token(self, refresh_token: str | None) -> None:
|
|
58
58
|
self._set(key=self._settings.REFRESH_TOKEN_KEY, value=refresh_token)
|
|
59
59
|
|
|
60
60
|
@abc.abstractmethod
|
|
61
|
-
def _get(self, key: str) ->
|
|
61
|
+
def _get(self, key: str) -> str | None:
|
|
62
62
|
pass
|
|
63
63
|
|
|
64
64
|
@abc.abstractmethod
|
|
65
|
-
def _set(self, key: str, value:
|
|
65
|
+
def _set(self, key: str, value: str | None) -> None:
|
|
66
66
|
pass
|
|
67
67
|
|
|
68
68
|
@abc.abstractmethod
|
|
@@ -76,10 +76,10 @@ class PasswordManager(abc.ABC):
|
|
|
76
76
|
|
|
77
77
|
|
|
78
78
|
class KeyringPasswordManager(PasswordManager):
|
|
79
|
-
def _get(self, key: str) ->
|
|
79
|
+
def _get(self, key: str) -> str | None:
|
|
80
80
|
return keyring.get_password(service_name=self._SERVICE_NAME, username=key)
|
|
81
81
|
|
|
82
|
-
def _set(self, key: str, value:
|
|
82
|
+
def _set(self, key: str, value: str | None) -> None:
|
|
83
83
|
if value is None:
|
|
84
84
|
self._clear(key)
|
|
85
85
|
return
|
|
@@ -101,10 +101,10 @@ class KeyringPasswordManager(PasswordManager):
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
class DummyPasswordManager(PasswordManager):
|
|
104
|
-
def _get(self, key: str) ->
|
|
104
|
+
def _get(self, key: str) -> str | None:
|
|
105
105
|
return None
|
|
106
106
|
|
|
107
|
-
def _set(self, key: str, value:
|
|
107
|
+
def _set(self, key: str, value: str | None) -> None:
|
|
108
108
|
return
|
|
109
109
|
|
|
110
110
|
def _clear(self, key: str) -> None:
|
|
@@ -134,13 +134,13 @@ class FilePasswordManager(PasswordManager):
|
|
|
134
134
|
return json.loads(self.credentials_file.read_text())
|
|
135
135
|
return {}
|
|
136
136
|
|
|
137
|
-
def _get(self, key: str) ->
|
|
137
|
+
def _get(self, key: str) -> str | None:
|
|
138
138
|
token_dict = self._get_token_dict()
|
|
139
139
|
if key in token_dict:
|
|
140
140
|
return token_dict[key]
|
|
141
141
|
return None
|
|
142
142
|
|
|
143
|
-
def _set(self, key: str, value:
|
|
143
|
+
def _set(self, key: str, value: str | None) -> None:
|
|
144
144
|
token_dict = self._get_token_dict()
|
|
145
145
|
token_dict[key] = value
|
|
146
146
|
self._update_file(token_dict)
|
|
@@ -3,7 +3,6 @@ import logging
|
|
|
3
3
|
import threading
|
|
4
4
|
import warnings
|
|
5
5
|
from collections.abc import Sequence
|
|
6
|
-
from typing import Optional
|
|
7
6
|
|
|
8
7
|
from classiq.interface.exceptions import (
|
|
9
8
|
ClassiqAuthenticationError,
|
|
@@ -26,7 +25,7 @@ class TokenManager:
|
|
|
26
25
|
def __init__(
|
|
27
26
|
self,
|
|
28
27
|
config: Configuration,
|
|
29
|
-
password_manager:
|
|
28
|
+
password_manager: pm.PasswordManager | None = None,
|
|
30
29
|
) -> None:
|
|
31
30
|
self._config = config
|
|
32
31
|
if password_manager is None:
|
|
@@ -35,8 +34,8 @@ class TokenManager:
|
|
|
35
34
|
# to a specific event loop, which is undesirable
|
|
36
35
|
self._lock = threading.Lock()
|
|
37
36
|
self._password_manager: pm.PasswordManager = password_manager
|
|
38
|
-
self._access_token:
|
|
39
|
-
self._refresh_token:
|
|
37
|
+
self._access_token: str | None = self._password_manager.access_token
|
|
38
|
+
self._refresh_token: str | None = self._password_manager.refresh_token
|
|
40
39
|
if self._access_token is None and self._refresh_token is not None:
|
|
41
40
|
_logger.info(
|
|
42
41
|
"Inconsistent state, access token is absent and refresh token is present."
|
|
@@ -67,7 +66,7 @@ class TokenManager:
|
|
|
67
66
|
"Password Manager not found, we could not store your credentials securely. Please contact support@classiq.io"
|
|
68
67
|
)
|
|
69
68
|
|
|
70
|
-
def get_access_token(self) ->
|
|
69
|
+
def get_access_token(self) -> str | None:
|
|
71
70
|
return self._access_token
|
|
72
71
|
|
|
73
72
|
async def _refresh(self) -> None:
|
classiq/_internals/client.py
CHANGED
|
@@ -7,9 +7,8 @@ import os
|
|
|
7
7
|
import platform
|
|
8
8
|
import sys
|
|
9
9
|
import time
|
|
10
|
-
from collections.abc import Awaitable
|
|
11
|
-
from
|
|
12
|
-
from typing import Any, Callable, NoReturn, Optional, TypeVar, Union
|
|
10
|
+
from collections.abc import Awaitable, Callable
|
|
11
|
+
from typing import Any, NoReturn, TypeVar
|
|
13
12
|
|
|
14
13
|
import httpx
|
|
15
14
|
from typing_extensions import ParamSpec
|
|
@@ -146,27 +145,6 @@ def try_again_on_failure(
|
|
|
146
145
|
return wrapper
|
|
147
146
|
|
|
148
147
|
|
|
149
|
-
class _AsyncNullContext(contextlib.AbstractAsyncContextManager):
|
|
150
|
-
"""
|
|
151
|
-
This class is meant to replace `contextlib.nullcontext`, which hadn't supported
|
|
152
|
-
async context manager until python 3.10.
|
|
153
|
-
"""
|
|
154
|
-
|
|
155
|
-
def __init__(self, enter_result: Any = None) -> None:
|
|
156
|
-
self._enter_result = enter_result
|
|
157
|
-
|
|
158
|
-
async def __aenter__(self) -> Any:
|
|
159
|
-
return self._enter_result
|
|
160
|
-
|
|
161
|
-
async def __aexit__(
|
|
162
|
-
self,
|
|
163
|
-
exc_type: Optional[type[BaseException]],
|
|
164
|
-
exc_val: Optional[BaseException],
|
|
165
|
-
exc_tb: Optional[TracebackType],
|
|
166
|
-
) -> None:
|
|
167
|
-
pass
|
|
168
|
-
|
|
169
|
-
|
|
170
148
|
class Client:
|
|
171
149
|
_UNKNOWN_VERSION = HostChecker._UNKNOWN_VERSION
|
|
172
150
|
_SESSION_HEADER = "Classiq-Session"
|
|
@@ -177,7 +155,7 @@ class Client:
|
|
|
177
155
|
self._config = conf
|
|
178
156
|
self._token_manager = token_manager.TokenManager(config=self._config)
|
|
179
157
|
self._api_prefix = self._make_api_prefix()
|
|
180
|
-
self._session_id:
|
|
158
|
+
self._session_id: str | None = None
|
|
181
159
|
|
|
182
160
|
@staticmethod
|
|
183
161
|
def _make_api_prefix() -> str:
|
|
@@ -229,9 +207,9 @@ class Client:
|
|
|
229
207
|
http_client: httpx.AsyncClient,
|
|
230
208
|
method: str,
|
|
231
209
|
url: str,
|
|
232
|
-
json:
|
|
233
|
-
params:
|
|
234
|
-
headers:
|
|
210
|
+
json: dict | None = None,
|
|
211
|
+
params: dict | None = None,
|
|
212
|
+
headers: dict[str, str] | None = None,
|
|
235
213
|
) -> httpx.Response:
|
|
236
214
|
http_client.headers.update(self._get_headers())
|
|
237
215
|
|
|
@@ -265,12 +243,12 @@ class Client:
|
|
|
265
243
|
self,
|
|
266
244
|
http_method: str,
|
|
267
245
|
url: str,
|
|
268
|
-
body:
|
|
269
|
-
params:
|
|
246
|
+
body: dict | None = None,
|
|
247
|
+
params: dict | None = None,
|
|
270
248
|
use_versioned_url: bool = True,
|
|
271
|
-
headers:
|
|
272
|
-
http_client:
|
|
273
|
-
) ->
|
|
249
|
+
headers: dict[str, str] | None = None,
|
|
250
|
+
http_client: httpx.AsyncClient | None = None,
|
|
251
|
+
) -> dict | list | str:
|
|
274
252
|
if use_versioned_url:
|
|
275
253
|
url = self.make_versioned_url(url)
|
|
276
254
|
async with self.use_client_or_create(http_client) as async_client:
|
|
@@ -285,26 +263,21 @@ class Client:
|
|
|
285
263
|
return response.json()
|
|
286
264
|
|
|
287
265
|
def use_client_or_create(
|
|
288
|
-
self, http_client:
|
|
266
|
+
self, http_client: httpx.AsyncClient | None
|
|
289
267
|
) -> contextlib.AbstractAsyncContextManager[httpx.AsyncClient]:
|
|
290
268
|
if http_client is None:
|
|
291
269
|
return self.async_client()
|
|
292
270
|
else:
|
|
293
|
-
|
|
294
|
-
# remove this `if` and the `_AsyncNullContext` class when we stop
|
|
295
|
-
# supporting python 3.9
|
|
296
|
-
return _AsyncNullContext(enter_result=http_client)
|
|
297
|
-
else:
|
|
298
|
-
return contextlib.nullcontext(enter_result=http_client)
|
|
271
|
+
return contextlib.nullcontext(enter_result=http_client)
|
|
299
272
|
|
|
300
273
|
def sync_call_api(
|
|
301
274
|
self,
|
|
302
275
|
http_method: str,
|
|
303
276
|
url: str,
|
|
304
|
-
body:
|
|
305
|
-
headers:
|
|
277
|
+
body: dict | None = None,
|
|
278
|
+
headers: dict | None = None,
|
|
306
279
|
use_versioned_url: bool = True,
|
|
307
|
-
) ->
|
|
280
|
+
) -> dict | str:
|
|
308
281
|
if use_versioned_url:
|
|
309
282
|
url = self.make_versioned_url(url)
|
|
310
283
|
with httpx.Client(**self._make_client_args()) as sync_client:
|
|
@@ -356,7 +329,7 @@ class Client:
|
|
|
356
329
|
return self._config
|
|
357
330
|
|
|
358
331
|
|
|
359
|
-
DEFAULT_CLIENT:
|
|
332
|
+
DEFAULT_CLIENT: Client | None = None
|
|
360
333
|
|
|
361
334
|
|
|
362
335
|
def client() -> Client:
|
classiq/_internals/config.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import os
|
|
4
4
|
import pathlib
|
|
5
|
-
from typing import Optional, Union
|
|
6
5
|
|
|
7
6
|
import configargparse # type: ignore[import]
|
|
8
7
|
import pydantic
|
|
@@ -53,7 +52,7 @@ if os.name == "posix":
|
|
|
53
52
|
] + _DEFAULT_CONFIG_FILES
|
|
54
53
|
|
|
55
54
|
|
|
56
|
-
def init(args:
|
|
55
|
+
def init(args: str | list[str] | None = None) -> Configuration:
|
|
57
56
|
"""Initialize the configuration object.
|
|
58
57
|
|
|
59
58
|
Args:
|
classiq/_internals/help.py
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import webbrowser
|
|
2
|
-
from typing import Optional
|
|
3
2
|
|
|
4
3
|
from classiq.interface._version import SEMVER_VERSION
|
|
5
4
|
|
|
6
5
|
DOCS_BASE_URL = "https://docs.classiq.io/"
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
def open_help(version:
|
|
8
|
+
def open_help(version: str | None = None) -> None:
|
|
10
9
|
if version is None:
|
|
11
10
|
version = SEMVER_VERSION
|
|
12
11
|
if version == "0.0.0":
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import logging
|
|
4
4
|
import warnings
|
|
5
5
|
from datetime import datetime
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
7
|
|
|
8
8
|
import httpx
|
|
9
9
|
import pydantic
|
|
@@ -38,7 +38,7 @@ class HostChecker:
|
|
|
38
38
|
self._client_version = client_version
|
|
39
39
|
self._interface_version = interface_version
|
|
40
40
|
|
|
41
|
-
def _get_interface_version(self) ->
|
|
41
|
+
def _get_interface_version(self) -> str | None:
|
|
42
42
|
global_interfaces = GlobalVersions.model_validate(
|
|
43
43
|
self._client.sync_call_api(
|
|
44
44
|
"get", "/interface_versions", use_versioned_url=False
|
|
@@ -52,7 +52,7 @@ class HostChecker:
|
|
|
52
52
|
)
|
|
53
53
|
return host.classiq_interface
|
|
54
54
|
|
|
55
|
-
def _get_deprecation_info(self) ->
|
|
55
|
+
def _get_deprecation_info(self) -> DeprecationInfo | None:
|
|
56
56
|
global_versions = GlobalVersions.model_validate(
|
|
57
57
|
self._client.sync_call_api("get", "/versions", use_versioned_url=False)
|
|
58
58
|
)
|
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()
|
|
@@ -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)
|