classiq 0.93.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.

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.0.dist-info}/METADATA +2 -3
  236. {classiq-0.93.0.dist-info → classiq-0.94.0.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.0.dist-info}/WHEEL +0 -0
  261. {classiq-0.93.0.dist-info → classiq-0.94.0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -1,11 +1,11 @@
1
1
  from collections.abc import Sequence
2
2
  from enum import IntEnum
3
- from typing import TYPE_CHECKING, Annotated, Any, Optional, Union
3
+ from typing import TYPE_CHECKING, Annotated, Any, Optional, TypeAlias
4
4
 
5
5
  import pydantic
6
6
  from pydantic import Field
7
7
  from pydantic_core.core_schema import ValidationInfo
8
- from typing_extensions import Self, TypeAlias
8
+ from typing_extensions import Self
9
9
 
10
10
  from classiq.interface.backend.backend_preferences import (
11
11
  BackendPreferences,
@@ -135,21 +135,15 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
135
135
  - If `backend_service_provider` is not valid.
136
136
  """
137
137
 
138
- _backend_preferences: Optional[BackendPreferences] = pydantic.PrivateAttr(
139
- default=None
140
- )
138
+ _backend_preferences: BackendPreferences | None = pydantic.PrivateAttr(default=None)
141
139
  machine_precision: PydanticMachinePrecision = DEFAULT_MACHINE_PRECISION
142
140
 
143
- backend_service_provider: Optional[Union[Provider, ProviderVendor, str]] = (
144
- pydantic.Field(
145
- default=None,
146
- description="Provider company or cloud for the requested backend.",
147
- )
141
+ backend_service_provider: Provider | ProviderVendor | str | None = pydantic.Field(
142
+ default=None,
143
+ description="Provider company or cloud for the requested backend.",
148
144
  )
149
- backend_name: Optional[Union[PydanticBackendName, AllBackendsNameByVendor]] = (
150
- pydantic.Field(
151
- default=None, description="Name of the requested backend or target."
152
- )
145
+ backend_name: PydanticBackendName | AllBackendsNameByVendor | None = pydantic.Field(
146
+ default=None, description="Name of the requested backend or target."
153
147
  )
154
148
  custom_hardware_settings: CustomHardwareSettings = pydantic.Field(
155
149
  default_factory=CustomHardwareSettings,
@@ -182,7 +176,7 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
182
176
  "declarations).",
183
177
  )
184
178
 
185
- qasm3: Optional[bool] = pydantic.Field(
179
+ qasm3: bool | None = pydantic.Field(
186
180
  None,
187
181
  description="Output OpenQASM 3.0 instead of OpenQASM 2.0. Relevant only for "
188
182
  "the `qasm` and `transpiled_circuit.qasm` attributes of `GeneratedCircuit`.",
@@ -194,7 +188,7 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
194
188
  "transpiled circuit and its depth",
195
189
  )
196
190
 
197
- solovay_kitaev_max_iterations: Optional[pydantic.PositiveInt] = pydantic.Field(
191
+ solovay_kitaev_max_iterations: pydantic.PositiveInt | None = pydantic.Field(
198
192
  None,
199
193
  description="Maximum iterations for the Solovay-Kitaev algorithm (if applied).",
200
194
  )
@@ -203,7 +197,7 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
203
197
  default=300, description="Generation timeout in seconds"
204
198
  )
205
199
 
206
- optimization_timeout_seconds: Optional[pydantic.PositiveInt] = pydantic.Field(
200
+ optimization_timeout_seconds: pydantic.PositiveInt | None = pydantic.Field(
207
201
  default=None,
208
202
  description="Optimization timeout in seconds, or None for no "
209
203
  "optimization timeout (will still timeout when the generation timeout is over)",
@@ -217,9 +211,9 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
217
211
  @classmethod
218
212
  def optimization_timeout_less_than_generation_timeout(
219
213
  cls,
220
- optimization_timeout_seconds: Optional[pydantic.PositiveInt],
214
+ optimization_timeout_seconds: pydantic.PositiveInt | None,
221
215
  info: ValidationInfo,
222
- ) -> Optional[pydantic.PositiveInt]:
216
+ ) -> pydantic.PositiveInt | None:
223
217
  generation_timeout_seconds = info.data.get("timeout_seconds")
224
218
  if generation_timeout_seconds is None or optimization_timeout_seconds is None:
225
219
  return optimization_timeout_seconds
@@ -256,7 +250,7 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
256
250
 
257
251
  @pydantic.field_validator("backend_name")
258
252
  @classmethod
259
- def validate_backend_name(cls, backend_name: Optional[str]) -> Optional[str]:
253
+ def validate_backend_name(cls, backend_name: str | None) -> str | None:
260
254
  if backend_name is None:
261
255
  return backend_name
262
256
  return backend_name.rstrip()
@@ -270,7 +264,7 @@ class Preferences(pydantic.BaseModel, extra="forbid"):
270
264
  return self
271
265
 
272
266
  @property
273
- def backend_preferences(self) -> Optional[BackendPreferences]:
267
+ def backend_preferences(self) -> BackendPreferences | None:
274
268
  """
275
269
  Returns the backend preferences. If the backend preferences are not provided, the function sets the backend preferences according to backend name and provider.
276
270
 
@@ -1,11 +1,8 @@
1
1
  import itertools
2
- import sys
3
2
  from collections.abc import Iterator
4
3
  from types import GenericAlias as TypesGenericAlias
5
4
  from typing import ( # type: ignore[attr-defined]
6
5
  Any,
7
- Optional,
8
- Union,
9
6
  _GenericAlias,
10
7
  )
11
8
 
@@ -31,7 +28,7 @@ class QRegGenericAlias(_GenericAlias, _root=True): # type: ignore[call-arg]
31
28
  return super().__call__(*args, **kwargs, **arith_info)
32
29
 
33
30
  def __eq__(self, other: Any) -> bool:
34
- if sys.version_info >= (3, 9) and isinstance(other, TypesGenericAlias):
31
+ if isinstance(other, TypesGenericAlias):
35
32
  return (
36
33
  self.__origin__ == other.__origin__ and self.__args__ == other.__args__
37
34
  )
@@ -39,23 +36,23 @@ class QRegGenericAlias(_GenericAlias, _root=True): # type: ignore[call-arg]
39
36
  return super().__eq__(other)
40
37
 
41
38
  @property
42
- def role(self) -> Optional[RegisterRole]:
39
+ def role(self) -> RegisterRole | None:
43
40
  return getattr(self.__origin__, "role", None)
44
41
 
45
42
  @property
46
- def size(self) -> Optional[int]:
43
+ def size(self) -> int | None:
47
44
  if self.integer_places is not None:
48
45
  return self.integer_places + (self.fraction_places or 0)
49
46
  return None
50
47
 
51
48
  @property
52
- def integer_places(self) -> Optional[int]:
49
+ def integer_places(self) -> int | None:
53
50
  if len(self.__args__) in (1, 2) and isinstance(self.__args__[0], int):
54
51
  return self.__args__[0]
55
52
  return None
56
53
 
57
54
  @property
58
- def fraction_places(self) -> Optional[int]:
55
+ def fraction_places(self) -> int | None:
59
56
  if len(self.__args__) == 2 and isinstance(self.__args__[1], int):
60
57
  return self.__args__[1]
61
58
  return None
@@ -96,11 +93,11 @@ class QReg:
96
93
  qreg._qubits = qubits
97
94
  return qreg
98
95
 
99
- def __getitem__(self, key: Union[int, slice]) -> "QReg":
96
+ def __getitem__(self, key: int | slice) -> "QReg":
100
97
  state = self._qubits[key]
101
98
  return QReg._from_qubits(state if isinstance(state, list) else [state])
102
99
 
103
- def __setitem__(self, key: Union[int, slice], value: "QReg") -> None:
100
+ def __setitem__(self, key: int | slice, value: "QReg") -> None:
104
101
  if isinstance(key, int) and len(value) != 1:
105
102
  raise ClassiqQRegError(
106
103
  f"Size mismatch: value size {len(value)}, expected size 1"
@@ -1,5 +1,3 @@
1
- from typing import Optional
2
-
3
1
  import pydantic
4
2
  from pydantic import BaseModel
5
3
 
@@ -7,9 +5,7 @@ from classiq.interface.helpers.custom_pydantic_types import PydanticProbabilityF
7
5
 
8
6
 
9
7
  class NoiseProperties(BaseModel):
10
- measurement_bit_flip_probability: Optional[PydanticProbabilityFloat] = (
11
- pydantic.Field(
12
- default=None,
13
- description="Probability of measuring the wrong value for each qubit.",
14
- )
8
+ measurement_bit_flip_probability: PydanticProbabilityFloat | None = pydantic.Field(
9
+ default=None,
10
+ description="Probability of measuring the wrong value for each qubit.",
15
11
  )
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Any, Union
3
3
  from classiq.interface.generator.complex_type import Complex
4
4
 
5
5
  if TYPE_CHECKING:
6
- from typing_extensions import TypeAlias
6
+ from typing import TypeAlias
7
7
  else:
8
8
  TypeAlias = Any
9
9
 
@@ -1,7 +1,6 @@
1
1
  import itertools
2
2
  from collections.abc import Iterator
3
3
  from dataclasses import dataclass
4
- from typing import Optional
5
4
 
6
5
  from classiq.interface.exceptions import ClassiqValueError
7
6
  from classiq.interface.generator.slice_parsing_utils import parse_io_slicing
@@ -72,7 +71,7 @@ class RegisterPartition:
72
71
  partitioned_register: PartitionedRegister
73
72
 
74
73
  # index == None means this is the partition containing the leftover qubits.
75
- _index: Optional[int]
74
+ _index: int | None
76
75
 
77
76
  def __post_init__(self) -> None:
78
77
  num_partitions = len(self.partitioned_register.partitions)
@@ -5,8 +5,19 @@ from classiq.interface.enum_utils import StrEnum
5
5
 
6
6
 
7
7
  class QmodFormat(StrEnum):
8
+ """
9
+ Qmod code format.
10
+ """
11
+
8
12
  NATIVE = "native"
13
+ """
14
+ Native Qmod (`.qmod`).
15
+ """
16
+
9
17
  PYTHON = "python"
18
+ """
19
+ Python Qmod (`.py`).
20
+ """
10
21
 
11
22
 
12
23
  class QasmToQmodParams(BaseModel):
@@ -1,4 +1,4 @@
1
- from typing import Literal, Optional, Union
1
+ from typing import Literal, Union
2
2
 
3
3
  import numpy as np
4
4
  import pydantic
@@ -28,7 +28,7 @@ class QSVMFeatureMapEntanglement(StrEnum):
28
28
 
29
29
 
30
30
  class QSVMFeatureMapDimensional(HashablePydanticBaseModel):
31
- feature_dimension: Optional[int] = None
31
+ feature_dimension: int | None = None
32
32
  model_config = ConfigDict(frozen=True)
33
33
 
34
34
 
@@ -10,7 +10,6 @@ from collections.abc import Iterable, Mapping, Sequence
10
10
  from re import Match
11
11
  from typing import (
12
12
  Any,
13
- Optional,
14
13
  Union,
15
14
  )
16
15
  from uuid import UUID, uuid4
@@ -151,13 +150,11 @@ class SynthesisQuantumFunctionCall(BaseModel):
151
150
  description="The name of the function instance. "
152
151
  "If not set, determined automatically.",
153
152
  )
154
- caller_parameters: Optional[list[str]] = pydantic.Field(default=None)
155
- parameter_assignments: Optional[dict[str, ClassicalArg]] = pydantic.Field(
156
- default=None
157
- )
158
- source_id: Optional[UUID] = pydantic.Field(default=None)
159
- arithmetic_id: Optional[str] = pydantic.Field(default=None)
160
- inverse_op_id: Optional[UUID] = pydantic.Field(default=None)
153
+ caller_parameters: list[str] | None = pydantic.Field(default=None)
154
+ parameter_assignments: dict[str, ClassicalArg] | None = pydantic.Field(default=None)
155
+ source_id: UUID | None = pydantic.Field(default=None)
156
+ arithmetic_id: str | None = pydantic.Field(default=None)
157
+ inverse_op_id: UUID | None = pydantic.Field(default=None)
161
158
 
162
159
  uuid: UUID = pydantic.Field(default_factory=uuid4)
163
160
 
@@ -222,7 +219,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
222
219
 
223
220
  @pydantic.field_validator("name", mode="before")
224
221
  @classmethod
225
- def _create_name(cls, name: Optional[str], info: ValidationInfo) -> str:
222
+ def _create_name(cls, name: str | None, info: ValidationInfo) -> str:
226
223
  """
227
224
  generates a name to a user defined-functions as follows:
228
225
  <function_name>_<SUFFIX_MARKER>_<random_suffix>
@@ -400,7 +397,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
400
397
  @pydantic.field_validator("inputs", mode="before")
401
398
  @classmethod
402
399
  def _validate_inputs(cls, inputs: IOType, info: ValidationInfo) -> WireDict:
403
- params: Optional[FunctionParams] = info.data.get("function_params")
400
+ params: FunctionParams | None = info.data.get("function_params")
404
401
  is_inverse: bool = info.data.get("is_inverse", False)
405
402
  strict_zero_ios: bool = info.data.get("strict_zero_ios", True)
406
403
  control_states: list[ControlState] = info.data.get("control_states", list())
@@ -556,7 +553,7 @@ class SynthesisQuantumFunctionCall(BaseModel):
556
553
  control_states: list[ControlState],
557
554
  strict_zero_ios: bool,
558
555
  ) -> tuple[list[str], list[str], list[str]]:
559
- expression_matches: Iterable[Optional[Match]] = map(
556
+ expression_matches: Iterable[Match | None] = map(
560
557
  functools.partial(re.fullmatch, IO_REGEX), expressions
561
558
  )
562
559
 
@@ -2,10 +2,9 @@ import uuid
2
2
  import warnings
3
3
  from datetime import datetime, timezone
4
4
  from pathlib import Path
5
- from typing import Optional, Union
5
+ from typing import TypeAlias
6
6
 
7
7
  import pydantic
8
- from typing_extensions import TypeAlias
9
8
 
10
9
  from classiq.interface.compression_utils import decompress
11
10
  from classiq.interface.exceptions import (
@@ -60,19 +59,17 @@ def _get_formatted_utc_current_time() -> str:
60
59
 
61
60
  class QuantumProgram(VersionedModel, CircuitCodeInterface):
62
61
  hardware_data: SynthesisHardwareData
63
- initial_values: Optional[InitialConditions] = pydantic.Field(default=None)
62
+ initial_values: InitialConditions | None = pydantic.Field(default=None)
64
63
  data: GeneratedCircuitData
65
64
  model: ExecutionModel
66
- transpiled_circuit: Optional[TranspiledCircuitData] = pydantic.Field(default=None)
65
+ transpiled_circuit: TranspiledCircuitData | None = pydantic.Field(default=None)
67
66
  creation_time: str = pydantic.Field(default_factory=_get_formatted_utc_current_time)
68
- synthesis_duration: Optional[SynthesisStepDurations] = pydantic.Field(default=None)
69
- debug_info: Optional[list[FunctionDebugInfoInterface]] = pydantic.Field(
70
- default=None
71
- )
72
- compressed_debug_info: Optional[bytes] = pydantic.Field(default=None)
67
+ synthesis_duration: SynthesisStepDurations | None = pydantic.Field(default=None)
68
+ debug_info: list[FunctionDebugInfoInterface] | None = pydantic.Field(default=None)
69
+ compressed_debug_info: bytes | None = pydantic.Field(default=None)
73
70
  program_id: str = pydantic.Field(default_factory=get_uuid_as_str)
74
- execution_primitives_input: Optional[PrimitivesInput] = pydantic.Field(default=None)
75
- synthesis_warnings: Optional[list[str]] = pydantic.Field(default=None)
71
+ execution_primitives_input: PrimitivesInput | None = pydantic.Field(default=None)
72
+ synthesis_warnings: list[str] | None = pydantic.Field(default=None)
76
73
  should_warn: bool = pydantic.Field(default=False)
77
74
  # Unique identifier for the circuit (since the program_id might change when running show). Used for the circuit store.
78
75
  circuit_id: str = pydantic.Field(default_factory=get_uuid_as_str)
@@ -95,8 +92,8 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
95
92
 
96
93
  def to_program(
97
94
  self,
98
- initial_values: Optional[InitialConditions] = None,
99
- instruction_set: Optional[QuantumInstructionSet] = None,
95
+ initial_values: InitialConditions | None = None,
96
+ instruction_set: QuantumInstructionSet | None = None,
100
97
  ) -> quantum_code.QuantumCode:
101
98
  initial_values = initial_values or self.initial_values
102
99
  if instruction_set is not None:
@@ -141,7 +138,7 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
141
138
  for name, init_value in initial_values.items()
142
139
  }
143
140
 
144
- def save_results(self, filename: Optional[Union[str, Path]] = None) -> None:
141
+ def save_results(self, filename: str | Path | None = None) -> None:
145
142
  """
146
143
  Saves quantum program results as json into a file.
147
144
  Parameters:
@@ -171,7 +168,7 @@ class QuantumProgram(VersionedModel, CircuitCodeInterface):
171
168
  else self
172
169
  )
173
170
 
174
- def get_debug_info(self) -> Optional[list[FunctionDebugInfoInterface]]:
171
+ def get_debug_info(self) -> list[FunctionDebugInfoInterface] | None:
175
172
  # Support legacy uncompressed debug info
176
173
  if self.debug_info is not None:
177
174
  return self.debug_info
@@ -1,5 +1,5 @@
1
1
  import math
2
- from typing import Generic, Optional, TypeVar
2
+ from typing import Generic, TypeVar
3
3
 
4
4
  import pydantic
5
5
  from pydantic import BaseModel, ConfigDict
@@ -17,8 +17,8 @@ DEF_RTOL: float = 1e-05
17
17
 
18
18
 
19
19
  class Range(BaseModel, Generic[RangeType]):
20
- lower_bound: Optional[RangeType] = None
21
- upper_bound: Optional[RangeType] = None
20
+ lower_bound: RangeType | None = None
21
+ upper_bound: RangeType | None = None
22
22
  model_config = ConfigDict(frozen=True)
23
23
 
24
24
  @pydantic.model_validator(mode="after")
@@ -1,6 +1,5 @@
1
1
  import re
2
2
  from re import Match
3
- from typing import Optional
4
3
 
5
4
  from classiq.interface.exceptions import ClassiqValueError
6
5
  from classiq.interface.generator.function_params import NAME_REGEX
@@ -17,8 +16,8 @@ def parse_io_slicing(io_str: str) -> tuple[str, slice]:
17
16
  return name, get_slice(slicing)
18
17
 
19
18
 
20
- def separate_name_and_slice(io_str: str) -> tuple[str, Optional[str]]:
21
- match: Optional[Match] = re.fullmatch(IO_REGEX, io_str)
19
+ def separate_name_and_slice(io_str: str) -> tuple[str, str | None]:
20
+ match: Match | None = re.fullmatch(IO_REGEX, io_str)
22
21
  if match is None:
23
22
  raise AssertionError("Input/output name validation error")
24
23
  name, slicing = (match.groupdict().get(x) for x in [NAME, SLICING])
@@ -27,7 +26,7 @@ def separate_name_and_slice(io_str: str) -> tuple[str, Optional[str]]:
27
26
  return name, slicing
28
27
 
29
28
 
30
- def get_slice(slicing: Optional[str]) -> slice:
29
+ def get_slice(slicing: str | None) -> slice:
31
30
  if slicing is None:
32
31
  return slice(None)
33
32
 
@@ -61,5 +60,5 @@ def get_slice(slicing: Optional[str]) -> slice:
61
60
  raise AssertionError("Input/output slicing validation error")
62
61
 
63
62
 
64
- def _int_or_none(v: str) -> Optional[int]:
63
+ def _int_or_none(v: str) -> int | None:
65
64
  return int(v) if v else None
@@ -1,4 +1,4 @@
1
- from typing import Any, Literal, Optional
1
+ from typing import Any, Literal
2
2
 
3
3
  import pydantic
4
4
 
@@ -38,9 +38,7 @@ class _StandardGate(FunctionParams, metaclass=MyMetaAngledClassModel): # type:
38
38
  def num_target_qubits(self) -> int:
39
39
  return self._num_target_qubits
40
40
 
41
- def __init_subclass__(
42
- cls, angles: Optional[list[str]] = None, **kwargs: Any
43
- ) -> None:
41
+ def __init_subclass__(cls, angles: list[str] | None = None, **kwargs: Any) -> None:
44
42
  super().__init_subclass__(**kwargs)
45
43
 
46
44
 
@@ -1,5 +1,3 @@
1
- from typing import Optional, Union
2
-
3
1
  import numpy as np
4
2
  import pydantic
5
3
  from pydantic_core.core_schema import ValidationInfo
@@ -26,12 +24,12 @@ from classiq.interface.generator.validations.validator_functions import (
26
24
 
27
25
 
28
26
  class StatePreparation(StatePreparationABC):
29
- amplitudes: Optional[Amplitudes] = pydantic.Field(
27
+ amplitudes: Amplitudes | None = pydantic.Field(
30
28
  description="vector of probabilities",
31
29
  default=None,
32
30
  validate_default=True,
33
31
  )
34
- probabilities: Optional[Probabilities] = pydantic.Field(
32
+ probabilities: Probabilities | None = pydantic.Field(
35
33
  description="vector of amplitudes",
36
34
  default=None,
37
35
  validate_default=True,
@@ -46,8 +44,8 @@ class StatePreparation(StatePreparationABC):
46
44
  @pydantic.field_validator("amplitudes", mode="before")
47
45
  @classmethod
48
46
  def _initialize_amplitudes(
49
- cls, amplitudes: Optional[FlexibleAmplitudes]
50
- ) -> Optional[Amplitudes]:
47
+ cls, amplitudes: FlexibleAmplitudes | None
48
+ ) -> Amplitudes | None:
51
49
  if amplitudes is None:
52
50
  return None
53
51
  amplitudes = np.array(amplitudes).squeeze()
@@ -61,8 +59,8 @@ class StatePreparation(StatePreparationABC):
61
59
  @pydantic.field_validator("probabilities", mode="before")
62
60
  @classmethod
63
61
  def _initialize_probabilities(
64
- cls, probabilities: Optional[FlexibleProbabilities]
65
- ) -> Optional[Union[PMF, GaussianMixture, dict]]:
62
+ cls, probabilities: FlexibleProbabilities | None
63
+ ) -> PMF | GaussianMixture | dict | None:
66
64
  if probabilities is None:
67
65
  return None
68
66
  if isinstance(probabilities, Probabilities.__args__): # type: ignore[attr-defined]
@@ -1,6 +1,4 @@
1
- from typing import Union
2
-
3
- from typing_extensions import TypeAlias
1
+ from typing import TypeAlias, Union
4
2
 
5
3
  from classiq.interface.backend.pydantic_backend import PydanticExecutionParameter
6
4
 
@@ -1,5 +1,4 @@
1
1
  from itertools import chain
2
- from typing import Optional
3
2
 
4
3
  import pydantic
5
4
  import sympy
@@ -10,10 +9,10 @@ from classiq.interface.generator.parameters import ParameterType
10
9
 
11
10
 
12
11
  class FunctionExecutionData(pydantic.BaseModel):
13
- power_parameter: Optional[ParameterType] = pydantic.Field(default=None)
12
+ power_parameter: ParameterType | None = pydantic.Field(default=None)
14
13
 
15
14
  @property
16
- def power_vars(self) -> Optional[list[str]]:
15
+ def power_vars(self) -> list[str] | None:
17
16
  if self.power_parameter is None:
18
17
  return None
19
18
  return list(map(str, sympy.sympify(self.power_parameter).free_symbols))
@@ -1,6 +1,4 @@
1
- from typing import TYPE_CHECKING, Optional
2
-
3
- from typing_extensions import TypeAlias
1
+ from typing import TYPE_CHECKING, TypeAlias
4
2
 
5
3
  from classiq.interface.enum_utils import StrEnum
6
4
 
@@ -80,7 +78,7 @@ ALL_GATES_DICT = {gate.upper(): gate.lower() for gate in sorted(ALL_GATES)}
80
78
 
81
79
  class LowerValsEnum(StrEnum):
82
80
  @classmethod
83
- def _missing_(cls, value: Optional[str]) -> Optional[str]: # type: ignore[override]
81
+ def _missing_(cls, value: str | None) -> str | None: # type: ignore[override]
84
82
  if not isinstance(value, str):
85
83
  return None
86
84
  lower = value.lower()
@@ -4,139 +4,6 @@
4
4
  from enum import IntEnum
5
5
 
6
6
 
7
- class Element(IntEnum):
8
- H = 0
9
- He = 1
10
- Li = 2
11
- Be = 3
12
- B = 4
13
- C = 5
14
- N = 6
15
- O = 7 # noqa: E741
16
- F = 8
17
- Ne = 9
18
- Na = 10
19
- Mg = 11
20
- Al = 12
21
- Si = 13
22
- P = 14
23
- S = 15
24
- Cl = 16
25
- Ar = 17
26
- K = 18
27
- Ca = 19
28
- Sc = 20
29
- Ti = 21
30
- V = 22
31
- Cr = 23
32
- Mn = 24
33
- Fe = 25
34
- Co = 26
35
- Ni = 27
36
- Cu = 28
37
- Zn = 29
38
- Ga = 30
39
- Ge = 31
40
- As = 32
41
- Se = 33
42
- Br = 34
43
- Kr = 35
44
- Rb = 36
45
- Sr = 37
46
- Y = 38
47
- Zr = 39
48
- Nb = 40
49
- Mo = 41
50
- Tc = 42
51
- Ru = 43
52
- Rh = 44
53
- Pd = 45
54
- Ag = 46
55
- Cd = 47
56
- In = 48
57
- Sn = 49
58
- Sb = 50
59
- Te = 51
60
- I = 52 # noqa: E741
61
- Xe = 53
62
- Cs = 54
63
- Ba = 55
64
- La = 56
65
- Ce = 57
66
- Pr = 58
67
- Nd = 59
68
- Pm = 60
69
- Sm = 61
70
- Eu = 62
71
- Gd = 63
72
- Tb = 64
73
- Dy = 65
74
- Ho = 66
75
- Er = 67
76
- Tm = 68
77
- Yb = 69
78
- Lu = 70
79
- Hf = 71
80
- Ta = 72
81
- W = 73
82
- Re = 74
83
- Os = 75
84
- Ir = 76
85
- Pt = 77
86
- Au = 78
87
- Hg = 79
88
- Tl = 80
89
- Pb = 81
90
- Bi = 82
91
- Po = 83
92
- At = 84
93
- Rn = 85
94
- Fr = 86
95
- Ra = 87
96
- Ac = 88
97
- Th = 89
98
- Pa = 90
99
- U = 91
100
- Np = 92
101
- Pu = 93
102
- Am = 94
103
- Cm = 95
104
- Bk = 96
105
- Cf = 97
106
- Es = 98
107
- Fm = 99
108
- Md = 100
109
- No = 101
110
- Lr = 102
111
- Rf = 103
112
- Db = 104
113
- Sg = 105
114
- Bh = 106
115
- Hs = 107
116
- Mt = 108
117
- Ds = 109
118
- Rg = 110
119
- Cn = 111
120
- Nh = 112
121
- Fl = 113
122
- Mc = 114
123
- Lv = 115
124
- Ts = 116
125
- Og = 117
126
-
127
-
128
- class FermionMapping(IntEnum):
129
- JORDAN_WIGNER = 0
130
- PARITY = 1
131
- BRAVYI_KITAEV = 2
132
- FAST_BRAVYI_KITAEV = 3
133
-
134
-
135
- class LadderOperator(IntEnum):
136
- PLUS = 0
137
- MINUS = 1
138
-
139
-
140
7
  class Optimizer(IntEnum):
141
8
  COBYLA = 1
142
9
  SPSA = 2
@@ -162,9 +29,6 @@ class QSVMFeatureMapEntanglement(IntEnum):
162
29
 
163
30
 
164
31
  __all__ = [
165
- "Element",
166
- "FermionMapping",
167
- "LadderOperator",
168
32
  "Optimizer",
169
33
  "Pauli",
170
34
  "QSVMFeatureMapEntanglement",