classiq 0.93.0__py3-none-any.whl → 0.94.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of classiq might be problematic. Click here for more details.

Files changed (261) hide show
  1. classiq/__init__.py +6 -19
  2. classiq/_analyzer_extras/_ipywidgets_async_extension.py +7 -7
  3. classiq/_analyzer_extras/interactive_hardware.py +19 -12
  4. classiq/_internals/api_wrapper.py +38 -52
  5. classiq/_internals/async_utils.py +4 -7
  6. classiq/_internals/authentication/auth0.py +3 -3
  7. classiq/_internals/authentication/device.py +4 -4
  8. classiq/_internals/authentication/password_manager.py +13 -13
  9. classiq/_internals/authentication/token_manager.py +4 -5
  10. classiq/_internals/client.py +17 -44
  11. classiq/_internals/config.py +1 -2
  12. classiq/_internals/help.py +1 -2
  13. classiq/_internals/host_checker.py +3 -3
  14. classiq/_internals/jobs.py +14 -14
  15. classiq/_internals/type_validation.py +3 -3
  16. classiq/analyzer/analyzer.py +18 -18
  17. classiq/analyzer/rb.py +17 -8
  18. classiq/applications/chemistry/__init__.py +0 -30
  19. classiq/applications/chemistry/op_utils.py +4 -4
  20. classiq/applications/chemistry/problems.py +3 -3
  21. classiq/applications/chemistry/ucc.py +1 -2
  22. classiq/applications/chemistry/z2_symmetries.py +4 -4
  23. classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
  24. classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
  25. classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
  26. classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
  27. classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
  28. classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
  29. classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
  30. classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
  31. classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
  32. classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
  33. classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
  34. classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
  35. classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
  36. classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
  37. classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
  38. classiq/applications/iqae/iqae.py +8 -8
  39. classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
  40. classiq/applications/qnn/datasets/dataset_parity.py +6 -6
  41. classiq/applications/qnn/qlayer.py +8 -7
  42. classiq/applications/qnn/torch_utils.py +3 -4
  43. classiq/applications/qnn/types.py +2 -1
  44. classiq/applications/qsp/qsp.py +5 -4
  45. classiq/applications/qsvm/qsvm_data_generation.py +1 -2
  46. classiq/evaluators/classical_expression.py +0 -4
  47. classiq/evaluators/parameter_types.py +7 -8
  48. classiq/evaluators/qmod_annotated_expression.py +24 -26
  49. classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
  50. classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
  51. classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
  52. classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +4 -4
  53. classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
  54. classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
  55. classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
  56. classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
  57. classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
  58. classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
  59. classiq/execution/execution_session.py +18 -19
  60. classiq/execution/jobs.py +26 -26
  61. classiq/execution/qnn.py +1 -2
  62. classiq/execution/user_budgets.py +52 -7
  63. classiq/executor.py +1 -3
  64. classiq/interface/_version.py +1 -1
  65. classiq/interface/analyzer/analysis_params.py +4 -4
  66. classiq/interface/analyzer/cytoscape_graph.py +3 -3
  67. classiq/interface/analyzer/result.py +4 -4
  68. classiq/interface/applications/qsvm.py +5 -8
  69. classiq/interface/ast_node.py +3 -3
  70. classiq/interface/backend/backend_preferences.py +16 -16
  71. classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
  72. classiq/interface/chemistry/ansatz_library.py +3 -5
  73. classiq/interface/chemistry/operator.py +3 -3
  74. classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
  75. classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
  76. classiq/interface/compression_utils.py +2 -3
  77. classiq/interface/debug_info/debug_info.py +7 -7
  78. classiq/interface/exceptions.py +2 -3
  79. classiq/interface/execution/iqcc.py +1 -3
  80. classiq/interface/execution/primitives.py +6 -6
  81. classiq/interface/executor/estimate_cost.py +1 -1
  82. classiq/interface/executor/execution_preferences.py +3 -5
  83. classiq/interface/executor/execution_request.py +10 -10
  84. classiq/interface/executor/execution_result.py +1 -2
  85. classiq/interface/executor/quantum_code.py +8 -8
  86. classiq/interface/executor/result.py +28 -18
  87. classiq/interface/executor/user_budget.py +2 -3
  88. classiq/interface/executor/vqe_result.py +5 -6
  89. classiq/interface/generator/ansatz_library.py +6 -8
  90. classiq/interface/generator/application_apis/__init__.py +0 -2
  91. classiq/interface/generator/arith/arithmetic.py +2 -2
  92. classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
  93. classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
  94. classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
  95. classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
  96. classiq/interface/generator/arith/arithmetic_operations.py +4 -6
  97. classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
  98. classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
  99. classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
  100. classiq/interface/generator/arith/binary_ops.py +7 -36
  101. classiq/interface/generator/arith/logical_ops.py +2 -3
  102. classiq/interface/generator/arith/number_utils.py +2 -2
  103. classiq/interface/generator/arith/register_user_input.py +2 -2
  104. classiq/interface/generator/arith/unary_ops.py +2 -2
  105. classiq/interface/generator/circuit_code/circuit_code.py +8 -10
  106. classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
  107. classiq/interface/generator/complex_type.py +2 -2
  108. classiq/interface/generator/copy.py +1 -3
  109. classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
  110. classiq/interface/generator/expressions/evaluated_expression.py +2 -3
  111. classiq/interface/generator/expressions/expression.py +2 -2
  112. classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
  113. classiq/interface/generator/function_param_list.py +0 -20
  114. classiq/interface/generator/function_params.py +5 -6
  115. classiq/interface/generator/functions/classical_function_declaration.py +2 -2
  116. classiq/interface/generator/functions/classical_type.py +3 -3
  117. classiq/interface/generator/functions/type_modifier.py +0 -14
  118. classiq/interface/generator/functions/type_name.py +2 -2
  119. classiq/interface/generator/generated_circuit_data.py +12 -13
  120. classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
  121. classiq/interface/generator/hardware/hardware_data.py +8 -8
  122. classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
  123. classiq/interface/generator/mcu.py +3 -3
  124. classiq/interface/generator/mcx.py +3 -3
  125. classiq/interface/generator/model/constraints.py +34 -5
  126. classiq/interface/generator/model/preferences/preferences.py +15 -21
  127. classiq/interface/generator/model/quantum_register.py +7 -10
  128. classiq/interface/generator/noise_properties.py +3 -7
  129. classiq/interface/generator/parameters.py +1 -1
  130. classiq/interface/generator/partitioned_register.py +1 -2
  131. classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
  132. classiq/interface/generator/qsvm.py +2 -2
  133. classiq/interface/generator/quantum_function_call.py +8 -11
  134. classiq/interface/generator/quantum_program.py +12 -15
  135. classiq/interface/generator/range_types.py +3 -3
  136. classiq/interface/generator/slice_parsing_utils.py +4 -5
  137. classiq/interface/generator/standard_gates/standard_gates.py +2 -4
  138. classiq/interface/generator/state_preparation/state_preparation.py +6 -8
  139. classiq/interface/generator/synthesis_execution_parameter.py +1 -3
  140. classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
  141. classiq/interface/generator/transpiler_basis_gates.py +2 -4
  142. classiq/interface/generator/types/builtin_enum_declarations.py +0 -136
  143. classiq/interface/generator/types/compilation_metadata.py +12 -1
  144. classiq/interface/generator/types/enum_declaration.py +2 -1
  145. classiq/interface/generator/validations/flow_graph.py +3 -3
  146. classiq/interface/generator/visitor.py +10 -12
  147. classiq/interface/hardware.py +2 -2
  148. classiq/interface/helpers/classproperty.py +2 -2
  149. classiq/interface/helpers/custom_encoders.py +2 -1
  150. classiq/interface/helpers/custom_pydantic_types.py +1 -1
  151. classiq/interface/helpers/text_utils.py +1 -4
  152. classiq/interface/ide/visual_model.py +5 -5
  153. classiq/interface/jobs.py +3 -3
  154. classiq/interface/model/allocate.py +4 -4
  155. classiq/interface/model/block.py +2 -2
  156. classiq/interface/model/bounds.py +3 -3
  157. classiq/interface/model/control.py +1 -1
  158. classiq/interface/model/inplace_binary_operation.py +2 -2
  159. classiq/interface/model/model.py +4 -4
  160. classiq/interface/model/parameter.py +1 -3
  161. classiq/interface/model/port_declaration.py +1 -1
  162. classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
  163. classiq/interface/model/quantum_function_call.py +3 -6
  164. classiq/interface/model/quantum_function_declaration.py +1 -0
  165. classiq/interface/model/quantum_lambda_function.py +4 -4
  166. classiq/interface/model/quantum_statement.py +4 -4
  167. classiq/interface/model/quantum_type.py +14 -14
  168. classiq/interface/model/validation_handle.py +2 -3
  169. classiq/interface/model/variable_declaration_statement.py +2 -2
  170. classiq/interface/pretty_print/expression_to_qmod.py +3 -4
  171. classiq/interface/server/routes.py +0 -4
  172. classiq/interface/source_reference.py +3 -4
  173. classiq/model_expansions/arithmetic.py +6 -7
  174. classiq/model_expansions/arithmetic_compute_result_attrs.py +4 -5
  175. classiq/model_expansions/capturing/captured_vars.py +3 -3
  176. classiq/model_expansions/capturing/mangling_utils.py +1 -2
  177. classiq/model_expansions/closure.py +12 -11
  178. classiq/model_expansions/function_builder.py +14 -6
  179. classiq/model_expansions/generative_functions.py +1 -4
  180. classiq/model_expansions/interpreters/base_interpreter.py +2 -6
  181. classiq/model_expansions/interpreters/generative_interpreter.py +5 -3
  182. classiq/model_expansions/quantum_operations/allocate.py +4 -4
  183. classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -4
  184. classiq/model_expansions/quantum_operations/call_emitter.py +31 -37
  185. classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
  186. classiq/model_expansions/quantum_operations/emitter.py +3 -5
  187. classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
  188. classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
  189. classiq/model_expansions/quantum_operations/variable_decleration.py +2 -2
  190. classiq/model_expansions/scope.py +7 -7
  191. classiq/model_expansions/scope_initialization.py +4 -0
  192. classiq/model_expansions/visitors/symbolic_param_inference.py +3 -3
  193. classiq/model_expansions/visitors/uncomputation_signature_inference.py +317 -0
  194. classiq/model_expansions/visitors/variable_references.py +15 -14
  195. classiq/open_library/functions/__init__.py +6 -0
  196. classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
  197. classiq/open_library/functions/grover.py +8 -10
  198. classiq/open_library/functions/modular_exponentiation.py +96 -8
  199. classiq/qmod/__init__.py +5 -2
  200. classiq/qmod/builtins/classical_execution_primitives.py +4 -11
  201. classiq/qmod/builtins/classical_functions.py +1 -42
  202. classiq/qmod/builtins/enums.py +0 -136
  203. classiq/qmod/builtins/functions/__init__.py +0 -13
  204. classiq/qmod/builtins/functions/allocation.py +4 -4
  205. classiq/qmod/builtins/functions/arithmetic.py +22 -27
  206. classiq/qmod/builtins/functions/standard_gates.py +27 -27
  207. classiq/qmod/builtins/operations.py +35 -58
  208. classiq/qmod/builtins/structs.py +2 -58
  209. classiq/qmod/cfunc.py +3 -2
  210. classiq/qmod/classical_function.py +2 -1
  211. classiq/qmod/cparam.py +2 -8
  212. classiq/qmod/create_model_function.py +7 -7
  213. classiq/qmod/declaration_inferrer.py +33 -30
  214. classiq/qmod/model_state_container.py +2 -2
  215. classiq/qmod/native/pretty_printer.py +25 -14
  216. classiq/qmod/pretty_print/expression_to_python.py +5 -3
  217. classiq/qmod/pretty_print/pretty_printer.py +39 -17
  218. classiq/qmod/python_classical_type.py +40 -13
  219. classiq/qmod/qfunc.py +139 -16
  220. classiq/qmod/qmod_constant.py +2 -2
  221. classiq/qmod/qmod_parameter.py +5 -2
  222. classiq/qmod/qmod_variable.py +47 -43
  223. classiq/qmod/quantum_callable.py +18 -13
  224. classiq/qmod/quantum_expandable.py +31 -26
  225. classiq/qmod/quantum_function.py +51 -32
  226. classiq/qmod/semantics/annotation/call_annotation.py +2 -2
  227. classiq/qmod/semantics/error_manager.py +5 -6
  228. classiq/qmod/semantics/lambdas.py +1 -2
  229. classiq/qmod/semantics/validation/types_validation.py +1 -2
  230. classiq/qmod/symbolic.py +2 -4
  231. classiq/qmod/utilities.py +13 -10
  232. classiq/qmod/write_qmod.py +3 -4
  233. classiq/quantum_program.py +1 -3
  234. classiq/synthesis.py +11 -7
  235. {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/METADATA +2 -3
  236. {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/RECORD +238 -260
  237. classiq/applications/chemistry/ansatz_parameters.py +0 -29
  238. classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
  239. classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
  240. classiq/applications/chemistry/ground_state_problem.py +0 -42
  241. classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
  242. classiq/interface/chemistry/elements.py +0 -120
  243. classiq/interface/chemistry/fermionic_operator.py +0 -208
  244. classiq/interface/chemistry/ground_state_problem.py +0 -132
  245. classiq/interface/chemistry/ground_state_result.py +0 -8
  246. classiq/interface/chemistry/molecule.py +0 -71
  247. classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
  248. classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
  249. classiq/interface/generator/chemistry_function_params.py +0 -50
  250. classiq/interface/generator/entangler_params.py +0 -72
  251. classiq/interface/generator/entanglers.py +0 -14
  252. classiq/interface/generator/hartree_fock.py +0 -26
  253. classiq/interface/generator/hva.py +0 -22
  254. classiq/interface/generator/linear_pauli_rotations.py +0 -92
  255. classiq/interface/generator/qft.py +0 -37
  256. classiq/interface/generator/ucc.py +0 -74
  257. classiq/interface/helpers/backward_compatibility.py +0 -9
  258. classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
  259. classiq/qmod/builtins/functions/chemistry.py +0 -123
  260. {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/WHEEL +0 -0
  261. {classiq-0.93.0.dist-info → classiq-0.94.1.dist-info}/licenses/LICENSE.txt +0 -0
@@ -5,7 +5,7 @@ import os
5
5
  import pathlib
6
6
  import platform
7
7
  import stat
8
- from typing import Any, Optional
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) -> Optional[str]:
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: Optional[str]) -> None:
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) -> Optional[str]:
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: Optional[str]) -> None:
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) -> Optional[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: Optional[str]) -> None:
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) -> Optional[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: Optional[str]) -> None:
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) -> Optional[str]:
104
+ def _get(self, key: str) -> str | None:
105
105
  return None
106
106
 
107
- def _set(self, key: str, value: Optional[str]) -> None:
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) -> Optional[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: Optional[str]) -> None:
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: Optional[pm.PasswordManager] = None,
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: Optional[str] = self._password_manager.access_token
39
- self._refresh_token: Optional[str] = self._password_manager.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) -> Optional[str]:
69
+ def get_access_token(self) -> str | None:
71
70
  return self._access_token
72
71
 
73
72
  async def _refresh(self) -> None:
@@ -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 types import TracebackType
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: Optional[str] = None
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: Optional[dict] = None,
233
- params: Optional[dict] = None,
234
- headers: Optional[dict[str, str]] = None,
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: Optional[dict] = None,
269
- params: Optional[dict] = None,
246
+ body: dict | None = None,
247
+ params: dict | None = None,
270
248
  use_versioned_url: bool = True,
271
- headers: Optional[dict[str, str]] = None,
272
- http_client: Optional[httpx.AsyncClient] = None,
273
- ) -> Union[dict, list, str]:
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: Optional[httpx.AsyncClient]
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
- if sys.version_info[0:2] < (3, 10):
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: Optional[dict] = None,
305
- headers: Optional[dict] = None,
277
+ body: dict | None = None,
278
+ headers: dict | None = None,
306
279
  use_versioned_url: bool = True,
307
- ) -> Union[dict, str]:
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: Optional[Client] = None
332
+ DEFAULT_CLIENT: Client | None = None
360
333
 
361
334
 
362
335
  def client() -> Client:
@@ -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: Optional[Union[str, list[str]]] = None) -> Configuration:
55
+ def init(args: str | list[str] | None = None) -> Configuration:
57
56
  """Initialize the configuration object.
58
57
 
59
58
  Args:
@@ -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: Optional[str] = None) -> None:
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, Optional
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) -> Optional[str]:
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) -> Optional[DeprecationInfo]:
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
  )
@@ -1,7 +1,7 @@
1
1
  import json
2
2
  import logging
3
- from collections.abc import Iterable
4
- from typing import Callable, Optional, TypeVar
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
- ) -> Optional[GeneralJobDescription]:
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: Optional[dict[str, str]] = None,
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: Optional[dict] = None,
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: Optional[float],
115
- response_parser: Callable[[JSONObject], Optional[T]] = _general_job_description_parser, # type: ignore[assignment]
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: Optional[float],
136
- response_parser: Callable[[JSONObject], Optional[T]] = _general_job_description_parser, # type: ignore[assignment]
137
- http_client: Optional[httpx.AsyncClient] = None,
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: Optional[float],
157
- http_client: Optional[httpx.AsyncClient] = None,
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: Optional[float],
177
- http_client: Optional[httpx.AsyncClient] = None,
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, Union, overload
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
- ) -> Union[T, U]: ...
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: Union[tuple[type, ...], type],
37
+ expected_type: tuple[type, ...] | type,
38
38
  operation: str,
39
39
  exception_type: type[Exception],
40
40
  ) -> Any:
@@ -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 Any, Optional, Union
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
- find_ipywidgets = find_spec("ipywidgets")
25
- VBox = Any
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: Optional[list[ProviderNameEnum]] = None
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: Optional[ProviderNameEnum] = None,
89
- device: Optional[DeviceName] = None,
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: Optional[Sequence[Union[str, AnalyzerProviderVendor]]] = None,
119
- devices: Optional[list[str]] = None,
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: Optional[list[Union[str, AnalyzerProviderVendor]]] = None,
146
- devices: Optional[list[str]] = None,
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: Optional[Sequence[Union[str, AnalyzerProviderVendor]]] = None,
160
- devices: Optional[list[str]] = None,
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 Optional, Union
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: Union[PythonEnum, str]) -> str:
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 Optional, cast
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: Optional[int]) -> int:
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: Optional[int] = None
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: Optional[int] = None
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)