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
@@ -17,19 +17,22 @@ from classiq.qmod.builtins.functions import (
17
17
  RY,
18
18
  H,
19
19
  X,
20
+ free,
20
21
  inplace_prepare_amplitudes,
21
22
  )
22
23
  from classiq.qmod.builtins.operations import (
23
24
  allocate,
25
+ bind,
24
26
  control,
25
27
  if_,
26
28
  inplace_add,
27
29
  inplace_xor,
30
+ invert,
28
31
  repeat,
29
32
  within_apply,
30
33
  )
31
34
  from classiq.qmod.cparam import CArray, CInt, CReal
32
- from classiq.qmod.qfunc import qfunc
35
+ from classiq.qmod.qfunc import qfunc, qperm
33
36
  from classiq.qmod.qmod_variable import Output, QArray, QBit, QNum
34
37
  from classiq.qmod.symbolic import (
35
38
  acos,
@@ -248,7 +251,7 @@ def prepare_bell_state(
248
251
  CX(qpair[0], qpair[1])
249
252
 
250
253
 
251
- @qfunc
254
+ @qperm
252
255
  def inplace_prepare_int(value: CInt, target: QNum) -> None:
253
256
  """
254
257
  [Qmod Classiq-library function]
@@ -273,7 +276,7 @@ def inplace_prepare_int(value: CInt, target: QNum) -> None:
273
276
  target ^= value
274
277
 
275
278
 
276
- @qfunc
279
+ @qperm
277
280
  def prepare_int(
278
281
  value: CInt,
279
282
  out: Output[QNum[Literal["floor(log(value, 2)) + 1"]]],
@@ -324,7 +327,7 @@ def _classical_hadamard_transform(arr: list[float]) -> np.ndarray:
324
327
  return 1 / np.sqrt(len(arr)) * np.array(sympy.fwht(np.array(arr)))
325
328
 
326
329
 
327
- @qfunc
330
+ @qperm
328
331
  def apply_phase_table(
329
332
  phases: list[float],
330
333
  target: QArray[QBit, Literal["log(phases.len, 2)"]],
@@ -390,7 +393,7 @@ def _dicke_split_cycle_shift(k: int, qvar: QArray[QBit]) -> None:
390
393
  internal function, assumes the input is in the form |11..100..0> with up to k ones.
391
394
  transforms the state to: sqrt(1/n)*|11..100..0> + sqrt((n-1)/n)*|01..110..0>.
392
395
  """
393
- for i in range(k):
396
+ for i in range(min(k, qvar.len - 1)):
394
397
  within_apply(
395
398
  lambda i=i: CX(qvar[i + 1], qvar[0]), # type: ignore[misc]
396
399
  lambda i=i: ( # type: ignore[misc]
@@ -412,7 +415,7 @@ def prepare_dicke_state_unary_input(max_k: int, qvar: QArray[QBit]) -> None:
412
415
  """
413
416
  [Qmod Classiq-library function]
414
417
 
415
- Prepares a Dicke state with a variable number of excitations based on an unary-encoded input.
418
+ Prepares a Dicke state with a variable number of excitations based on a unary-encoded input.
416
419
 
417
420
  The Dicke state is defined to be:
418
421
 
@@ -427,9 +430,12 @@ def prepare_dicke_state_unary_input(max_k: int, qvar: QArray[QBit]) -> None:
427
430
  max_k: The maximum number of allowed excitations (upper bound for k).
428
431
  qvar: Unary-encoded quantum input register of length >= max_k. Must be pre-initialized.
429
432
  """
430
- if qvar.len > max(1, max_k):
433
+ if qvar.len >= max(1, max_k):
431
434
  _dicke_split_cycle_shift(max_k, qvar)
432
- prepare_dicke_state_unary_input(min(max_k, qvar.len - 2), qvar[1 : qvar.len])
435
+ if qvar.len > 2:
436
+ prepare_dicke_state_unary_input(
437
+ min(max_k, qvar.len - 2), qvar[1 : qvar.len]
438
+ )
433
439
 
434
440
 
435
441
  @qfunc
@@ -456,7 +462,7 @@ def prepare_dicke_state(k: int, qvar: QArray[QBit]) -> None:
456
462
  prepare_dicke_state_unary_input(k, qvar)
457
463
 
458
464
 
459
- @qfunc
465
+ @qperm
460
466
  def prepare_basis_state(state: list[bool], arr: Output[QArray]) -> None:
461
467
  """
462
468
  [Qmod Classiq-library function]
@@ -515,7 +521,7 @@ def prepare_linear_amplitudes(x: QArray) -> None:
515
521
  hadamard_transform(x)
516
522
 
517
523
 
518
- @qfunc
524
+ @qperm
519
525
  def swap_states(a: int, b: int, target: QArray) -> None:
520
526
  """
521
527
  Swap 2 computational basis states a and b, leave all other states untouched.
@@ -538,7 +544,7 @@ def swap_states(a: int, b: int, target: QArray) -> None:
538
544
  if anchor < target.len - 1:
539
545
  target_without_anchor.append(target[anchor + 1 : target.len])
540
546
 
541
- @qfunc
547
+ @qperm
542
548
  def _xor_if_equal(n: CInt, ctrl: QNum, target: QBit) -> None:
543
549
  target ^= ctrl == n
544
550
 
@@ -564,6 +570,115 @@ def swap_states(a: int, b: int, target: QArray) -> None:
564
570
  )
565
571
 
566
572
 
573
+ @qperm
574
+ def _controlled_xor(
575
+ target: QNum, target_value: CInt, ctrl: QNum, ctrl_value: CInt
576
+ ) -> None:
577
+ control(ctrl == ctrl_value, lambda: inplace_xor(target_value, target))
578
+
579
+
580
+ @qperm
581
+ def _inplace_xor(i: CInt, target: QNum) -> None:
582
+ inplace_xor(i, target)
583
+
584
+
585
+ def _update_states(
586
+ states: list[int],
587
+ q: QArray,
588
+ assignment_indices: list[int],
589
+ assignment_value: int,
590
+ pivot_indices: list[int],
591
+ pivot_value: int,
592
+ ) -> None:
593
+ _controlled_xor(
594
+ [q[i] for i in assignment_indices],
595
+ assignment_value,
596
+ [q[i] for i in pivot_indices],
597
+ pivot_value,
598
+ )
599
+ for j in range(len(states)):
600
+ s = states[j]
601
+ ctrl_bits = sum(((s >> i) & 1) << k for k, i in enumerate(pivot_indices))
602
+ if ctrl_bits == pivot_value:
603
+ for k, i in enumerate(assignment_indices):
604
+ if (assignment_value >> k) & 1:
605
+ s ^= 1 << i
606
+
607
+ states[j] = s
608
+
609
+
610
+ @qperm
611
+ def pack_amplitudes(states: list[int], target: QArray) -> None:
612
+ """
613
+ [Qmod Classiq-library function]
614
+
615
+ Perform the inverse operation for sparse state preparation - for each given state in `states`,
616
+ move it to the first available computational basis state, according to the order in the array.
617
+ The function does not guarantee what happens to the other states which are not in the list.
618
+
619
+ Args:
620
+ states: A list of distinct computational basis indices to pack. The order of the list will
621
+ reflect the order of the packed states.
622
+ target: The quantum variable to act upon. Assumed to be larged enough to populate all given `states`,
623
+ and at least of size `2 * len(states)`.
624
+ """
625
+ target_size = target.len
626
+
627
+ # handle the dense case by using an additional auxilliary qubit
628
+ if len(states) > 2 ** (target_size - 1):
629
+ # allocate a pivot
630
+ p = QBit()
631
+ p |= 0
632
+ temp_target: QArray = QArray("extended_target")
633
+ bind([target, p], temp_target)
634
+ # replace register to unify the different flows
635
+ target, temp_target = temp_target, target
636
+
637
+ for index, _ in enumerate(states):
638
+ state = states[
639
+ index
640
+ ] # access this way because `states` is changing in each iteration
641
+
642
+ if state == index:
643
+ continue # nothing to do
644
+
645
+ if index == 0:
646
+ _inplace_xor(state, target)
647
+ states = [s ^ state for s in states]
648
+ continue
649
+
650
+ # if no pivot, create one:
651
+ if state < 2 ** index.bit_length():
652
+ pivot = index.bit_length()
653
+ _update_states(states, target, [pivot], 1, list(range(pivot)), state)
654
+ else:
655
+ pivot = state.bit_length() - 1
656
+
657
+ # use the pivot to update the quantum array
658
+ _update_states(
659
+ states,
660
+ target,
661
+ list(range(pivot)),
662
+ (state % (1 << pivot)) ^ index,
663
+ [pivot],
664
+ 1,
665
+ )
666
+
667
+ # finally clean the pivot
668
+ if index == 2 ** (index.bit_length() - 1) and pivot < target_size:
669
+ # this specific case requires only a single ctrl qubit for the cleaning
670
+ # It won't work though if the auxilliary is used
671
+ _update_states(states, target, [pivot], 1, [index.bit_length() - 1], 1)
672
+ else:
673
+ _update_states(
674
+ states, target, [pivot], 1, list(range(index.bit_length())), index
675
+ )
676
+
677
+ if len(states) > 2 ** (target_size - 1):
678
+ bind(target, [temp_target, p])
679
+ free(p)
680
+
681
+
567
682
  @qfunc
568
683
  def inplace_prepare_sparse_amplitudes(
569
684
  states: list[int], amplitudes: list[complex], target: QArray
@@ -596,32 +711,23 @@ def inplace_prepare_sparse_amplitudes(
596
711
  dense_size = max(int(np.ceil(np.log2(len(states)))), 1)
597
712
  dense_amplitudes = np.zeros(2**dense_size, dtype=complex)
598
713
 
599
- ## make sure the states with number smaller than the dense state size are located in their place already
600
- for i, state in enumerate(states):
601
- if state < len(dense_amplitudes):
714
+ if max(states) < 2**dense_size:
715
+ for i, state in enumerate(states):
602
716
  dense_amplitudes[state] = amplitudes[i]
603
-
604
- ## make a swap list for all other states
605
- swap_list = []
606
- free_index = 0
607
- for i, state in enumerate(states):
608
- if state < len(dense_amplitudes):
609
- continue # already populated
610
- while dense_amplitudes[free_index]:
611
- free_index += 1 # index is not free
612
-
613
- dense_amplitudes[free_index] = amplitudes[i]
614
- swap_list.append((free_index, state))
615
- free_index += 1
717
+ else:
718
+ dense_amplitudes = np.pad(
719
+ amplitudes, (0, 2**dense_size - len(amplitudes)), "constant"
720
+ )
616
721
 
617
722
  inplace_prepare_complex_amplitudes(
618
723
  np.abs(dense_amplitudes), np.angle(dense_amplitudes), target[0:dense_size]
619
724
  )
620
725
 
621
- # swap all required states
622
- sparse_size = max(int(np.ceil(np.log2(max(list(states) + [1])))), 1)
623
- for a, b in swap_list:
624
- swap_states(a, b, target[0:sparse_size])
726
+ if max(states) < 2**dense_size:
727
+ return
728
+
729
+ # Shuffle states to the desired position using the inverse operation of packing them
730
+ invert(lambda: pack_amplitudes(states, target))
625
731
 
626
732
 
627
733
  @qfunc
classiq/qmod/__init__.py CHANGED
@@ -4,11 +4,11 @@ from .cfunc import cfunc
4
4
  from .classical_variable import measure
5
5
  from .create_model_function import create_model
6
6
  from .expression_query import get_expression_numeric_attributes
7
- from .qfunc import qfunc
7
+ from .qfunc import qfunc, qperm
8
8
  from .qmod_constant import QConstant
9
9
  from .qmod_parameter import Array, CArray, CBool, CInt, CReal
10
- from .qmod_variable import Const, Input, Output, Permutable, QArray, QBit, QNum, QStruct
11
- from .quantum_callable import QCallable, QCallableList
10
+ from .qmod_variable import Const, Input, Output, QArray, QBit, QNum, QStruct
11
+ from .quantum_callable import QCallable, QCallableList, QPerm, QPermList
12
12
  from .write_qmod import write_qmod
13
13
 
14
14
  __all__ = [
@@ -20,18 +20,20 @@ __all__ = [
20
20
  "Input",
21
21
  "Output",
22
22
  "Const",
23
- "Permutable",
24
23
  "QArray",
25
24
  "QBit",
26
25
  "QNum",
27
26
  "QCallable",
28
27
  "QCallableList",
29
28
  "QConstant",
29
+ "QPerm",
30
+ "QPermList",
30
31
  "QStruct",
31
32
  "cfunc",
32
33
  "create_model",
33
34
  "measure",
34
35
  "get_expression_numeric_attributes",
35
36
  "qfunc",
37
+ "qperm",
36
38
  "write_qmod",
37
39
  ] + _builtins_all
@@ -1,4 +1,4 @@
1
- from typing import Final, Optional
1
+ from typing import Final
2
2
 
3
3
  from classiq.interface.applications.iqae.iqae_result import IQAEResult
4
4
  from classiq.interface.exceptions import ClassiqError
@@ -13,7 +13,6 @@ from classiq.interface.executor.result import (
13
13
  from classiq.interface.executor.vqe_result import VQESolverResult
14
14
  from classiq.interface.generator.functions.qmod_python_interface import QmodPyStruct
15
15
 
16
- from classiq.applications.qsvm.qsvm import Data, Labels
17
16
  from classiq.qmod.builtins.enums import Optimizer
18
17
 
19
18
  _CALL_IN_QFUNC_ERROR = (
@@ -32,7 +31,7 @@ def save(values_to_save: dict) -> None:
32
31
 
33
32
 
34
33
  def sample( # type: ignore[return]
35
- execution_params: Optional[ExecutionParams] = None,
34
+ execution_params: ExecutionParams | None = None,
36
35
  ) -> ExecutionDetails:
37
36
  _raise_error("sample")
38
37
 
@@ -44,7 +43,7 @@ def batch_sample( # type: ignore[return]
44
43
 
45
44
 
46
45
  def estimate( # type: ignore[return]
47
- hamiltonian: list[QmodPyStruct], execution_params: Optional[ExecutionParams] = None
46
+ hamiltonian: list[QmodPyStruct], execution_params: ExecutionParams | None = None
48
47
  ) -> EstimationResult:
49
48
  _raise_error("estimate")
50
49
 
@@ -78,38 +77,20 @@ def qae_with_qpe_result_post_processing( # type: ignore[return]
78
77
  _raise_error("qae_with_qpe_result_post_processing")
79
78
 
80
79
 
81
- def qsvm_full_run( # type: ignore[return]
82
- train_data: Data,
83
- train_labels: Labels,
84
- test_data: Data,
85
- test_labels: Labels,
86
- predict_data: Data,
87
- ) -> QmodPyStruct:
88
- _raise_error("qsvm_full_run")
89
-
90
-
91
80
  def iqae( # type: ignore[return]
92
81
  epsilon: float,
93
82
  alpha: float,
94
- execution_params: Optional[ExecutionParams] = None,
83
+ execution_params: ExecutionParams | None = None,
95
84
  ) -> IQAEResult:
96
85
  _raise_error("iqae")
97
86
 
98
87
 
99
- def molecule_ground_state_solution_post_process( # type: ignore[return]
100
- problem: QmodPyStruct, vqe_result: VQESolverResult
101
- ) -> QmodPyStruct:
102
- _raise_error("molecule_ground_state_solution_post_process")
103
-
104
-
105
88
  __all__ = [
106
89
  "batch_estimate",
107
90
  "batch_sample",
108
91
  "estimate",
109
92
  "iqae",
110
- "molecule_ground_state_solution_post_process",
111
93
  "qae_with_qpe_result_post_processing",
112
- "qsvm_full_run",
113
94
  "sample",
114
95
  "save",
115
96
  "vqe",
@@ -1,7 +1,7 @@
1
1
  # This file was generated automatically - do not edit manually
2
2
 
3
3
 
4
- from classiq.qmod.qmod_parameter import CArray, CBool, CInt, CReal
4
+ from classiq.qmod.qmod_parameter import CInt, CReal
5
5
  from classiq.qmod.symbolic import symbolic_function
6
6
 
7
7
  from .structs import *
@@ -17,47 +17,6 @@ def qft_const_adder_phase(
17
17
  )
18
18
 
19
19
 
20
- def fock_hamiltonian_problem_to_hamiltonian(
21
- problem: FockHamiltonianProblem,
22
- ) -> CArray[PauliTerm]:
23
- return symbolic_function(
24
- problem, return_type=CArray[PauliTerm] # type:ignore[type-abstract]
25
- )
26
-
27
-
28
- def molecule_problem_to_hamiltonian(
29
- problem: MoleculeProblem,
30
- ) -> CArray[PauliTerm]:
31
- return symbolic_function(
32
- problem, return_type=CArray[PauliTerm] # type:ignore[type-abstract]
33
- )
34
-
35
-
36
- def grid_entangler_graph(
37
- num_qubits: CInt,
38
- schmidt_rank: CInt,
39
- grid_randomization: CBool,
40
- ) -> CArray[CArray[CInt]]:
41
- return symbolic_function(
42
- num_qubits,
43
- schmidt_rank,
44
- grid_randomization,
45
- return_type=CArray[CArray[CInt]], # type:ignore[type-abstract]
46
- )
47
-
48
-
49
- def hypercube_entangler_graph(
50
- num_qubits: CInt,
51
- ) -> CArray[CArray[CInt]]:
52
- return symbolic_function(
53
- num_qubits, return_type=CArray[CArray[CInt]] # type:ignore[type-abstract]
54
- )
55
-
56
-
57
20
  __all__ = [
58
21
  "qft_const_adder_phase",
59
- "fock_hamiltonian_problem_to_hamiltonian",
60
- "molecule_problem_to_hamiltonian",
61
- "grid_entangler_graph",
62
- "hypercube_entangler_graph",
63
22
  ]
@@ -2,144 +2,12 @@ from enum import IntEnum
2
2
  from typing import TYPE_CHECKING
3
3
 
4
4
  from classiq.interface.generator.types.enum_declaration import EnumDeclaration
5
+ from classiq.interface.helpers.datastructures import LenList
5
6
 
6
7
  if TYPE_CHECKING:
7
8
  from classiq.qmod.builtins.structs import SparsePauliOp
8
9
 
9
10
 
10
- class Element(IntEnum):
11
- H = 0
12
- He = 1
13
- Li = 2
14
- Be = 3
15
- B = 4
16
- C = 5
17
- N = 6
18
- O = 7 # noqa: E741
19
- F = 8
20
- Ne = 9
21
- Na = 10
22
- Mg = 11
23
- Al = 12
24
- Si = 13
25
- P = 14
26
- S = 15
27
- Cl = 16
28
- Ar = 17
29
- K = 18
30
- Ca = 19
31
- Sc = 20
32
- Ti = 21
33
- V = 22
34
- Cr = 23
35
- Mn = 24
36
- Fe = 25
37
- Co = 26
38
- Ni = 27
39
- Cu = 28
40
- Zn = 29
41
- Ga = 30
42
- Ge = 31
43
- As = 32
44
- Se = 33
45
- Br = 34
46
- Kr = 35
47
- Rb = 36
48
- Sr = 37
49
- Y = 38
50
- Zr = 39
51
- Nb = 40
52
- Mo = 41
53
- Tc = 42
54
- Ru = 43
55
- Rh = 44
56
- Pd = 45
57
- Ag = 46
58
- Cd = 47
59
- In = 48
60
- Sn = 49
61
- Sb = 50
62
- Te = 51
63
- I = 52 # noqa: E741
64
- Xe = 53
65
- Cs = 54
66
- Ba = 55
67
- La = 56
68
- Ce = 57
69
- Pr = 58
70
- Nd = 59
71
- Pm = 60
72
- Sm = 61
73
- Eu = 62
74
- Gd = 63
75
- Tb = 64
76
- Dy = 65
77
- Ho = 66
78
- Er = 67
79
- Tm = 68
80
- Yb = 69
81
- Lu = 70
82
- Hf = 71
83
- Ta = 72
84
- W = 73
85
- Re = 74
86
- Os = 75
87
- Ir = 76
88
- Pt = 77
89
- Au = 78
90
- Hg = 79
91
- Tl = 80
92
- Pb = 81
93
- Bi = 82
94
- Po = 83
95
- At = 84
96
- Rn = 85
97
- Fr = 86
98
- Ra = 87
99
- Ac = 88
100
- Th = 89
101
- Pa = 90
102
- U = 91
103
- Np = 92
104
- Pu = 93
105
- Am = 94
106
- Cm = 95
107
- Bk = 96
108
- Cf = 97
109
- Es = 98
110
- Fm = 99
111
- Md = 100
112
- No = 101
113
- Lr = 102
114
- Rf = 103
115
- Db = 104
116
- Sg = 105
117
- Bh = 106
118
- Hs = 107
119
- Mt = 108
120
- Ds = 109
121
- Rg = 110
122
- Cn = 111
123
- Nh = 112
124
- Fl = 113
125
- Mc = 114
126
- Lv = 115
127
- Ts = 116
128
- Og = 117
129
-
130
-
131
- class FermionMapping(IntEnum):
132
- JORDAN_WIGNER = 0
133
- PARITY = 1
134
- BRAVYI_KITAEV = 2
135
- FAST_BRAVYI_KITAEV = 3
136
-
137
-
138
- class LadderOperator(IntEnum):
139
- PLUS = 0
140
- MINUS = 1
141
-
142
-
143
11
  class Optimizer(IntEnum):
144
12
  COBYLA = 1
145
13
  SPSA = 2
@@ -195,26 +63,24 @@ class Pauli(IntEnum):
195
63
  )
196
64
 
197
65
  return SparsePauliOp(
198
- terms=[
199
- SparsePauliTerm(
200
- paulis=[ # type:ignore[arg-type]
201
- IndexedPauli(pauli=self, index=index) # type:ignore[arg-type]
202
- ],
203
- coefficient=1.0, # type:ignore[arg-type]
204
- )
205
- ],
66
+ terms=LenList(
67
+ [
68
+ SparsePauliTerm(
69
+ paulis=LenList(
70
+ [ # type:ignore[arg-type]
71
+ IndexedPauli(
72
+ pauli=self, index=index # type:ignore[arg-type]
73
+ )
74
+ ]
75
+ ),
76
+ coefficient=1.0, # type:ignore[arg-type]
77
+ )
78
+ ]
79
+ ),
206
80
  num_qubits=index + 1,
207
81
  )
208
82
 
209
83
 
210
- class QSVMFeatureMapEntanglement(IntEnum):
211
- FULL = 0
212
- LINEAR = 1
213
- CIRCULAR = 2
214
- SCA = 3
215
- PAIRWISE = 4
216
-
217
-
218
84
  BUILTIN_ENUM_DECLARATIONS = {
219
85
  enum_def.__name__: EnumDeclaration(
220
86
  name=enum_def.__name__,
@@ -229,10 +95,6 @@ BUILTIN_ENUM_DECLARATIONS = {
229
95
  }
230
96
 
231
97
  __all__ = [
232
- "Element",
233
- "FermionMapping",
234
- "LadderOperator",
235
98
  "Optimizer",
236
99
  "Pauli",
237
- "QSVMFeatureMapEntanglement",
238
100
  ]