luna-quantum 1.0.0__cp313-cp313-macosx_10_12_x86_64.whl

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

Potentially problematic release.


This version of luna-quantum might be problematic. Click here for more details.

Files changed (252) hide show
  1. luna_quantum/__init__.py +96 -0
  2. luna_quantum/__init__.pyi +68 -0
  3. luna_quantum/_core.cpython-313-darwin.so +0 -0
  4. luna_quantum/_core.pyi +3017 -0
  5. luna_quantum/aqm_overwrites/__init__.py +3 -0
  6. luna_quantum/aqm_overwrites/model.py +184 -0
  7. luna_quantum/client/__init__.py +0 -0
  8. luna_quantum/client/controllers/__init__.py +4 -0
  9. luna_quantum/client/controllers/luna_http_client.py +37 -0
  10. luna_quantum/client/controllers/luna_platform_client.py +153 -0
  11. luna_quantum/client/controllers/luna_q.py +62 -0
  12. luna_quantum/client/controllers/luna_solve.py +125 -0
  13. luna_quantum/client/error/__init__.py +0 -0
  14. luna_quantum/client/error/luna_api_key_invalid_error.py +10 -0
  15. luna_quantum/client/error/luna_api_key_missing_error.py +10 -0
  16. luna_quantum/client/error/luna_error.py +2 -0
  17. luna_quantum/client/error/luna_server_error.py +20 -0
  18. luna_quantum/client/error/timeout_error.py +12 -0
  19. luna_quantum/client/error/transformation_error.py +18 -0
  20. luna_quantum/client/error/utils/__init__.py +0 -0
  21. luna_quantum/client/error/utils/http_error_utils.py +112 -0
  22. luna_quantum/client/interfaces/__init__.py +4 -0
  23. luna_quantum/client/interfaces/clients/__init__.py +25 -0
  24. luna_quantum/client/interfaces/clients/circuit_rest_client_i.py +68 -0
  25. luna_quantum/client/interfaces/clients/info_rest_client_i.py +53 -0
  26. luna_quantum/client/interfaces/clients/model_rest_client_i.py +139 -0
  27. luna_quantum/client/interfaces/clients/qpu_token_rest_client_i.py +364 -0
  28. luna_quantum/client/interfaces/clients/rest_client_i.py +21 -0
  29. luna_quantum/client/interfaces/clients/solve_job_rest_client_i.py +201 -0
  30. luna_quantum/client/interfaces/clients/users_rest_client_i.py +29 -0
  31. luna_quantum/client/interfaces/services/__init__.py +0 -0
  32. luna_quantum/client/interfaces/services/luna_q_i.py +34 -0
  33. luna_quantum/client/interfaces/services/luna_solve_i.py +72 -0
  34. luna_quantum/client/interfaces/services/service_i.py +36 -0
  35. luna_quantum/client/rest_client/__init__.py +15 -0
  36. luna_quantum/client/rest_client/circuit_rest_client.py +107 -0
  37. luna_quantum/client/rest_client/info_rest_client.py +76 -0
  38. luna_quantum/client/rest_client/model_rest_client.py +216 -0
  39. luna_quantum/client/rest_client/qpu_token_rest_client.py +504 -0
  40. luna_quantum/client/rest_client/solve_job_rest_client.py +286 -0
  41. luna_quantum/client/rest_client/users_rest_client.py +35 -0
  42. luna_quantum/client/schemas/__init__.py +26 -0
  43. luna_quantum/client/schemas/circuit.py +49 -0
  44. luna_quantum/client/schemas/create/__init__.py +6 -0
  45. luna_quantum/client/schemas/create/circuit.py +31 -0
  46. luna_quantum/client/schemas/create/optimization.py +39 -0
  47. luna_quantum/client/schemas/create/qpu_token.py +25 -0
  48. luna_quantum/client/schemas/create/qpu_token_time_quota.py +29 -0
  49. luna_quantum/client/schemas/create/qubo.py +19 -0
  50. luna_quantum/client/schemas/create/solve_job_create.py +43 -0
  51. luna_quantum/client/schemas/enums/__init__.py +0 -0
  52. luna_quantum/client/schemas/enums/call_style.py +13 -0
  53. luna_quantum/client/schemas/enums/circuit.py +42 -0
  54. luna_quantum/client/schemas/enums/model_format.py +11 -0
  55. luna_quantum/client/schemas/enums/problem.py +50 -0
  56. luna_quantum/client/schemas/enums/qpu_token_type.py +20 -0
  57. luna_quantum/client/schemas/enums/sense.py +8 -0
  58. luna_quantum/client/schemas/enums/status.py +40 -0
  59. luna_quantum/client/schemas/enums/timeframe.py +11 -0
  60. luna_quantum/client/schemas/error_message.py +14 -0
  61. luna_quantum/client/schemas/model_metadata.py +35 -0
  62. luna_quantum/client/schemas/qpu_token/__init__.py +0 -0
  63. luna_quantum/client/schemas/qpu_token/qpu_token.py +161 -0
  64. luna_quantum/client/schemas/qpu_token/qpu_token_source.py +19 -0
  65. luna_quantum/client/schemas/qpu_token/qpu_token_time_quota.py +28 -0
  66. luna_quantum/client/schemas/qpu_token/token_provider.py +135 -0
  67. luna_quantum/client/schemas/representation.py +19 -0
  68. luna_quantum/client/schemas/solution.py +106 -0
  69. luna_quantum/client/schemas/solve_job.py +47 -0
  70. luna_quantum/client/schemas/solver_info.py +11 -0
  71. luna_quantum/client/schemas/user.py +11 -0
  72. luna_quantum/client/schemas/wrappers/__init__.py +5 -0
  73. luna_quantum/client/schemas/wrappers/datetime_wrapper.py +32 -0
  74. luna_quantum/client/utils/__init__.py +0 -0
  75. luna_quantum/client/utils/qpu_token_utils.py +147 -0
  76. luna_quantum/errors.py +1 -0
  77. luna_quantum/errors.pyi +202 -0
  78. luna_quantum/exceptions/__init__.py +0 -0
  79. luna_quantum/exceptions/base_luna_quantum_error.py +2 -0
  80. luna_quantum/exceptions/patch_class_field_exists_error.py +10 -0
  81. luna_quantum/factories/__init__.py +4 -0
  82. luna_quantum/factories/luna_solve_client_factory.py +75 -0
  83. luna_quantum/factories/usecase_factory.py +457 -0
  84. luna_quantum/py.typed +0 -0
  85. luna_quantum/solve/__init__.py +13 -0
  86. luna_quantum/solve/default_token.py +304 -0
  87. luna_quantum/solve/domain/__init__.py +0 -0
  88. luna_quantum/solve/domain/abstract/__init__.py +4 -0
  89. luna_quantum/solve/domain/abstract/luna_algorithm.py +203 -0
  90. luna_quantum/solve/domain/abstract/qpu_token_backend.py +34 -0
  91. luna_quantum/solve/domain/model_metadata.py +54 -0
  92. luna_quantum/solve/domain/solve_job.py +187 -0
  93. luna_quantum/solve/errors/__init__.py +0 -0
  94. luna_quantum/solve/errors/incompatible_backend_error.py +15 -0
  95. luna_quantum/solve/errors/model_metadata_missing_error.py +11 -0
  96. luna_quantum/solve/errors/solve_base_error.py +5 -0
  97. luna_quantum/solve/errors/token_missing_error.py +11 -0
  98. luna_quantum/solve/interfaces/__init__.py +0 -0
  99. luna_quantum/solve/interfaces/algorithm_i.py +47 -0
  100. luna_quantum/solve/interfaces/backend_i.py +28 -0
  101. luna_quantum/solve/interfaces/usecases/__init__.py +55 -0
  102. luna_quantum/solve/interfaces/usecases/model_delete_usecase_i.py +27 -0
  103. luna_quantum/solve/interfaces/usecases/model_fetch_metadata_usecase_i.py +33 -0
  104. luna_quantum/solve/interfaces/usecases/model_get_solutions_usecase_i.py +33 -0
  105. luna_quantum/solve/interfaces/usecases/model_get_solve_jobs_usecase_i.py +33 -0
  106. luna_quantum/solve/interfaces/usecases/model_load_by_id_usecase_i.py +32 -0
  107. luna_quantum/solve/interfaces/usecases/model_load_by_metadata_usecase_i.py +37 -0
  108. luna_quantum/solve/interfaces/usecases/model_load_metadata_by_hash_usecase_i.py +38 -0
  109. luna_quantum/solve/interfaces/usecases/model_save_usecase_i.py +36 -0
  110. luna_quantum/solve/interfaces/usecases/solve_job_cancel_usecase_i.py +33 -0
  111. luna_quantum/solve/interfaces/usecases/solve_job_create_usecase_i.py +44 -0
  112. luna_quantum/solve/interfaces/usecases/solve_job_delete_usecase_i.py +32 -0
  113. luna_quantum/solve/interfaces/usecases/solve_job_fetch_updates_usecase_i.py +38 -0
  114. luna_quantum/solve/interfaces/usecases/solve_job_get_result_usecase_i.py +63 -0
  115. luna_quantum/solve/parameters/__init__.py +0 -0
  116. luna_quantum/solve/parameters/algorithms/__init__.py +49 -0
  117. luna_quantum/solve/parameters/algorithms/base_params/__init__.py +24 -0
  118. luna_quantum/solve/parameters/algorithms/base_params/decomposer.py +57 -0
  119. luna_quantum/solve/parameters/algorithms/base_params/qaoa_circuit_params.py +95 -0
  120. luna_quantum/solve/parameters/algorithms/base_params/quantum_annealing_params.py +78 -0
  121. luna_quantum/solve/parameters/algorithms/base_params/scipy_optimizer.py +120 -0
  122. luna_quantum/solve/parameters/algorithms/base_params/simulated_annealing_params.py +106 -0
  123. luna_quantum/solve/parameters/algorithms/base_params/tabu_kerberos_params.py +39 -0
  124. luna_quantum/solve/parameters/algorithms/base_params/tabu_search_params.py +129 -0
  125. luna_quantum/solve/parameters/algorithms/flexible_parameter_algorithm.py +59 -0
  126. luna_quantum/solve/parameters/algorithms/genetic_algorithms/__init__.py +4 -0
  127. luna_quantum/solve/parameters/algorithms/genetic_algorithms/qaga.py +131 -0
  128. luna_quantum/solve/parameters/algorithms/genetic_algorithms/saga.py +139 -0
  129. luna_quantum/solve/parameters/algorithms/optimization_solvers/__init__.py +3 -0
  130. luna_quantum/solve/parameters/algorithms/optimization_solvers/scip.py +51 -0
  131. luna_quantum/solve/parameters/algorithms/quantum_annealing/__init__.py +19 -0
  132. luna_quantum/solve/parameters/algorithms/quantum_annealing/kerberos.py +149 -0
  133. luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_bqm.py +75 -0
  134. luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_cqm.py +75 -0
  135. luna_quantum/solve/parameters/algorithms/quantum_annealing/parallel_tempering_qpu.py +139 -0
  136. luna_quantum/solve/parameters/algorithms/quantum_annealing/population_annealing_qpu.py +109 -0
  137. luna_quantum/solve/parameters/algorithms/quantum_annealing/qbsolv_like_qpu.py +111 -0
  138. luna_quantum/solve/parameters/algorithms/quantum_annealing/quantum_annealing.py +105 -0
  139. luna_quantum/solve/parameters/algorithms/quantum_annealing/repeated_reverse_quantum_annealing.py +174 -0
  140. luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py +6 -0
  141. luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py +26 -0
  142. luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/config.py +80 -0
  143. luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/flex_qaoa.py +226 -0
  144. luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/optimizers.py +97 -0
  145. luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/pipeline.py +87 -0
  146. luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa.py +104 -0
  147. luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa_fo.py +69 -0
  148. luna_quantum/solve/parameters/algorithms/quantum_gate/vqe.py +109 -0
  149. luna_quantum/solve/parameters/algorithms/search_algorithms/__init__.py +5 -0
  150. luna_quantum/solve/parameters/algorithms/search_algorithms/dialectic_search.py +152 -0
  151. luna_quantum/solve/parameters/algorithms/search_algorithms/qbsolv_like_tabu_search.py +117 -0
  152. luna_quantum/solve/parameters/algorithms/search_algorithms/tabu_search.py +126 -0
  153. luna_quantum/solve/parameters/algorithms/simulated_annealing/__init__.py +13 -0
  154. luna_quantum/solve/parameters/algorithms/simulated_annealing/parallel_tempering.py +131 -0
  155. luna_quantum/solve/parameters/algorithms/simulated_annealing/population_annealing.py +95 -0
  156. luna_quantum/solve/parameters/algorithms/simulated_annealing/qbsolv_like_simulated_annealing.py +141 -0
  157. luna_quantum/solve/parameters/algorithms/simulated_annealing/repeated_reverse_simulated_annealing.py +172 -0
  158. luna_quantum/solve/parameters/algorithms/simulated_annealing/simulated_annealing.py +126 -0
  159. luna_quantum/solve/parameters/backends/__init__.py +20 -0
  160. luna_quantum/solve/parameters/backends/aqarios.py +17 -0
  161. luna_quantum/solve/parameters/backends/aws/__init__.py +11 -0
  162. luna_quantum/solve/parameters/backends/aws/aws.py +36 -0
  163. luna_quantum/solve/parameters/backends/aws/aws_backend_base.py +74 -0
  164. luna_quantum/solve/parameters/backends/aws/ionq.py +43 -0
  165. luna_quantum/solve/parameters/backends/aws/iqm.py +31 -0
  166. luna_quantum/solve/parameters/backends/aws/rigetti.py +31 -0
  167. luna_quantum/solve/parameters/backends/dwave.py +17 -0
  168. luna_quantum/solve/parameters/backends/dwave_qpu.py +164 -0
  169. luna_quantum/solve/parameters/backends/ibm.py +132 -0
  170. luna_quantum/solve/parameters/backends/qctrl.py +130 -0
  171. luna_quantum/solve/parameters/backends/zib.py +17 -0
  172. luna_quantum/solve/parameters/constants.py +11 -0
  173. luna_quantum/solve/parameters/mixins/__init__.py +0 -0
  174. luna_quantum/solve/parameters/mixins/fujitsu_common_params_mixin.py +239 -0
  175. luna_quantum/solve/parameters/mixins/fujitsu_v2_mixin.py +70 -0
  176. luna_quantum/solve/parameters/mixins/qbsolv_like_mixin.py +60 -0
  177. luna_quantum/solve/use_cases/__init__.py +119 -0
  178. luna_quantum/solve/use_cases/arbitrage_edge_based.py +50 -0
  179. luna_quantum/solve/use_cases/arbitrage_node_based.py +55 -0
  180. luna_quantum/solve/use_cases/base.py +7 -0
  181. luna_quantum/solve/use_cases/binary_integer_linear_programming.py +54 -0
  182. luna_quantum/solve/use_cases/binary_paint_shop_problem.py +37 -0
  183. luna_quantum/solve/use_cases/credit_scoring_feature_selection.py +40 -0
  184. luna_quantum/solve/use_cases/dynamic_portfolio_optimization.py +64 -0
  185. luna_quantum/solve/use_cases/exact_cover.py +51 -0
  186. luna_quantum/solve/use_cases/flight_gate_assignment.py +79 -0
  187. luna_quantum/solve/use_cases/graph_coloring.py +42 -0
  188. luna_quantum/solve/use_cases/graph_isomorphism.py +52 -0
  189. luna_quantum/solve/use_cases/graph_partitioning.py +46 -0
  190. luna_quantum/solve/use_cases/hamiltonian_cycle.py +49 -0
  191. luna_quantum/solve/use_cases/induced_subgraph_isomorphism.py +50 -0
  192. luna_quantum/solve/use_cases/job_shop_scheduling.py +44 -0
  193. luna_quantum/solve/use_cases/k_medoids_clustering.py +49 -0
  194. luna_quantum/solve/use_cases/knapsack_integer_weights.py +56 -0
  195. luna_quantum/solve/use_cases/linear_regression.py +60 -0
  196. luna_quantum/solve/use_cases/lmwcs.py +84 -0
  197. luna_quantum/solve/use_cases/longest_path.py +50 -0
  198. luna_quantum/solve/use_cases/market_graph_clustering.py +61 -0
  199. luna_quantum/solve/use_cases/max2sat.py +54 -0
  200. luna_quantum/solve/use_cases/max3sat.py +55 -0
  201. luna_quantum/solve/use_cases/max_clique.py +60 -0
  202. luna_quantum/solve/use_cases/max_cut.py +48 -0
  203. luna_quantum/solve/use_cases/max_independent_set.py +37 -0
  204. luna_quantum/solve/use_cases/minimal_maximal_matching.py +54 -0
  205. luna_quantum/solve/use_cases/minimal_spanning_tree.py +90 -0
  206. luna_quantum/solve/use_cases/minimum_vertex_cover.py +45 -0
  207. luna_quantum/solve/use_cases/number_partitioning.py +32 -0
  208. luna_quantum/solve/use_cases/portfolio_optimization.py +46 -0
  209. luna_quantum/solve/use_cases/portfolio_optimization_ib_tv.py +63 -0
  210. luna_quantum/solve/use_cases/quadratic_assignment.py +49 -0
  211. luna_quantum/solve/use_cases/quadratic_knapsack.py +48 -0
  212. luna_quantum/solve/use_cases/satellite_scheduling.py +73 -0
  213. luna_quantum/solve/use_cases/sensor_placement.py +58 -0
  214. luna_quantum/solve/use_cases/set_cover.py +56 -0
  215. luna_quantum/solve/use_cases/set_packing.py +54 -0
  216. luna_quantum/solve/use_cases/set_partitioning.py +52 -0
  217. luna_quantum/solve/use_cases/subgraph_isomorphism.py +55 -0
  218. luna_quantum/solve/use_cases/subset_sum.py +37 -0
  219. luna_quantum/solve/use_cases/support_vector_machine.py +64 -0
  220. luna_quantum/solve/use_cases/traffic_flow.py +35 -0
  221. luna_quantum/solve/use_cases/travelling_salesman_problem.py +53 -0
  222. luna_quantum/solve/use_cases/type_aliases.py +9 -0
  223. luna_quantum/solve/use_cases/weighted_max_cut.py +37 -0
  224. luna_quantum/solve/usecases/__init__.py +45 -0
  225. luna_quantum/solve/usecases/model_delete_usecase.py +49 -0
  226. luna_quantum/solve/usecases/model_fetch_metadata_usecase.py +50 -0
  227. luna_quantum/solve/usecases/model_get_solution_usecase.py +56 -0
  228. luna_quantum/solve/usecases/model_get_solve_jobs_usecase.py +62 -0
  229. luna_quantum/solve/usecases/model_load_by_id_usecase.py +47 -0
  230. luna_quantum/solve/usecases/model_load_by_metadata_usecase.py +52 -0
  231. luna_quantum/solve/usecases/model_load_metadata_by_hash_usecase.py +51 -0
  232. luna_quantum/solve/usecases/model_save_usecase.py +63 -0
  233. luna_quantum/solve/usecases/solve_job_cancel_usecase.py +51 -0
  234. luna_quantum/solve/usecases/solve_job_create_usecase.py +112 -0
  235. luna_quantum/solve/usecases/solve_job_delete_usecase.py +38 -0
  236. luna_quantum/solve/usecases/solve_job_fetch_updates_usecase.py +49 -0
  237. luna_quantum/solve/usecases/solve_job_get_result_usecase.py +97 -0
  238. luna_quantum/translator.py +1 -0
  239. luna_quantum/translator.pyi +833 -0
  240. luna_quantum/util/__init__.py +0 -0
  241. luna_quantum/util/active_waiting.py +79 -0
  242. luna_quantum/util/class_patcher.py +164 -0
  243. luna_quantum/util/log_utils.py +167 -0
  244. luna_quantum/util/pretty_base.py +67 -0
  245. luna_quantum/util/pydantic_utils.py +38 -0
  246. luna_quantum/utils.py +54 -0
  247. luna_quantum/utils.pyi +35 -0
  248. luna_quantum-1.0.0.dist-info/METADATA +37 -0
  249. luna_quantum-1.0.0.dist-info/RECORD +252 -0
  250. luna_quantum-1.0.0.dist-info/WHEEL +4 -0
  251. luna_quantum-1.0.0.dist-info/licenses/LICENSE +176 -0
  252. luna_quantum-1.0.0.dist-info/licenses/NOTICE +13 -0
@@ -0,0 +1,833 @@
1
+ from pathlib import Path
2
+ from typing import Any, overload
3
+
4
+ from dimod import BinaryQuadraticModel, ConstrainedQuadraticModel, SampleSet
5
+ from numpy.typing import NDArray
6
+ from pyscipopt import Model as SciModel
7
+ from qiskit.primitives import PrimitiveResult, PubResult
8
+ from qiskit_optimization import QuadraticProgram
9
+
10
+ from ._core import Environment, Model, Solution, Timing, Vtype
11
+
12
+ class ZibTranslator:
13
+ """
14
+ Utility class for converting between a Zib solution and our solution format.
15
+
16
+ `ZibTranslator` provides methods to:
17
+
18
+ - Convert a Zib-style solution into our solution `Solution`.
19
+
20
+ The conversions are especially required when interacting with external zib solvers/samplers or
21
+ libraries that operate on zib-based problem-solving/sampling.
22
+
23
+ Examples
24
+ --------
25
+ >>> import luna_quantum as lq
26
+ >>> from pyscipopt import Model
27
+ >>> model = Model()
28
+ >>> model.readProblem("./path/to/my/model.lp")
29
+ >>> model.optimize()
30
+ >>> aqs = lq.translator.ZibTranslator.to_aq(model)
31
+ """
32
+
33
+ @overload
34
+ @staticmethod
35
+ def to_aq(model: SciModel) -> Solution: ...
36
+ @overload
37
+ @staticmethod
38
+ def to_aq(model: SciModel, timing: Timing) -> Solution: ...
39
+ @overload
40
+ @staticmethod
41
+ def to_aq(model: SciModel, *, env: Environment) -> Solution: ...
42
+ @overload
43
+ @staticmethod
44
+ def to_aq(model: SciModel, timing: Timing, *, env: Environment) -> Solution: ...
45
+ @staticmethod
46
+ def to_aq(
47
+ model: SciModel, timing: Timing | None = ..., *, env: Environment | None = ...
48
+ ) -> Solution:
49
+ """
50
+ Extract a solution from a ZIB model.
51
+
52
+ Parameters
53
+ ----------
54
+ model : pyscipopt.Model
55
+ The Model that ran the optimization.
56
+ timing : Timing, optional
57
+ The timing object produced while generating the result.
58
+ env : Environment, optional
59
+ The environment of the model for which the result is produced.
60
+
61
+ Raises
62
+ ------
63
+ NoActiveEnvironmentFoundError
64
+ If no environment is passed to the method or available from the context.
65
+ SolutionTranslationError
66
+ Generally if the solution translation fails. Might be specified by one of the
67
+ two following errors.
68
+ SampleIncorrectLengthError
69
+ If a solution's sample has a different number of variables than the model
70
+ environment passed to the translator.
71
+ ModelVtypeError
72
+ If the result's variable types are incompatible with the model environment's
73
+ variable types.
74
+ """
75
+
76
+ class Qubo:
77
+ """
78
+ A wrapper around qubo matrices that holds all relevant metadata, e.g., the model offset.
79
+ """
80
+
81
+ @property
82
+ def matrix(self, /) -> NDArray:
83
+ """
84
+ The actual QUBO matrix.
85
+
86
+ Returns
87
+ -------
88
+ NDArray
89
+ A square NumPy array representing the QUBO matrix derived from
90
+ the model's objective.
91
+ """
92
+
93
+ @property
94
+ def variable_names(self, /) -> list[str]:
95
+ """
96
+ The name of the variables in the same order as in the QUBO matrix.
97
+
98
+ Returns
99
+ -------
100
+ list[Variable]
101
+ The variable names in the order they appear in the QUBO.
102
+ """
103
+
104
+ @property
105
+ def name(self, /) -> str:
106
+ """
107
+ The name of the model the QUBO matrix was generated from.
108
+
109
+ Returns
110
+ -------
111
+ str
112
+ The model name.
113
+ """
114
+
115
+ @property
116
+ def offset(self, /) -> float:
117
+ """
118
+ The constant offset of the original model passed to the QuboTranslator.
119
+
120
+ Returns
121
+ -------
122
+ float
123
+ The constant offset of the model.
124
+ """
125
+
126
+ @property
127
+ def vtype(self, /) -> Vtype:
128
+ """
129
+ The type of the model variables. Can be `Binary` or `Spin`.
130
+
131
+ Returns
132
+ -------
133
+ Vtype
134
+ The variable type.
135
+ """
136
+
137
+ class QuboTranslator:
138
+ """
139
+ Utility class for converting between dense QUBO matrices and symbolic models.
140
+
141
+ `QuboTranslator` provides methods to:
142
+ - Convert a NumPy-style QUBO matrix into a symbolic `Model`
143
+ - Convert a `Model` (with quadratic objective) into a dense QUBO matrix
144
+
145
+ These conversions are especially useful when interacting with external solvers
146
+ or libraries that operate on matrix-based problem definitions.
147
+
148
+ Examples
149
+ --------
150
+ >>> import numpy as np
151
+ >>> from luna_quantum import QuboTranslator, Vtype
152
+ >>> q = np.array([[1.0, -1.0], [-1.0, 2.0]])
153
+
154
+ Create a model from a matrix:
155
+
156
+ >>> model = QuboTranslator.to_aq(
157
+ ... q, offset=4.2, name="qubo_model", vtype=Vtype.Binary
158
+ ... )
159
+
160
+ Convert it back to a dense matrix:
161
+
162
+ >>> recovered = QuboTranslator.from_aq(model)
163
+ >>> assert np.allclose(q, recovered.matrix)
164
+ """
165
+
166
+ @staticmethod
167
+ def to_aq(
168
+ qubo: NDArray,
169
+ *,
170
+ offset: float | None = ...,
171
+ variable_names: list[str] | None = ...,
172
+ name: str | None = ...,
173
+ vtype: Vtype | None = ...,
174
+ ) -> Model:
175
+ """
176
+ Convert a dense QUBO matrix into a symbolic `Model`.
177
+
178
+ Parameters
179
+ ----------
180
+ qubo : NDArray
181
+ A square 2D NumPy array representing the QUBO matrix.
182
+ Diagonal entries correspond to linear coefficients;
183
+ off-diagonal entries represent pairwise quadratic terms.
184
+ name : str, optional
185
+ An optional name to assign to the resulting model.
186
+ vtype : Vtype, optional
187
+ The variable type to assign to all variables (e.g. Binary, Spin).
188
+
189
+ Returns
190
+ -------
191
+ Model
192
+ A symbolic model representing the given QUBO structure.
193
+
194
+ Raises
195
+ ------
196
+ TranslationError
197
+ Generally if the translation fails. Might be specified by the following
198
+ error.
199
+ VariableNamesError
200
+ If a list of variable names is provided but contains duplicates or has an
201
+ incorrect length.
202
+ """
203
+
204
+ @staticmethod
205
+ def from_aq(model: Model) -> Qubo:
206
+ """
207
+ Convert a symbolic model to a dense QUBO matrix representation.
208
+
209
+ Parameters
210
+ ----------
211
+ model : Model
212
+ The symbolic model to convert. The objective must be quadratic-only
213
+ and unconstrained.
214
+
215
+ Returns
216
+ -------
217
+ Qubo
218
+ An object representing a QUBO with information additional to the square NumPy array
219
+ representing the QUBO matrix derived from the model's objective. This object also
220
+ includes the `variable_ordering` as well as the `offset` of the original model.
221
+
222
+ Raises
223
+ ------
224
+ TranslationError
225
+ Generally if the translation fails. Might be specified by one of the
226
+ four following errors.
227
+ ModelNotQuadraticError
228
+ If the objective contains higher-order (non-quadratic) terms.
229
+ ModelNotUnconstrainedError
230
+ If the model contains any constraints.
231
+ ModelSenseNotMinimizeError
232
+ If the model's optimization sense is 'maximize'.
233
+ ModelVtypeError
234
+ If the model contains different vtypes or vtypes other than binary and
235
+ spin.
236
+ """
237
+
238
+ class QctrlTranslator:
239
+ """
240
+ Utility class for converting between a QCTRL solution and our solution format.
241
+
242
+ `QctrlTranslator` provides methods to:
243
+ - Convert a Qctrl-style solution into our solution `Solution`.
244
+
245
+ The conversions are especially required when interacting with external qctrl solvers/samplers or
246
+ libraries that operate on qctrl-based problem-solving/sampling.
247
+
248
+ Examples
249
+ --------
250
+ >>> import luna_quantum as lq
251
+ >>> ...
252
+ >>> qctrl_result = ...
253
+ >>> aqs = lq.translator.QctrlTranslator.to_aq(qctrl_result)
254
+ """
255
+
256
+ @overload
257
+ @staticmethod
258
+ def to_aq(result: dict[str, Any]) -> Solution: ...
259
+ @overload
260
+ @staticmethod
261
+ def to_aq(result: dict[str, Any], timing: Timing) -> Solution: ...
262
+ @overload
263
+ @staticmethod
264
+ def to_aq(result: dict[str, Any], *, env: Environment) -> Solution: ...
265
+ @overload
266
+ @staticmethod
267
+ def to_aq(
268
+ result: dict[str, Any], timing: Timing, *, env: Environment
269
+ ) -> Solution: ...
270
+ @staticmethod
271
+ def to_aq(
272
+ result: dict[str, Any],
273
+ timing: Timing | None = ...,
274
+ *,
275
+ env: Environment | None = ...,
276
+ ) -> Solution:
277
+ """
278
+ Convert a QCTRL result to our solution format.
279
+
280
+ Parameters
281
+ ----------
282
+ result : dict[str, Any]
283
+ The qctrl result as a dictionary.
284
+ timing : Timing, optional
285
+ The timing object produced while generating the result.
286
+ env : Environment, optional
287
+ The environment of the model for which the result is produced.
288
+
289
+ Raises
290
+ ------
291
+ NoActiveEnvironmentFoundError
292
+ If no environment is passed to the method or available from the context.
293
+ SolutionTranslationError
294
+ Generally if the solution translation fails. Might be specified by one of the
295
+ two following errors.
296
+ SampleIncorrectLengthError
297
+ If a solution's sample has a different number of variables than the model
298
+ environment passed to the translator.
299
+ ModelVtypeError
300
+ If the result's variable types are incompatible with the model environment's
301
+ variable types.
302
+ """
303
+
304
+ class NumpyTranslator:
305
+ """
306
+ Utility class for converting between a result consisting of numpy arrays and our solution
307
+ format.
308
+
309
+ `NumpyTranslator` provides methods to:
310
+ - Convert a numpy-array result into our solution `Solution`.
311
+
312
+ Examples
313
+ --------
314
+ >>> import luna_quantum as lq
315
+ >>> from numpy.typing import NDArray
316
+ >>> result: NDArray = ...
317
+ >>> energies: NDArray = ...
318
+ >>> aqs = lq.translator.NumpyTranslator.to_aq(result, energies)
319
+ """
320
+
321
+ @overload
322
+ @staticmethod
323
+ def to_aq(result: NDArray, energies: NDArray) -> Solution: ...
324
+ @overload
325
+ @staticmethod
326
+ def to_aq(result: NDArray, energies: NDArray, timing: Timing) -> Solution: ...
327
+ @overload
328
+ @staticmethod
329
+ def to_aq(result: NDArray, energies: NDArray, *, env: Environment) -> Solution: ...
330
+ @overload
331
+ @staticmethod
332
+ def to_aq(
333
+ result: NDArray, energies: NDArray, timing: Timing, *, env: Environment
334
+ ) -> Solution: ...
335
+ @staticmethod
336
+ def to_aq(
337
+ result: NDArray,
338
+ energies: NDArray,
339
+ timing: Timing | None = ...,
340
+ *,
341
+ env: Environment | None = ...,
342
+ ) -> Solution:
343
+ """
344
+ Convert an IBM solution to our solution format.
345
+
346
+ Parameters
347
+ ----------
348
+ result : NDArray
349
+ The samples as a 2D array where each row corresponds to one sample.
350
+ energies : NDArray
351
+ The energies of the single samples as a 1D array.
352
+ timing : Timing, optional
353
+ The timing object produced while generating the result.
354
+ env : Environment, optional
355
+ The environment of the model for which the result is produced.
356
+
357
+ Raises
358
+ ------
359
+ NoActiveEnvironmentFoundError
360
+ If no environment is passed to the method or available from the context.
361
+ SolutionTranslationError
362
+ Generally if the solution translation fails. Might be specified by one of the
363
+ two following errors.
364
+ SampleIncorrectLengthError
365
+ If a solution's sample has a different number of variables than the model
366
+ environment passed to the translator.
367
+ ModelVtypeError
368
+ If the result's variable types are incompatible with the model environment's
369
+ variable types.
370
+ """
371
+
372
+ class LpTranslator:
373
+ """
374
+ Utility class for converting between LP files and symbolic models.
375
+
376
+ `LpTranslator` provides methods to:
377
+ - Convert an LP file into a symbolic `Model`
378
+ - Convert a `Model` into an Lp file.
379
+
380
+ These conversions are especially useful when interacting with external solvers
381
+ or libraries that operate on LP-based problem definitions.
382
+
383
+ Examples
384
+ --------
385
+ >>> from pathlib import Path
386
+ >>> from luna_quantum import LpTranslator
387
+ >>> lp_filepath = Path("path/to/the/lp_file")
388
+
389
+ >>> model = LpTranslator.to_aq(lp_filepath)
390
+
391
+ Convert it back to an LP file:
392
+
393
+ >>> recovered = LpTranslator.to_file(model)
394
+ """
395
+
396
+ @overload
397
+ @staticmethod
398
+ def to_aq(file: Path) -> Model: ...
399
+ @overload
400
+ @staticmethod
401
+ def to_aq(file: str) -> Model:
402
+ """
403
+ Convert an LP file into a symbolic `Model`.
404
+
405
+ Parameters
406
+ ----------
407
+ file: Path | String
408
+ An LP file representing a symbolic model, either given as a
409
+ Path object to the LP file or its contents as a string.
410
+ If you pass the path as a string, it will be interpreted as a
411
+ model and thus fail to be parsed to a Model.
412
+
413
+ Returns
414
+ -------
415
+ Model
416
+ A symbolic model representing the given lp file structure.
417
+
418
+ Raises
419
+ ------
420
+ TypeError
421
+ If `file` is not of type `str` or `Path`.
422
+ TranslationError
423
+ If the translation fails for a different reason.
424
+ """
425
+
426
+ @overload
427
+ @staticmethod
428
+ def from_aq(model: Model) -> str: ...
429
+ @overload
430
+ @staticmethod
431
+ def from_aq(model: Model, *, filepath: Path) -> None:
432
+ """
433
+ Convert a symbolic model to an LP file representation.
434
+
435
+ Parameters
436
+ ----------
437
+ model : Model
438
+ The symbolic model to convert.
439
+ file : Path, optional
440
+ The filepath to write the model contents to.
441
+
442
+ Returns
443
+ -------
444
+ str
445
+ If no file to write to is given, i.e., the file is None.
446
+
447
+ Raises
448
+ ------
449
+ TranslationError
450
+ If the translation fails for some reason.
451
+ """
452
+
453
+ class IbmTranslator:
454
+ """
455
+ Utility class for converting between an IBM solution and our solution format.
456
+
457
+ `IbmTranslator` provides methods to:
458
+ - Convert an IBM-style solution into our solution `Solution`.
459
+
460
+ The conversions are especially required when interacting with external ibm solvers/samplers or
461
+ libraries that operate on ibm-based problem-solving/sampling.
462
+
463
+ Examples
464
+ --------
465
+ >>> import luna_quantum as lq
466
+ >>> ...
467
+ >>> ibm_result = ...
468
+ >>> aqs = lq.translator.IbmTranslator.to_aq(ibm_result)
469
+ """
470
+
471
+ @overload
472
+ @staticmethod
473
+ def to_aq(
474
+ result: PrimitiveResult[PubResult], quadratic_program: QuadraticProgram
475
+ ) -> Solution: ...
476
+ @overload
477
+ @staticmethod
478
+ def to_aq(
479
+ result: PrimitiveResult[PubResult],
480
+ quadratic_program: QuadraticProgram,
481
+ timing: Timing,
482
+ ) -> Solution: ...
483
+ @overload
484
+ @staticmethod
485
+ def to_aq(
486
+ result: PrimitiveResult[PubResult],
487
+ quadratic_program: QuadraticProgram,
488
+ *,
489
+ env: Environment,
490
+ ) -> Solution: ...
491
+ @overload
492
+ @staticmethod
493
+ def to_aq(
494
+ result: PrimitiveResult[PubResult],
495
+ quadratic_program: QuadraticProgram,
496
+ timing: Timing,
497
+ *,
498
+ env: Environment,
499
+ ) -> Solution: ...
500
+ @staticmethod
501
+ def to_aq(
502
+ result: PrimitiveResult[PubResult],
503
+ quadratic_program: QuadraticProgram,
504
+ timing: Timing | None = ...,
505
+ *,
506
+ env: Environment | None = ...,
507
+ ) -> Solution:
508
+ """
509
+ Convert an IBM solution to our solution format.
510
+
511
+ Parameters
512
+ ----------
513
+ result : PrimitiveResult[PubResult]
514
+ The ibm result.
515
+ quadratic_program : QuadraticProgram
516
+ The quadratic program defining the optimization problem.
517
+ timing : Timing, optional
518
+ The timing object produced while generating the result.
519
+ env : Environment, optional
520
+ The environment of the model for which the result is produced.
521
+
522
+ Raises
523
+ ------
524
+ NoActiveEnvironmentFoundError
525
+ If no environment is passed to the method or available from the context.
526
+ SolutionTranslationError
527
+ Generally if the solution translation fails. Might be specified by one of the
528
+ two following errors.
529
+ SampleIncorrectLengthError
530
+ If a solution's sample has a different number of variables than the model
531
+ environment passed to the translator.
532
+ ModelVtypeError
533
+ If the result's variable types are incompatible with the model environment's
534
+ variable types.
535
+ """
536
+
537
+ class DwaveTranslator:
538
+ """
539
+ Utility class for converting between a DWAVE solution and our solution format.
540
+
541
+ `DWaveSolutionTranslator` provides methods to:
542
+ - Convert a dimod-style solution into our solution `Solution`.
543
+
544
+ The conversions are especially required when interacting with external dwave/dimod
545
+ solvers/samplers or libraries that operate on dwave/dimod-based problem-solving/sampling.
546
+
547
+ Examples
548
+ --------
549
+ >>> import dimod
550
+ >>> import luna_quantum as lq
551
+ >>> dwave_sampleset = ...
552
+ >>> aqs = lq.translator.DwaveTranslator.to_aq(dwave_sampleset)
553
+ """
554
+
555
+ @overload
556
+ @staticmethod
557
+ def to_aq(sample_set: SampleSet) -> Solution: ...
558
+ @overload
559
+ @staticmethod
560
+ def to_aq(sample_set: SampleSet, timing: Timing) -> Solution: ...
561
+ @overload
562
+ @staticmethod
563
+ def to_aq(sample_set: SampleSet, *, env: Environment) -> Solution: ...
564
+ @overload
565
+ @staticmethod
566
+ def to_aq(
567
+ sample_set: SampleSet, timing: Timing, *, env: Environment
568
+ ) -> Solution: ...
569
+ @staticmethod
570
+ def to_aq(
571
+ sample_set: SampleSet,
572
+ timing: Timing | None = ...,
573
+ *,
574
+ env: Environment | None = ...,
575
+ ) -> Solution:
576
+ """
577
+ Convert a DWave SampleSet to our solution format.
578
+
579
+ Parameters
580
+ ----------
581
+ sample_set : SampleSet
582
+ The SampleSet returned by a DWave solver.
583
+ timing : Timing, optional
584
+ The timing object produced while generating the result.
585
+ env : Environment, optional
586
+ The environment of the model for which the result is produced.
587
+
588
+ Raises
589
+ ------
590
+ NoActiveEnvironmentFoundError
591
+ If no environment is passed to the method or available from the context.
592
+ SolutionTranslationError
593
+ Generally if the solution translation fails. Might be specified by one of the
594
+ two following errors.
595
+ SampleIncorrectLengthError
596
+ If a solution's sample has a different number of variables than the model
597
+ environment passed to the translator.
598
+ ModelVtypeError
599
+ If the result's variable types are incompatible with the model environment's
600
+ variable types.
601
+ """
602
+
603
+ class CqmTranslator:
604
+ """
605
+ Utility class for converting between dimod.BinaryQuadraticModel (CQM) and symbolic
606
+ models.
607
+
608
+ `CqmTranslator` provides methods to:
609
+ - Convert a CQM into a symbolic `Model`
610
+ - Convert a `Model` (with quadratic objective) into a CQM
611
+
612
+ These conversions are especially useful when interacting with external solvers
613
+ or libraries that operate on CQMs.
614
+
615
+ Examples
616
+ --------
617
+ >>> import dimod
618
+ >>> import numpy as np
619
+ >>> from luna_quantum import CqmTranslator, Vtype
620
+ >>> bqm = dimod.generators.gnm_random_bqm(5, 10, "BINARY")
621
+
622
+ Create a model from a matrix:
623
+
624
+ >>> model = CqmTranslator.to_aq(bqm, name="bqm_model")
625
+
626
+ Convert it back to a dense matrix:
627
+
628
+ >>> recovered = CqmTranslator.from_aq(model)
629
+ """
630
+
631
+ @staticmethod
632
+ def to_aq(cqm: ConstrainedQuadraticModel) -> Model:
633
+ """
634
+ Convert a CQM into a symbolic `Model`.
635
+
636
+ Parameters
637
+ ----------
638
+ cqm : ConstrainedQuadraticModel
639
+ The CQM.
640
+
641
+ Returns
642
+ -------
643
+ Model
644
+ A symbolic model representing the given CQM.
645
+
646
+ Raises
647
+ ------
648
+ TypeError
649
+ If `cqm` is not of type `ConstrainedQuadraticModel`.
650
+ TranslationError
651
+ If the translation fails for some reason.
652
+ """
653
+ @staticmethod
654
+ def from_aq(model: Model) -> ConstrainedQuadraticModel:
655
+ """
656
+ Convert a symbolic model to a dense QUBO matrix representation.
657
+
658
+ Parameters
659
+ ----------
660
+ model : Model
661
+ The symbolic model to convert. The objective must be quadratic-only
662
+ and unconstrained.
663
+
664
+ Returns
665
+ -------
666
+ BinaryQuadraticModel
667
+ The resulting CQM.
668
+
669
+ Raises
670
+ ------
671
+ TranslationError
672
+ If the translation fails for some reason.
673
+ """
674
+
675
+ class BqmTranslator:
676
+ """
677
+ Utility class for converting between dimod.BinaryQuadraticModel (BQM) and symbolic
678
+ models.
679
+
680
+ `BqmTranslator` provides methods to:
681
+ - Convert a BQM into a symbolic `Model`
682
+ - Convert a `Model` (with quadratic objective) into a BQM
683
+
684
+ These conversions are especially useful when interacting with external solvers
685
+ or libraries that operate on BQMs.
686
+
687
+ Examples
688
+ --------
689
+ >>> import dimod
690
+ >>> import numpy as np
691
+ >>> from luna_quantum import BqmTranslator, Vtype
692
+ >>> bqm = dimod.generators.gnm_random_bqm(5, 10, "BINARY")
693
+
694
+ Create a model from a matrix:
695
+
696
+ >>> model = BqmTranslator.to_aq(bqm, name="bqm_model")
697
+
698
+ Convert it back to a dense matrix:
699
+
700
+ >>> recovered = BqmTranslator.from_aq(model)
701
+ """
702
+
703
+ @overload
704
+ @staticmethod
705
+ def to_aq(bqm: BinaryQuadraticModel) -> Model: ...
706
+ @overload
707
+ @staticmethod
708
+ def to_aq(bqm: BinaryQuadraticModel, *, name: str) -> Model:
709
+ """
710
+ Convert a BQM into a symbolic `Model`.
711
+
712
+ Parameters
713
+ ----------
714
+ bqm : BinaryQuadraticModel
715
+ The BQM.
716
+ name : str, optional
717
+ An optional name to assign to the resulting model.
718
+
719
+ Returns
720
+ -------
721
+ Model
722
+ A symbolic model representing the given BQM.
723
+ """
724
+ @staticmethod
725
+ def from_aq(model: Model) -> BinaryQuadraticModel:
726
+ """
727
+ Convert a symbolic model to a dense QUBO matrix representation.
728
+
729
+ Parameters
730
+ ----------
731
+ model : Model
732
+ The symbolic model to convert. The objective must be quadratic-only
733
+ and unconstrained.
734
+
735
+ Returns
736
+ -------
737
+ BinaryQuadraticModel
738
+ The resulting BQM.
739
+
740
+ Raises
741
+ ------
742
+ TranslationError
743
+ Generally if the translation fails. Might be specified by one of the
744
+ four following errors.
745
+ ModelNotQuadraticError
746
+ If the objective contains higher-order (non-quadratic) terms.
747
+ ModelNotUnconstrainedError
748
+ If the model contains any constraints.
749
+ ModelSenseNotMinimizeError
750
+ If the model's optimization sense is 'maximize'.
751
+ ModelVtypeError
752
+ If the model contains different vtypes or vtypes other than binary and
753
+ spin.
754
+ """
755
+
756
+ class AwsTranslator:
757
+ """
758
+ Utility class for converting between an AWS result and our solution format.
759
+
760
+ `AwsTranslator` provides methods to:
761
+ - Convert an AWS-style result into our solution `Solution`.
762
+
763
+ The conversions are especially required when interacting with external aws solvers/samplers or
764
+ libraries that operate on aws-based problem-solving/sampling.
765
+
766
+ Examples
767
+ --------
768
+ >>> import luna_quantum as lq
769
+ >>> aws_result = ...
770
+ >>> aqs = lq.translator.AwsTranslator.to_aq(aws_result)
771
+ """
772
+
773
+ @overload
774
+ @staticmethod
775
+ def to_aq(result: dict[str, Any]) -> Solution: ...
776
+ @overload
777
+ @staticmethod
778
+ def to_aq(result: dict[str, Any], timing: Timing) -> Solution: ...
779
+ @overload
780
+ @staticmethod
781
+ def to_aq(result: dict[str, Any], *, env: Environment) -> Solution: ...
782
+ @overload
783
+ @staticmethod
784
+ def to_aq(
785
+ result: dict[str, Any], timing: Timing, *, env: Environment
786
+ ) -> Solution: ...
787
+ @staticmethod
788
+ def to_aq(
789
+ result: dict[str, Any],
790
+ timing: Timing | None = ...,
791
+ *,
792
+ env: Environment | None = ...,
793
+ ) -> Solution:
794
+ """
795
+ Convert an AWS Braket result to our solution format.
796
+
797
+ Parameters
798
+ ----------
799
+ result : dict[str, Any]
800
+ The aws braket result.
801
+ timing : Timing, optional
802
+ The timing object produced while generating the result.
803
+ env : Environment, optional
804
+ The environment of the model for which the result is produced.
805
+
806
+ Raises
807
+ ------
808
+ NoActiveEnvironmentFoundError
809
+ If no environment is passed to the method or available from the context.
810
+ SolutionTranslationError
811
+ Generally if the solution translation fails. Might be specified by one of the
812
+ two following errors.
813
+ SampleIncorrectLengthError
814
+ If a solution's sample has a different number of variables than the model
815
+ environment passed to the translator.
816
+ ModelVtypeError
817
+ If the result's variable types are incompatible with the model environment's
818
+ variable types.
819
+ """
820
+
821
+ __all__ = [
822
+ "AwsTranslator",
823
+ "BqmTranslator",
824
+ "CqmTranslator",
825
+ "DwaveTranslator",
826
+ "IbmTranslator",
827
+ "LpTranslator",
828
+ "NumpyTranslator",
829
+ "QctrlTranslator",
830
+ "Qubo",
831
+ "QuboTranslator",
832
+ "ZibTranslator",
833
+ ]