classiq 0.92.0__py3-none-any.whl → 0.94.0__py3-none-any.whl

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

Potentially problematic release.


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

Files changed (264) 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 +6 -5
  45. classiq/applications/qsvm/qsvm_data_generation.py +1 -2
  46. classiq/evaluators/classical_expression.py +0 -4
  47. classiq/evaluators/parameter_types.py +17 -12
  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 +6 -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 +8 -4
  182. classiq/model_expansions/quantum_operations/allocate.py +4 -4
  183. classiq/model_expansions/quantum_operations/assignment_result_processor.py +8 -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 +61 -29
  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 +19 -14
  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 +43 -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/classical_variable.py +4 -2
  212. classiq/qmod/cparam.py +2 -8
  213. classiq/qmod/create_model_function.py +7 -7
  214. classiq/qmod/declaration_inferrer.py +33 -30
  215. classiq/qmod/model_state_container.py +2 -2
  216. classiq/qmod/native/pretty_printer.py +25 -14
  217. classiq/qmod/pretty_print/expression_to_python.py +5 -3
  218. classiq/qmod/pretty_print/pretty_printer.py +39 -17
  219. classiq/qmod/python_classical_type.py +40 -13
  220. classiq/qmod/qfunc.py +139 -16
  221. classiq/qmod/qmod_constant.py +2 -2
  222. classiq/qmod/qmod_parameter.py +5 -2
  223. classiq/qmod/qmod_variable.py +47 -43
  224. classiq/qmod/quantum_callable.py +18 -13
  225. classiq/qmod/quantum_expandable.py +33 -26
  226. classiq/qmod/quantum_function.py +51 -32
  227. classiq/qmod/semantics/annotation/call_annotation.py +2 -2
  228. classiq/qmod/semantics/error_manager.py +5 -6
  229. classiq/qmod/semantics/lambdas.py +1 -2
  230. classiq/qmod/semantics/validation/types_validation.py +1 -2
  231. classiq/qmod/symbolic.py +2 -4
  232. classiq/qmod/symbolic_expr.py +12 -4
  233. classiq/qmod/utilities.py +13 -10
  234. classiq/qmod/write_qmod.py +3 -4
  235. classiq/quantum_program.py +1 -3
  236. classiq/synthesis.py +11 -7
  237. {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/METADATA +38 -37
  238. {classiq-0.92.0.dist-info → classiq-0.94.0.dist-info}/RECORD +240 -261
  239. classiq-0.94.0.dist-info/WHEEL +4 -0
  240. classiq-0.94.0.dist-info/licenses/LICENSE.txt +27 -0
  241. classiq/applications/chemistry/ansatz_parameters.py +0 -29
  242. classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
  243. classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
  244. classiq/applications/chemistry/ground_state_problem.py +0 -42
  245. classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
  246. classiq/interface/chemistry/elements.py +0 -120
  247. classiq/interface/chemistry/fermionic_operator.py +0 -208
  248. classiq/interface/chemistry/ground_state_problem.py +0 -132
  249. classiq/interface/chemistry/ground_state_result.py +0 -8
  250. classiq/interface/chemistry/molecule.py +0 -71
  251. classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
  252. classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
  253. classiq/interface/generator/chemistry_function_params.py +0 -50
  254. classiq/interface/generator/entangler_params.py +0 -72
  255. classiq/interface/generator/entanglers.py +0 -14
  256. classiq/interface/generator/hartree_fock.py +0 -26
  257. classiq/interface/generator/hva.py +0 -22
  258. classiq/interface/generator/linear_pauli_rotations.py +0 -92
  259. classiq/interface/generator/qft.py +0 -37
  260. classiq/interface/generator/ucc.py +0 -74
  261. classiq/interface/helpers/backward_compatibility.py +0 -9
  262. classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
  263. classiq/qmod/builtins/functions/chemistry.py +0 -123
  264. classiq-0.92.0.dist-info/WHEEL +0 -4
@@ -1,5 +1,5 @@
1
1
  from enum import IntEnum
2
- from typing import Any, Optional, Union
2
+ from typing import Any
3
3
 
4
4
  import sympy
5
5
 
@@ -18,14 +18,13 @@ from classiq.interface.generator.functions.classical_type import (
18
18
  )
19
19
  from classiq.interface.generator.functions.type_name import Enum, Struct, TypeName
20
20
  from classiq.interface.generator.types.struct_declaration import StructDeclaration
21
- from classiq.interface.helpers.backward_compatibility import zip_strict
22
21
 
23
22
  from classiq.evaluators.qmod_node_evaluators.utils import get_sympy_type
24
23
 
25
24
 
26
25
  def _copy_generative_flag(
27
- from_type: ClassicalType, to_type: Optional[ClassicalType]
28
- ) -> Optional[ClassicalType]:
26
+ from_type: ClassicalType, to_type: ClassicalType | None
27
+ ) -> ClassicalType | None:
29
28
  if to_type is None:
30
29
  return None
31
30
  if from_type.is_generative:
@@ -65,11 +64,11 @@ def infer_classical_type(value: Any) -> ClassicalType:
65
64
 
66
65
 
67
66
  def _inject_classical_array_attributes(
68
- from_type: ClassicalType, to_type: Union[ClassicalArray, ClassicalTuple]
69
- ) -> Optional[ClassicalType]:
67
+ from_type: ClassicalType, to_type: ClassicalArray | ClassicalTuple
68
+ ) -> ClassicalType | None:
70
69
  if isinstance(to_type, ClassicalArray):
71
70
  if isinstance(from_type, ClassicalArray):
72
- length: Optional[Expression]
71
+ length: Expression | None
73
72
  if from_type.has_constant_length:
74
73
  if (
75
74
  to_type.has_constant_length
@@ -116,7 +115,7 @@ def _inject_classical_array_attributes(
116
115
  return None
117
116
  element_types = [
118
117
  inject_classical_type_attributes(from_element_type, to_element_type)
119
- for from_element_type, to_element_type in zip_strict(
118
+ for from_element_type, to_element_type in zip(
120
119
  from_type.element_types, to_type.element_types, strict=True
121
120
  )
122
121
  ]
@@ -128,7 +127,7 @@ def _inject_classical_array_attributes(
128
127
 
129
128
  def _inject_classical_type_name_attributes(
130
129
  from_type: ClassicalType, to_type: TypeName
131
- ) -> Optional[ClassicalType]:
130
+ ) -> ClassicalType | None:
132
131
  if to_type.is_enum:
133
132
  if isinstance(from_type, Integer) or (
134
133
  isinstance(from_type, TypeName) and from_type.name == to_type.name
@@ -157,7 +156,7 @@ def _inject_classical_type_name_attributes(
157
156
 
158
157
  def inject_classical_type_attributes(
159
158
  from_type: ClassicalType, to_type: ClassicalType
160
- ) -> Optional[ClassicalType]:
159
+ ) -> ClassicalType | None:
161
160
  if isinstance(to_type, Bool):
162
161
  if isinstance(from_type, Bool):
163
162
  return _copy_generative_flag(to_type, Bool())
@@ -1,4 +1,4 @@
1
- from typing import TYPE_CHECKING, Optional
1
+ from typing import TYPE_CHECKING
2
2
 
3
3
  from classiq.interface.exceptions import (
4
4
  ClassiqExpansionError,
@@ -80,7 +80,7 @@ def _same_shape(quantum_type_1: QuantumType, quantum_type_2: QuantumType) -> boo
80
80
  def _inject_qnum_type_attributes(
81
81
  from_type: QuantumType, to_type: QuantumNumeric
82
82
  ) -> QuantumNumeric:
83
- size: Optional[Expression]
83
+ size: Expression | None
84
84
  if from_type.has_size_in_bits:
85
85
  size = Expression(expr=str(from_type.size_in_bits))
86
86
  else:
@@ -126,7 +126,7 @@ def _inject_qnum_type_attributes(
126
126
 
127
127
  def _inject_qarray_type_attributes(
128
128
  from_type: QuantumType, to_type: QuantumBitvector
129
- ) -> Optional[QuantumBitvector]:
129
+ ) -> QuantumBitvector | None:
130
130
  if _same_shape(from_type, to_type):
131
131
  if TYPE_CHECKING:
132
132
  assert isinstance(from_type, QuantumBitvector)
@@ -182,7 +182,7 @@ def _inject_qarray_type_attributes(
182
182
 
183
183
  def _inject_qstruct_type_attributes(
184
184
  from_type: QuantumType, to_type: TypeName
185
- ) -> Optional[TypeName]:
185
+ ) -> TypeName | None:
186
186
  if isinstance(from_type, TypeName) and from_type.name == to_type.name:
187
187
  fields = {
188
188
  field_name: inject_quantum_type_attributes(
@@ -241,7 +241,7 @@ def _inject_qstruct_type_attributes(
241
241
 
242
242
  def inject_quantum_type_attributes(
243
243
  from_type: QuantumType, to_type: QuantumType
244
- ) -> Optional[QuantumType]:
244
+ ) -> QuantumType | None:
245
245
  for qmod_type in (from_type, to_type):
246
246
  if isinstance(qmod_type, TypeName) and not qmod_type.has_fields:
247
247
  raise ClassiqInternalExpansionError
@@ -1,8 +1,9 @@
1
1
  import inspect
2
2
  import random
3
3
  import warnings
4
+ from collections.abc import Callable
4
5
  from types import TracebackType
5
- from typing import Any, Callable, Optional, Union, cast
6
+ from typing import Any, Optional, Union, cast
6
7
 
7
8
  from classiq.interface.chemistry.operator import PauliOperator, pauli_integers_to_str
8
9
  from classiq.interface.exceptions import (
@@ -104,7 +105,7 @@ class ExecutionSession:
104
105
  def __init__(
105
106
  self,
106
107
  quantum_program: QuantumProgram,
107
- execution_preferences: Optional[ExecutionPreferences] = None,
108
+ execution_preferences: ExecutionPreferences | None = None,
108
109
  ):
109
110
  self.program: QuantumProgram = quantum_program
110
111
  self.update_execution_preferences(execution_preferences)
@@ -124,9 +125,9 @@ class ExecutionSession:
124
125
 
125
126
  def __exit__(
126
127
  self,
127
- exc_type: Optional[type[BaseException]],
128
- exc_val: Optional[BaseException],
129
- exc_tb: Optional[TracebackType],
128
+ exc_type: type[BaseException] | None,
129
+ exc_val: BaseException | None,
130
+ exc_tb: TracebackType | None,
130
131
  ) -> None:
131
132
  self.close()
132
133
 
@@ -156,7 +157,7 @@ class ExecutionSession:
156
157
  return ExecutionJob(details=result)
157
158
 
158
159
  def update_execution_preferences(
159
- self, execution_preferences: Optional[ExecutionPreferences]
160
+ self, execution_preferences: ExecutionPreferences | None
160
161
  ) -> None:
161
162
  """
162
163
  Update the execution preferences for the session.
@@ -170,7 +171,7 @@ class ExecutionSession:
170
171
  if execution_preferences is not None:
171
172
  self.program.model.execution_preferences = execution_preferences
172
173
 
173
- def sample(self, parameters: Optional[ExecutionParams] = None) -> ExecutionDetails:
174
+ def sample(self, parameters: ExecutionParams | None = None) -> ExecutionDetails:
174
175
  """
175
176
  Samples the quantum program with the given parameters, if any.
176
177
 
@@ -183,9 +184,7 @@ class ExecutionSession:
183
184
  job = self.submit_sample(parameters=parameters)
184
185
  return job.get_sample_result(_http_client=self._async_client)
185
186
 
186
- def submit_sample(
187
- self, parameters: Optional[ExecutionParams] = None
188
- ) -> ExecutionJob:
187
+ def submit_sample(self, parameters: ExecutionParams | None = None) -> ExecutionJob:
189
188
  """
190
189
  Initiates an execution job with the `sample` primitive.
191
190
 
@@ -235,7 +234,7 @@ class ExecutionSession:
235
234
  return self._execute(execution_primitives_input)
236
235
 
237
236
  def estimate(
238
- self, hamiltonian: Hamiltonian, parameters: Optional[ExecutionParams] = None
237
+ self, hamiltonian: Hamiltonian, parameters: ExecutionParams | None = None
239
238
  ) -> EstimationResult:
240
239
  """
241
240
  Estimates the expectation value of the given Hamiltonian using the quantum program.
@@ -256,7 +255,7 @@ class ExecutionSession:
256
255
  def submit_estimate(
257
256
  self,
258
257
  hamiltonian: Hamiltonian,
259
- parameters: Optional[ExecutionParams] = None,
258
+ parameters: ExecutionParams | None = None,
260
259
  *,
261
260
  _check_deprecation: bool = True,
262
261
  ) -> ExecutionJob:
@@ -336,11 +335,11 @@ class ExecutionSession:
336
335
 
337
336
  def minimize(
338
337
  self,
339
- cost_function: Union[Hamiltonian, QmodExpressionCreator],
338
+ cost_function: Hamiltonian | QmodExpressionCreator,
340
339
  initial_params: ExecutionParams,
341
340
  max_iteration: int,
342
341
  quantile: float = 1.0,
343
- tolerance: Optional[float] = None,
342
+ tolerance: float | None = None,
344
343
  ) -> list[tuple[float, ExecutionParams]]:
345
344
  """
346
345
  Minimizes the given cost function using the quantum program.
@@ -378,11 +377,11 @@ class ExecutionSession:
378
377
 
379
378
  def submit_minimize(
380
379
  self,
381
- cost_function: Union[Hamiltonian, QmodExpressionCreator],
380
+ cost_function: Hamiltonian | QmodExpressionCreator,
382
381
  initial_params: ExecutionParams,
383
382
  max_iteration: int,
384
383
  quantile: float = 1.0,
385
- tolerance: Optional[float] = None,
384
+ tolerance: float | None = None,
386
385
  *,
387
386
  _check_deprecation: bool = True,
388
387
  ) -> ExecutionJob:
@@ -416,9 +415,9 @@ class ExecutionSession:
416
415
  "The initial parameters must be a dictionary with a single key-value pair."
417
416
  )
418
417
 
419
- _cost_function: Union[PauliOperator, Expression]
418
+ _cost_function: PauliOperator | Expression
420
419
  _initial_params = parse_params(initial_params)
421
- minimize: Union[MinimizeQuantumCostInput, MinimizeClassicalCostInput]
420
+ minimize: MinimizeQuantumCostInput | MinimizeClassicalCostInput
422
421
  if callable(cost_function):
423
422
  circuit_output_types = self.program.model.circuit_output_types
424
423
  _cost_function = self._create_qmod_expression(
@@ -447,7 +446,7 @@ class ExecutionSession:
447
446
  def estimate_cost(
448
447
  self,
449
448
  cost_func: Callable[[ParsedState], float],
450
- parameters: Optional[ExecutionParams] = None,
449
+ parameters: ExecutionParams | None = None,
451
450
  quantile: float = 1.0,
452
451
  ) -> float:
453
452
  """
classiq/execution/jobs.py CHANGED
@@ -1,7 +1,7 @@
1
1
  import warnings
2
2
  import webbrowser
3
3
  from datetime import datetime
4
- from typing import Any, Optional, Union
4
+ from typing import Any
5
5
  from urllib.parse import urljoin
6
6
 
7
7
  import httpx
@@ -39,7 +39,7 @@ class ClassiqExecutionResultError(ClassiqError):
39
39
 
40
40
  class ExecutionJob:
41
41
  _details: ExecutionJobDetails
42
- _result: Optional[ResultsCollection]
42
+ _result: ResultsCollection | None
43
43
 
44
44
  def __init__(self, details: ExecutionJobDetails) -> None:
45
45
  self._details = details
@@ -50,7 +50,7 @@ class ExecutionJob:
50
50
  return self._details.id
51
51
 
52
52
  @property
53
- def name(self) -> Optional[str]:
53
+ def name(self) -> str | None:
54
54
  return self._details.name
55
55
 
56
56
  @property
@@ -58,15 +58,15 @@ class ExecutionJob:
58
58
  return self._details.start_time
59
59
 
60
60
  @property
61
- def end_time(self) -> Optional[datetime]:
61
+ def end_time(self) -> datetime | None:
62
62
  return self._details.end_time
63
63
 
64
64
  @property
65
- def provider(self) -> Optional[str]:
65
+ def provider(self) -> str | None:
66
66
  return self._details.provider
67
67
 
68
68
  @property
69
- def backend_name(self) -> Optional[str]:
69
+ def backend_name(self) -> str | None:
70
70
  return self._details.backend_name
71
71
 
72
72
  @property
@@ -74,15 +74,15 @@ class ExecutionJob:
74
74
  return self._details.status
75
75
 
76
76
  @property
77
- def num_shots(self) -> Optional[int]:
77
+ def num_shots(self) -> int | None:
78
78
  return self._details.num_shots
79
79
 
80
80
  @property
81
- def program_id(self) -> Optional[str]:
81
+ def program_id(self) -> str | None:
82
82
  return self._details.program_id
83
83
 
84
84
  @property
85
- def error(self) -> Optional[str]:
85
+ def error(self) -> str | None:
86
86
  return self._details.error
87
87
 
88
88
  def __repr__(self) -> str:
@@ -92,7 +92,7 @@ class ExecutionJob:
92
92
  else:
93
93
  return f"{class_name}(name={self.name!r}, id={self.id!r})"
94
94
 
95
- def cost(self, *, verbose: bool = False) -> Union[str, JobCost]:
95
+ def cost(self, *, verbose: bool = False) -> str | JobCost:
96
96
  if self._details.cost is None:
97
97
  self._details.cost = JobCost()
98
98
  if verbose:
@@ -103,7 +103,7 @@ class ExecutionJob:
103
103
  async def from_id_async(
104
104
  cls,
105
105
  id: str,
106
- _http_client: Optional[httpx.AsyncClient] = None,
106
+ _http_client: httpx.AsyncClient | None = None,
107
107
  ) -> "ExecutionJob":
108
108
  details = await ApiWrapper.call_get_execution_job_details(
109
109
  JobID(job_id=id), http_client=_http_client
@@ -116,7 +116,7 @@ class ExecutionJob:
116
116
  def from_id(
117
117
  cls,
118
118
  id: str,
119
- _http_client: Optional[httpx.AsyncClient] = None,
119
+ _http_client: httpx.AsyncClient | None = None,
120
120
  ) -> "ExecutionJob":
121
121
  return syncify_function(cls.from_id_async)(id, _http_client=_http_client)
122
122
 
@@ -126,8 +126,8 @@ class ExecutionJob:
126
126
 
127
127
  async def result_async(
128
128
  self,
129
- timeout_sec: Optional[float] = None,
130
- _http_client: Optional[httpx.AsyncClient] = None,
129
+ timeout_sec: float | None = None,
130
+ _http_client: httpx.AsyncClient | None = None,
131
131
  ) -> ResultsCollection:
132
132
  await self.poll_async(timeout_sec=timeout_sec, _http_client=_http_client)
133
133
 
@@ -151,7 +151,7 @@ class ExecutionJob:
151
151
  return self.result(*args, **kwargs)[0].value
152
152
 
153
153
  def get_sample_result(
154
- self, _http_client: Optional[httpx.AsyncClient] = None
154
+ self, _http_client: httpx.AsyncClient | None = None
155
155
  ) -> ExecutionDetails:
156
156
  """
157
157
  Returns the job's result as a single sample result after validation. If the result is not yet available, waits for it.
@@ -177,7 +177,7 @@ class ExecutionJob:
177
177
  return result
178
178
 
179
179
  def get_batch_sample_result(
180
- self, _http_client: Optional[httpx.AsyncClient] = None
180
+ self, _http_client: httpx.AsyncClient | None = None
181
181
  ) -> list[ExecutionDetails]:
182
182
  """
183
183
  Returns the job's result as a single batch_sample result after validation. If the result is not yet available, waits for it.
@@ -209,7 +209,7 @@ class ExecutionJob:
209
209
  return result_list
210
210
 
211
211
  def get_estimate_result(
212
- self, _http_client: Optional[httpx.AsyncClient] = None
212
+ self, _http_client: httpx.AsyncClient | None = None
213
213
  ) -> EstimationResult:
214
214
  """
215
215
  Returns the job's result as a single estimate result after validation. If the result is not yet available, waits for it.
@@ -233,7 +233,7 @@ class ExecutionJob:
233
233
  raise ClassiqExecutionResultError("estimate")
234
234
 
235
235
  def get_batch_estimate_result(
236
- self, _http_client: Optional[httpx.AsyncClient] = None
236
+ self, _http_client: httpx.AsyncClient | None = None
237
237
  ) -> list[EstimationResult]:
238
238
  """
239
239
  Returns the job's result as a single batch_estimate result after validation. If the result is not yet available, waits for it.
@@ -258,7 +258,7 @@ class ExecutionJob:
258
258
  raise ClassiqExecutionResultError("batch_estimate")
259
259
 
260
260
  def get_minimization_result(
261
- self, _http_client: Optional[httpx.AsyncClient] = None
261
+ self, _http_client: httpx.AsyncClient | None = None
262
262
  ) -> TaggedMinimizeResult:
263
263
  """
264
264
  Returns the job's result as a single minimization result after validation. If the result is not yet available, waits for it.
@@ -281,8 +281,8 @@ class ExecutionJob:
281
281
 
282
282
  async def poll_async(
283
283
  self,
284
- timeout_sec: Optional[float] = None,
285
- _http_client: Optional[httpx.AsyncClient] = None,
284
+ timeout_sec: float | None = None,
285
+ _http_client: httpx.AsyncClient | None = None,
286
286
  ) -> None:
287
287
  if not self.status.is_final():
288
288
  await self._poll_job(timeout_sec=timeout_sec, _http_client=_http_client)
@@ -291,10 +291,10 @@ class ExecutionJob:
291
291
 
292
292
  async def _poll_job(
293
293
  self,
294
- timeout_sec: Optional[float] = None,
295
- _http_client: Optional[httpx.AsyncClient] = None,
294
+ timeout_sec: float | None = None,
295
+ _http_client: httpx.AsyncClient | None = None,
296
296
  ) -> None:
297
- def response_parser(json_response: JSONObject) -> Optional[bool]:
297
+ def response_parser(json_response: JSONObject) -> bool | None:
298
298
  self._details = ExecutionJobDetails.model_validate(json_response)
299
299
  if self.status.is_final():
300
300
  return True
@@ -313,7 +313,7 @@ class ExecutionJob:
313
313
  async def rename_async(
314
314
  self,
315
315
  name: str,
316
- _http_client: Optional[httpx.AsyncClient] = None,
316
+ _http_client: httpx.AsyncClient | None = None,
317
317
  ) -> None:
318
318
  self._details = await ApiWrapper.call_patch_execution_job(
319
319
  self._job_id,
@@ -325,7 +325,7 @@ class ExecutionJob:
325
325
 
326
326
  async def cancel_async(
327
327
  self,
328
- _http_client: Optional[httpx.AsyncClient] = None,
328
+ _http_client: httpx.AsyncClient | None = None,
329
329
  ) -> None:
330
330
  """
331
331
  Cancels the execution job. This implies the cancellation of any ongoing jobs
classiq/execution/qnn.py CHANGED
@@ -1,5 +1,4 @@
1
1
  import functools
2
- from typing import Optional
3
2
 
4
3
  import more_itertools
5
4
 
@@ -60,7 +59,7 @@ def _execute_qnn_sample(
60
59
  def execute_qnn(
61
60
  quantum_program: QuantumProgram,
62
61
  arguments: MultipleArguments,
63
- observable: Optional[PauliOperator] = None,
62
+ observable: PauliOperator | None = None,
64
63
  ) -> ResultsCollection:
65
64
  with ExecutionSession(quantum_program) as session:
66
65
  if observable:
@@ -1,10 +1,8 @@
1
- from typing import Optional
2
-
3
1
  from classiq.interface.backend.quantum_backend_providers import ProviderVendor
4
2
  from classiq.interface.executor.user_budget import UserBudgets
5
3
 
4
+ from classiq._internals import async_utils
6
5
  from classiq._internals.api_wrapper import ApiWrapper
7
- from classiq._internals.async_utils import syncify_function
8
6
 
9
7
  PROVIDER_MAPPER = {
10
8
  ProviderVendor.IONQ: "IONQ",
@@ -22,7 +20,7 @@ PROVIDER_MAPPER = {
22
20
 
23
21
 
24
22
  async def get_budget_async(
25
- provider_vendor: Optional[ProviderVendor] = None,
23
+ provider_vendor: ProviderVendor | None = None,
26
24
  ) -> UserBudgets:
27
25
 
28
26
  budgets_list = await ApiWrapper().call_get_all_budgets()
@@ -35,7 +33,21 @@ async def get_budget_async(
35
33
  return UserBudgets(budgets=budgets_list)
36
34
 
37
35
 
38
- get_budget = syncify_function(get_budget_async)
36
+ def get_budget(
37
+ provider_vendor: ProviderVendor | None = None,
38
+ ) -> UserBudgets:
39
+ """
40
+ Retrieve the user's budget information for quantum computing resources.
41
+
42
+ Args:
43
+ provider_vendor:
44
+ (Optional) The quantum backend provider to filter budgets by.
45
+ If not provided, budgets for all providers will be returned.
46
+
47
+ Returns:
48
+ UserBudgets: An object containing the user's budget information.
49
+ """
50
+ return async_utils.run(get_budget_async(provider_vendor))
39
51
 
40
52
 
41
53
  async def set_budget_limit_async(
@@ -62,7 +74,26 @@ async def set_budget_limit_async(
62
74
  return UserBudgets(budgets=[budgets_list])
63
75
 
64
76
 
65
- set_budget_limit = syncify_function(set_budget_limit_async)
77
+ def set_budget_limit(
78
+ provider_vendor: ProviderVendor,
79
+ limit: float,
80
+ ) -> UserBudgets:
81
+ """
82
+ Set a budget limit for a specific quantum backend provider.
83
+
84
+ Args:
85
+ provider_vendor:
86
+ The quantum backend provider for which to set the budget limit.
87
+ limit:
88
+ The budget limit to set. Must be greater than zero and not exceed the available budget.
89
+
90
+ Returns:
91
+ UserBudgets: An object containing the updated budget information.
92
+
93
+ Raises:
94
+ ValueError: If the provider is unsupported, no budget is found, or the limit is invalid.
95
+ """
96
+ return async_utils.run(set_budget_limit_async(provider_vendor, limit))
66
97
 
67
98
 
68
99
  async def clear_budget_limit_async(provider_vendor: ProviderVendor) -> UserBudgets:
@@ -74,4 +105,18 @@ async def clear_budget_limit_async(provider_vendor: ProviderVendor) -> UserBudge
74
105
  return UserBudgets(budgets=[budgets_list])
75
106
 
76
107
 
77
- clear_budget_limit = syncify_function(clear_budget_limit_async)
108
+ def clear_budget_limit(provider_vendor: ProviderVendor) -> UserBudgets:
109
+ """
110
+ Clear the budget limit for a specific quantum backend provider.
111
+
112
+ Args:
113
+ provider_vendor:
114
+ The quantum backend provider for which to clear the budget limit.
115
+
116
+ Returns:
117
+ UserBudgets: An object containing the updated budget information.
118
+
119
+ Raises:
120
+ ValueError: If the provider is unsupported.
121
+ """
122
+ return async_utils.run(clear_budget_limit_async(provider_vendor))
classiq/executor.py CHANGED
@@ -1,8 +1,6 @@
1
1
  """Executor module, implementing facilities for executing quantum programs using Classiq platform."""
2
2
 
3
- from typing import Union
4
-
5
- from typing_extensions import TypeAlias
3
+ from typing import TypeAlias, Union
6
4
 
7
5
  from classiq.interface.backend.backend_preferences import BackendPreferencesTypes
8
6
  from classiq.interface.executor.estimation import OperatorsEstimation
@@ -3,5 +3,5 @@ from packaging.version import Version
3
3
  # This file was generated automatically
4
4
  # Please don't track in version control (DONTTRACK)
5
5
 
6
- SEMVER_VERSION = '0.92.0'
6
+ SEMVER_VERSION = '0.94.0'
7
7
  VERSION = str(Version(SEMVER_VERSION))
@@ -1,4 +1,4 @@
1
- from typing import Annotated, Optional
1
+ from typing import Annotated
2
2
 
3
3
  import pydantic
4
4
  from pydantic import Field, StringConstraints
@@ -26,7 +26,7 @@ class AnalysisParams(pydantic.BaseModel):
26
26
 
27
27
 
28
28
  class HardwareListParams(pydantic.BaseModel):
29
- devices: Optional[list[PydanticNonEmptyString]] = pydantic.Field(
29
+ devices: list[PydanticNonEmptyString] | None = pydantic.Field(
30
30
  default=None, description="Devices"
31
31
  )
32
32
  providers: list[Provider]
@@ -35,7 +35,7 @@ class HardwareListParams(pydantic.BaseModel):
35
35
  @pydantic.field_validator("providers")
36
36
  @classmethod
37
37
  def set_default_providers(
38
- cls, providers: Optional[list[AnalyzerProviderVendor]]
38
+ cls, providers: list[AnalyzerProviderVendor] | None
39
39
  ) -> list[AnalyzerProviderVendor]:
40
40
  if providers is None:
41
41
  providers = list(AnalyzerProviderVendor)
@@ -67,7 +67,7 @@ class LatexParams(AnalysisParams):
67
67
 
68
68
 
69
69
  class AnalysisHardwareTranspilationParams(pydantic.BaseModel):
70
- hardware_data: Optional[SynthesisHardwareData] = None
70
+ hardware_data: SynthesisHardwareData | None = None
71
71
  random_seed: int
72
72
  transpilation_option: TranspilationOption
73
73
 
@@ -1,4 +1,4 @@
1
- from typing import Any, Optional
1
+ from typing import Any
2
2
 
3
3
  import pydantic
4
4
 
@@ -42,7 +42,7 @@ class CytoScapeNode(pydantic.BaseModel):
42
42
  default=...,
43
43
  description="Data of the Node, such as label, and color, can be of free form",
44
44
  )
45
- position: Optional[CytoScapePosition] = pydantic.Field(
45
+ position: CytoScapePosition | None = pydantic.Field(
46
46
  default=..., description="Position of the Node to be rendered in Cytocape"
47
47
  )
48
48
 
@@ -66,7 +66,7 @@ class ConnectivityErrors(StrEnum):
66
66
 
67
67
 
68
68
  class HardwareConnectivityGraphResult(VersionedModel):
69
- graph: Optional[CytoScapeGraph] = pydantic.Field(
69
+ graph: CytoScapeGraph | None = pydantic.Field(
70
70
  default=...,
71
71
  description="The Cytoscape graph in the desired Structure for the FE",
72
72
  )
@@ -1,4 +1,4 @@
1
- from typing import Annotated, Literal, Optional, Union
1
+ from typing import Annotated, Literal, Union
2
2
 
3
3
  import pydantic
4
4
  from pydantic import Field
@@ -125,15 +125,15 @@ class HardwareComparisonDataColumns(pydantic.BaseModel):
125
125
 
126
126
 
127
127
  class AvailableHardware(pydantic.BaseModel):
128
- ibm_quantum: Optional[dict[PydanticNonEmptyString, bool]] = pydantic.Field(
128
+ ibm_quantum: dict[PydanticNonEmptyString, bool] | None = pydantic.Field(
129
129
  default=None,
130
130
  description="available IBM Quantum devices with boolean indicates if a given device has enough qubits.",
131
131
  )
132
- azure_quantum: Optional[dict[PydanticNonEmptyString, bool]] = pydantic.Field(
132
+ azure_quantum: dict[PydanticNonEmptyString, bool] | None = pydantic.Field(
133
133
  default=None,
134
134
  description="available Azure Quantum devices with boolean indicates if a given device has enough qubits.",
135
135
  )
136
- amazon_braket: Optional[dict[PydanticNonEmptyString, bool]] = pydantic.Field(
136
+ amazon_braket: dict[PydanticNonEmptyString, bool] | None = pydantic.Field(
137
137
  default=None,
138
138
  description="available Amazon Braket devices with boolean indicates if a given device has enough qubits.",
139
139
  )
@@ -1,7 +1,6 @@
1
1
  from collections.abc import Iterable as IterableType, Sequence
2
2
  from typing import (
3
3
  Any,
4
- Optional,
5
4
  Union,
6
5
  )
7
6
 
@@ -16,7 +15,7 @@ DataList = list[list[float]]
16
15
  LabelsInt = list[int]
17
16
 
18
17
 
19
- def listify(obj: Union[IterableType, ArrayLike]) -> list:
18
+ def listify(obj: IterableType | ArrayLike) -> list:
20
19
  if isinstance(obj, np.ndarray):
21
20
  return obj.tolist()
22
21
  elif isinstance(obj, Sequence) and obj and isinstance(obj[0], np.ndarray):
@@ -85,20 +84,18 @@ class QSVMInternalState(VersionedModel):
85
84
 
86
85
  class QSVMData(VersionedModel):
87
86
  data: DataList
88
- labels: Optional[LabelsInt] = None
89
- internal_state: Optional[QSVMInternalState] = None
87
+ labels: LabelsInt | None = None
88
+ internal_state: QSVMInternalState | None = None
90
89
  model_config = ConfigDict(extra="forbid")
91
90
 
92
91
  @pydantic.field_validator("data", mode="before")
93
92
  @classmethod
94
- def set_data(cls, data: Union[IterableType, ArrayLike]) -> list:
93
+ def set_data(cls, data: IterableType | ArrayLike) -> list:
95
94
  return listify(data)
96
95
 
97
96
  @pydantic.field_validator("labels", mode="before")
98
97
  @classmethod
99
- def set_labels(
100
- cls, labels: Optional[Union[IterableType, ArrayLike]]
101
- ) -> Optional[list]:
98
+ def set_labels(cls, labels: IterableType | ArrayLike | None) -> list | None:
102
99
  if labels is None:
103
100
  return None
104
101
  else: