classiq 0.93.0__py3-none-any.whl → 0.100.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.
Files changed (318) hide show
  1. classiq/__init__.py +11 -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 +31 -142
  5. classiq/_internals/async_utils.py +4 -7
  6. classiq/_internals/authentication/auth0.py +41 -15
  7. classiq/_internals/authentication/authorization_code.py +9 -0
  8. classiq/_internals/authentication/authorization_flow.py +41 -0
  9. classiq/_internals/authentication/device.py +33 -52
  10. classiq/_internals/authentication/hybrid_flow.py +19 -0
  11. classiq/_internals/authentication/password_manager.py +13 -13
  12. classiq/_internals/authentication/token_manager.py +9 -9
  13. classiq/_internals/client.py +17 -44
  14. classiq/_internals/config.py +19 -5
  15. classiq/_internals/help.py +1 -2
  16. classiq/_internals/host_checker.py +3 -3
  17. classiq/_internals/jobs.py +14 -14
  18. classiq/_internals/type_validation.py +3 -3
  19. classiq/analyzer/analyzer.py +18 -18
  20. classiq/analyzer/rb.py +17 -8
  21. classiq/analyzer/show_interactive_hack.py +1 -1
  22. classiq/applications/__init__.py +2 -2
  23. classiq/applications/chemistry/__init__.py +0 -30
  24. classiq/applications/chemistry/op_utils.py +4 -4
  25. classiq/applications/chemistry/problems.py +3 -3
  26. classiq/applications/chemistry/ucc.py +1 -2
  27. classiq/applications/chemistry/z2_symmetries.py +4 -4
  28. classiq/applications/combinatorial_helpers/allowed_constraints.py +1 -3
  29. classiq/applications/combinatorial_helpers/arithmetic/arithmetic_expression.py +2 -1
  30. classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +2 -2
  31. classiq/applications/combinatorial_helpers/encoding_mapping.py +2 -3
  32. classiq/applications/combinatorial_helpers/encoding_utils.py +2 -2
  33. classiq/applications/combinatorial_helpers/optimization_model.py +3 -4
  34. classiq/applications/combinatorial_helpers/pauli_helpers/pauli_sparsing.py +2 -2
  35. classiq/applications/combinatorial_helpers/pyomo_utils.py +8 -8
  36. classiq/applications/combinatorial_helpers/sympy_utils.py +1 -3
  37. classiq/applications/combinatorial_helpers/transformations/encoding.py +3 -3
  38. classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +1 -2
  39. classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -3
  40. classiq/applications/combinatorial_optimization/combinatorial_optimization_model_constructor.py +4 -6
  41. classiq/applications/combinatorial_optimization/combinatorial_problem.py +15 -10
  42. classiq/applications/hamiltonian/pauli_decomposition.py +6 -4
  43. classiq/applications/iqae/iqae.py +14 -11
  44. classiq/applications/qnn/datasets/dataset_base_classes.py +6 -6
  45. classiq/applications/qnn/datasets/dataset_parity.py +6 -6
  46. classiq/applications/qnn/gradients/simple_quantum_gradient.py +1 -1
  47. classiq/applications/qnn/qlayer.py +9 -8
  48. classiq/applications/qnn/torch_utils.py +5 -6
  49. classiq/applications/qnn/types.py +2 -1
  50. classiq/applications/qsp/__init__.py +20 -2
  51. classiq/applications/qsp/qsp.py +238 -10
  52. classiq/applications/qsvm/qsvm_data_generation.py +1 -2
  53. classiq/evaluators/classical_expression.py +0 -4
  54. classiq/evaluators/parameter_types.py +10 -8
  55. classiq/evaluators/qmod_annotated_expression.py +31 -26
  56. classiq/evaluators/qmod_expression_visitors/qmod_expression_evaluator.py +14 -14
  57. classiq/evaluators/qmod_expression_visitors/qmod_expression_simplifier.py +2 -1
  58. classiq/evaluators/qmod_expression_visitors/sympy_wrappers.py +8 -8
  59. classiq/evaluators/qmod_node_evaluators/binary_op_evaluation.py +4 -4
  60. classiq/evaluators/qmod_node_evaluators/classical_function_evaluation.py +14 -4
  61. classiq/evaluators/qmod_node_evaluators/list_evaluation.py +2 -2
  62. classiq/evaluators/qmod_node_evaluators/numeric_attrs_utils.py +3 -3
  63. classiq/evaluators/qmod_node_evaluators/subscript_evaluation.py +9 -9
  64. classiq/evaluators/qmod_node_evaluators/utils.py +6 -6
  65. classiq/evaluators/qmod_type_inference/classical_type_inference.py +9 -10
  66. classiq/evaluators/qmod_type_inference/quantum_type_inference.py +5 -5
  67. classiq/execution/__init__.py +0 -3
  68. classiq/execution/execution_session.py +28 -21
  69. classiq/execution/jobs.py +26 -26
  70. classiq/execution/qnn.py +1 -2
  71. classiq/execution/user_budgets.py +71 -37
  72. classiq/executor.py +1 -3
  73. classiq/interface/_version.py +1 -1
  74. classiq/interface/analyzer/analysis_params.py +4 -4
  75. classiq/interface/analyzer/cytoscape_graph.py +3 -3
  76. classiq/interface/analyzer/result.py +4 -4
  77. classiq/interface/ast_node.py +3 -3
  78. classiq/interface/backend/backend_preferences.py +26 -50
  79. classiq/interface/backend/ionq/ionq_quantum_program.py +5 -5
  80. classiq/interface/backend/provider_config/__init__.py +0 -0
  81. classiq/interface/backend/provider_config/provider_config.py +8 -0
  82. classiq/interface/backend/provider_config/providers/__init__.py +0 -0
  83. classiq/interface/backend/provider_config/providers/alice_bob.py +47 -0
  84. classiq/interface/backend/provider_config/providers/aqt.py +16 -0
  85. classiq/interface/backend/provider_config/providers/azure.py +37 -0
  86. classiq/interface/backend/provider_config/providers/braket.py +39 -0
  87. classiq/interface/backend/provider_config/providers/ibm.py +26 -0
  88. classiq/interface/backend/provider_config/providers/ionq.py +22 -0
  89. classiq/interface/backend/quantum_backend_providers.py +20 -2
  90. classiq/interface/chemistry/ansatz_library.py +3 -5
  91. classiq/interface/chemistry/operator.py +3 -3
  92. classiq/interface/combinatorial_optimization/examples/knapsack.py +2 -4
  93. classiq/interface/combinatorial_optimization/examples/tsp_digraph.py +1 -2
  94. classiq/interface/compression_utils.py +2 -3
  95. classiq/interface/debug_info/debug_info.py +8 -7
  96. classiq/interface/exceptions.py +6 -7
  97. classiq/interface/execution/primitives.py +6 -6
  98. classiq/interface/executor/estimate_cost.py +1 -1
  99. classiq/interface/executor/execution_preferences.py +3 -5
  100. classiq/interface/executor/execution_request.py +10 -10
  101. classiq/interface/executor/execution_result.py +1 -2
  102. classiq/interface/executor/quantum_code.py +8 -8
  103. classiq/interface/executor/result.py +28 -18
  104. classiq/interface/executor/user_budget.py +21 -17
  105. classiq/interface/executor/vqe_result.py +5 -6
  106. classiq/interface/generator/ansatz_library.py +6 -8
  107. classiq/interface/generator/application_apis/__init__.py +0 -3
  108. classiq/interface/generator/arith/arithmetic.py +2 -2
  109. classiq/interface/generator/arith/arithmetic_arg_type_validator.py +2 -3
  110. classiq/interface/generator/arith/arithmetic_expression_abc.py +4 -5
  111. classiq/interface/generator/arith/arithmetic_expression_parser.py +11 -4
  112. classiq/interface/generator/arith/arithmetic_expression_validator.py +12 -15
  113. classiq/interface/generator/arith/arithmetic_operations.py +4 -6
  114. classiq/interface/generator/arith/arithmetic_param_getters.py +70 -107
  115. classiq/interface/generator/arith/arithmetic_result_builder.py +4 -4
  116. classiq/interface/generator/arith/ast_node_rewrite.py +8 -4
  117. classiq/interface/generator/arith/binary_ops.py +15 -40
  118. classiq/interface/generator/arith/logical_ops.py +2 -3
  119. classiq/interface/generator/arith/number_utils.py +2 -2
  120. classiq/interface/generator/arith/register_user_input.py +3 -3
  121. classiq/interface/generator/arith/unary_ops.py +2 -2
  122. classiq/interface/generator/circuit_code/circuit_code.py +8 -10
  123. classiq/interface/generator/circuit_code/types_and_constants.py +1 -1
  124. classiq/interface/generator/complex_type.py +2 -2
  125. classiq/interface/generator/copy.py +1 -3
  126. classiq/interface/generator/expressions/atomic_expression_functions.py +0 -5
  127. classiq/interface/generator/expressions/evaluated_expression.py +2 -3
  128. classiq/interface/generator/expressions/expression.py +2 -2
  129. classiq/interface/generator/expressions/proxies/classical/classical_array_proxy.py +4 -7
  130. classiq/interface/generator/function_param_list.py +0 -40
  131. classiq/interface/generator/function_params.py +5 -6
  132. classiq/interface/generator/functions/classical_function_declaration.py +2 -2
  133. classiq/interface/generator/functions/classical_type.py +3 -3
  134. classiq/interface/generator/functions/type_modifier.py +0 -15
  135. classiq/interface/generator/functions/type_name.py +2 -2
  136. classiq/interface/generator/generated_circuit_data.py +14 -18
  137. classiq/interface/generator/generation_request.py +35 -0
  138. classiq/interface/generator/hamiltonian_evolution/exponentiation.py +2 -4
  139. classiq/interface/generator/hardware/hardware_data.py +8 -8
  140. classiq/interface/generator/hardware_efficient_ansatz.py +9 -9
  141. classiq/interface/generator/mcu.py +3 -3
  142. classiq/interface/generator/mcx.py +3 -3
  143. classiq/interface/generator/model/constraints.py +34 -5
  144. classiq/interface/generator/model/preferences/preferences.py +15 -21
  145. classiq/interface/generator/model/quantum_register.py +7 -10
  146. classiq/interface/generator/noise_properties.py +3 -7
  147. classiq/interface/generator/parameters.py +1 -1
  148. classiq/interface/generator/partitioned_register.py +1 -2
  149. classiq/interface/generator/preferences/qasm_to_qmod_params.py +11 -0
  150. classiq/interface/generator/quantum_function_call.py +9 -12
  151. classiq/interface/generator/quantum_program.py +10 -23
  152. classiq/interface/generator/range_types.py +3 -3
  153. classiq/interface/generator/slice_parsing_utils.py +4 -5
  154. classiq/interface/generator/standard_gates/standard_gates.py +2 -4
  155. classiq/interface/generator/synthesis_execution_parameter.py +1 -3
  156. classiq/interface/generator/synthesis_metadata/synthesis_duration.py +9 -0
  157. classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +2 -3
  158. classiq/interface/generator/transpiler_basis_gates.py +10 -4
  159. classiq/interface/generator/types/builtin_enum_declarations.py +0 -145
  160. classiq/interface/generator/types/compilation_metadata.py +13 -2
  161. classiq/interface/generator/types/enum_declaration.py +2 -1
  162. classiq/interface/generator/validations/flow_graph.py +3 -3
  163. classiq/interface/generator/visitor.py +10 -12
  164. classiq/interface/hardware.py +2 -3
  165. classiq/interface/helpers/classproperty.py +2 -2
  166. classiq/interface/helpers/custom_encoders.py +2 -1
  167. classiq/interface/helpers/custom_pydantic_types.py +1 -1
  168. classiq/interface/helpers/text_utils.py +5 -4
  169. classiq/interface/ide/visual_model.py +6 -5
  170. classiq/interface/interface_version.py +1 -1
  171. classiq/interface/jobs.py +3 -3
  172. classiq/interface/model/allocate.py +4 -4
  173. classiq/interface/model/bind_operation.py +3 -0
  174. classiq/interface/model/block.py +6 -2
  175. classiq/interface/model/bounds.py +3 -3
  176. classiq/interface/model/classical_if.py +4 -0
  177. classiq/interface/model/control.py +8 -1
  178. classiq/interface/model/inplace_binary_operation.py +2 -2
  179. classiq/interface/model/invert.py +4 -0
  180. classiq/interface/model/model.py +4 -4
  181. classiq/interface/model/model_visitor.py +40 -1
  182. classiq/interface/model/parameter.py +1 -3
  183. classiq/interface/model/port_declaration.py +1 -1
  184. classiq/interface/model/power.py +4 -0
  185. classiq/interface/model/quantum_expressions/quantum_expression.py +1 -2
  186. classiq/interface/model/quantum_function_call.py +3 -6
  187. classiq/interface/model/quantum_function_declaration.py +1 -0
  188. classiq/interface/model/quantum_lambda_function.py +4 -4
  189. classiq/interface/model/quantum_statement.py +11 -4
  190. classiq/interface/model/quantum_type.py +14 -14
  191. classiq/interface/model/repeat.py +4 -0
  192. classiq/interface/model/skip_control.py +4 -0
  193. classiq/interface/model/validation_handle.py +2 -3
  194. classiq/interface/model/variable_declaration_statement.py +2 -2
  195. classiq/interface/model/within_apply_operation.py +4 -0
  196. classiq/interface/pretty_print/expression_to_qmod.py +3 -4
  197. classiq/interface/server/routes.py +0 -16
  198. classiq/interface/source_reference.py +3 -4
  199. classiq/model_expansions/arithmetic.py +11 -7
  200. classiq/model_expansions/arithmetic_compute_result_attrs.py +40 -28
  201. classiq/model_expansions/capturing/captured_vars.py +3 -3
  202. classiq/model_expansions/capturing/mangling_utils.py +1 -2
  203. classiq/model_expansions/closure.py +12 -11
  204. classiq/model_expansions/function_builder.py +14 -6
  205. classiq/model_expansions/generative_functions.py +7 -12
  206. classiq/model_expansions/interpreters/base_interpreter.py +3 -7
  207. classiq/model_expansions/interpreters/frontend_generative_interpreter.py +2 -1
  208. classiq/model_expansions/interpreters/generative_interpreter.py +5 -3
  209. classiq/model_expansions/quantum_operations/allocate.py +4 -4
  210. classiq/model_expansions/quantum_operations/assignment_result_processor.py +2 -4
  211. classiq/model_expansions/quantum_operations/call_emitter.py +31 -40
  212. classiq/model_expansions/quantum_operations/declarative_call_emitter.py +2 -2
  213. classiq/model_expansions/quantum_operations/emitter.py +3 -5
  214. classiq/model_expansions/quantum_operations/expression_evaluator.py +3 -3
  215. classiq/model_expansions/quantum_operations/skip_control_verifier.py +1 -2
  216. classiq/model_expansions/quantum_operations/variable_decleration.py +2 -2
  217. classiq/model_expansions/scope.py +7 -7
  218. classiq/model_expansions/scope_initialization.py +4 -0
  219. classiq/model_expansions/visitors/symbolic_param_inference.py +6 -6
  220. classiq/model_expansions/visitors/uncomputation_signature_inference.py +328 -0
  221. classiq/model_expansions/visitors/variable_references.py +15 -14
  222. classiq/open_library/functions/__init__.py +41 -11
  223. classiq/open_library/functions/amplitude_loading.py +81 -0
  224. classiq/open_library/functions/discrete_sine_cosine_transform.py +5 -5
  225. classiq/open_library/functions/encodings.py +182 -0
  226. classiq/open_library/functions/grover.py +8 -10
  227. classiq/open_library/functions/lcu.py +47 -18
  228. classiq/open_library/functions/modular_exponentiation.py +93 -8
  229. classiq/open_library/functions/qsvt.py +66 -79
  230. classiq/open_library/functions/qsvt_temp.py +536 -0
  231. classiq/open_library/functions/state_preparation.py +137 -31
  232. classiq/qmod/__init__.py +6 -4
  233. classiq/qmod/builtins/classical_execution_primitives.py +4 -23
  234. classiq/qmod/builtins/classical_functions.py +1 -42
  235. classiq/qmod/builtins/enums.py +15 -153
  236. classiq/qmod/builtins/functions/__init__.py +9 -18
  237. classiq/qmod/builtins/functions/allocation.py +25 -4
  238. classiq/qmod/builtins/functions/arithmetic.py +22 -27
  239. classiq/qmod/builtins/functions/exponentiation.py +51 -2
  240. classiq/qmod/builtins/functions/mcx_func.py +7 -0
  241. classiq/qmod/builtins/functions/standard_gates.py +46 -27
  242. classiq/qmod/builtins/operations.py +165 -79
  243. classiq/qmod/builtins/structs.py +24 -91
  244. classiq/qmod/cfunc.py +3 -2
  245. classiq/qmod/classical_function.py +2 -1
  246. classiq/qmod/cparam.py +2 -8
  247. classiq/qmod/create_model_function.py +7 -7
  248. classiq/qmod/declaration_inferrer.py +33 -30
  249. classiq/qmod/expression_query.py +7 -4
  250. classiq/qmod/model_state_container.py +2 -2
  251. classiq/qmod/native/pretty_printer.py +25 -14
  252. classiq/qmod/pretty_print/expression_to_python.py +5 -3
  253. classiq/qmod/pretty_print/pretty_printer.py +39 -17
  254. classiq/qmod/python_classical_type.py +40 -13
  255. classiq/qmod/qfunc.py +124 -19
  256. classiq/qmod/qmod_constant.py +2 -2
  257. classiq/qmod/qmod_parameter.py +5 -2
  258. classiq/qmod/qmod_variable.py +48 -47
  259. classiq/qmod/quantum_callable.py +18 -13
  260. classiq/qmod/quantum_expandable.py +31 -26
  261. classiq/qmod/quantum_function.py +84 -36
  262. classiq/qmod/semantics/annotation/call_annotation.py +5 -5
  263. classiq/qmod/semantics/error_manager.py +23 -15
  264. classiq/qmod/semantics/lambdas.py +1 -2
  265. classiq/qmod/semantics/validation/types_validation.py +1 -2
  266. classiq/qmod/symbolic.py +2 -4
  267. classiq/qmod/utilities.py +13 -20
  268. classiq/qmod/write_qmod.py +3 -4
  269. classiq/quantum_program.py +1 -3
  270. classiq/synthesis.py +11 -7
  271. {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/METADATA +2 -3
  272. {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/RECORD +274 -300
  273. {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/WHEEL +1 -1
  274. classiq/applications/chemistry/ansatz_parameters.py +0 -29
  275. classiq/applications/chemistry/chemistry_execution_parameters.py +0 -16
  276. classiq/applications/chemistry/chemistry_model_constructor.py +0 -532
  277. classiq/applications/chemistry/ground_state_problem.py +0 -42
  278. classiq/applications/qsvm/__init__.py +0 -8
  279. classiq/applications/qsvm/qsvm.py +0 -11
  280. classiq/evaluators/qmod_expression_visitors/qmod_expression_bwc.py +0 -129
  281. classiq/execution/iqcc.py +0 -128
  282. classiq/interface/applications/qsvm.py +0 -117
  283. classiq/interface/chemistry/elements.py +0 -120
  284. classiq/interface/chemistry/fermionic_operator.py +0 -208
  285. classiq/interface/chemistry/ground_state_problem.py +0 -132
  286. classiq/interface/chemistry/ground_state_result.py +0 -8
  287. classiq/interface/chemistry/molecule.py +0 -71
  288. classiq/interface/execution/iqcc.py +0 -44
  289. classiq/interface/generator/application_apis/chemistry_declarations.py +0 -69
  290. classiq/interface/generator/application_apis/entangler_declarations.py +0 -29
  291. classiq/interface/generator/application_apis/qsvm_declarations.py +0 -6
  292. classiq/interface/generator/chemistry_function_params.py +0 -50
  293. classiq/interface/generator/entangler_params.py +0 -72
  294. classiq/interface/generator/entanglers.py +0 -14
  295. classiq/interface/generator/hamiltonian_evolution/qdrift.py +0 -27
  296. classiq/interface/generator/hartree_fock.py +0 -26
  297. classiq/interface/generator/hva.py +0 -22
  298. classiq/interface/generator/linear_pauli_rotations.py +0 -92
  299. classiq/interface/generator/qft.py +0 -37
  300. classiq/interface/generator/qsvm.py +0 -96
  301. classiq/interface/generator/state_preparation/__init__.py +0 -14
  302. classiq/interface/generator/state_preparation/bell_state_preparation.py +0 -27
  303. classiq/interface/generator/state_preparation/computational_basis_state_preparation.py +0 -28
  304. classiq/interface/generator/state_preparation/distributions.py +0 -53
  305. classiq/interface/generator/state_preparation/exponential_state_preparation.py +0 -14
  306. classiq/interface/generator/state_preparation/ghz_state_preparation.py +0 -14
  307. classiq/interface/generator/state_preparation/metrics.py +0 -41
  308. classiq/interface/generator/state_preparation/state_preparation.py +0 -113
  309. classiq/interface/generator/state_preparation/state_preparation_abc.py +0 -24
  310. classiq/interface/generator/state_preparation/uniform_distibution_state_preparation.py +0 -13
  311. classiq/interface/generator/state_preparation/w_state_preparation.py +0 -13
  312. classiq/interface/generator/ucc.py +0 -74
  313. classiq/interface/helpers/backward_compatibility.py +0 -9
  314. classiq/model_expansions/transformers/type_modifier_inference.py +0 -392
  315. classiq/open_library/functions/lookup_table.py +0 -58
  316. classiq/qmod/builtins/functions/chemistry.py +0 -123
  317. classiq/qmod/builtins/functions/qsvm.py +0 -24
  318. {classiq-0.93.0.dist-info → classiq-0.100.0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -1,11 +1,16 @@
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
 
7
5
  BasisGates: TypeAlias = frozenset[str]
8
6
 
7
+ NATIVE_GATES_TO_CLASSIQ_GATES_MAP: dict[str, str] = {
8
+ "cnot": "cx",
9
+ "toffoli": "ccx",
10
+ "p": "rz",
11
+ "i": "id",
12
+ }
13
+
9
14
  SINGLE_QUBIT_GATES: BasisGates = frozenset(
10
15
  (
11
16
  "u1",
@@ -66,6 +71,7 @@ DEFAULT_BASIS_GATES: BasisGates = SINGLE_QUBIT_GATES | BASIC_TWO_QUBIT_GATES
66
71
  ALL_GATES: BasisGates = (
67
72
  SINGLE_QUBIT_GATES | TWO_QUBIT_GATES | THREE_QUBIT_GATES | NON_UNITARY_GATES
68
73
  )
74
+ ALL_NON_3_QBIT_GATES: BasisGates = ALL_GATES - THREE_QUBIT_GATES
69
75
 
70
76
  ROUTING_TWO_QUBIT_BASIS_GATES: BasisGates = frozenset(
71
77
  ("cx", "ecr", "rzx", "ryy", "rxx", "rzz", "cy", "cz", "cp", "swap")
@@ -80,7 +86,7 @@ ALL_GATES_DICT = {gate.upper(): gate.lower() for gate in sorted(ALL_GATES)}
80
86
 
81
87
  class LowerValsEnum(StrEnum):
82
88
  @classmethod
83
- def _missing_(cls, value: Optional[str]) -> Optional[str]: # type: ignore[override]
89
+ def _missing_(cls, value: str | None) -> str | None: # type: ignore[override]
84
90
  if not isinstance(value, str):
85
91
  return None
86
92
  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
@@ -153,19 +20,7 @@ class Pauli(IntEnum):
153
20
  Z = 3
154
21
 
155
22
 
156
- class QSVMFeatureMapEntanglement(IntEnum):
157
- FULL = 0
158
- LINEAR = 1
159
- CIRCULAR = 2
160
- SCA = 3
161
- PAIRWISE = 4
162
-
163
-
164
23
  __all__ = [
165
- "Element",
166
- "FermionMapping",
167
- "LadderOperator",
168
24
  "Optimizer",
169
25
  "Pauli",
170
- "QSVMFeatureMapEntanglement",
171
26
  ]
@@ -3,9 +3,10 @@ from pydantic import BaseModel, Field, NonNegativeInt, PrivateAttr
3
3
 
4
4
  class CompilationMetadata(BaseModel):
5
5
  should_synthesize_separately: bool = Field(default=False)
6
- occurrences_number: NonNegativeInt = Field(default=1)
6
+ occurrences_number: NonNegativeInt = Field(default=0)
7
7
  _occupation_number: NonNegativeInt = PrivateAttr(default=0)
8
- unchecked: list[str] = Field(default_factory=list)
8
+ disable_perm_check: bool = Field(default=False)
9
+ disable_const_checks: list[str] | bool = Field(default=False)
9
10
 
10
11
  @property
11
12
  def occupation_number(self) -> NonNegativeInt:
@@ -14,3 +15,13 @@ class CompilationMetadata(BaseModel):
14
15
  @occupation_number.setter
15
16
  def occupation_number(self, value: NonNegativeInt) -> None:
16
17
  self._occupation_number = value
18
+
19
+ @property
20
+ def has_user_directives(self) -> bool:
21
+ return bool(self.disable_perm_check or self.disable_const_checks)
22
+
23
+ def copy_user_directives(self) -> "CompilationMetadata":
24
+ return CompilationMetadata(
25
+ disable_perm_check=self.disable_perm_check,
26
+ disable_const_checks=self.disable_const_checks,
27
+ )
@@ -1,6 +1,7 @@
1
1
  from collections import Counter
2
+ from collections.abc import Callable
2
3
  from enum import Enum, EnumMeta, IntEnum
3
- from typing import Any, Callable
4
+ from typing import Any
4
5
 
5
6
  import pydantic
6
7
 
@@ -2,7 +2,7 @@ from collections import Counter, defaultdict
2
2
  from collections.abc import Collection, Iterable, Mapping
3
3
  from dataclasses import dataclass
4
4
  from itertools import chain
5
- from typing import Optional, TypeVar
5
+ from typing import TypeVar
6
6
 
7
7
  import networkx as nx
8
8
 
@@ -23,8 +23,8 @@ RECURRING_NAMES_ERROR_MSG = "Recurring wire names"
23
23
 
24
24
  @dataclass
25
25
  class Wire:
26
- start: Optional[PydanticNonEmptyString] = None
27
- end: Optional[PydanticNonEmptyString] = None
26
+ start: PydanticNonEmptyString | None = None
27
+ end: PydanticNonEmptyString | None = None
28
28
 
29
29
 
30
30
  def _parse_call_inputs(
@@ -1,11 +1,9 @@
1
1
  from collections import abc, defaultdict
2
- from collections.abc import Collection, Mapping, Sequence
2
+ from collections.abc import Callable, Collection, Mapping, Sequence
3
3
  from functools import partial
4
4
  from typing import (
5
5
  TYPE_CHECKING,
6
6
  Any,
7
- Callable,
8
- Optional,
9
7
  TypeVar,
10
8
  Union,
11
9
  )
@@ -30,7 +28,7 @@ Ret = TypeVar("Ret", bound=RetType)
30
28
 
31
29
 
32
30
  class Visitor:
33
- def visit(self, node: NodeType) -> Optional[RetType]:
31
+ def visit(self, node: NodeType) -> RetType | None:
34
32
  for cls in type(node).__mro__:
35
33
  method = "visit_" + cls.__name__
36
34
  if hasattr(self, method):
@@ -38,40 +36,40 @@ class Visitor:
38
36
  return visitor(node)
39
37
  return self.generic_visit(node)
40
38
 
41
- def generic_visit(self, node: NodeType) -> Optional[RetType]:
39
+ def generic_visit(self, node: NodeType) -> RetType | None:
42
40
  if isinstance(node, BaseModel):
43
41
  return self.visit_BaseModel(node)
44
42
 
45
43
  return node
46
44
 
47
- def visit_list(self, node: list[NodeType]) -> Optional[RetType]:
45
+ def visit_list(self, node: list[NodeType]) -> RetType | None:
48
46
  for elem in node:
49
47
  self.visit(elem)
50
48
 
51
49
  return None
52
50
 
53
- def visit_dict(self, node: dict[Key, NodeType]) -> Optional[RetType]:
51
+ def visit_dict(self, node: dict[Key, NodeType]) -> RetType | None:
54
52
  for value in node.values():
55
53
  self.visit(value)
56
54
 
57
55
  return None
58
56
 
59
- def visit_tuple(self, node: tuple[NodeType, ...]) -> Optional[tuple[RetType, ...]]:
57
+ def visit_tuple(self, node: tuple[NodeType, ...]) -> tuple[RetType, ...] | None:
60
58
  for value in node:
61
59
  self.visit(value)
62
60
 
63
61
  return None
64
62
 
65
- def visit_BaseModel(self, node: BaseModel) -> Optional[RetType]:
63
+ def visit_BaseModel(self, node: BaseModel) -> RetType | None:
66
64
  for _, value in node:
67
65
  self.visit(value)
68
66
 
69
67
  return None
70
68
 
71
- def visit_int(self, n: int) -> Optional[RetType]:
69
+ def visit_int(self, n: int) -> RetType | None:
72
70
  return None
73
71
 
74
- def visit_bool(self, b: bool) -> Optional[RetType]:
72
+ def visit_bool(self, b: bool) -> RetType | None:
75
73
  return None
76
74
 
77
75
 
@@ -103,7 +101,7 @@ class Transformer(Visitor):
103
101
  return tuple(self.visit(value) for value in node)
104
102
 
105
103
  def visit_BaseModel(
106
- self, node: BaseModel, fields_to_skip: Optional[Collection[str]] = None
104
+ self, node: BaseModel, fields_to_skip: Collection[str] | None = None
107
105
  ) -> RetType:
108
106
  fields_to_skip = fields_to_skip or set()
109
107
 
@@ -32,7 +32,6 @@ class Provider(StrEnum):
32
32
  OQC = "OQC"
33
33
  INTEL = "Intel"
34
34
  AQT = "AQT"
35
- IQCC = "IQCC"
36
35
  CINECA = "CINECA"
37
36
 
38
37
  @property
@@ -71,7 +70,7 @@ class HardwareStatus(pydantic.BaseModel):
71
70
  default=None,
72
71
  description="The estimated queue time for the hardware in seconds.",
73
72
  )
74
- pending_jobs: Optional[int] = None
73
+ pending_jobs: int | None = None
75
74
 
76
75
 
77
76
  if TYPE_CHECKING:
@@ -87,7 +86,7 @@ class HardwareInformation(pydantic.BaseModel):
87
86
  display_name: str
88
87
  device_type: DeviceType
89
88
  number_of_qubits: int
90
- connectivity_map: Optional[list[ConnectivityMapEntry]] = None
89
+ connectivity_map: list[ConnectivityMapEntry] | None = None
91
90
  basis_gates: list[str]
92
91
  status: HardwareStatus
93
92
 
@@ -1,8 +1,8 @@
1
- from typing import TYPE_CHECKING, Any, Optional
1
+ from typing import TYPE_CHECKING, Any
2
2
 
3
3
 
4
4
  class classproperty(property): # noqa: N801
5
- def __get__(self, owner_self: Any, owner_cls: Optional[type] = None) -> Any:
5
+ def __get__(self, owner_self: Any, owner_cls: type | None = None) -> Any:
6
6
  if TYPE_CHECKING:
7
7
  assert self.fget is not None
8
8
  return self.fget(owner_cls)
@@ -1,3 +1,4 @@
1
- from typing import Any, Callable
1
+ from collections.abc import Callable
2
+ from typing import Any
2
3
 
3
4
  CUSTOM_ENCODERS: dict[type, Callable[[Any], Any]] = {complex: str}
@@ -8,7 +8,7 @@ from classiq.interface.generator.parameters import ParameterComplexType
8
8
 
9
9
  # General int types
10
10
 
11
- MAX_EXPRESSION_SIZE = 32768
11
+ MAX_EXPRESSION_SIZE = 2**20
12
12
 
13
13
  if TYPE_CHECKING:
14
14
  PydanticLargerThanOneInteger = int
@@ -1,7 +1,4 @@
1
- from typing import Union
2
-
3
-
4
- def s(items: Union[list, int]) -> str:
1
+ def s(items: list | int) -> str:
5
2
  if isinstance(items, list):
6
3
  items = len(items)
7
4
  return "" if items == 1 else "s"
@@ -15,6 +12,10 @@ def they(items: list) -> str:
15
12
  return "it" if len(items) == 1 else "they"
16
13
 
17
14
 
15
+ def conj(items: list) -> str:
16
+ return "s" if len(items) == 1 else ""
17
+
18
+
18
19
  def readable_list(items: list, quote: bool = False) -> str:
19
20
  if quote:
20
21
  items = [repr(str(item)) for item in items]
@@ -3,7 +3,7 @@ from collections import Counter
3
3
  from collections.abc import Iterator
4
4
  from functools import cached_property
5
5
  from itertools import count
6
- from typing import Any, Optional
6
+ from typing import Any
7
7
 
8
8
  import pydantic
9
9
  from pydantic import ConfigDict, field_validator
@@ -43,10 +43,11 @@ class OperationType(StrEnum):
43
43
  FREE = "FREE"
44
44
  BIND = "BIND"
45
45
  ATOMIC = "ATOMIC"
46
+ UNORDERED_CHILDREN = "UNORDERED_CHILDREN"
46
47
 
47
48
 
48
49
  class OperationData(pydantic.BaseModel):
49
- approximated_depth: Optional[int] = None
50
+ approximated_depth: int | None = None
50
51
  width: int
51
52
  gate_count: Counter[str] = pydantic.Field(default_factory=dict)
52
53
 
@@ -65,7 +66,7 @@ class ProgramData(pydantic.BaseModel):
65
66
 
66
67
  class OperationLink(pydantic.BaseModel):
67
68
  label: str
68
- inner_label: Optional[str] = None
69
+ inner_label: str | None = None
69
70
  qubits: tuple[int, ...]
70
71
  type: str
71
72
  is_captured: bool = False
@@ -148,14 +149,14 @@ class AtomicGate(StrEnum):
148
149
 
149
150
  class Operation(pydantic.BaseModel):
150
151
  name: str
151
- inner_label: Optional[str] = None
152
+ inner_label: str | None = None
152
153
  _id: int = pydantic.PrivateAttr(default_factory=_operation_id_counter.next_id)
153
154
  qasm_name: str = pydantic.Field(default="")
154
155
  details: str = pydantic.Field(default="")
155
156
  children: list["Operation"] = pydantic.Field(default_factory=list)
156
157
  # children_ids is optional in order to support backwards compatibility.
157
158
  children_ids: list[int] = pydantic.Field(default_factory=list)
158
- operation_data: Optional[OperationData] = None
159
+ operation_data: OperationData | None = None
159
160
  operation_links: OperationLinks
160
161
  control_qubits: tuple[int, ...] = pydantic.Field(default_factory=tuple)
161
162
  auxiliary_qubits: tuple[int, ...]
@@ -1 +1 @@
1
- INTERFACE_VERSION = "13"
1
+ INTERFACE_VERSION = "15"
classiq/interface/jobs.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Any, Generic, Optional, TypeVar, Union
1
+ from typing import Any, Generic, TypeVar, Union
2
2
 
3
3
  import pydantic
4
4
  from pydantic import BaseModel
@@ -43,8 +43,8 @@ For unsuccessful jobs, we expect failure_details to be a string and result to be
43
43
 
44
44
  class JobDescription(BaseModel, Generic[T], json_encoders=CUSTOM_ENCODERS):
45
45
  status: JobStatus
46
- failure_details: Optional[str] = pydantic.Field(default=None)
47
- result: Optional[T] = pydantic.Field(default=None)
46
+ failure_details: str | None = pydantic.Field(default=None)
47
+ result: T | None = pydantic.Field(default=None)
48
48
 
49
49
  @pydantic.model_validator(mode="after")
50
50
  def validate_status_and_fields(self) -> Self:
@@ -1,5 +1,5 @@
1
1
  from collections.abc import Mapping
2
- from typing import Literal, Optional
2
+ from typing import Literal
3
3
 
4
4
  from classiq.interface.generator.expressions.expression import Expression
5
5
  from classiq.interface.model.handle_binding import ConcreteHandleBinding, HandleBinding
@@ -8,9 +8,9 @@ from classiq.interface.model.quantum_statement import QuantumOperation
8
8
 
9
9
  class Allocate(QuantumOperation):
10
10
  kind: Literal["Allocate"]
11
- size: Optional[Expression] = None
12
- is_signed: Optional[Expression] = None
13
- fraction_digits: Optional[Expression] = None
11
+ size: Expression | None = None
12
+ is_signed: Expression | None = None
13
+ fraction_digits: Expression | None = None
14
14
  target: ConcreteHandleBinding
15
15
 
16
16
  @property
@@ -46,3 +46,6 @@ class BindOperation(QuantumOperation):
46
46
  )
47
47
  for handle in self.out_handles
48
48
  ]
49
+
50
+ def inverse(self) -> "BindOperation":
51
+ return BindOperation(in_handles=self.out_handles, out_handles=self.in_handles)
@@ -1,4 +1,4 @@
1
- from typing import TYPE_CHECKING, Literal, Optional
1
+ from typing import TYPE_CHECKING, Literal
2
2
 
3
3
  import pydantic
4
4
 
@@ -13,4 +13,8 @@ class Block(QuantumOperation):
13
13
 
14
14
  statements: "StatementBlock"
15
15
 
16
- label: Optional[str] = pydantic.Field(default=None)
16
+ label: str | None = pydantic.Field(default=None)
17
+
18
+ @property
19
+ def blocks(self) -> dict[str, "StatementBlock"]:
20
+ return {"statements": self.statements}
@@ -1,4 +1,4 @@
1
- from typing import Literal, Optional
1
+ from typing import Literal
2
2
 
3
3
  from classiq.interface.generator.expressions.expression import Expression
4
4
  from classiq.interface.model.handle_binding import ConcreteHandleBinding
@@ -9,8 +9,8 @@ class SetBoundsStatement(QuantumOperation):
9
9
  kind: Literal["SetBoundsStatement"]
10
10
 
11
11
  target: ConcreteHandleBinding
12
- lower_bound: Optional[Expression]
13
- upper_bound: Optional[Expression]
12
+ lower_bound: Expression | None
13
+ upper_bound: Expression | None
14
14
 
15
15
  @property
16
16
  def expressions(self) -> list[Expression]:
@@ -31,6 +31,10 @@ class ClassicalIf(QuantumOperation):
31
31
  def expressions(self) -> list[Expression]:
32
32
  return [self.condition]
33
33
 
34
+ @property
35
+ def blocks(self) -> dict[str, "StatementBlock"]:
36
+ return {"then": self.then, "else_": self.else_}
37
+
34
38
  @property
35
39
  def wiring_inputs(self) -> Mapping[str, HandleBinding]:
36
40
  return functools.reduce(
@@ -19,7 +19,7 @@ class Control(QuantumExpressionOperation):
19
19
  else_block: Optional["StatementBlock"] = None
20
20
 
21
21
  _ctrl_size: int = pydantic.PrivateAttr(default=0)
22
- _result_type: Optional[QuantumType] = pydantic.PrivateAttr(
22
+ _result_type: QuantumType | None = pydantic.PrivateAttr(
23
23
  default=None,
24
24
  )
25
25
 
@@ -47,3 +47,10 @@ class Control(QuantumExpressionOperation):
47
47
 
48
48
  def _as_back_ref(self: ASTNodeType) -> ASTNodeType:
49
49
  return reset_lists(self, ["body", "else_block"])
50
+
51
+ @property
52
+ def blocks(self) -> dict[str, "StatementBlock"]:
53
+ blocks = {"body": self.body}
54
+ if self.else_block is not None:
55
+ blocks["else_block"] = self.else_block
56
+ return blocks
@@ -1,5 +1,5 @@
1
1
  from collections.abc import Mapping, Sequence
2
- from typing import Literal, Union
2
+ from typing import Literal
3
3
 
4
4
  from classiq.interface.enum_utils import StrEnum
5
5
  from classiq.interface.generator.expressions.expression import Expression
@@ -16,7 +16,7 @@ class InplaceBinaryOperation(QuantumOperation):
16
16
  kind: Literal["InplaceBinaryOperation"]
17
17
 
18
18
  target: ConcreteHandleBinding
19
- value: Union[ConcreteHandleBinding, Expression]
19
+ value: ConcreteHandleBinding | Expression
20
20
  operation: BinaryOperation
21
21
 
22
22
  @property
@@ -14,3 +14,7 @@ class Invert(QuantumOperation):
14
14
 
15
15
  def _as_back_ref(self: ASTNodeType) -> ASTNodeType:
16
16
  return reset_lists(self, ["body"])
17
+
18
+ @property
19
+ def blocks(self) -> dict[str, "StatementBlock"]:
20
+ return {"body": self.body}
@@ -185,14 +185,14 @@ class Model(VersionedModel, ASTNode):
185
185
  return constants
186
186
 
187
187
  def dump_no_metadata(self) -> dict[str, Any]:
188
- compilation_metadata_with_unchecked = {
189
- name: CompilationMetadata(unchecked=comp_metadata.unchecked)
188
+ compilation_metadata_user_directives = {
189
+ name: comp_metadata.copy_user_directives()
190
190
  for name, comp_metadata in self.functions_compilation_metadata.items()
191
- if len(comp_metadata.unchecked) > 0
191
+ if comp_metadata.has_user_directives
192
192
  }
193
193
  model = self.model_copy(
194
194
  update={
195
- "functions_compilation_metadata": compilation_metadata_with_unchecked,
195
+ "functions_compilation_metadata": compilation_metadata_user_directives,
196
196
  }
197
197
  )
198
198
  return model.model_dump(
@@ -1,5 +1,12 @@
1
+ from collections.abc import Collection
2
+
3
+ from pydantic import BaseModel
4
+
1
5
  from classiq.interface.debug_info.debug_info import DebugInfoCollection
2
- from classiq.interface.generator.visitor import Transformer, Visitor
6
+ from classiq.interface.generator.visitor import RetType, Transformer, Visitor
7
+ from classiq.interface.model.model import Model
8
+ from classiq.interface.model.native_function_definition import NativeFunctionDefinition
9
+ from classiq.interface.model.quantum_statement import QuantumStatement
3
10
 
4
11
 
5
12
  class ModelVisitor(Visitor):
@@ -7,8 +14,40 @@ class ModelVisitor(Visitor):
7
14
  return
8
15
 
9
16
 
17
+ class ModelStatementsVisitor(ModelVisitor):
18
+ def visit_BaseModel(self, node: BaseModel) -> RetType | None:
19
+ if isinstance(node, Model):
20
+ return self.visit(node.functions)
21
+ if isinstance(node, NativeFunctionDefinition):
22
+ return self.visit(node.body)
23
+ if isinstance(node, QuantumStatement):
24
+ for block in node.blocks.values():
25
+ self.visit(block)
26
+ return None
27
+ return super().visit_BaseModel(node)
28
+
29
+
10
30
  class ModelTransformer(Transformer):
11
31
  def visit_DebugInfoCollection(
12
32
  self, debug_info: DebugInfoCollection
13
33
  ) -> DebugInfoCollection:
14
34
  return debug_info
35
+
36
+
37
+ class ModelStatementsTransformer(ModelTransformer):
38
+ def visit_BaseModel(
39
+ self, node: BaseModel, fields_to_skip: Collection[str] | None = None
40
+ ) -> RetType:
41
+ if isinstance(node, Model):
42
+ new_functions = self.visit(node.functions)
43
+ return node.model_copy(update=dict(functions=new_functions))
44
+ if isinstance(node, NativeFunctionDefinition):
45
+ new_body = self.visit(node.body)
46
+ return node.model_copy(update=dict(body=new_body))
47
+ if isinstance(node, QuantumStatement):
48
+ new_blocks = {
49
+ block_name: self.visit(block)
50
+ for block_name, block in node.blocks.items()
51
+ }
52
+ return node.model_copy(update=new_blocks)
53
+ return super().visit_BaseModel(node, fields_to_skip)