luna-quantum 1.1.0__cp312-cp312-win_amd64.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 (276) hide show
  1. luna_quantum/__init__.py +139 -0
  2. luna_quantum/__init__.pyi +98 -0
  3. luna_quantum/_core.cp312-win_amd64.pyd +0 -0
  4. luna_quantum/_core.pyi +4286 -0
  5. luna_quantum/_utility.py +148 -0
  6. luna_quantum/_utility.pyi +20 -0
  7. luna_quantum/algorithms/__init__.py +1 -0
  8. luna_quantum/aqm_overwrites/__init__.py +3 -0
  9. luna_quantum/aqm_overwrites/model.py +184 -0
  10. luna_quantum/backends/__init__.py +1 -0
  11. luna_quantum/client/__init__.py +0 -0
  12. luna_quantum/client/controllers/__init__.py +4 -0
  13. luna_quantum/client/controllers/luna_http_client.py +37 -0
  14. luna_quantum/client/controllers/luna_platform_client.py +256 -0
  15. luna_quantum/client/controllers/luna_q.py +67 -0
  16. luna_quantum/client/controllers/luna_solve.py +129 -0
  17. luna_quantum/client/error/__init__.py +0 -0
  18. luna_quantum/client/error/luna_api_key_invalid_error.py +10 -0
  19. luna_quantum/client/error/luna_api_key_missing_error.py +10 -0
  20. luna_quantum/client/error/luna_error.py +2 -0
  21. luna_quantum/client/error/luna_server_error.py +20 -0
  22. luna_quantum/client/error/timeout_error.py +12 -0
  23. luna_quantum/client/error/transformation_error.py +18 -0
  24. luna_quantum/client/error/utils/__init__.py +0 -0
  25. luna_quantum/client/error/utils/http_error_utils.py +112 -0
  26. luna_quantum/client/interfaces/__init__.py +4 -0
  27. luna_quantum/client/interfaces/clients/__init__.py +25 -0
  28. luna_quantum/client/interfaces/clients/circuit_rest_client_i.py +68 -0
  29. luna_quantum/client/interfaces/clients/info_rest_client_i.py +53 -0
  30. luna_quantum/client/interfaces/clients/model_rest_client_i.py +139 -0
  31. luna_quantum/client/interfaces/clients/qpu_token_rest_client_i.py +364 -0
  32. luna_quantum/client/interfaces/clients/rest_client_i.py +21 -0
  33. luna_quantum/client/interfaces/clients/solve_job_rest_client_i.py +201 -0
  34. luna_quantum/client/interfaces/clients/users_rest_client_i.py +29 -0
  35. luna_quantum/client/interfaces/services/__init__.py +0 -0
  36. luna_quantum/client/interfaces/services/luna_q_i.py +34 -0
  37. luna_quantum/client/interfaces/services/luna_solve_i.py +72 -0
  38. luna_quantum/client/interfaces/services/service_i.py +56 -0
  39. luna_quantum/client/rest_client/__init__.py +15 -0
  40. luna_quantum/client/rest_client/circuit_rest_client.py +107 -0
  41. luna_quantum/client/rest_client/info_rest_client.py +74 -0
  42. luna_quantum/client/rest_client/model_rest_client.py +216 -0
  43. luna_quantum/client/rest_client/qpu_token_rest_client.py +508 -0
  44. luna_quantum/client/rest_client/solve_job_rest_client.py +286 -0
  45. luna_quantum/client/rest_client/users_rest_client.py +35 -0
  46. luna_quantum/client/schemas/__init__.py +26 -0
  47. luna_quantum/client/schemas/circuit.py +48 -0
  48. luna_quantum/client/schemas/create/__init__.py +15 -0
  49. luna_quantum/client/schemas/create/circuit.py +30 -0
  50. luna_quantum/client/schemas/create/optimization.py +39 -0
  51. luna_quantum/client/schemas/create/qpu_token.py +22 -0
  52. luna_quantum/client/schemas/create/qpu_token_time_quota.py +35 -0
  53. luna_quantum/client/schemas/create/qpu_token_time_quota_update.py +24 -0
  54. luna_quantum/client/schemas/create/qubo.py +19 -0
  55. luna_quantum/client/schemas/create/solve_job_create.py +43 -0
  56. luna_quantum/client/schemas/enums/__init__.py +0 -0
  57. luna_quantum/client/schemas/enums/call_style.py +13 -0
  58. luna_quantum/client/schemas/enums/circuit.py +42 -0
  59. luna_quantum/client/schemas/enums/model_format.py +11 -0
  60. luna_quantum/client/schemas/enums/problem.py +50 -0
  61. luna_quantum/client/schemas/enums/qpu_token_type.py +20 -0
  62. luna_quantum/client/schemas/enums/sense.py +8 -0
  63. luna_quantum/client/schemas/enums/status.py +40 -0
  64. luna_quantum/client/schemas/enums/timeframe.py +11 -0
  65. luna_quantum/client/schemas/error_message.py +14 -0
  66. luna_quantum/client/schemas/model_metadata.py +35 -0
  67. luna_quantum/client/schemas/qpu_token/__init__.py +0 -0
  68. luna_quantum/client/schemas/qpu_token/qpu_token.py +154 -0
  69. luna_quantum/client/schemas/qpu_token/qpu_token_source.py +19 -0
  70. luna_quantum/client/schemas/qpu_token/qpu_token_time_quota.py +30 -0
  71. luna_quantum/client/schemas/qpu_token/token_provider.py +132 -0
  72. luna_quantum/client/schemas/representation.py +19 -0
  73. luna_quantum/client/schemas/solution.py +106 -0
  74. luna_quantum/client/schemas/solve_job.py +50 -0
  75. luna_quantum/client/schemas/solver_info.py +11 -0
  76. luna_quantum/client/schemas/user.py +11 -0
  77. luna_quantum/client/schemas/wrappers/__init__.py +5 -0
  78. luna_quantum/client/schemas/wrappers/datetime_wrapper.py +32 -0
  79. luna_quantum/client/utils/__init__.py +0 -0
  80. luna_quantum/client/utils/qpu_token_utils.py +147 -0
  81. luna_quantum/config.py +11 -0
  82. luna_quantum/decorators.py +248 -0
  83. luna_quantum/errors.py +34 -0
  84. luna_quantum/errors.pyi +287 -0
  85. luna_quantum/exceptions/__init__.py +0 -0
  86. luna_quantum/exceptions/base_luna_quantum_error.py +2 -0
  87. luna_quantum/exceptions/luna_quantum_call_type_error.py +9 -0
  88. luna_quantum/exceptions/patch_class_field_exists_error.py +10 -0
  89. luna_quantum/factories/__init__.py +4 -0
  90. luna_quantum/factories/luna_solve_client_factory.py +100 -0
  91. luna_quantum/factories/usecase_factory.py +489 -0
  92. luna_quantum/py.typed +0 -0
  93. luna_quantum/solve/__init__.py +13 -0
  94. luna_quantum/solve/default_token.py +304 -0
  95. luna_quantum/solve/domain/__init__.py +0 -0
  96. luna_quantum/solve/domain/abstract/__init__.py +4 -0
  97. luna_quantum/solve/domain/abstract/luna_algorithm.py +205 -0
  98. luna_quantum/solve/domain/abstract/qpu_token_backend.py +34 -0
  99. luna_quantum/solve/domain/model_metadata.py +56 -0
  100. luna_quantum/solve/domain/solve_job.py +230 -0
  101. luna_quantum/solve/errors/__init__.py +0 -0
  102. luna_quantum/solve/errors/incompatible_backend_error.py +15 -0
  103. luna_quantum/solve/errors/model_metadata_missing_error.py +11 -0
  104. luna_quantum/solve/errors/solve_base_error.py +5 -0
  105. luna_quantum/solve/errors/token_missing_error.py +11 -0
  106. luna_quantum/solve/interfaces/__init__.py +0 -0
  107. luna_quantum/solve/interfaces/algorithm_i.py +49 -0
  108. luna_quantum/solve/interfaces/backend_i.py +28 -0
  109. luna_quantum/solve/interfaces/usecases/__init__.py +59 -0
  110. luna_quantum/solve/interfaces/usecases/model_delete_usecase_i.py +27 -0
  111. luna_quantum/solve/interfaces/usecases/model_fetch_metadata_usecase_i.py +33 -0
  112. luna_quantum/solve/interfaces/usecases/model_get_solutions_usecase_i.py +33 -0
  113. luna_quantum/solve/interfaces/usecases/model_get_solve_jobs_usecase_i.py +33 -0
  114. luna_quantum/solve/interfaces/usecases/model_load_by_id_usecase_i.py +32 -0
  115. luna_quantum/solve/interfaces/usecases/model_load_by_metadata_usecase_i.py +37 -0
  116. luna_quantum/solve/interfaces/usecases/model_load_metadata_by_hash_usecase_i.py +38 -0
  117. luna_quantum/solve/interfaces/usecases/model_save_usecase_i.py +36 -0
  118. luna_quantum/solve/interfaces/usecases/solve_job_cancel_usecase_i.py +33 -0
  119. luna_quantum/solve/interfaces/usecases/solve_job_create_usecase_i.py +44 -0
  120. luna_quantum/solve/interfaces/usecases/solve_job_delete_usecase_i.py +32 -0
  121. luna_quantum/solve/interfaces/usecases/solve_job_fetch_updates_usecase_i.py +38 -0
  122. luna_quantum/solve/interfaces/usecases/solve_job_get_by_id_usecase_i.py +27 -0
  123. luna_quantum/solve/interfaces/usecases/solve_job_get_result_usecase_i.py +63 -0
  124. luna_quantum/solve/parameters/__init__.py +0 -0
  125. luna_quantum/solve/parameters/algorithms/__init__.py +51 -0
  126. luna_quantum/solve/parameters/algorithms/base_params/__init__.py +24 -0
  127. luna_quantum/solve/parameters/algorithms/base_params/decomposer.py +57 -0
  128. luna_quantum/solve/parameters/algorithms/base_params/qaoa_circuit_params.py +95 -0
  129. luna_quantum/solve/parameters/algorithms/base_params/quantum_annealing_params.py +79 -0
  130. luna_quantum/solve/parameters/algorithms/base_params/scipy_optimizer.py +122 -0
  131. luna_quantum/solve/parameters/algorithms/base_params/simulated_annealing_params.py +106 -0
  132. luna_quantum/solve/parameters/algorithms/base_params/tabu_kerberos_params.py +39 -0
  133. luna_quantum/solve/parameters/algorithms/base_params/tabu_search_params.py +129 -0
  134. luna_quantum/solve/parameters/algorithms/flexible_parameter_algorithm.py +59 -0
  135. luna_quantum/solve/parameters/algorithms/genetic_algorithms/__init__.py +4 -0
  136. luna_quantum/solve/parameters/algorithms/genetic_algorithms/qaga.py +131 -0
  137. luna_quantum/solve/parameters/algorithms/genetic_algorithms/saga.py +139 -0
  138. luna_quantum/solve/parameters/algorithms/lq_fda/__init__.py +3 -0
  139. luna_quantum/solve/parameters/algorithms/lq_fda/fujits_da_base.py +85 -0
  140. luna_quantum/solve/parameters/algorithms/lq_fda/fujitsu_da_v3c.py +155 -0
  141. luna_quantum/solve/parameters/algorithms/optimization_solvers/__init__.py +3 -0
  142. luna_quantum/solve/parameters/algorithms/optimization_solvers/scip.py +51 -0
  143. luna_quantum/solve/parameters/algorithms/quantum_annealing/__init__.py +19 -0
  144. luna_quantum/solve/parameters/algorithms/quantum_annealing/kerberos.py +149 -0
  145. luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_bqm.py +75 -0
  146. luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_cqm.py +75 -0
  147. luna_quantum/solve/parameters/algorithms/quantum_annealing/parallel_tempering_qpu.py +139 -0
  148. luna_quantum/solve/parameters/algorithms/quantum_annealing/population_annealing_qpu.py +109 -0
  149. luna_quantum/solve/parameters/algorithms/quantum_annealing/qbsolv_like_qpu.py +111 -0
  150. luna_quantum/solve/parameters/algorithms/quantum_annealing/quantum_annealing.py +121 -0
  151. luna_quantum/solve/parameters/algorithms/quantum_annealing/repeated_reverse_quantum_annealing.py +174 -0
  152. luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py +6 -0
  153. luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py +10 -0
  154. luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/__init__.py +29 -0
  155. luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/config.py +58 -0
  156. luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/flexqaoa.py +188 -0
  157. luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/optimizers.py +53 -0
  158. luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/pipeline.py +164 -0
  159. luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa.py +112 -0
  160. luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa_fo.py +69 -0
  161. luna_quantum/solve/parameters/algorithms/quantum_gate/vqe.py +108 -0
  162. luna_quantum/solve/parameters/algorithms/search_algorithms/__init__.py +5 -0
  163. luna_quantum/solve/parameters/algorithms/search_algorithms/dialectic_search.py +136 -0
  164. luna_quantum/solve/parameters/algorithms/search_algorithms/qbsolv_like_tabu_search.py +117 -0
  165. luna_quantum/solve/parameters/algorithms/search_algorithms/tabu_search.py +126 -0
  166. luna_quantum/solve/parameters/algorithms/simulated_annealing/__init__.py +13 -0
  167. luna_quantum/solve/parameters/algorithms/simulated_annealing/parallel_tempering.py +131 -0
  168. luna_quantum/solve/parameters/algorithms/simulated_annealing/population_annealing.py +95 -0
  169. luna_quantum/solve/parameters/algorithms/simulated_annealing/qbsolv_like_simulated_annealing.py +141 -0
  170. luna_quantum/solve/parameters/algorithms/simulated_annealing/repeated_reverse_simulated_annealing.py +172 -0
  171. luna_quantum/solve/parameters/algorithms/simulated_annealing/simulated_annealing.py +126 -0
  172. luna_quantum/solve/parameters/backends/__init__.py +27 -0
  173. luna_quantum/solve/parameters/backends/aqarios.py +17 -0
  174. luna_quantum/solve/parameters/backends/aqarios_gpu.py +17 -0
  175. luna_quantum/solve/parameters/backends/aws/__init__.py +11 -0
  176. luna_quantum/solve/parameters/backends/aws/aws.py +36 -0
  177. luna_quantum/solve/parameters/backends/aws/aws_backend_base.py +74 -0
  178. luna_quantum/solve/parameters/backends/aws/ionq.py +43 -0
  179. luna_quantum/solve/parameters/backends/aws/iqm.py +31 -0
  180. luna_quantum/solve/parameters/backends/aws/rigetti.py +31 -0
  181. luna_quantum/solve/parameters/backends/cudaq/__init__.py +5 -0
  182. luna_quantum/solve/parameters/backends/cudaq/cudaq_base.py +16 -0
  183. luna_quantum/solve/parameters/backends/cudaq/cudaq_cpu.py +30 -0
  184. luna_quantum/solve/parameters/backends/cudaq/cudaq_gpu.py +32 -0
  185. luna_quantum/solve/parameters/backends/dwave.py +17 -0
  186. luna_quantum/solve/parameters/backends/dwave_qpu.py +166 -0
  187. luna_quantum/solve/parameters/backends/fda.py +17 -0
  188. luna_quantum/solve/parameters/backends/ibm.py +138 -0
  189. luna_quantum/solve/parameters/backends/qctrl.py +103 -0
  190. luna_quantum/solve/parameters/backends/zib.py +17 -0
  191. luna_quantum/solve/parameters/constants.py +11 -0
  192. luna_quantum/solve/parameters/errors.py +30 -0
  193. luna_quantum/solve/parameters/mixins/__init__.py +0 -0
  194. luna_quantum/solve/parameters/mixins/fujitsu_common_params_mixin.py +239 -0
  195. luna_quantum/solve/parameters/mixins/fujitsu_v2_mixin.py +70 -0
  196. luna_quantum/solve/parameters/mixins/qbsolv_like_mixin.py +60 -0
  197. luna_quantum/solve/use_cases/__init__.py +119 -0
  198. luna_quantum/solve/use_cases/arbitrage_edge_based.py +50 -0
  199. luna_quantum/solve/use_cases/arbitrage_node_based.py +55 -0
  200. luna_quantum/solve/use_cases/base.py +7 -0
  201. luna_quantum/solve/use_cases/binary_integer_linear_programming.py +54 -0
  202. luna_quantum/solve/use_cases/binary_paint_shop_problem.py +37 -0
  203. luna_quantum/solve/use_cases/credit_scoring_feature_selection.py +40 -0
  204. luna_quantum/solve/use_cases/dynamic_portfolio_optimization.py +64 -0
  205. luna_quantum/solve/use_cases/exact_cover.py +51 -0
  206. luna_quantum/solve/use_cases/flight_gate_assignment.py +79 -0
  207. luna_quantum/solve/use_cases/graph_coloring.py +42 -0
  208. luna_quantum/solve/use_cases/graph_isomorphism.py +52 -0
  209. luna_quantum/solve/use_cases/graph_partitioning.py +46 -0
  210. luna_quantum/solve/use_cases/hamiltonian_cycle.py +49 -0
  211. luna_quantum/solve/use_cases/induced_subgraph_isomorphism.py +50 -0
  212. luna_quantum/solve/use_cases/job_shop_scheduling.py +44 -0
  213. luna_quantum/solve/use_cases/k_medoids_clustering.py +49 -0
  214. luna_quantum/solve/use_cases/knapsack_integer_weights.py +56 -0
  215. luna_quantum/solve/use_cases/linear_regression.py +60 -0
  216. luna_quantum/solve/use_cases/lmwcs.py +84 -0
  217. luna_quantum/solve/use_cases/longest_path.py +50 -0
  218. luna_quantum/solve/use_cases/market_graph_clustering.py +61 -0
  219. luna_quantum/solve/use_cases/max2sat.py +54 -0
  220. luna_quantum/solve/use_cases/max3sat.py +55 -0
  221. luna_quantum/solve/use_cases/max_clique.py +60 -0
  222. luna_quantum/solve/use_cases/max_cut.py +48 -0
  223. luna_quantum/solve/use_cases/max_independent_set.py +37 -0
  224. luna_quantum/solve/use_cases/minimal_maximal_matching.py +54 -0
  225. luna_quantum/solve/use_cases/minimal_spanning_tree.py +90 -0
  226. luna_quantum/solve/use_cases/minimum_vertex_cover.py +45 -0
  227. luna_quantum/solve/use_cases/number_partitioning.py +32 -0
  228. luna_quantum/solve/use_cases/portfolio_optimization.py +46 -0
  229. luna_quantum/solve/use_cases/portfolio_optimization_ib_tv.py +63 -0
  230. luna_quantum/solve/use_cases/quadratic_assignment.py +49 -0
  231. luna_quantum/solve/use_cases/quadratic_knapsack.py +48 -0
  232. luna_quantum/solve/use_cases/satellite_scheduling.py +73 -0
  233. luna_quantum/solve/use_cases/sensor_placement.py +58 -0
  234. luna_quantum/solve/use_cases/set_cover.py +56 -0
  235. luna_quantum/solve/use_cases/set_packing.py +54 -0
  236. luna_quantum/solve/use_cases/set_partitioning.py +52 -0
  237. luna_quantum/solve/use_cases/subgraph_isomorphism.py +55 -0
  238. luna_quantum/solve/use_cases/subset_sum.py +37 -0
  239. luna_quantum/solve/use_cases/support_vector_machine.py +64 -0
  240. luna_quantum/solve/use_cases/traffic_flow.py +35 -0
  241. luna_quantum/solve/use_cases/travelling_salesman_problem.py +53 -0
  242. luna_quantum/solve/use_cases/type_aliases.py +9 -0
  243. luna_quantum/solve/use_cases/weighted_max_cut.py +37 -0
  244. luna_quantum/solve/usecases/__init__.py +45 -0
  245. luna_quantum/solve/usecases/model_delete_usecase.py +49 -0
  246. luna_quantum/solve/usecases/model_fetch_metadata_usecase.py +50 -0
  247. luna_quantum/solve/usecases/model_get_solution_usecase.py +59 -0
  248. luna_quantum/solve/usecases/model_get_solve_jobs_usecase.py +62 -0
  249. luna_quantum/solve/usecases/model_load_by_id_usecase.py +47 -0
  250. luna_quantum/solve/usecases/model_load_by_metadata_usecase.py +52 -0
  251. luna_quantum/solve/usecases/model_load_metadata_by_hash_usecase.py +51 -0
  252. luna_quantum/solve/usecases/model_save_usecase.py +63 -0
  253. luna_quantum/solve/usecases/solve_job_cancel_usecase.py +51 -0
  254. luna_quantum/solve/usecases/solve_job_create_usecase.py +112 -0
  255. luna_quantum/solve/usecases/solve_job_delete_usecase.py +38 -0
  256. luna_quantum/solve/usecases/solve_job_fetch_updates_usecase.py +49 -0
  257. luna_quantum/solve/usecases/solve_job_get_by_id_usecase.py +44 -0
  258. luna_quantum/solve/usecases/solve_job_get_result_usecase.py +105 -0
  259. luna_quantum/transformations.py +18 -0
  260. luna_quantum/transformations.pyi +371 -0
  261. luna_quantum/translator.py +23 -0
  262. luna_quantum/translator.pyi +869 -0
  263. luna_quantum/util/__init__.py +0 -0
  264. luna_quantum/util/active_waiting.py +79 -0
  265. luna_quantum/util/class_patcher.py +164 -0
  266. luna_quantum/util/debug_info.py +52 -0
  267. luna_quantum/util/log_utils.py +187 -0
  268. luna_quantum/util/pretty_base.py +67 -0
  269. luna_quantum/util/pydantic_utils.py +38 -0
  270. luna_quantum/utils.py +3 -0
  271. luna_quantum/utils.pyi +67 -0
  272. luna_quantum-1.1.0.dist-info/METADATA +36 -0
  273. luna_quantum-1.1.0.dist-info/RECORD +276 -0
  274. luna_quantum-1.1.0.dist-info/WHEEL +4 -0
  275. luna_quantum-1.1.0.dist-info/licenses/LICENSE +176 -0
  276. luna_quantum-1.1.0.dist-info/licenses/NOTICE +13 -0
@@ -0,0 +1,304 @@
1
+ from typing import ClassVar
2
+
3
+ from luna_quantum.client.schemas import QpuToken, QpuTokenSource
4
+
5
+
6
+ class DefaultToken:
7
+ """
8
+ Set default tokens for various quantum computing providers.
9
+
10
+ This class is used to set, retrieve, and remove the default QPU tokens for different
11
+ quantum computing providers. It supports providers such as D-Wave, IBM,
12
+ Fujitsu, Q-CTRL, and AWS. The purpose is to centralize token management
13
+ for seamless integration with quantum computing platforms.
14
+ """
15
+
16
+ _dwave: ClassVar[QpuToken | None] = None
17
+ _ibm: ClassVar[QpuToken | None] = None
18
+ _fujitsu: ClassVar[QpuToken | None] = None
19
+ _qctrl: ClassVar[QpuToken | None] = None
20
+ _aws_access_key: ClassVar[QpuToken | None] = None
21
+ _aws_secret_access_key: ClassVar[QpuToken | None] = None
22
+ _aws_session_token: ClassVar[QpuToken | None] = None
23
+
24
+ @classmethod
25
+ def set_token(cls, provider: str, token: QpuToken | str) -> None:
26
+ """
27
+ Set the token for a specific provider.
28
+
29
+ This method associates a token with a given provider, allowing for
30
+ authenticated interactions with the provider's services.
31
+
32
+ Parameters
33
+ ----------
34
+ provider : str
35
+ The name or identifier of the provider.
36
+ token : Union[QpuToken, str]
37
+ The token object or string to authenticate with the provider.
38
+ """
39
+ if isinstance(token, str):
40
+ token = QpuToken(token=token, source=QpuTokenSource.INLINE)
41
+ cls._set_token(provider, token)
42
+
43
+ @classmethod
44
+ def set_dwave_token(cls, token: QpuToken | str) -> None:
45
+ """
46
+ Set the token for the D-Wave platform.
47
+
48
+ Allow users to set a default token for accessing the D-Wave platform by
49
+ specifying it as a parameter.
50
+
51
+ Parameters
52
+ ----------
53
+ token : Union[QpuToken, str]
54
+ The token to use for D-Wave access.
55
+
56
+ Returns
57
+ -------
58
+ None
59
+
60
+ """
61
+ cls.set_token("dwave", token)
62
+
63
+ @classmethod
64
+ def set_ibm_token(cls, token: QpuToken | str) -> None:
65
+ """
66
+ Set the token for the IBM platform.
67
+
68
+ Allow users to set a default token for accessing the IBM platform by
69
+ specifying it as a parameter.
70
+
71
+ Parameters
72
+ ----------
73
+ token : Union[QpuToken, str]
74
+ The token to use for IBM access.
75
+
76
+ Returns
77
+ -------
78
+ None
79
+
80
+ """
81
+ cls.set_token("ibm", token)
82
+
83
+ @classmethod
84
+ def set_fujitsu_token(cls, token: QpuToken | str) -> None:
85
+ """
86
+ Set the token for the Fujitsu platform.
87
+
88
+ Allow users to set a default token for accessing the Fujitsu platform by
89
+ specifying it as a parameter.
90
+
91
+ Parameters
92
+ ----------
93
+ token : Union[QpuToken, str]
94
+ The token to use for Fujitsu access.
95
+
96
+ Returns
97
+ -------
98
+ None
99
+
100
+ """
101
+ cls.set_token("fujitsu", token)
102
+
103
+ @classmethod
104
+ def set_qctrl_token(cls, token: QpuToken | str) -> None:
105
+ """
106
+ Set the token for the QCTRL platform.
107
+
108
+ Allow users to set a default token for accessing the QCTRL platform by
109
+ specifying it as a parameter.
110
+
111
+ Parameters
112
+ ----------
113
+ token : Union[QpuToken, str]
114
+ The token to use for QCTRL access.
115
+
116
+ Returns
117
+ -------
118
+ None
119
+
120
+ """
121
+ cls.set_token("qctrl", token)
122
+
123
+ @classmethod
124
+ def set_aws_access_token(
125
+ cls,
126
+ access_key: QpuToken | str,
127
+ secret_access_key: QpuToken | str,
128
+ aws_session_token: QpuToken | str,
129
+ ) -> None:
130
+ """
131
+ Set the tokens for the AWS platform.
132
+
133
+ Allow users to set a default token for accessing the AWS platform by
134
+ specifying it as a parameter.
135
+
136
+ Parameters
137
+ ----------
138
+ access_key : Union[QpuToken, str]
139
+ The access key to use for AWS.
140
+ secret_access_key : Union[QpuToken, str]
141
+ The secret access key to use for AWS.
142
+
143
+ Returns
144
+ -------
145
+ None
146
+
147
+ """
148
+ cls.set_token("aws_access_key", access_key)
149
+ cls.set_token("aws_secret_access_key", secret_access_key)
150
+ cls.set_token("aws_session_token", aws_session_token)
151
+
152
+ @classmethod
153
+ def remove_token(cls, provider: str) -> None:
154
+ """
155
+ Remove a token for a specific provider.
156
+
157
+ This method removes the token associated with a particular provider by setting
158
+ its value to None.
159
+
160
+ Parameters
161
+ ----------
162
+ provider : str
163
+ The identifier for the provider whose token is to be removed.
164
+
165
+ Returns
166
+ -------
167
+ None
168
+ This method does not return a value.
169
+ """
170
+ cls._set_token(provider, None)
171
+
172
+ @classmethod
173
+ def remove_dwave_token(cls) -> None:
174
+ """
175
+ Remove the D-Wave token from the default token provider.
176
+
177
+ Returns
178
+ -------
179
+ None
180
+ This method does not return anything.
181
+ """
182
+ cls.remove_token("dwave")
183
+
184
+ @classmethod
185
+ def remove_ibm_token(cls) -> None:
186
+ """
187
+ Remove the IBM token from the default token provider.
188
+
189
+ Returns
190
+ -------
191
+ None
192
+ This method does not return anything.
193
+ """
194
+ cls.remove_token("ibm")
195
+
196
+ @classmethod
197
+ def remove_fujitsu_token(cls) -> None:
198
+ """
199
+ Remove the Fujitsu token from the default token provider.
200
+
201
+ Returns
202
+ -------
203
+ None
204
+ This method does not return anything.
205
+ """
206
+ cls.remove_token("fujitsu")
207
+
208
+ @classmethod
209
+ def remove_qctrl_token(cls) -> None:
210
+ """
211
+ Remove the QCTRl token from the default token provider.
212
+
213
+ Returns
214
+ -------
215
+ None
216
+ This method does not return anything.
217
+ """
218
+ cls.remove_token("qctrl")
219
+
220
+ @classmethod
221
+ def remove_aws_token(cls) -> None:
222
+ """
223
+ Remove the AWS tokens from the default token provider.
224
+
225
+ Returns
226
+ -------
227
+ None
228
+ This method does not return anything.
229
+ """
230
+ cls.remove_token("aws_access_key")
231
+ cls.remove_token("aws_secret_access_key")
232
+ cls.remove_token("aws_session_token")
233
+
234
+ @classmethod
235
+ def get_token(cls, provider: str) -> QpuToken | None:
236
+ """
237
+ Get the token for a specified quantum computing provider.
238
+
239
+ This method returns the token associated with the given provider name. If the
240
+ provider is not recognized, it returns None.
241
+
242
+ Parameters
243
+ ----------
244
+ provider : str
245
+ The name of the quantum computing provider.
246
+
247
+ Returns
248
+ -------
249
+ Union[QpuToken, None]
250
+ The token associated with the specified provider, or None if the provider is
251
+ """
252
+ to_return: QpuToken | None = None
253
+ if provider == "dwave":
254
+ to_return = cls._dwave
255
+ elif provider == "ibm":
256
+ to_return = cls._ibm
257
+ elif provider == "fujitsu":
258
+ to_return = cls._fujitsu
259
+ elif provider == "qctrl":
260
+ to_return = cls._qctrl
261
+ elif provider == "aws_access_key":
262
+ to_return = cls._aws_access_key
263
+ elif provider == "aws_secret_access_key":
264
+ to_return = cls._aws_secret_access_key
265
+ elif provider == "aws_session_token":
266
+ to_return = cls._aws_session_token
267
+ else:
268
+ to_return = None
269
+ return to_return
270
+
271
+ @classmethod
272
+ def _set_token(cls, provider: str, token: QpuToken | None) -> None:
273
+ """
274
+ Set token for the specified quantum provider.
275
+
276
+ The method updates the corresponding class-level attribute for the given
277
+ quantum provider with the token provided.
278
+
279
+ Parameters
280
+ ----------
281
+ provider : str
282
+ The name of the quantum provider to set the token for.
283
+ token : Union[QpuToken, None]
284
+ The token to associate with the given provider.
285
+
286
+ Raises
287
+ ------
288
+ KeyError
289
+ If the provider name does not match any supported providers.
290
+ """
291
+ if provider == "dwave":
292
+ cls._dwave = token
293
+ elif provider == "ibm":
294
+ cls._ibm = token
295
+ elif provider == "fujitsu":
296
+ cls._fujitsu = token
297
+ elif provider == "qctrl":
298
+ cls._qctrl = token
299
+ elif provider == "aws_access_key":
300
+ cls._aws_access_key = token
301
+ elif provider == "aws_secret_access_key":
302
+ cls._aws_secret_access_key = token
303
+ elif provider == "aws_session_token":
304
+ cls._aws_session_token = token
File without changes
@@ -0,0 +1,4 @@
1
+ from .luna_algorithm import LunaAlgorithm
2
+ from .qpu_token_backend import QpuTokenBackend
3
+
4
+ __all__ = ["LunaAlgorithm", "QpuTokenBackend"]
@@ -0,0 +1,205 @@
1
+ from abc import abstractmethod
2
+ from logging import Logger
3
+ from typing import TYPE_CHECKING, Any, ClassVar, Generic
4
+
5
+ from pydantic import ConfigDict, Field, field_validator
6
+
7
+ from luna_quantum.aqm_overwrites.model import Model
8
+ from luna_quantum.client.controllers.luna_solve import LunaSolve
9
+ from luna_quantum.factories.luna_solve_client_factory import LunaSolveClientFactory
10
+ from luna_quantum.solve.domain.solve_job import SolveJob
11
+ from luna_quantum.solve.errors.incompatible_backend_error import (
12
+ IncompatibleBackendError,
13
+ )
14
+ from luna_quantum.solve.interfaces.algorithm_i import BACKEND_TYPE, IAlgorithm
15
+ from luna_quantum.util.log_utils import Logging
16
+
17
+ if TYPE_CHECKING:
18
+ from luna_quantum.solve.interfaces.usecases import ISolveJobCreateUseCase
19
+
20
+
21
+ class LunaAlgorithm(IAlgorithm[BACKEND_TYPE], Generic[BACKEND_TYPE]):
22
+ """
23
+ Class representing a solver for Luna model problems.
24
+
25
+ This class serves as a base model combining functionality for model
26
+ solvers, client management, and configurations needed for integrating with
27
+ Luna's solving capabilities.
28
+ """
29
+
30
+ _logger: ClassVar[Logger] = Logging.get_logger(__name__)
31
+ backend: BACKEND_TYPE | None = Field(
32
+ default=None,
33
+ exclude=True,
34
+ repr=False,
35
+ )
36
+
37
+ @field_validator("backend", mode="before")
38
+ @classmethod
39
+ def backend_validator(cls, v: Any) -> BACKEND_TYPE | None: # noqa: ANN401 # Ignore ANN401 here because the type for validation could be every type.
40
+ """
41
+ Validate and ensure the compatibility of the backend.
42
+
43
+ Convert or validate the backend input to ensure compatibility with
44
+ the expected backend type. This method is called before assigning a
45
+ value to the backend attribute.
46
+
47
+ Parameters
48
+ ----------
49
+ v : Any
50
+ The value to be validated or converted into the compatible backend type.
51
+
52
+ Returns
53
+ -------
54
+ Optional[BACKEND_TYPE]
55
+ The validated or converted backend type. It returns None if the validation
56
+ fails and no compatible backend type can be determined.
57
+
58
+ Raises
59
+ ------
60
+ IncompatibleBackendError
61
+ Raised if the value cannot be ensured to meet the backend compatibility
62
+ requirements.
63
+ """
64
+ return cls._ensure_backend_compatibility(v)
65
+
66
+ @classmethod
67
+ def _ensure_backend_compatibility(cls, backend: Any) -> BACKEND_TYPE | None: # noqa: ANN401 Disabled since we want to check every possible input if its valid
68
+ """
69
+ Ensure the compatibility of the provided backend.
70
+
71
+ Check if the given backend is compatible with the current algorithm. If not,
72
+ log an error and raise an exception. Return without any action if the
73
+ backend is None.
74
+
75
+ Parameters
76
+ ----------
77
+ backend : Optional[BACKEND_TYPE]
78
+ Backend instance to be verified for compatibility.
79
+
80
+ Raises
81
+ ------
82
+ IncompatibleBackendError
83
+ If the backend is not compatible with the algorithm.
84
+ """
85
+ if backend is None:
86
+ return None
87
+
88
+ if not isinstance(backend, cls.get_compatible_backends()):
89
+ cls._logger.error(
90
+ f"Backend of type {type(backend)}"
91
+ f" is not compatible with the '{cls.__name__}' Algorithm. "
92
+ f"Use one of the following: {cls.get_compatible_backends()}",
93
+ )
94
+ raise IncompatibleBackendError(backend, cls)
95
+
96
+ # We checked before if its a instance of BACKEND_TYPE
97
+ # so we know here that this is correct,
98
+ # unless we implement cls.get_compatible_backends() wrong.
99
+ return backend
100
+
101
+ def run(
102
+ self,
103
+ model: Model | str,
104
+ name: str | None = None,
105
+ backend: BACKEND_TYPE | None = None,
106
+ client: LunaSolve | str | None = None,
107
+ *args: Any, # noqa: ARG002 its set here in case a child needs more set parameters
108
+ **kwargs: Any, # noqa: ARG002 its set here in case a child needs more set parameters
109
+ ) -> SolveJob:
110
+ """
111
+ Run the configured solver.
112
+
113
+ Parameters
114
+ ----------
115
+ model : Model or str
116
+ The model to be optimized or solved. It could be an Model instance or
117
+ a string identifier representing the model id.
118
+ name: Optional[str]
119
+ If provided, the name of the job. Defaults to None.
120
+ backend: Optional[BACKEND_TYPE]
121
+ Backend to use for the solver. If not provided, the default backend is
122
+ used.
123
+ client : LunaSolve or str, optional
124
+ The client interface used to interact with the backend services. If
125
+ not provided, a default client will be used.
126
+ *args : Any
127
+ Additional arguments that will be passed to the solver or client.
128
+ **kwargs : Any
129
+ Additional keyword parameters for configuration or customization.
130
+
131
+ Returns
132
+ -------
133
+ SolveJob
134
+ The job object containing the information about the solve process.
135
+ """
136
+ from luna_quantum.factories.usecase_factory import ( # noqa: PLC0415
137
+ UseCaseFactory,
138
+ )
139
+
140
+ b: BACKEND_TYPE
141
+ if backend is not None:
142
+ b = backend
143
+ elif self.backend is not None:
144
+ b = self.backend
145
+ else:
146
+ b = self.get_default_backend()
147
+
148
+ self._ensure_backend_compatibility(b)
149
+
150
+ c = LunaSolveClientFactory.get_client(client=client)
151
+
152
+ uc: ISolveJobCreateUseCase = UseCaseFactory.solve_job_create(client=c)
153
+
154
+ return uc(model=model, luna_solver=self, backend=b, name=name)
155
+
156
+ @property
157
+ @abstractmethod
158
+ def algorithm_name(self) -> str:
159
+ """
160
+ Returns the name of the algorithm.
161
+
162
+ This abstract property method is intended to be overridden by subclasses.
163
+ It should provide the name of the algorithm being implemented.
164
+
165
+ Returns
166
+ -------
167
+ str
168
+ The name of the algorithm.
169
+ """
170
+
171
+ @classmethod
172
+ @abstractmethod
173
+ def get_default_backend(cls) -> BACKEND_TYPE:
174
+ """
175
+ Return the default backend implementation.
176
+
177
+ This property must be implemented by subclasses to provide
178
+ the default backend instance to use when no specific backend
179
+ is specified.
180
+
181
+ Returns
182
+ -------
183
+ BACKEND_TYPE
184
+ An instance of a class implementing the IBackend interface that serves
185
+ as the default backend.
186
+ """
187
+
188
+ @classmethod
189
+ @abstractmethod
190
+ def get_compatible_backends(cls) -> tuple[type[BACKEND_TYPE], ...]:
191
+ """
192
+ Check at runtime if the used backend is compatible with the solver.
193
+
194
+ Returns
195
+ -------
196
+ tuple[type[IBackend], ...]
197
+ True if the backend is compatible with the solver, False otherwise.
198
+
199
+ """
200
+
201
+ model_config = ConfigDict(
202
+ arbitrary_types_allowed=True,
203
+ extra="allow",
204
+ validate_assignment=True,
205
+ )
@@ -0,0 +1,34 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from luna_quantum.client.schemas.qpu_token.qpu_token import TokenProvider
4
+ from luna_quantum.client.utils.qpu_token_utils import QpuTokenUtils
5
+ from luna_quantum.solve.interfaces.backend_i import IBackend
6
+
7
+
8
+ class QpuTokenBackend(IBackend, ABC):
9
+ """Abstract base class for backend providers that require QPU tokens."""
10
+
11
+ @abstractmethod
12
+ def _get_token(self) -> TokenProvider | None:
13
+ pass
14
+
15
+ def get_qpu_tokens(self) -> TokenProvider | None:
16
+ """
17
+ Retrieve a QPU token.
18
+
19
+ This method is intended to be implemented by subclasses to provide the
20
+ mechanism for fetching the required Quantum Processing Unit (QPU) tokens, if
21
+ they are required by the solver implementation. The tokens may either be
22
+ sourced from a `TokenProvider` object or result in a `None` if unavailable.
23
+
24
+ Returns
25
+ -------
26
+ TokenProvider | None:
27
+ An object implementing the `TokenProvider` interface if tokens are
28
+ available/needed, otherwise `None`.
29
+ """
30
+ token = self._get_token()
31
+ if token is None:
32
+ token = TokenProvider()
33
+
34
+ return QpuTokenUtils.patch_qpu_tokens_from_env(token)
@@ -0,0 +1,56 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import TYPE_CHECKING
4
+
5
+ from pydantic import BaseModel
6
+
7
+ from luna_quantum.client.schemas.wrappers import (
8
+ PydanticDatetimeWrapper, # noqa: TC001 Otherwise Pydantic will break
9
+ )
10
+ from luna_quantum.factories.luna_solve_client_factory import LunaSolveClientFactory
11
+
12
+ if TYPE_CHECKING:
13
+ from luna_quantum.aqm_overwrites import Model
14
+ from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
15
+
16
+
17
+ class ModelMetadata(BaseModel):
18
+ """Metadata of an AQ model."""
19
+
20
+ id: str
21
+
22
+ created_date: PydanticDatetimeWrapper
23
+ created_by: str
24
+
25
+ modified_date: PydanticDatetimeWrapper | None = None
26
+ modified_by: str | None = None
27
+
28
+ def fetch_model(self, client: ILunaSolve | str | None = None) -> Model:
29
+ """
30
+ Fetch a Model instance using the provided client input.
31
+
32
+ The method uses the client input, which can be an instance of ILunaSolve or a
33
+ string, to create a client. It then loads the Model instance based on the
34
+ metadata tied to the client.
35
+
36
+ Parameters
37
+ ----------
38
+ client : Optional[Union[ILunaSolve, str]]
39
+ The client object or identifier used to retrieve model metadata.
40
+
41
+ Returns
42
+ -------
43
+ Model
44
+ An Model instance loaded based on provided client metadata.
45
+ """
46
+ c = LunaSolveClientFactory.get_client(client=client)
47
+
48
+ from luna_quantum.factories.usecase_factory import ( # noqa: PLC0415
49
+ UseCaseFactory,
50
+ )
51
+
52
+ aq_model: Model = UseCaseFactory.model_load_by_metadata(client=c).__call__(
53
+ model_metadata=self
54
+ )
55
+
56
+ return aq_model