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
@@ -1,4 +1,4 @@
1
- from typing import Any, Optional, TypeVar
1
+ from typing import Any, TypeVar
2
2
  from uuid import UUID
3
3
 
4
4
  import pydantic
@@ -13,8 +13,8 @@ ASTNodeType = TypeVar("ASTNodeType", bound="ASTNode")
13
13
 
14
14
 
15
15
  class ASTNode(HashablePydanticBaseModel):
16
- source_ref: Optional[SourceReference] = pydantic.Field(default=None)
17
- back_ref: Optional[UUID] = pydantic.Field(default=None)
16
+ source_ref: SourceReference | None = pydantic.Field(default=None)
17
+ back_ref: UUID | None = pydantic.Field(default=None)
18
18
 
19
19
  def _as_back_ref(self: Self) -> Self:
20
20
  return self
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import warnings
4
4
  from collections.abc import Iterable
5
- from typing import Any, Optional, Union
5
+ from typing import Any, Union
6
6
 
7
7
  import pydantic
8
8
  from pydantic import BaseModel
@@ -103,19 +103,19 @@ class AliceBobBackendPreferences(BackendPreferences):
103
103
  backend_service_provider: ProviderTypeVendor.ALICE_BOB = pydantic.Field(
104
104
  default=ProviderVendor.ALICE_AND_BOB
105
105
  )
106
- distance: Optional[int] = pydantic.Field(
106
+ distance: int | None = pydantic.Field(
107
107
  default=None, description="Repetition code distance"
108
108
  )
109
- kappa_1: Optional[float] = pydantic.Field(
109
+ kappa_1: float | None = pydantic.Field(
110
110
  default=None, description="One-photon dissipation rate (Hz)"
111
111
  )
112
- kappa_2: Optional[float] = pydantic.Field(
112
+ kappa_2: float | None = pydantic.Field(
113
113
  default=None, description="Two-photon dissipation rate (Hz)"
114
114
  )
115
- average_nb_photons: Optional[float] = pydantic.Field(
115
+ average_nb_photons: float | None = pydantic.Field(
116
116
  default=None, description="Average number of photons"
117
117
  )
118
- api_key: Optional[pydantic_backend.PydanticAliceBobApiKeyType] = pydantic.Field(
118
+ api_key: pydantic_backend.PydanticAliceBobApiKeyType | None = pydantic.Field(
119
119
  default=None, description="AliceBob API key"
120
120
  )
121
121
 
@@ -131,7 +131,7 @@ class AliceBobBackendPreferences(BackendPreferences):
131
131
 
132
132
  @pydantic.field_validator("api_key", mode="after")
133
133
  @classmethod
134
- def _validate_api_key(cls, api_key: Optional[str]) -> Optional[str]:
134
+ def _validate_api_key(cls, api_key: str | None) -> str | None:
135
135
  if api_key is not None:
136
136
  warnings.warn(
137
137
  "API key is no longer required for Alice&Bob backends.",
@@ -193,14 +193,14 @@ class AwsBackendPreferences(BackendPreferences):
193
193
  backend_service_provider: ProviderTypeVendor.AMAZON_BRAKET = pydantic.Field(
194
194
  default=ProviderVendor.AMAZON_BRAKET
195
195
  )
196
- aws_role_arn: Optional[str] = pydantic.Field(
196
+ aws_role_arn: str | None = pydantic.Field(
197
197
  default=None,
198
198
  description="ARN of the role to be assumed for execution on your Braket account.",
199
199
  )
200
- s3_bucket_name: Optional[str] = pydantic.Field(
200
+ s3_bucket_name: str | None = pydantic.Field(
201
201
  default=None, description="S3 Bucket Name"
202
202
  )
203
- s3_folder: Optional[str] = pydantic.Field(
203
+ s3_folder: str | None = pydantic.Field(
204
204
  default=None, description="S3 Folder Path Within The S3 Bucket"
205
205
  )
206
206
  run_through_classiq: bool = pydantic.Field(
@@ -229,15 +229,15 @@ class IBMBackendPreferences(BackendPreferences):
229
229
  backend_service_provider: ProviderTypeVendor.IBM_CLOUD = pydantic.Field(
230
230
  default=ProviderVendor.IBM_QUANTUM
231
231
  )
232
- access_token: Optional[str] = pydantic.Field(
232
+ access_token: str | None = pydantic.Field(
233
233
  default=None,
234
234
  description="IBM Cloud access token to be used"
235
235
  " with IBM Quantum hosted backends",
236
236
  )
237
- channel: Optional[str] = pydantic.Field(
237
+ channel: str | None = pydantic.Field(
238
238
  default=None, description="Channel to use for IBM cloud backends."
239
239
  )
240
- instance_crn: Optional[str] = pydantic.Field(
240
+ instance_crn: str | None = pydantic.Field(
241
241
  default=None, description="IBM Cloud instance CRN."
242
242
  )
243
243
  run_through_classiq: bool = pydantic.Field(
@@ -303,12 +303,12 @@ class AzureBackendPreferences(BackendPreferences):
303
303
  default="East US", description="Azure personal resource region"
304
304
  )
305
305
 
306
- credentials: Optional[AzureCredential] = pydantic.Field(
306
+ credentials: AzureCredential | None = pydantic.Field(
307
307
  default=None,
308
308
  description="The service principal credential to access personal quantum workspace",
309
309
  )
310
310
 
311
- ionq_error_mitigation_flag: Optional[bool] = pydantic.Field(
311
+ ionq_error_mitigation_flag: bool | None = pydantic.Field(
312
312
  default=False,
313
313
  description="Error mitigation configuration upon running on IonQ through Azure.",
314
314
  )
@@ -343,7 +343,7 @@ class IonqBackendPreferences(BackendPreferences):
343
343
  backend_service_provider: ProviderTypeVendor.IONQ = pydantic.Field(
344
344
  default=ProviderVendor.IONQ
345
345
  )
346
- api_key: Optional[pydantic_backend.PydanticIonQApiKeyType] = pydantic.Field(
346
+ api_key: pydantic_backend.PydanticIonQApiKeyType | None = pydantic.Field(
347
347
  default=None, description="IonQ API key"
348
348
  )
349
349
  error_mitigation: bool = pydantic.Field(
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import TYPE_CHECKING, Annotated, Optional
3
+ from typing import TYPE_CHECKING, Annotated
4
4
 
5
5
  from pydantic import BaseModel, ConfigDict, Field
6
6
 
@@ -22,10 +22,10 @@ else:
22
22
 
23
23
  class Gate(BaseModel):
24
24
  gate: PydanticGateName
25
- target: Optional[int] = None
26
- control: Optional[int] = None
27
- targets: Optional[list[int]] = None
28
- controls: Optional[list[int]] = None
25
+ target: int | None = None
26
+ control: int | None = None
27
+ targets: list[int] | None = None
28
+ controls: list[int] | None = None
29
29
  model_config = ConfigDict(extra="allow")
30
30
 
31
31
 
@@ -1,13 +1,11 @@
1
- from typing import Optional
2
-
3
1
  from pydantic import BaseModel
4
2
 
5
3
 
6
4
  class HardwareEfficientConstraints(BaseModel):
7
5
  num_qubits: int
8
- num_two_qubit_gates: Optional[int] = None
9
- num_one_qubit_gates: Optional[int] = None
10
- max_depth: Optional[int] = None
6
+ num_two_qubit_gates: int | None = None
7
+ num_one_qubit_gates: int | None = None
8
+ max_depth: int | None = None
11
9
 
12
10
 
13
11
  class HardwareEfficient(BaseModel):
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Collection, Iterable
2
2
  from functools import reduce
3
3
  from itertools import combinations
4
- from typing import Any, Optional, Union, cast
4
+ from typing import Any, cast
5
5
 
6
6
  import numpy as np
7
7
  import pydantic
@@ -65,7 +65,7 @@ class PauliOperator(HashablePydanticBaseModel, VersionedModel):
65
65
 
66
66
  @staticmethod
67
67
  def _validate_monomial_coefficient(
68
- coeff: Union[sympy.Expr, ParameterComplexType],
68
+ coeff: sympy.Expr | ParameterComplexType,
69
69
  ) -> ParameterComplexType:
70
70
  if isinstance(coeff, str):
71
71
  validate_expression_str(coeff)
@@ -219,7 +219,7 @@ class PauliOperator(HashablePydanticBaseModel, VersionedModel):
219
219
  def from_unzipped_lists(
220
220
  cls,
221
221
  operators: list[list["Pauli"]],
222
- coefficients: Optional[list[complex]] = None,
222
+ coefficients: list[complex] | None = None,
223
223
  ) -> "PauliOperator":
224
224
  if coefficients is None:
225
225
  coefficients = [1] * len(operators)
@@ -1,5 +1,3 @@
1
- from typing import Optional
2
-
3
1
  import numpy as np
4
2
  import pyomo.core as pyo
5
3
 
@@ -7,8 +5,8 @@ import pyomo.core as pyo
7
5
  def knapsack(
8
6
  values: list[int],
9
7
  upper_bound: int,
10
- weights: Optional[list[int]] = None,
11
- max_weight: Optional[int] = None,
8
+ weights: list[int] | None = None,
9
+ max_weight: int | None = None,
12
10
  ) -> pyo.ConcreteModel:
13
11
  model = pyo.ConcreteModel()
14
12
 
@@ -1,12 +1,11 @@
1
1
  import itertools
2
- from typing import Union
3
2
 
4
3
  import networkx as nx
5
4
  import pyomo.core as pyo
6
5
 
7
6
 
8
7
  def tsp_digraph(
9
- graph: nx.DiGraph, source: Union[int, str], sink: Union[int, str], nonedge: int
8
+ graph: nx.DiGraph, source: int | str, sink: int | str, nonedge: int
10
9
  ) -> pyo.ConcreteModel:
11
10
  model = pyo.ConcreteModel()
12
11
 
@@ -1,19 +1,18 @@
1
1
  import base64
2
2
  from collections.abc import Sequence
3
- from typing import Union
4
3
 
5
4
  import zstandard as zstd
6
5
  from pydantic import BaseModel
7
6
  from pydantic_core import from_json, to_json
8
7
 
9
8
 
10
- def compress_pydantic(obj: Union[BaseModel, Sequence[BaseModel]]) -> bytes:
9
+ def compress_pydantic(obj: BaseModel | Sequence[BaseModel]) -> bytes:
11
10
  json_data = to_json(obj)
12
11
  compressed_data = _compress(json_data, level=22) # max compression level
13
12
  return compressed_data
14
13
 
15
14
 
16
- def decompress(compressed_data: bytes) -> Union[dict, list[dict]]:
15
+ def decompress(compressed_data: bytes) -> dict | list[dict]:
17
16
  decompressed_data = _decompress(compressed_data)
18
17
  return from_json(decompressed_data)
19
18
 
@@ -1,5 +1,5 @@
1
1
  from collections.abc import Mapping, Sequence
2
- from typing import Optional, Union, cast
2
+ from typing import Union, cast
3
3
  from uuid import UUID
4
4
 
5
5
  from pydantic import BaseModel, Field
@@ -20,11 +20,11 @@ ParameterValue = Union[float, int, str, None]
20
20
 
21
21
  class FunctionDebugInfo(BaseModel):
22
22
  name: str
23
- statement_type: Union[StatementType, None] = None
23
+ statement_type: StatementType | None = None
24
24
  is_inverse: bool = Field(default=False)
25
- control_variable: Optional[str] = Field(default=None)
25
+ control_variable: str | None = Field(default=None)
26
26
  port_to_passed_variable_map: dict[str, str] = Field(default_factory=dict)
27
- node: Optional[ConcreteQuantumStatement] = None
27
+ node: ConcreteQuantumStatement | None = None
28
28
 
29
29
  @property
30
30
  def is_allocate_or_free(self) -> bool:
@@ -61,7 +61,7 @@ class DebugInfoCollection(BaseModel):
61
61
  def __setitem__(self, key: UUID, value: FunctionDebugInfo) -> None:
62
62
  self.data[str(key)] = value
63
63
 
64
- def get(self, key: UUID) -> Optional[FunctionDebugInfo]:
64
+ def get(self, key: UUID) -> FunctionDebugInfo | None:
65
65
  return self.data.get(str(key))
66
66
 
67
67
  def __getitem__(self, key: UUID) -> FunctionDebugInfo:
@@ -70,7 +70,7 @@ class DebugInfoCollection(BaseModel):
70
70
  def __contains__(self, key: UUID) -> bool:
71
71
  return str(key) in self.data
72
72
 
73
- def get_blackbox_data(self, key: UUID) -> Optional[FunctionDebugInfoInterface]:
73
+ def get_blackbox_data(self, key: UUID) -> FunctionDebugInfoInterface | None:
74
74
  if (debug_info := self.get(key)) is None:
75
75
  return None
76
76
  return self.blackbox_data.get(debug_info.name)
@@ -103,7 +103,7 @@ def new_function_debug_info_by_node(
103
103
 
104
104
 
105
105
  def calculate_port_to_passed_variable_mapping(
106
- arg_decls: Sequence[PositionalArg], args: Sequence[Union[ArgValue, None]]
106
+ arg_decls: Sequence[PositionalArg], args: Sequence[ArgValue | None]
107
107
  ) -> dict[str, str]:
108
108
  return {
109
109
  arg_decl.name: str(cast(ConcreteHandleBinding, arg))
@@ -1,6 +1,5 @@
1
1
  import logging
2
2
  from collections.abc import Iterable
3
- from typing import Optional
4
3
 
5
4
  _logger = logging.getLogger(__name__)
6
5
 
@@ -53,7 +52,7 @@ class ClassiqAnalyzerVisualizationError(ClassiqError):
53
52
 
54
53
 
55
54
  class ClassiqAPIError(ClassiqError):
56
- def __init__(self, message: str, status_code: Optional[int] = None) -> None:
55
+ def __init__(self, message: str, status_code: int | None = None) -> None:
57
56
  self.status_code = status_code
58
57
  super().__init__(message)
59
58
 
@@ -191,7 +190,7 @@ class ClassiqExpansionError(ClassiqError):
191
190
 
192
191
 
193
192
  class ClassiqInternalError(ClassiqError):
194
- def __init__(self, message: Optional[str] = None) -> None:
193
+ def __init__(self, message: str | None = None) -> None:
195
194
  final_message = "Internal error occurred. Please contact Classiq support."
196
195
  if message is not None:
197
196
  final_message += f"\nError: {message}"
@@ -1,5 +1,3 @@
1
- from typing import Optional
2
-
3
1
  from pydantic import BaseModel, Field
4
2
 
5
3
  from classiq.interface.helpers.versioned_model import VersionedModel
@@ -27,7 +25,7 @@ class IQCCAuthItemDetails(BaseModel):
27
25
  id: str
28
26
  name: str
29
27
  description: str
30
- scope_id: Optional[str] = Field(default=None)
28
+ scope_id: str | None = Field(default=None)
31
29
 
32
30
 
33
31
  class IQCCAuthItemsDetails(VersionedModel):
@@ -1,4 +1,4 @@
1
- from typing import Annotated, Literal, Optional, Union
1
+ from typing import Annotated, Literal, Union
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
@@ -17,7 +17,7 @@ class MinimizeCostInput(BaseModel, json_encoders=CUSTOM_ENCODERS):
17
17
  initial_params: Arguments
18
18
  max_iteration: int
19
19
  quantile: float
20
- tolerance: Optional[float]
20
+ tolerance: float | None
21
21
 
22
22
 
23
23
  class MinimizeClassicalCostInput(MinimizeCostInput):
@@ -41,7 +41,7 @@ ConcreteMinimizeCostInput = Annotated[
41
41
 
42
42
 
43
43
  class PrimitivesInput(BaseModel, json_encoders=CUSTOM_ENCODERS):
44
- sample: Optional[list[Arguments]] = Field(default=None)
45
- estimate: Optional[EstimateInput] = Field(default=None)
46
- minimize: Optional[ConcreteMinimizeCostInput] = Field(default=None)
47
- random_seed: Optional[int] = Field(default=None)
44
+ sample: list[Arguments] | None = Field(default=None)
45
+ estimate: EstimateInput | None = Field(default=None)
46
+ minimize: ConcreteMinimizeCostInput | None = Field(default=None)
47
+ random_seed: int | None = Field(default=None)
@@ -1,4 +1,4 @@
1
- from typing import Callable
1
+ from collections.abc import Callable
2
2
 
3
3
  import numpy as np
4
4
 
@@ -1,5 +1,3 @@
1
- from typing import Optional
2
-
3
1
  import pydantic
4
2
 
5
3
  from classiq.interface.backend.backend_preferences import (
@@ -43,7 +41,7 @@ class ExecutionPreferences(pydantic.BaseModel):
43
41
  job_name (Optional[str]): The name of the job, with a minimum length of 1 character.
44
42
  """
45
43
 
46
- noise_properties: Optional[NoiseProperties] = pydantic.Field(
44
+ noise_properties: NoiseProperties | None = pydantic.Field(
47
45
  default=None, description="Properties of the noise in the circuit"
48
46
  )
49
47
  random_seed: int = pydantic.Field(
@@ -53,13 +51,13 @@ class ExecutionPreferences(pydantic.BaseModel):
53
51
  backend_preferences: BackendPreferencesTypes = backend_preferences_field(
54
52
  backend_name=ClassiqSimulatorBackendNames.SIMULATOR
55
53
  )
56
- num_shots: Optional[pydantic.PositiveInt] = pydantic.Field(default=None)
54
+ num_shots: pydantic.PositiveInt | None = pydantic.Field(default=None)
57
55
  transpile_to_hardware: TranspilationOption = pydantic.Field(
58
56
  default=TranspilationOption.DECOMPOSE,
59
57
  description="Transpile the circuit to the hardware basis gates before execution",
60
58
  title="Transpilation Option",
61
59
  )
62
- job_name: Optional[str] = pydantic.Field(
60
+ job_name: str | None = pydantic.Field(
63
61
  min_length=1, description="The job name", default=None
64
62
  )
65
63
 
@@ -1,5 +1,5 @@
1
1
  from datetime import datetime
2
- from typing import Annotated, Literal, Optional, Union
2
+ from typing import Annotated, Literal, Union
3
3
 
4
4
  import pydantic
5
5
  from pydantic import BaseModel, Field
@@ -51,28 +51,28 @@ class ProviderJobs(BaseModel):
51
51
  class JobCost(BaseModel):
52
52
  total_cost: float = Field(default=0)
53
53
  currency_code: str = Field(default="USD")
54
- organization: Optional[str] = Field(default=None)
54
+ organization: str | None = Field(default=None)
55
55
  jobs: list[ProviderJobs] = Field(default=[])
56
56
 
57
57
 
58
58
  class ExecutionJobDetails(VersionedModel):
59
59
  id: str
60
60
 
61
- name: Optional[str] = Field(default=None)
61
+ name: str | None = Field(default=None)
62
62
  start_time: datetime
63
- end_time: Optional[datetime] = Field(default=None)
63
+ end_time: datetime | None = Field(default=None)
64
64
 
65
- provider: Optional[str] = Field(default=None)
66
- backend_name: Optional[str] = Field(default=None)
65
+ provider: str | None = Field(default=None)
66
+ backend_name: str | None = Field(default=None)
67
67
 
68
68
  status: JobStatus
69
69
 
70
- num_shots: Optional[int] = Field(default=None)
71
- program_id: Optional[str] = Field(default=None)
70
+ num_shots: int | None = Field(default=None)
71
+ program_id: str | None = Field(default=None)
72
72
 
73
- error: Optional[str] = Field(default=None)
73
+ error: str | None = Field(default=None)
74
74
 
75
- cost: Optional[JobCost] = Field(default=None)
75
+ cost: JobCost | None = Field(default=None)
76
76
 
77
77
 
78
78
  class ExecutionJobsQueryResults(VersionedModel):
@@ -1,7 +1,6 @@
1
- from typing import Annotated, Any, Literal, Union
1
+ from typing import Annotated, Any, Literal, TypeAlias, Union
2
2
 
3
3
  from pydantic import BaseModel, ConfigDict, Field
4
- from typing_extensions import TypeAlias
5
4
 
6
5
  from classiq.interface.applications.iqae.iqae_result import IQAEResult
7
6
  from classiq.interface.enum_utils import StrEnum
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from pathlib import Path
4
- from typing import Any, Optional, Union
4
+ from typing import Any
5
5
 
6
6
  import pydantic
7
7
  from pydantic import BaseModel, ConfigDict
@@ -35,7 +35,7 @@ class QuantumBaseCode(BaseModel):
35
35
  @pydantic.field_validator("code")
36
36
  @classmethod
37
37
  def load_quantum_program(
38
- cls, code: Union[CodeType, IonqQuantumCircuit], values: ValidationInfo
38
+ cls, code: CodeType | IonqQuantumCircuit, values: ValidationInfo
39
39
  ) -> CodeType:
40
40
  syntax = values.data.get("syntax")
41
41
  if isinstance(code, IonqQuantumCircuit):
@@ -57,11 +57,11 @@ class QuantumCode(QuantumBaseCode):
57
57
  default_factory=dict,
58
58
  description="The map of outputs to their qubits in the circuit.",
59
59
  )
60
- registers_initialization: Optional[RegistersInitialization] = pydantic.Field(
60
+ registers_initialization: RegistersInitialization | None = pydantic.Field(
61
61
  default=None,
62
62
  description="Initial conditions for the different registers in the circuit.",
63
63
  )
64
- synthesis_execution_data: Optional[ExecutionData] = pydantic.Field(default=None)
64
+ synthesis_execution_data: ExecutionData | None = pydantic.Field(default=None)
65
65
  synthesis_execution_arguments: Arguments = pydantic.Field(default_factory=dict)
66
66
  model_config = ConfigDict(validate_assignment=True)
67
67
 
@@ -90,9 +90,9 @@ class QuantumCode(QuantumBaseCode):
90
90
  @classmethod
91
91
  def validate_synthesis_execution_data(
92
92
  cls,
93
- synthesis_execution_data: Optional[ExecutionData],
93
+ synthesis_execution_data: ExecutionData | None,
94
94
  values: ValidationInfo,
95
- ) -> Optional[ExecutionData]:
95
+ ) -> ExecutionData | None:
96
96
  if (
97
97
  synthesis_execution_data is not None
98
98
  and synthesis_execution_data.function_execution
@@ -103,8 +103,8 @@ class QuantumCode(QuantumBaseCode):
103
103
 
104
104
  @staticmethod
105
105
  def from_file(
106
- file_path: Union[str, Path],
107
- syntax: Optional[Union[str, QuantumInstructionSet]] = None,
106
+ file_path: str | Path,
107
+ syntax: str | QuantumInstructionSet | None = None,
108
108
  arguments: MultipleArguments = (),
109
109
  ) -> QuantumCode:
110
110
  path = Path(file_path)
@@ -9,13 +9,13 @@ from typing import (
9
9
  Any,
10
10
  DefaultDict,
11
11
  Optional,
12
+ TypeAlias,
12
13
  Union,
13
14
  )
14
15
 
15
- import pandas as pd
16
16
  import pydantic
17
17
  from pydantic import BaseModel
18
- from typing_extensions import Self, TypeAlias
18
+ from typing_extensions import Self
19
19
 
20
20
  from classiq.interface.exceptions import (
21
21
  ClassiqError,
@@ -52,6 +52,8 @@ MAGNITUDE = "magnitude"
52
52
  PHASE = "phase"
53
53
 
54
54
  if TYPE_CHECKING:
55
+ import pandas as pd
56
+
55
57
  DotAccessParsedState = Mapping[Name, Any]
56
58
  else:
57
59
  DotAccessParsedState = ParsedState
@@ -90,8 +92,8 @@ ParsedStateVector: TypeAlias = list[SimulatedState]
90
92
 
91
93
 
92
94
  class VaRResult(BaseModel):
93
- var: Optional[float] = None
94
- alpha: Optional[float] = None
95
+ var: float | None = None
96
+ alpha: float | None = None
95
97
 
96
98
 
97
99
  class GroverSimulationResults(VersionedModel):
@@ -119,7 +121,7 @@ def flip_counts_qubit_order(counts: Counts) -> Counts:
119
121
 
120
122
  def get_sampled_state(
121
123
  parsed_counts: ParsedCounts, state: ParsedState
122
- ) -> Optional[SampledState]:
124
+ ) -> SampledState | None:
123
125
  for sampled_state in parsed_counts:
124
126
  if sampled_state.state == state:
125
127
  return sampled_state
@@ -150,7 +152,7 @@ def get_parsed_counts(counts: Counts, parsed_states: ParsedStates) -> ParsedCoun
150
152
 
151
153
  def prepare_parsed_state_vector(
152
154
  state_vector: StateVector, parsed_state_vector_states: ParsedStates
153
- ) -> Optional[ParsedStateVector]:
155
+ ) -> ParsedStateVector | None:
154
156
  if not state_vector:
155
157
  return None
156
158
 
@@ -165,7 +167,11 @@ def prepare_parsed_state_vector(
165
167
  return sorted(parsed_state_vector, key=lambda k: abs(k.amplitude), reverse=True)
166
168
 
167
169
 
168
- def _flatten_columns(df: pd.DataFrame, columns_to_flatten: list[str]) -> pd.DataFrame:
170
+ def _flatten_columns(
171
+ df: "pd.DataFrame", columns_to_flatten: list[str]
172
+ ) -> "pd.DataFrame":
173
+ import pandas as pd
174
+
169
175
  if len(df.columns) == 0:
170
176
  return df
171
177
 
@@ -221,7 +227,7 @@ class ExecutionDetails(BaseModel, QmodPyObject):
221
227
  default_factory=dict,
222
228
  description="A mapping between the raw states of counts (bitstrings) to their parsed states (registers' values)",
223
229
  )
224
- histogram: Optional[dict[State, pydantic.NonNegativeFloat]] = pydantic.Field(
230
+ histogram: dict[State, pydantic.NonNegativeFloat] | None = pydantic.Field(
225
231
  None,
226
232
  description="Histogram of probability per state (an alternative to counts)",
227
233
  )
@@ -233,15 +239,15 @@ class ExecutionDetails(BaseModel, QmodPyObject):
233
239
  default=None,
234
240
  description="The state vector when executed on a simulator, with LSB right qubit order",
235
241
  )
236
- parsed_state_vector_states: Optional[ParsedStates] = pydantic.Field(
242
+ parsed_state_vector_states: ParsedStates | None = pydantic.Field(
237
243
  default=None,
238
244
  description="A mapping between the raw states of the state vector (bitstrings) to their parsed states (registers' values)",
239
245
  )
240
- physical_qubits_map: Optional[OutputQubitsMap] = pydantic.Field(
246
+ physical_qubits_map: OutputQubitsMap | None = pydantic.Field(
241
247
  default=None,
242
248
  description="The map of all registers (also non measured) to their qubits in the circuit. Used for state_vector which represent also the non-measured qubits.",
243
249
  )
244
- num_shots: Optional[pydantic.NonNegativeInt] = pydantic.Field(
250
+ num_shots: pydantic.NonNegativeInt | None = pydantic.Field(
245
251
  default=None, description="The total number of shots the circuit was executed"
246
252
  )
247
253
 
@@ -274,7 +280,7 @@ class ExecutionDetails(BaseModel, QmodPyObject):
274
280
  return get_parsed_counts(self.counts, self.parsed_states)
275
281
 
276
282
  @property
277
- def parsed_state_vector(self) -> Optional[ParsedStateVector]:
283
+ def parsed_state_vector(self) -> ParsedStateVector | None:
278
284
  if TYPE_CHECKING:
279
285
  assert self.parsed_state_vector_states is not None
280
286
  return prepare_parsed_state_vector(
@@ -327,7 +333,7 @@ class ExecutionDetails(BaseModel, QmodPyObject):
327
333
  return dict(reduced_counts)
328
334
 
329
335
  def parsed_counts_of_outputs(
330
- self, output_names: Union[Name, tuple[Name, ...]]
336
+ self, output_names: Name | tuple[Name, ...]
331
337
  ) -> ParsedCounts:
332
338
  if isinstance(output_names, Name):
333
339
  output_names = (output_names,)
@@ -361,7 +367,9 @@ class ExecutionDetails(BaseModel, QmodPyObject):
361
367
  )[::-1]
362
368
  return number_utils.binary_to_float_or_int(bin_rep=register_binary_string)
363
369
 
364
- def _counts_df(self) -> pd.DataFrame:
370
+ def _counts_df(self) -> "pd.DataFrame":
371
+ import pandas as pd
372
+
365
373
  data: dict[str, Any] = defaultdict(list)
366
374
 
367
375
  for bitstring, count in self.counts.items():
@@ -382,7 +390,9 @@ class ExecutionDetails(BaseModel, QmodPyObject):
382
390
 
383
391
  return pd.DataFrame(data, columns=columns)
384
392
 
385
- def _state_vector_df(self) -> pd.DataFrame:
393
+ def _state_vector_df(self) -> "pd.DataFrame":
394
+ import pandas as pd
395
+
386
396
  data: dict[str, Any] = defaultdict(list)
387
397
 
388
398
  if not self.state_vector:
@@ -408,7 +418,7 @@ class ExecutionDetails(BaseModel, QmodPyObject):
408
418
  return pd.DataFrame(data, columns=columns)
409
419
 
410
420
  @functools.cached_property
411
- def dataframe(self) -> pd.DataFrame:
421
+ def dataframe(self) -> "pd.DataFrame":
412
422
  reserved_words = frozenset(
413
423
  [BITSTRING, PROBABILITY, COUNT, AMPLITUDE, PHASE, MAGNITUDE]
414
424
  )
@@ -449,9 +459,9 @@ class MultipleExecutionDetails(VersionedModel):
449
459
 
450
460
 
451
461
  class EstimationMetadata(BaseModel, extra="allow"):
452
- shots: Optional[pydantic.NonNegativeInt] = None
462
+ shots: pydantic.NonNegativeInt | None = None
453
463
  remapped_qubits: bool = False
454
- input_qubit_map: Optional[list[PydanticNonNegIntTuple]] = None
464
+ input_qubit_map: list[PydanticNonNegIntTuple] | None = None
455
465
 
456
466
 
457
467
  class EstimationResult(BaseModel, QmodPyObject):