classiq 0.53.0__py3-none-any.whl → 0.54.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 (296) hide show
  1. classiq/__init__.py +1 -3
  2. classiq/_analyzer_extras/_ipywidgets_async_extension.py +2 -1
  3. classiq/_internals/__init__.py +0 -20
  4. classiq/_internals/api_wrapper.py +8 -8
  5. classiq/_internals/async_utils.py +1 -3
  6. classiq/_internals/authentication/auth0.py +5 -5
  7. classiq/_internals/authentication/device.py +5 -4
  8. classiq/_internals/authentication/password_manager.py +3 -3
  9. classiq/_internals/authentication/token_manager.py +3 -2
  10. classiq/_internals/client.py +10 -12
  11. classiq/_internals/config.py +2 -2
  12. classiq/_internals/jobs.py +7 -6
  13. classiq/_internals/type_validation.py +9 -9
  14. classiq/analyzer/__init__.py +1 -3
  15. classiq/analyzer/analyzer.py +8 -7
  16. classiq/analyzer/analyzer_utilities.py +8 -8
  17. classiq/analyzer/rb.py +11 -11
  18. classiq/applications/__init__.py +1 -3
  19. classiq/applications/chemistry/__init__.py +1 -3
  20. classiq/applications/chemistry/ansatz_parameters.py +4 -4
  21. classiq/applications/chemistry/chemistry_model_constructor.py +10 -9
  22. classiq/applications/combinatorial_helpers/combinatorial_problem_utils.py +26 -9
  23. classiq/applications/combinatorial_helpers/encoding_mapping.py +10 -10
  24. classiq/applications/combinatorial_helpers/encoding_utils.py +4 -4
  25. classiq/applications/combinatorial_helpers/memory.py +5 -7
  26. classiq/applications/combinatorial_helpers/optimization_model.py +43 -24
  27. classiq/applications/combinatorial_helpers/pauli_helpers/pauli_utils.py +4 -6
  28. classiq/applications/combinatorial_helpers/pyomo_utils.py +95 -24
  29. classiq/applications/combinatorial_helpers/sympy_utils.py +2 -2
  30. classiq/applications/combinatorial_helpers/transformations/encoding.py +8 -8
  31. classiq/applications/combinatorial_helpers/transformations/fixed_variables.py +5 -5
  32. classiq/applications/combinatorial_helpers/transformations/ising_converter.py +7 -9
  33. classiq/applications/combinatorial_helpers/transformations/penalty.py +1 -2
  34. classiq/applications/combinatorial_helpers/transformations/sign_seperation.py +1 -2
  35. classiq/applications/combinatorial_helpers/transformations/slack_variables.py +1 -2
  36. classiq/applications/combinatorial_optimization/__init__.py +1 -3
  37. classiq/applications/combinatorial_optimization/combinatorial_optimization_config.py +2 -2
  38. classiq/applications/combinatorial_optimization/examples/__init__.py +1 -3
  39. classiq/applications/finance/__init__.py +1 -3
  40. classiq/applications/grover/__init__.py +1 -3
  41. classiq/applications/grover/grover_model_constructor.py +7 -9
  42. classiq/applications/hamiltonian/pauli_decomposition.py +6 -6
  43. classiq/applications/qnn/__init__.py +1 -3
  44. classiq/applications/qnn/circuit_utils.py +5 -5
  45. classiq/applications/qnn/datasets/__init__.py +1 -3
  46. classiq/applications/qnn/datasets/dataset_base_classes.py +5 -4
  47. classiq/applications/qnn/datasets/dataset_parity.py +2 -2
  48. classiq/applications/qnn/gradients/simple_quantum_gradient.py +2 -1
  49. classiq/applications/qnn/qlayer.py +3 -3
  50. classiq/applications/qnn/torch_utils.py +2 -2
  51. classiq/applications/qnn/types.py +5 -5
  52. classiq/applications/qsvm/qsvm.py +1 -3
  53. classiq/applications/qsvm/qsvm_data_generation.py +3 -3
  54. classiq/applications/qsvm/qsvm_model_constructor.py +5 -5
  55. classiq/execution/__init__.py +1 -3
  56. classiq/execution/all_hardware_devices.py +1 -3
  57. classiq/execution/execution_session.py +16 -16
  58. classiq/execution/jobs.py +4 -4
  59. classiq/execution/qaoa.py +3 -3
  60. classiq/execution/qnn.py +3 -3
  61. classiq/executor.py +3 -3
  62. classiq/interface/_version.py +1 -1
  63. classiq/interface/analyzer/analysis_params.py +9 -10
  64. classiq/interface/analyzer/cytoscape_graph.py +5 -5
  65. classiq/interface/analyzer/result.py +17 -17
  66. classiq/interface/applications/qsvm.py +6 -10
  67. classiq/interface/backend/backend_preferences.py +4 -3
  68. classiq/interface/backend/ionq/ionq_quantum_program.py +4 -5
  69. classiq/interface/backend/pydantic_backend.py +1 -2
  70. classiq/interface/chemistry/fermionic_operator.py +5 -5
  71. classiq/interface/chemistry/ground_state_problem.py +7 -8
  72. classiq/interface/chemistry/molecule.py +4 -4
  73. classiq/interface/chemistry/operator.py +11 -13
  74. classiq/interface/combinatorial_optimization/examples/ascending_sequence.py +1 -3
  75. classiq/interface/combinatorial_optimization/examples/integer_portfolio_optimization.py +2 -4
  76. classiq/interface/combinatorial_optimization/examples/knapsack.py +3 -3
  77. classiq/interface/combinatorial_optimization/examples/mht.py +2 -3
  78. classiq/interface/combinatorial_optimization/examples/portfolio_variations.py +2 -2
  79. classiq/interface/combinatorial_optimization/examples/set_cover.py +1 -2
  80. classiq/interface/combinatorial_optimization/mht_qaoa_input.py +5 -7
  81. classiq/interface/combinatorial_optimization/optimization_problem.py +2 -2
  82. classiq/interface/combinatorial_optimization/result.py +1 -3
  83. classiq/interface/debug_info/debug_info.py +8 -7
  84. classiq/interface/exceptions.py +8 -6
  85. classiq/interface/execution/jobs.py +2 -2
  86. classiq/interface/execution/primitives.py +3 -3
  87. classiq/interface/executor/aws_execution_cost.py +4 -4
  88. classiq/interface/executor/execution_request.py +2 -3
  89. classiq/interface/executor/execution_result.py +3 -3
  90. classiq/interface/executor/iqae_result.py +3 -5
  91. classiq/interface/executor/optimizer_preferences.py +2 -2
  92. classiq/interface/executor/quantum_code.py +6 -6
  93. classiq/interface/executor/register_initialization.py +2 -4
  94. classiq/interface/executor/result.py +23 -27
  95. classiq/interface/executor/vqe_result.py +8 -8
  96. classiq/interface/finance/function_input.py +2 -2
  97. classiq/interface/finance/gaussian_model_input.py +5 -5
  98. classiq/interface/finance/log_normal_model_input.py +2 -2
  99. classiq/interface/finance/model_input.py +1 -2
  100. classiq/interface/generator/adjacency.py +1 -3
  101. classiq/interface/generator/ansatz_library.py +4 -4
  102. classiq/interface/generator/application_apis/finance_declarations.py +1 -1
  103. classiq/interface/generator/arith/argument_utils.py +3 -3
  104. classiq/interface/generator/arith/arithmetic.py +7 -7
  105. classiq/interface/generator/arith/arithmetic_arg_type_validator.py +5 -5
  106. classiq/interface/generator/arith/arithmetic_expression_abc.py +11 -11
  107. classiq/interface/generator/arith/arithmetic_expression_parser.py +8 -7
  108. classiq/interface/generator/arith/arithmetic_expression_validator.py +8 -8
  109. classiq/interface/generator/arith/arithmetic_operations.py +4 -3
  110. classiq/interface/generator/arith/arithmetic_param_getters.py +6 -6
  111. classiq/interface/generator/arith/arithmetic_result_builder.py +9 -9
  112. classiq/interface/generator/arith/ast_node_rewrite.py +2 -1
  113. classiq/interface/generator/arith/binary_ops.py +10 -13
  114. classiq/interface/generator/arith/extremum_operations.py +3 -2
  115. classiq/interface/generator/arith/logical_ops.py +7 -6
  116. classiq/interface/generator/arith/number_utils.py +4 -4
  117. classiq/interface/generator/arith/register_user_input.py +4 -4
  118. classiq/interface/generator/arith/unary_ops.py +2 -1
  119. classiq/interface/generator/builtin_api_builder.py +2 -1
  120. classiq/interface/generator/circuit_code/circuit_code.py +4 -4
  121. classiq/interface/generator/circuit_code/types_and_constants.py +3 -5
  122. classiq/interface/generator/complex_type.py +1 -2
  123. classiq/interface/generator/control_state.py +2 -2
  124. classiq/interface/generator/custom_ansatz.py +1 -3
  125. classiq/interface/generator/distance.py +3 -5
  126. classiq/interface/generator/excitations.py +3 -2
  127. classiq/interface/generator/expressions/enums/finance_functions.py +1 -3
  128. classiq/interface/generator/expressions/evaluated_expression.py +4 -3
  129. classiq/interface/generator/expressions/expression.py +4 -5
  130. classiq/interface/generator/expressions/expression_constants.py +4 -4
  131. classiq/interface/generator/expressions/qmod_qarray_proxy.py +2 -1
  132. classiq/interface/generator/expressions/qmod_qscalar_proxy.py +2 -1
  133. classiq/interface/generator/expressions/qmod_qstruct_proxy.py +2 -1
  134. classiq/interface/generator/expressions/qmod_sized_proxy.py +2 -1
  135. classiq/interface/generator/expressions/qmod_struct_instance.py +2 -1
  136. classiq/interface/generator/expressions/sympy_supported_expressions.py +11 -13
  137. classiq/interface/generator/finance.py +2 -2
  138. classiq/interface/generator/function_param_library.py +6 -6
  139. classiq/interface/generator/function_params.py +13 -19
  140. classiq/interface/generator/functions/classical_function_declaration.py +4 -3
  141. classiq/interface/generator/functions/classical_type.py +13 -13
  142. classiq/interface/generator/functions/concrete_types.py +1 -2
  143. classiq/interface/generator/functions/function_declaration.py +1 -1
  144. classiq/interface/generator/functions/qmod_python_interface.py +2 -1
  145. classiq/interface/generator/functions/type_name.py +3 -2
  146. classiq/interface/generator/generated_circuit_data.py +34 -22
  147. classiq/interface/generator/grover_diffuser.py +7 -7
  148. classiq/interface/generator/grover_operator.py +2 -2
  149. classiq/interface/generator/hardware/hardware_data.py +7 -6
  150. classiq/interface/generator/hardware_efficient_ansatz.py +8 -8
  151. classiq/interface/generator/identity.py +5 -6
  152. classiq/interface/generator/linear_pauli_rotations.py +6 -6
  153. classiq/interface/generator/mcu.py +2 -2
  154. classiq/interface/generator/mcx.py +6 -6
  155. classiq/interface/generator/model/__init__.py +1 -3
  156. classiq/interface/generator/model/constraints.py +2 -2
  157. classiq/interface/generator/model/model.py +5 -6
  158. classiq/interface/generator/model/preferences/preferences.py +7 -6
  159. classiq/interface/generator/model/quantum_register.py +6 -11
  160. classiq/interface/generator/oracles/arithmetic_oracle.py +1 -2
  161. classiq/interface/generator/oracles/custom_oracle.py +2 -2
  162. classiq/interface/generator/oracles/oracle_abc.py +6 -5
  163. classiq/interface/generator/partitioned_register.py +6 -5
  164. classiq/interface/generator/piecewise_linear_amplitude_loading.py +8 -7
  165. classiq/interface/generator/qpe.py +4 -4
  166. classiq/interface/generator/qsvm.py +3 -3
  167. classiq/interface/generator/quantum_function_call.py +24 -29
  168. classiq/interface/generator/quantum_program.py +9 -9
  169. classiq/interface/generator/register_role.py +2 -4
  170. classiq/interface/generator/slice_parsing_utils.py +4 -3
  171. classiq/interface/generator/standard_gates/standard_gates.py +3 -3
  172. classiq/interface/generator/state_preparation/bell_state_preparation.py +3 -3
  173. classiq/interface/generator/state_preparation/distributions.py +6 -5
  174. classiq/interface/generator/state_preparation/metrics.py +2 -4
  175. classiq/interface/generator/state_preparation/state_preparation.py +4 -4
  176. classiq/interface/generator/synthesis_metadata/synthesis_execution_data.py +3 -3
  177. classiq/interface/generator/transpiler_basis_gates.py +2 -2
  178. classiq/interface/generator/types/enum_declaration.py +2 -3
  179. classiq/interface/generator/types/qstruct_declaration.py +2 -1
  180. classiq/interface/generator/types/struct_declaration.py +3 -2
  181. classiq/interface/generator/ucc.py +2 -1
  182. classiq/interface/generator/unitary_gate.py +2 -2
  183. classiq/interface/generator/user_defined_function_params.py +1 -1
  184. classiq/interface/generator/validations/flow_graph.py +6 -5
  185. classiq/interface/generator/validations/validator_functions.py +3 -2
  186. classiq/interface/generator/visitor.py +9 -14
  187. classiq/interface/hardware.py +5 -6
  188. classiq/interface/helpers/custom_encoders.py +2 -2
  189. classiq/interface/helpers/custom_pydantic_types.py +8 -9
  190. classiq/interface/helpers/hashable_mixin.py +3 -2
  191. classiq/interface/helpers/hashable_pydantic_base_model.py +2 -1
  192. classiq/interface/helpers/pydantic_model_helpers.py +4 -3
  193. classiq/interface/helpers/validation_helpers.py +2 -2
  194. classiq/interface/ide/ide_data.py +11 -15
  195. classiq/interface/ide/visual_model.py +20 -22
  196. classiq/interface/jobs.py +2 -2
  197. classiq/interface/model/bind_operation.py +5 -4
  198. classiq/interface/model/classical_parameter_declaration.py +2 -2
  199. classiq/interface/model/handle_binding.py +3 -2
  200. classiq/interface/model/inplace_binary_operation.py +2 -1
  201. classiq/interface/model/model.py +12 -11
  202. classiq/interface/model/port_declaration.py +2 -2
  203. classiq/interface/model/quantum_expressions/amplitude_loading_operation.py +3 -2
  204. classiq/interface/model/quantum_expressions/arithmetic_operation.py +3 -2
  205. classiq/interface/model/quantum_expressions/quantum_expression.py +8 -7
  206. classiq/interface/model/quantum_function_call.py +9 -14
  207. classiq/interface/model/quantum_function_declaration.py +10 -12
  208. classiq/interface/model/quantum_lambda_function.py +3 -16
  209. classiq/interface/model/quantum_statement.py +4 -3
  210. classiq/interface/model/quantum_type.py +5 -5
  211. classiq/interface/model/statement_block.py +2 -3
  212. classiq/interface/model/validation_handle.py +5 -4
  213. classiq/interface/server/global_versions.py +3 -3
  214. classiq/model_expansions/atomic_expression_functions_defs.py +3 -2
  215. classiq/model_expansions/call_to_model_converter.py +190 -0
  216. classiq/model_expansions/capturing/captured_var_manager.py +4 -6
  217. classiq/model_expansions/capturing/propagated_var_stack.py +7 -7
  218. classiq/model_expansions/closure.py +17 -9
  219. classiq/model_expansions/evaluators/arg_type_match.py +3 -2
  220. classiq/model_expansions/evaluators/argument_types.py +3 -3
  221. classiq/model_expansions/evaluators/control.py +3 -3
  222. classiq/model_expansions/evaluators/parameter_types.py +7 -7
  223. classiq/model_expansions/evaluators/quantum_type_utils.py +2 -1
  224. classiq/model_expansions/evaluators/type_type_match.py +1 -1
  225. classiq/model_expansions/expression_evaluator.py +10 -9
  226. classiq/model_expansions/expression_renamer.py +6 -6
  227. classiq/model_expansions/function_builder.py +19 -12
  228. classiq/model_expansions/generative_functions.py +3 -2
  229. classiq/model_expansions/interpreter.py +31 -19
  230. classiq/model_expansions/model_tables.py +14 -14
  231. classiq/model_expansions/quantum_operations/bind.py +2 -4
  232. classiq/model_expansions/quantum_operations/classicalif.py +1 -1
  233. classiq/model_expansions/quantum_operations/control.py +2 -4
  234. classiq/model_expansions/quantum_operations/emitter.py +10 -13
  235. classiq/model_expansions/quantum_operations/expression_operation.py +23 -16
  236. classiq/model_expansions/quantum_operations/inplace_binary_operation.py +160 -35
  237. classiq/model_expansions/quantum_operations/phase.py +6 -6
  238. classiq/model_expansions/quantum_operations/quantum_assignment_operation.py +25 -5
  239. classiq/model_expansions/quantum_operations/quantum_function_call.py +41 -2
  240. classiq/model_expansions/quantum_operations/repeat.py +1 -3
  241. classiq/model_expansions/scope.py +11 -10
  242. classiq/model_expansions/scope_initialization.py +6 -5
  243. classiq/model_expansions/sympy_conversion/expression_to_sympy.py +6 -6
  244. classiq/model_expansions/sympy_conversion/sympy_to_python.py +2 -2
  245. classiq/model_expansions/visitors/variable_references.py +5 -4
  246. classiq/qmod/builtins/classical_execution_primitives.py +9 -9
  247. classiq/qmod/builtins/functions/__init__.py +72 -55
  248. classiq/qmod/builtins/functions/amplitude_estimation.py +4 -1
  249. classiq/qmod/builtins/functions/arithmetic.py +14 -1
  250. classiq/qmod/builtins/functions/discrete_sine_cosine_transform.py +86 -6
  251. classiq/qmod/builtins/functions/grover.py +41 -45
  252. classiq/qmod/builtins/functions/hea.py +60 -4
  253. classiq/qmod/builtins/functions/linear_pauli_rotation.py +26 -4
  254. classiq/qmod/builtins/functions/modular_exponentiation.py +90 -29
  255. classiq/qmod/builtins/functions/operators.py +1 -1
  256. classiq/qmod/builtins/functions/qaoa_penalty.py +14 -5
  257. classiq/qmod/builtins/functions/qft_functions.py +57 -0
  258. classiq/qmod/builtins/functions/qpe.py +20 -4
  259. classiq/qmod/builtins/functions/qsvt.py +49 -4
  260. classiq/qmod/builtins/functions/standard_gates.py +4 -4
  261. classiq/qmod/builtins/functions/state_preparation.py +92 -10
  262. classiq/qmod/builtins/functions/swap_test.py +7 -1
  263. classiq/qmod/builtins/functions/utility_functions.py +43 -0
  264. classiq/qmod/builtins/functions/variational.py +18 -2
  265. classiq/qmod/builtins/operations.py +4 -5
  266. classiq/qmod/cfunc.py +2 -2
  267. classiq/qmod/classical_function.py +3 -7
  268. classiq/qmod/create_model_function.py +7 -6
  269. classiq/qmod/declaration_inferrer.py +7 -10
  270. classiq/qmod/expression_query.py +3 -3
  271. classiq/qmod/generative.py +2 -1
  272. classiq/qmod/model_state_container.py +5 -7
  273. classiq/qmod/native/__init__.py +1 -3
  274. classiq/qmod/native/expression_to_qmod.py +9 -8
  275. classiq/qmod/native/pretty_printer.py +6 -5
  276. classiq/qmod/pretty_print/__init__.py +1 -3
  277. classiq/qmod/pretty_print/expression_to_python.py +13 -12
  278. classiq/qmod/pretty_print/pretty_printer.py +13 -12
  279. classiq/qmod/python_classical_type.py +8 -4
  280. classiq/qmod/qfunc.py +4 -4
  281. classiq/qmod/qmod_variable.py +11 -10
  282. classiq/qmod/quantum_expandable.py +12 -15
  283. classiq/qmod/quantum_function.py +10 -3
  284. classiq/qmod/semantics/annotation.py +1 -1
  285. classiq/qmod/semantics/error_manager.py +8 -7
  286. classiq/qmod/semantics/static_semantics_visitor.py +19 -24
  287. classiq/qmod/semantics/validation/constants_validation.py +1 -1
  288. classiq/qmod/semantics/validation/func_call_validation.py +2 -2
  289. classiq/qmod/semantics/validation/main_validation.py +33 -0
  290. classiq/qmod/semantics/validation/types_validation.py +2 -1
  291. classiq/qmod/symbolic.py +5 -8
  292. classiq/qmod/symbolic_type.py +2 -2
  293. {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/METADATA +1 -1
  294. {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/RECORD +295 -292
  295. classiq/qmod/builtins/functions/qft.py +0 -23
  296. {classiq-0.53.0.dist-info → classiq-0.54.0.dist-info}/WHEEL +0 -0
@@ -1,30 +1,26 @@
1
+ from classiq.qmod.builtins.classical_functions import qft_const_adder_phase
2
+ from classiq.qmod.builtins.functions.qft_functions import qft, qft_no_swap
3
+ from classiq.qmod.builtins.functions.standard_gates import PHASE, SWAP, X
4
+ from classiq.qmod.builtins.functions.state_preparation import allocate
5
+ from classiq.qmod.builtins.operations import bind, control, invert, repeat, within_apply
6
+ from classiq.qmod.cparam import CInt
1
7
  from classiq.qmod.qfunc import qfunc
2
- from classiq.qmod.qmod_parameter import CInt
3
8
  from classiq.qmod.qmod_variable import QArray, QBit, QNum
4
-
5
-
6
- @qfunc(external=True)
7
- def qft_no_swap(qbv: QArray[QBit]) -> None:
8
- """
9
- [Qmod Classiq-library function]
10
-
11
- Applies the Quantum Fourier Transform (QFT) without the swap gates.
12
-
13
- Args:
14
- qbv: The quantum number to which the QFT is applied.
15
-
16
- """
17
- pass
9
+ from classiq.qmod.symbolic import min, mod_inverse
18
10
 
19
11
 
20
12
  @qfunc(external=True)
21
13
  def _check_msb(ref: CInt, x: QArray[QBit], aux: QBit) -> None:
22
- pass
14
+ within_apply(
15
+ lambda: invert(lambda: qft_no_swap(x)), lambda: _ctrl_x(ref, x[0], aux)
16
+ )
23
17
 
24
18
 
25
19
  @qfunc(external=True)
26
- def _ctrl_x(ref: CInt, ctrl: QNum, aux: QBit) -> None:
27
- pass
20
+ def _ctrl_x(
21
+ ref: CInt, ctrl: QNum, aux: QBit
22
+ ) -> None: # TODO: remove qfunc when expressions of QBit is supported
23
+ control(ctrl == ref, lambda: X(aux))
28
24
 
29
25
 
30
26
  @qfunc(external=True)
@@ -43,7 +39,15 @@ def qft_space_add_const(value: CInt, phi_b: QArray[QBit]) -> None:
43
39
  phi_b: The quantum number (at the aft space) to which the constant is added.
44
40
 
45
41
  """
46
- pass
42
+ repeat(
43
+ count=phi_b.len,
44
+ iteration=lambda index: PHASE(
45
+ theta=qft_const_adder_phase(
46
+ index, value, phi_b.len # type:ignore[arg-type]
47
+ ),
48
+ target=phi_b[index],
49
+ ),
50
+ )
47
51
 
48
52
 
49
53
  @qfunc(external=True)
@@ -62,7 +66,33 @@ def cc_modular_add(n: CInt, a: CInt, phi_b: QArray[QBit], c1: QBit, c2: QBit) ->
62
66
  c2: a control qubit.
63
67
 
64
68
  """
65
- pass
69
+ ctrl: QArray[QBit] = QArray("ctrl")
70
+ aux = QBit("aux")
71
+
72
+ within_apply(
73
+ lambda: ( # type:ignore[arg-type]
74
+ allocate(1, aux),
75
+ bind([c1, c2], ctrl), # type:ignore[func-returns-value]
76
+ ),
77
+ lambda: ( # type:ignore[arg-type]
78
+ control( # type:ignore[func-returns-value]
79
+ ctrl, lambda: qft_space_add_const(a, phi_b)
80
+ ),
81
+ invert( # type:ignore[func-returns-value]
82
+ lambda: qft_space_add_const(n, phi_b)
83
+ ),
84
+ _check_msb(1, phi_b, aux),
85
+ control( # type:ignore[func-returns-value]
86
+ aux, lambda: qft_space_add_const(n, phi_b)
87
+ ),
88
+ within_apply(
89
+ lambda: invert( # type:ignore[func-returns-value]
90
+ lambda: control(ctrl, lambda: qft_space_add_const(a, phi_b))
91
+ ),
92
+ lambda: _check_msb(0, phi_b, aux),
93
+ ),
94
+ ),
95
+ )
66
96
 
67
97
 
68
98
  @qfunc(external=True)
@@ -82,7 +112,15 @@ def c_modular_multiply(
82
112
  x: The quantum factor.
83
113
  ctrl: The control bit.
84
114
  """
85
- pass
115
+ within_apply(
116
+ lambda: qft(b),
117
+ lambda: repeat(
118
+ count=x.len,
119
+ iteration=lambda index: cc_modular_add(
120
+ n, (a * (2**index)) % n, b, x[index], ctrl
121
+ ),
122
+ ),
123
+ )
86
124
 
87
125
 
88
126
  @qfunc(external=True)
@@ -98,7 +136,10 @@ def multiswap(x: QArray[QBit], y: QArray[QBit]) -> None:
98
136
  y: The second array
99
137
 
100
138
  """
101
- pass
139
+ repeat(
140
+ count=min(x.len, y.len),
141
+ iteration=lambda index: SWAP(x[index], y[index]),
142
+ )
102
143
 
103
144
 
104
145
  @qfunc(external=True)
@@ -115,7 +156,20 @@ def inplace_c_modular_multiply(n: CInt, a: CInt, x: QArray[QBit], ctrl: QBit) ->
115
156
  x: The quantum factor.
116
157
  ctrl: The control bit.
117
158
  """
118
- pass
159
+ b: QArray[QBit] = QArray("b")
160
+
161
+ within_apply(
162
+ lambda: allocate(x.len + 1, b),
163
+ lambda: ( # type:ignore[arg-type]
164
+ c_modular_multiply(n, a, b, x, ctrl),
165
+ control( # type:ignore[func-returns-value]
166
+ ctrl, lambda: multiswap(x, b)
167
+ ),
168
+ invert( # type:ignore[func-returns-value]
169
+ lambda: c_modular_multiply(n, mod_inverse(a, n), b, x, ctrl)
170
+ ),
171
+ ),
172
+ )
119
173
 
120
174
 
121
175
  @qfunc(external=True)
@@ -123,15 +177,22 @@ def modular_exp(n: CInt, a: CInt, x: QArray[QBit], power: QArray[QBit]) -> None:
123
177
  """
124
178
  [Qmod Classiq-library function]
125
179
 
126
- Raises a classical integer `a` to the power of a quantum number `x` modulo classical integer `n`
127
- times a quantum number `power`. Performs $power=(a^x \\mod n)*power$ in-place.
128
- (and specifically if at the input $power=1$, at the output $power=a^x \\mod n$).
180
+ Raises a classical integer `a` to the power of a quantum number `power` modulo classical integer `n`
181
+ times a quantum number `x`. Performs $x=(a^{power} \\mod n)*x$ in-place.
182
+ (and specifically if at the input $x=1$, at the output $x=a^{power} \\mod n$).
129
183
 
130
184
  Args:
131
185
  n: The modulus number. Should be non-negative.
132
186
  a: The base of the exponentiation. Should be non-negative.
133
- x: The power of the exponentiation.
134
- power: A quantum number which multiplies the modular exponentiation and holds the output.
187
+ x: A quantum number that multiplies the modular exponentiation and holds the output. It should be at least the size of $\\lceil \\log(n) \rceil$.
188
+ power: The power of the exponentiation.
135
189
 
190
+ Usage Example:
191
+ [Modular Exponentiation](https://docs.classiq.io/latest/explore/functions/function_usage_examples/arithmetic/modular_exp/modular_exp_example)
136
192
  """
137
- pass
193
+ repeat(
194
+ count=power.len,
195
+ iteration=lambda index: inplace_c_modular_multiply(
196
+ n, (a ** (2**index)) % n, x, power[index]
197
+ ),
198
+ )
@@ -19,4 +19,4 @@ def apply(
19
19
 
20
20
  @qfunc(external=True)
21
21
  def switch(selector: CInt, cases: QCallableList) -> None:
22
- pass
22
+ cases[selector]()
@@ -1,5 +1,7 @@
1
1
  from typing import Literal
2
2
 
3
+ from classiq.qmod.builtins.functions import RX, H, suzuki_trotter
4
+ from classiq.qmod.builtins.operations import repeat
3
5
  from classiq.qmod.builtins.structs import PauliTerm
4
6
  from classiq.qmod.qfunc import qfunc
5
7
  from classiq.qmod.qmod_parameter import CArray, CInt, CReal
@@ -22,7 +24,7 @@ def qaoa_mixer_layer(b: CReal, target: QArray[QBit]) -> None:
22
24
  b: The rotation parameter for the mixer layer.
23
25
  target: The target quantum array.
24
26
  """
25
- pass
27
+ repeat(target.len, lambda index: RX(b, target[index]))
26
28
 
27
29
 
28
30
  @qfunc(external=True)
@@ -44,7 +46,7 @@ def qaoa_cost_layer(
44
46
  hamiltonian: The Hamiltonian terms for the QAOA model.
45
47
  target: The target quantum array variable.
46
48
  """
47
- pass
49
+ suzuki_trotter(hamiltonian, g, 1, 1, target)
48
50
 
49
51
 
50
52
  @qfunc(external=True)
@@ -68,7 +70,8 @@ def qaoa_layer(
68
70
  target: The target quantum array variable.
69
71
 
70
72
  """
71
- pass
73
+ qaoa_cost_layer(g, hamiltonian, target)
74
+ qaoa_mixer_layer(b, target)
72
75
 
73
76
 
74
77
  @qfunc(external=True)
@@ -85,7 +88,7 @@ def qaoa_init(target: QArray[QBit]) -> None:
85
88
  Args:
86
89
  target: The target quantum array variable.
87
90
  """
88
- pass
91
+ repeat(target.len, lambda index: H(target[index]))
89
92
 
90
93
 
91
94
  @qfunc(external=True)
@@ -113,4 +116,10 @@ def qaoa_penalty(
113
116
  hamiltonian: The Hamiltonian terms for the QAOA model.
114
117
  target: The target quantum array variable.
115
118
  """
116
- pass
119
+ qaoa_init(target)
120
+ repeat(
121
+ params_list.len / 2, # type:ignore[arg-type]
122
+ lambda index: qaoa_layer(
123
+ params_list[2 * index], params_list[(2 * index) + 1], hamiltonian, target
124
+ ),
125
+ )
@@ -0,0 +1,57 @@
1
+ from classiq.qmod.builtins.functions.standard_gates import CPHASE, SWAP, H
2
+ from classiq.qmod.builtins.operations import repeat
3
+ from classiq.qmod.qfunc import qfunc
4
+ from classiq.qmod.qmod_variable import QArray, QBit
5
+ from classiq.qmod.symbolic import pi
6
+
7
+
8
+ @qfunc(external=True)
9
+ def qft_no_swap(qbv: QArray[QBit]) -> None:
10
+ """
11
+ [Qmod Classiq-library function]
12
+
13
+ Applies the Quantum Fourier Transform (QFT) without the swap gates.
14
+
15
+ Args:
16
+ qbv: The quantum number to which the QFT is applied.
17
+
18
+ """
19
+ repeat(
20
+ qbv.len,
21
+ lambda i: ( # type:ignore[arg-type]
22
+ H(qbv[i]),
23
+ repeat( # type:ignore[func-returns-value]
24
+ qbv.len - i - 1,
25
+ lambda j: CPHASE(
26
+ theta=pi / (2 ** (j + 1)),
27
+ ctrl=qbv[i + j + 1],
28
+ target=qbv[i],
29
+ ),
30
+ ),
31
+ ),
32
+ )
33
+
34
+
35
+ @qfunc(external=True)
36
+ def qft(target: QArray[QBit]) -> None:
37
+ """
38
+ [Qmod Classiq-library function]
39
+
40
+ Performs the Quantum Fourier Transform (QFT) on `target` in-place.
41
+ Implements the following transformation:
42
+
43
+ $$
44
+ y_{k} = \\frac{1}{\\sqrt{N}} \\sum_{j=0}^{N-1} x_j e^{2\\pi i \\frac{jk}{N}}
45
+ $$
46
+
47
+ Args:
48
+ target: The quantum object to be transformed
49
+
50
+ Further reading in Classiq Library:
51
+ Link: [qft library reference](https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/qft/qft.ipynb)
52
+ """
53
+ repeat(
54
+ target.len / 2, # type:ignore[arg-type]
55
+ lambda index: SWAP(target[index], target[(target.len - 1) - index]),
56
+ )
57
+ qft_no_swap(target)
@@ -1,6 +1,10 @@
1
+ from classiq.qmod.builtins.functions.qft_functions import qft
2
+ from classiq.qmod.builtins.functions.standard_gates import H
3
+ from classiq.qmod.builtins.functions.utility_functions import apply_to_all
4
+ from classiq.qmod.builtins.operations import bind, control, invert, power, repeat
5
+ from classiq.qmod.cparam import CInt
1
6
  from classiq.qmod.qfunc import qfunc
2
- from classiq.qmod.qmod_parameter import CInt
3
- from classiq.qmod.qmod_variable import QNum
7
+ from classiq.qmod.qmod_variable import QArray, QNum
4
8
  from classiq.qmod.quantum_callable import QCallable
5
9
 
6
10
 
@@ -19,7 +23,19 @@ def qpe_flexible(unitary_with_power: QCallable[CInt], phase: QNum) -> None:
19
23
  Further reading in Classiq Library:
20
24
  Link: [qpe library reference](https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb)
21
25
  """
22
- pass
26
+ phase_array: QArray = QArray("phase_array")
27
+ bind(phase, phase_array)
28
+ apply_to_all(H, phase_array)
29
+
30
+ repeat(
31
+ count=phase_array.len,
32
+ iteration=lambda index: control(
33
+ ctrl=phase_array[index], stmt_block=lambda: unitary_with_power(2**index)
34
+ ),
35
+ )
36
+
37
+ invert(lambda: qft(phase_array))
38
+ bind(phase_array, phase)
23
39
 
24
40
 
25
41
  @qfunc(external=True)
@@ -36,4 +52,4 @@ def qpe(unitary: QCallable, phase: QNum) -> None:
36
52
  Further reading in Classiq Library:
37
53
  Link: [qpe library reference](https://github.com/Classiq/classiq-library/blob/main/functions/qmod_library_reference/classiq_open_library/qpe/qpe.ipynb)
38
54
  """
39
- pass
55
+ qpe_flexible(unitary_with_power=lambda k: power(k, unitary), phase=phase)
@@ -1,7 +1,10 @@
1
+ from classiq.qmod.builtins.functions.standard_gates import IDENTITY, RZ, H
2
+ from classiq.qmod.builtins.operations import if_, invert, repeat
1
3
  from classiq.qmod.qfunc import qfunc
2
4
  from classiq.qmod.qmod_parameter import CArray, CReal
3
5
  from classiq.qmod.qmod_variable import QArray, QBit
4
6
  from classiq.qmod.quantum_callable import QCallable
7
+ from classiq.qmod.symbolic import floor
5
8
 
6
9
 
7
10
  @qfunc(external=True)
@@ -35,7 +38,10 @@ def qsvt_step(
35
38
  Further reading in Classiq Library:
36
39
  [QSVT function usage example](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt/)
37
40
  """
38
- pass
41
+ u(qvar)
42
+ projector_controlled_phase(phase1, proj_cnot_2, qvar, aux)
43
+ invert(lambda: u(qvar))
44
+ projector_controlled_phase(phase2, proj_cnot_1, qvar, aux)
39
45
 
40
46
 
41
47
  @qfunc(external=True)
@@ -78,7 +84,37 @@ def qsvt(
78
84
  Further reading in Classiq Library:
79
85
  [QSVT function usage example](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt/)
80
86
  """
81
- pass
87
+ H(aux)
88
+
89
+ projector_controlled_phase(phase_seq[0], proj_cnot_1, qvar, aux)
90
+ repeat(
91
+ count=floor((phase_seq.len - 1) / 2),
92
+ iteration=lambda index: qsvt_step(
93
+ phase_seq[2 * index + 1],
94
+ phase_seq[2 * index + 2],
95
+ proj_cnot_1,
96
+ proj_cnot_2,
97
+ u,
98
+ qvar,
99
+ aux,
100
+ ),
101
+ )
102
+
103
+ if_(
104
+ condition=phase_seq.len % 2 == 1,
105
+ then=lambda: IDENTITY(qvar),
106
+ else_=lambda: ( # type:ignore[arg-type]
107
+ u(qvar), # type:ignore[func-returns-value]
108
+ projector_controlled_phase(
109
+ phase_seq[phase_seq.len - 1],
110
+ proj_cnot_2,
111
+ qvar,
112
+ aux,
113
+ ),
114
+ ),
115
+ )
116
+
117
+ H(aux)
82
118
 
83
119
 
84
120
  @qfunc(external=True)
@@ -106,7 +142,9 @@ def projector_controlled_phase(
106
142
  Further reading in Classiq Library:
107
143
  [QSVT function usage example](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/qsvt/qsvt/)
108
144
  """
109
- pass
145
+ proj_cnot(qvar, aux)
146
+ RZ(phase, aux)
147
+ proj_cnot(qvar, aux)
110
148
 
111
149
 
112
150
  @qfunc(external=True)
@@ -133,4 +171,11 @@ def qsvt_inversion(
133
171
  For usage example, see:
134
172
  [QSVT matrix inversion example](https://docs.classiq.io/latest/explore/algorithms/qsvt/qsvt_matrix_inversion/qsvt_matrix_inversion)
135
173
  """
136
- pass
174
+ qsvt(
175
+ phase_seq,
176
+ block_encoding_cnot,
177
+ block_encoding_cnot,
178
+ lambda x: invert(lambda: u(x)),
179
+ qvar,
180
+ aux,
181
+ )
@@ -560,7 +560,7 @@ def CRY(theta: CReal, ctrl: QBit, target: QBit) -> None:
560
560
 
561
561
  Args:
562
562
  theta (CReal): The rotation angle in radians.
563
- control (QBit): The control qubit.
563
+ ctrl (QBit): The control qubit.
564
564
  target (QBit): The qubit to apply the RY gate on.
565
565
 
566
566
  Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
@@ -588,7 +588,7 @@ def CRZ(theta: CReal, ctrl: QBit, target: QBit) -> None:
588
588
 
589
589
  Args:
590
590
  theta (CReal): The rotation angle in radians.
591
- control (QBit): The control qubit.
591
+ ctrl (QBit): The control qubit.
592
592
  target (QBit): The qubit to apply the RZ gate on.
593
593
 
594
594
  Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
@@ -616,7 +616,7 @@ def CPHASE(theta: CReal, ctrl: QBit, target: QBit) -> None:
616
616
 
617
617
  Args:
618
618
  theta (CReal): The rotation angle in radians.
619
- control (QBit): The control qubit.
619
+ ctrl (QBit): The control qubit.
620
620
  target (QBit): The qubit to apply the PHASE gate on.
621
621
 
622
622
  Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
@@ -731,7 +731,7 @@ def CCX(ctrl: QArray[QBit, Literal[2]], target: QBit) -> None:
731
731
  More information can be found on [Wikipedia](https://en.wikipedia.org/wiki/Toffoli_gate).
732
732
 
733
733
  Args:
734
- control (QArray[QBit, Literal[2]]): The control qubits.
734
+ ctrl (QArray[QBit, Literal[2]]): The control qubits.
735
735
  target (QBit): The qubit to apply the conditioned Pauli-X gate on.
736
736
 
737
737
  Link: [Reference Manual](https://docs.classiq.io/latest/reference-manual/qmod/library-reference/core-library-functions/standard_gates/standard_gates/)
@@ -1,8 +1,24 @@
1
1
  from typing import Literal
2
2
 
3
- from classiq.qmod.cparam import CArray, CBool, CInt, CReal
3
+ from classiq.qmod.builtins.functions.arithmetic import modular_increment
4
+ from classiq.qmod.builtins.functions.standard_gates import CX, IDENTITY, RY, H, X
5
+ from classiq.qmod.builtins.functions.utility_functions import hadamard_transform
6
+ from classiq.qmod.builtins.operations import control, if_, repeat
7
+ from classiq.qmod.cparam import CBool, CInt
4
8
  from classiq.qmod.qfunc import qfunc
9
+ from classiq.qmod.qmod_parameter import CArray, CReal
5
10
  from classiq.qmod.qmod_variable import Input, Output, QArray, QBit, QNum
11
+ from classiq.qmod.symbolic import (
12
+ asin,
13
+ atan,
14
+ exp,
15
+ floor,
16
+ log,
17
+ max as qmax,
18
+ min as qmin,
19
+ pi,
20
+ sqrt,
21
+ )
6
22
 
7
23
 
8
24
  @qfunc(external=True)
@@ -53,7 +69,7 @@ def allocate_num(
53
69
  Further reading is available on the [reference manual](https://docs.classiq.io/latest/reference-manual/qmod/language-reference/quantum-types#allocate-num)
54
70
 
55
71
  """
56
- pass
72
+ allocate(num_qubits, out)
57
73
 
58
74
 
59
75
  @qfunc(external=True)
@@ -178,11 +194,31 @@ def inplace_prepare_amplitudes(
178
194
  pass
179
195
 
180
196
 
197
+ def prepare_uniform_trimmed_state_apply_rotation(
198
+ size_lsb: CInt, lsbs_val: CInt, rotation_var: QBit
199
+ ) -> None:
200
+ # max hold for the case where the value is on the left side
201
+ # the fraction in the sqrt is the wanted amount of probability
202
+ # in the left side divided by the total amount
203
+ RY(
204
+ -2 * (asin(sqrt(qmin((2 ** (size_lsb)) / lsbs_val, 1))) + pi / 4) + pi,
205
+ rotation_var,
206
+ )
207
+
208
+
181
209
  @qfunc(external=True)
182
210
  def _prepare_uniform_trimmed_state_step(
183
211
  size_lsb: CInt, ctrl_val: CInt, lsbs_val: CInt, ctrl_var: QNum, rotation_var: QBit
184
212
  ) -> None:
185
- pass
213
+ if_(
214
+ lsbs_val != 0, # stop condition
215
+ lambda: control(
216
+ ctrl_var == ctrl_val,
217
+ lambda: prepare_uniform_trimmed_state_apply_rotation(
218
+ size_lsb, lsbs_val, rotation_var
219
+ ),
220
+ ),
221
+ )
186
222
 
187
223
 
188
224
  @qfunc(external=True)
@@ -207,7 +243,28 @@ def prepare_uniform_trimmed_state(m: CInt, q: QArray[QBit]) -> None:
207
243
  1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
208
244
  2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
209
245
  """
210
- pass
246
+ hadamard_transform(q)
247
+
248
+ if_(
249
+ m < 2**q.len,
250
+ # initial step without control
251
+ lambda: prepare_uniform_trimmed_state_apply_rotation(
252
+ q.len - 1, # type:ignore[arg-type]
253
+ m,
254
+ q[q.len - 1],
255
+ ),
256
+ )
257
+
258
+ repeat(
259
+ qmax(q.len - 1, 0),
260
+ lambda i: _prepare_uniform_trimmed_state_step(
261
+ q.len - i - 2,
262
+ floor(m / (2 ** (q.len - i - 1))),
263
+ m % (2 ** (q.len - i - 1)),
264
+ q[q.len - i - 1 : q.len],
265
+ q[q.len - i - 2],
266
+ ),
267
+ )
211
268
 
212
269
 
213
270
  @qfunc(external=True)
@@ -232,7 +289,8 @@ def prepare_uniform_interval_state(start: CInt, end: CInt, q: QArray[QBit]) -> N
232
289
  1. If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
233
290
  2. The synthesis engine automatically handles the allocation, either by drawing new qubits from the available pool or by reusing existing ones.
234
291
  """
235
- pass
292
+ prepare_uniform_trimmed_state(end - start, q)
293
+ modular_increment(start, q)
236
294
 
237
295
 
238
296
  @qfunc(external=True)
@@ -251,7 +309,20 @@ def prepare_ghz_state(size: CInt, q: Output[QArray[QBit]]) -> None:
251
309
 
252
310
 
253
311
  """
254
- pass
312
+
313
+ def inner_lop(step: CInt) -> None:
314
+ repeat(
315
+ count=2**step,
316
+ iteration=lambda control_index: if_(
317
+ condition=control_index + 2**step >= size,
318
+ then=lambda: IDENTITY(q[0]),
319
+ else_=lambda: CX(q[control_index], q[control_index + 2**step]),
320
+ ),
321
+ )
322
+
323
+ allocate(size, q)
324
+ H(q[0])
325
+ repeat(floor(log(size - 1, 2)) + 1, inner_lop) # type:ignore[arg-type]
255
326
 
256
327
 
257
328
  @qfunc(external=True)
@@ -272,7 +343,7 @@ def prepare_exponential_state(rate: CInt, q: QArray[QBit]) -> None:
272
343
 
273
344
  Further reading is available on the [reference manual](https://docs.classiq.io/latest/explore/functions/qmod_library_reference/classiq_open_library/special_state_preparations/prepare_exponential_state)
274
345
  """
275
- pass
346
+ repeat(q.len, lambda i: RY(2.0 * atan(exp((-rate * 2.0**i) / 2.0)), q[i]))
276
347
 
277
348
 
278
349
  @qfunc(external=True)
@@ -318,7 +389,10 @@ def prepare_bell_state(state_num: CInt, q: Output[QArray[QBit, Literal[2]]]) ->
318
389
 
319
390
 
320
391
  """
321
- pass
392
+ allocate(2, q)
393
+ inplace_prepare_int(state_num, q)
394
+ H(q[0])
395
+ CX(q[0], q[1])
322
396
 
323
397
 
324
398
  @qfunc(external=True)
@@ -336,7 +410,14 @@ def inplace_prepare_int(value: CInt, target: QArray[QBit]) -> None:
336
410
  Note:
337
411
  If the value cannot fit into the quantum variable, it is truncated, i.e. treated as the value modulo $2^\\text{target.size}$.
338
412
  """
339
- pass
413
+ repeat(
414
+ target.len,
415
+ lambda index: if_(
416
+ (floor(value / (2**index)) % 2) == 1,
417
+ lambda: X(target[index]),
418
+ lambda: IDENTITY(target[index]),
419
+ ),
420
+ )
340
421
 
341
422
 
342
423
  @qfunc(external=True)
@@ -357,4 +438,5 @@ def prepare_int(
357
438
  Note:
358
439
  If the output variable has been declared with a specific number of qubits, it must match the number of allocated qubits.
359
440
  """
360
- pass
441
+ allocate(floor(log(value, 2)) + 1, out)
442
+ inplace_prepare_int(value, out)
@@ -1,3 +1,6 @@
1
+ from classiq.qmod.builtins.functions.standard_gates import SWAP, H
2
+ from classiq.qmod.builtins.functions.state_preparation import allocate
3
+ from classiq.qmod.builtins.operations import control, repeat
1
4
  from classiq.qmod.qfunc import qfunc
2
5
  from classiq.qmod.qmod_variable import Output, QArray, QBit
3
6
 
@@ -22,4 +25,7 @@ def swap_test(state1: QArray[QBit], state2: QArray[QBit], test: Output[QBit]) ->
22
25
  Example:
23
26
  Further reading in the Classiq library is found [here](https://docs.classiq.io/latest/explore/algorithms/swap_test/swap_test/).
24
27
  """
25
- pass
28
+ allocate(1, test)
29
+ H(test)
30
+ control(test, lambda: repeat(state1.len, lambda i: SWAP(state1[i], state2[i])))
31
+ H(test)
@@ -0,0 +1,43 @@
1
+ from typing import Annotated
2
+
3
+ from classiq.qmod.builtins.functions.standard_gates import H
4
+ from classiq.qmod.builtins.operations import repeat
5
+ from classiq.qmod.qfunc import qfunc
6
+ from classiq.qmod.qmod_variable import QArray, QBit, QCallable
7
+
8
+
9
+ @qfunc(external=True)
10
+ def apply_to_all(
11
+ gate_operand: QCallable[Annotated[QBit, "target"]], target: QArray[QBit]
12
+ ) -> None:
13
+ """
14
+ [Qmod Classiq-library function]
15
+
16
+ Applies the single-qubit operand `gate_operand` to each qubit in the qubit
17
+ array `target`.
18
+
19
+ Args:
20
+ gate_operand: The single-qubit gate to apply to each qubit in the array.
21
+ target: The qubit array to apply the gate to.
22
+ """
23
+ repeat(target.len, lambda index: gate_operand(target[index]))
24
+
25
+
26
+ @qfunc(external=True)
27
+ def hadamard_transform(target: QArray[QBit]) -> None:
28
+ """
29
+ [Qmod Classiq-library function]
30
+
31
+ Applies Hadamard transform to the target qubits.
32
+
33
+ Corresponds to the braket notation:
34
+
35
+ $$
36
+ H^{\\otimes n} |x\rangle = \frac{1}{\\sqrt{2^n}} \\sum_{y=0}^{2^n - 1} (-1)^{x \\cdot y} |y\rangle
37
+ $$
38
+
39
+ Args:
40
+ target: qubits to apply to Hadamard transform to.
41
+
42
+ """
43
+ apply_to_all(H, target)