luna-quantum 1.0.4rc1__cp311-cp311-win_amd64.whl → 1.0.4rc3__cp311-cp311-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.

Potentially problematic release.


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

Binary file
@@ -0,0 +1,247 @@
1
+ """Decorators."""
2
+
3
+ from collections.abc import Callable
4
+ from typing import Any, Generic, TypeVar, override
5
+
6
+ from . import Model, Solution
7
+ from .transformations import (
8
+ ActionType,
9
+ AnalysisCache,
10
+ AnalysisPass,
11
+ BasePass,
12
+ MetaAnalysisPass,
13
+ TransformationOutcome,
14
+ TransformationPass,
15
+ )
16
+
17
+ T = TypeVar("T")
18
+
19
+
20
+ type AnalysisSignature[T] = Callable[[Model, AnalysisCache], T]
21
+
22
+ type MetaAnalysisSignature[T] = Callable[[list[BasePass], AnalysisCache], T]
23
+
24
+ type Outcome = (
25
+ TransformationOutcome | tuple[Model, ActionType] | tuple[Model, ActionType, Any]
26
+ )
27
+ type TransformationSignature = Callable[
28
+ [Model, AnalysisCache],
29
+ Outcome,
30
+ ]
31
+ type BackwardsSignature = Callable[[Solution, AnalysisCache], Solution]
32
+
33
+
34
+ def __identity_backwards(solution: Solution, _: AnalysisCache) -> Solution:
35
+ return solution
36
+
37
+
38
+ class DynamicAnalysisPass(AnalysisPass, Generic[T]):
39
+ def __init__(
40
+ self,
41
+ name: str,
42
+ requires: list[str],
43
+ func: AnalysisSignature[T],
44
+ ) -> None:
45
+ self._name = name
46
+ self._requires = requires
47
+ self._func = func
48
+
49
+ @property
50
+ def name(self) -> str:
51
+ return self._name
52
+
53
+ @property
54
+ def requires(self) -> list[str]:
55
+ return self._requires
56
+
57
+ def __repr__(self) -> str:
58
+ return f'FunctionAnalysis(name="{self.name}")'
59
+
60
+ @override
61
+ def run(self, model: Model, cache: AnalysisCache) -> T:
62
+ return self._func(model, cache)
63
+
64
+ def __call__(self, model: Model, cache: AnalysisCache) -> T:
65
+ return self._func(model, cache)
66
+
67
+
68
+ class DynamicMetaAnalysisPass(MetaAnalysisPass, Generic[T]):
69
+ def __init__(
70
+ self,
71
+ name: str,
72
+ requires: list[str],
73
+ func: MetaAnalysisSignature[T],
74
+ ) -> None:
75
+ self._name = name
76
+ self._requires = requires
77
+ self._func = func
78
+
79
+ @property
80
+ def name(self) -> str:
81
+ return self._name
82
+
83
+ @property
84
+ def requires(self) -> list[str]:
85
+ return self._requires
86
+
87
+ def __repr__(self) -> str:
88
+ return f'FunctionMetaAnalysis(name="{self.name}")'
89
+
90
+ @override
91
+ def run(self, passes: list[BasePass], cache: AnalysisCache) -> T:
92
+ return self._func(passes, cache)
93
+
94
+ def __call__(self, passes: list[BasePass], cache: AnalysisCache) -> T:
95
+ return self._func(passes, cache)
96
+
97
+
98
+ class DynamicTransformationPass(TransformationPass):
99
+ def __init__(
100
+ self,
101
+ name: str,
102
+ requires: list[str],
103
+ invalidates: list[str],
104
+ func: TransformationSignature,
105
+ backwards: BackwardsSignature,
106
+ ) -> None:
107
+ self._name = name
108
+ self._requires = requires
109
+ self._invalidates = invalidates
110
+ self._func = func
111
+ self._backwards = backwards
112
+
113
+ @property
114
+ def name(self) -> str:
115
+ return self._name
116
+
117
+ @property
118
+ def requires(self) -> list[str]:
119
+ return self._requires
120
+
121
+ @override
122
+ def run(self, model: Model, cache: AnalysisCache) -> Outcome:
123
+ return self._func(model, cache)
124
+
125
+ @override
126
+ def backwards(self, solution: Solution, cache: AnalysisCache) -> Solution:
127
+ return self._backwards(solution, cache)
128
+
129
+ def __call__(self, model: Model, cache: AnalysisCache) -> Outcome:
130
+ return self._func(model, cache)
131
+
132
+ def __repr__(self) -> str:
133
+ return f'FunctionTransformation(name="{self.name}")'
134
+
135
+
136
+ def analyse(
137
+ name: str | None = None, requires: list[str] | None = None
138
+ ) -> Callable[[AnalysisSignature[T]], DynamicAnalysisPass[T]]:
139
+ """Create an AnalysisPass instance from a function.
140
+
141
+ Parameters
142
+ ----------
143
+ name: str | None
144
+ The name of the analysis pass. If no name provided, uses the function name.
145
+ requires: list[str] | None
146
+ List of required analysis passes (defaults to empty list)
147
+
148
+ Returns
149
+ -------
150
+ Callable[[Callable[[Model, AnalysisCache], Any]], AnalysisPass]
151
+ An instance of a dynamically created AnalysisPass subclass
152
+ """
153
+ if requires is None:
154
+ requires = []
155
+
156
+ _T = TypeVar("_T")
157
+
158
+ def _decorator(
159
+ func: AnalysisSignature[_T],
160
+ ) -> DynamicAnalysisPass[_T]:
161
+ loc_name = name or func.__name__.replace("_", "-")
162
+
163
+ return DynamicAnalysisPass(name=loc_name, requires=requires, func=func)
164
+
165
+ return _decorator
166
+
167
+
168
+ def meta_analyse(
169
+ name: str | None = None, requires: list[str] | None = None
170
+ ) -> Callable[[MetaAnalysisSignature[T]], DynamicMetaAnalysisPass[T]]:
171
+ """Create an MetaAnalysisPass instance from a function.
172
+
173
+ Parameters
174
+ ----------
175
+ name: str | None
176
+ The name of the analysis pass. If no name provided, uses the function name.
177
+ requires: list[str] | None
178
+ List of required analysis passes (defaults to empty list)
179
+
180
+ Returns
181
+ -------
182
+ Callable[[Callable[[list[BasePass], AnalysisCache], Any]], MetaAnalysisPass]
183
+ An instance of a dynamically created AnalysisPass subclass
184
+ """
185
+ if requires is None:
186
+ requires = []
187
+
188
+ _T = TypeVar("_T")
189
+
190
+ def _decorator(
191
+ func: MetaAnalysisSignature[_T],
192
+ ) -> DynamicMetaAnalysisPass[_T]:
193
+ loc_name = name or func.__name__.replace("_", "-")
194
+
195
+ return DynamicMetaAnalysisPass(name=loc_name, requires=requires, func=func)
196
+
197
+ return _decorator
198
+
199
+
200
+ def transform(
201
+ name: str | None = None,
202
+ requires: list[str] | None = None,
203
+ invalidates: list[str] | None = None,
204
+ backwards: BackwardsSignature | None = None,
205
+ ) -> Callable[[TransformationSignature], DynamicTransformationPass]:
206
+ """Create an TransformationPass instance from a function.
207
+
208
+ Parameters
209
+ ----------
210
+ name: str | None = None
211
+ The name of the analysis pass. If no name provided, uses the function name.
212
+ requires: list[str] | None = None
213
+ List of required analysis passes (defaults to empty list)
214
+ invalidates: list[str] | None = None
215
+ List of analysis results to invalidate (defaults to empty list)
216
+ backwards: BackwardsSignature | None = None,
217
+ Solution backwards mapping function. If none provided, pass solution upstream
218
+ without modification.
219
+
220
+ Returns
221
+ -------
222
+ Callable[[TransformationSignature], DynamicTransformationPass]
223
+ An instance of a dynamically created TransformationPass subclass
224
+ """
225
+ if requires is None:
226
+ requires = []
227
+ if invalidates is None:
228
+ invalidates = []
229
+
230
+ if backwards is None:
231
+ backwards = __identity_backwards
232
+
233
+ def _decorator(func: TransformationSignature) -> DynamicTransformationPass:
234
+ loc_name = name or func.__name__.replace("_", "-")
235
+
236
+ return DynamicTransformationPass(
237
+ name=loc_name,
238
+ requires=requires,
239
+ invalidates=invalidates,
240
+ func=func,
241
+ backwards=backwards,
242
+ )
243
+
244
+ return _decorator
245
+
246
+
247
+ __all__ = ["analyse", "transform"]
@@ -3,7 +3,7 @@ from collections.abc import Callable
3
3
  from enum import Enum
4
4
  from typing import Any, Literal, overload
5
5
 
6
- from aqmodels import Model, Sense, Solution, Timing, Vtype
6
+ from . import Model, Sense, Solution, Timing, Vtype
7
7
 
8
8
  class BasePass:
9
9
  @property
luna_quantum/utils.pyi CHANGED
@@ -1,7 +1,7 @@
1
1
  from collections.abc import Generator, Iterable
2
2
  from typing import overload
3
3
 
4
- from aqmodels import Expression, Variable
4
+ from . import Expression, Variable
5
5
 
6
6
  @overload
7
7
  def quicksum(iterable: Generator[Expression], /) -> Expression: ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: luna-quantum
3
- Version: 1.0.4rc1
3
+ Version: 1.0.4rc3
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: License :: OSI Approved :: Apache Software License
6
6
  Classifier: Operating System :: OS Independent
@@ -1,10 +1,10 @@
1
- luna_quantum-1.0.4rc1.dist-info/METADATA,sha256=Tg6Xtt1UIfDkUnxq6bBmPCP9MT7JYsa1rJsm66P61WE,1585
2
- luna_quantum-1.0.4rc1.dist-info/WHEEL,sha256=Ncll1xfKuKRSH9zs2vSEuHQoNZLcJWpzadJbiEni0qk,96
3
- luna_quantum-1.0.4rc1.dist-info/licenses/LICENSE,sha256=bR2Wj7Il7KNny38LiDGrASo12StUfpReF--OewXD5cw,10349
4
- luna_quantum-1.0.4rc1.dist-info/licenses/NOTICE,sha256=GHZYA5H4QFAhbhXliAi2SjWWXLjxl4hrHdEPyUbC0r0,601
1
+ luna_quantum-1.0.4rc3.dist-info/METADATA,sha256=0SVGFwI5zmYCuJShMOP6PA6cnWR6xJLRm4uBzGYHEy4,1585
2
+ luna_quantum-1.0.4rc3.dist-info/WHEEL,sha256=Ncll1xfKuKRSH9zs2vSEuHQoNZLcJWpzadJbiEni0qk,96
3
+ luna_quantum-1.0.4rc3.dist-info/licenses/LICENSE,sha256=bR2Wj7Il7KNny38LiDGrASo12StUfpReF--OewXD5cw,10349
4
+ luna_quantum-1.0.4rc3.dist-info/licenses/NOTICE,sha256=GHZYA5H4QFAhbhXliAi2SjWWXLjxl4hrHdEPyUbC0r0,601
5
5
  luna_quantum/__init__.py,sha256=9Dpk-wfL5fR_R74c-JsFKZmUy7OUfe4hj4ZXEJaPAt4,3342
6
6
  luna_quantum/__init__.pyi,sha256=9Md6njbzsErrktv0GlRGYSunQIrIyw5r0kEJx1yMpkw,1746
7
- luna_quantum/_core.cp311-win_amd64.pyd,sha256=5ui4_hE-v3eOzT7uiwd9yLWB9WvomiZzVIF2kAlQkKY,5993984
7
+ luna_quantum/_core.cp311-win_amd64.pyd,sha256=DooaabF_Grh0VVyqOZvj-esP20tKy-1wdV6nsTQjGoE,5996032
8
8
  luna_quantum/_core.pyi,sha256=mezdmnUnyZqfYqFIKG4a1UtM3A6Y4RqSNqdybbH9q-E,117664
9
9
  luna_quantum/algorithms/__init__.py,sha256=EoTNO0FXXjPrhpYfN7q9c_nUhmVHk2nEZsbhaVOBh_g,70
10
10
  luna_quantum/aqm_overwrites/__init__.py,sha256=ieIVhfslOwrznbvwqu3vNzU_nFIHS1hyeUgIV097WdQ,49
@@ -81,6 +81,7 @@ luna_quantum/client/schemas/wrappers/datetime_wrapper.py,sha256=11KmaftPtKoafhcg
81
81
  luna_quantum/client/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
82
82
  luna_quantum/client/utils/qpu_token_utils.py,sha256=goq4nwmxKz0GTqLep01ydoopqHb336FPv6CXGGtR260,4915
83
83
  luna_quantum/config.py,sha256=a5UgYn6TIT2pFfdprvDy0RzyI4eAI_OFSdFSxpjQr2M,228
84
+ luna_quantum/decorators.py,sha256=h9APzB-s3p_kCf0LfBPjG23hlswcWZfupK492DxUoJc,7084
84
85
  luna_quantum/errors.py,sha256=9qeMJY-hI1qlBqrWjaESVGx3ujEQuFdqONGgIl107kk,1458
85
86
  luna_quantum/errors.pyi,sha256=tf4cDmBtbE6Mjujl3B3nbT1zQzLM__iS9neFYA3chv4,9579
86
87
  luna_quantum/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -244,7 +245,7 @@ luna_quantum/solve/usecases/solve_job_delete_usecase.py,sha256=a-lo9CoWjePo-aq7Y
244
245
  luna_quantum/solve/usecases/solve_job_fetch_updates_usecase.py,sha256=9vcs3x5uLmBjkqSF12IMHrPjrPSodm0AHI0qPVAruNE,1735
245
246
  luna_quantum/solve/usecases/solve_job_get_result_usecase.py,sha256=_62COwl-I1iGaX2lfrUnmZmPyKJZRNrJGtRVBiW1SYc,3636
246
247
  luna_quantum/transformations.py,sha256=A00BqmKpZz1Ixrb77a_ynpuqtB7w-AlVshg-QHp2UwM,920
247
- luna_quantum/transformations.pyi,sha256=GwrS0LBFoFuDJvtnjHWgrtZ-2mlEvWFQfSrYiaMkV40,11142
248
+ luna_quantum/transformations.pyi,sha256=XjLxMhYGAeHABq19SHDBOTDEsOcHaBgTBQzlJ-5SxpQ,11135
248
249
  luna_quantum/translator.py,sha256=5RDTzFzd5sw3JzxFQsHdZQWhz2KDl03nzik5dUHebHI,1157
249
250
  luna_quantum/translator.pyi,sha256=RcePKY4Ztw-uv0Dfyx2DTw1TBMyem_SWts1MmzYZfn0,27347
250
251
  luna_quantum/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -255,5 +256,5 @@ luna_quantum/util/log_utils.py,sha256=0-ARoGkp7xyTvw1i-pRJoq1ylDKNC4eDoVY2DG05DS
255
256
  luna_quantum/util/pretty_base.py,sha256=rJy28OKfNdB1j5xdzOmFrCdbw-Gb-JJ5Dcz3NvOpIcQ,2182
256
257
  luna_quantum/util/pydantic_utils.py,sha256=KipyyVaajjFB-krdPl_j5BLogaiPqn0L8mrJuLwZtic,1301
257
258
  luna_quantum/utils.py,sha256=RlF0LFK0qXavL22BSjMuNcGBGJrEL8mde_rAPX66qhw,137
258
- luna_quantum/utils.pyi,sha256=JbBq1V2SpGy4IbwqCQQKoJUM17LiTD35Wv8Im1YY1pw,2008
259
- luna_quantum-1.0.4rc1.dist-info/RECORD,,
259
+ luna_quantum/utils.pyi,sha256=TRV-THwZJdYDD5q3kn4W-p4dslim54xNJW0yFbXPFhs,2001
260
+ luna_quantum-1.0.4rc3.dist-info/RECORD,,