luna-quantum 1.0.8rc3__cp311-cp311-manylinux_2_34_x86_64.whl → 1.0.8rc4__cp311-cp311-manylinux_2_34_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.
- luna_quantum/__init__.py +4 -0
- luna_quantum/_core.cpython-311-x86_64-linux-gnu.so +0 -0
- luna_quantum/factories/usecase_factory.py +32 -0
- luna_quantum/solve/domain/solve_job.py +42 -8
- luna_quantum/solve/interfaces/usecases/__init__.py +4 -0
- luna_quantum/solve/interfaces/usecases/solve_job_get_by_id_usecase_i.py +27 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py +1 -1
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py +9 -25
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/__init__.py +29 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/config.py +58 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/{flex_qaoa/flex_qaoa.py → flexqaoa/flexqaoa.py} +48 -86
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/optimizers.py +53 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/pipeline.py +164 -0
- luna_quantum/solve/parameters/backends/__init__.py +2 -0
- luna_quantum/solve/parameters/backends/aqarios_gpu.py +17 -0
- luna_quantum/solve/parameters/errors.py +30 -0
- luna_quantum/solve/usecases/solve_job_get_by_id_usecase.py +44 -0
- {luna_quantum-1.0.8rc3.dist-info → luna_quantum-1.0.8rc4.dist-info}/METADATA +1 -1
- {luna_quantum-1.0.8rc3.dist-info → luna_quantum-1.0.8rc4.dist-info}/RECORD +22 -17
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/config.py +0 -80
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/optimizers.py +0 -99
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/pipeline.py +0 -87
- {luna_quantum-1.0.8rc3.dist-info → luna_quantum-1.0.8rc4.dist-info}/WHEEL +0 -0
- {luna_quantum-1.0.8rc3.dist-info → luna_quantum-1.0.8rc4.dist-info}/licenses/LICENSE +0 -0
- {luna_quantum-1.0.8rc3.dist-info → luna_quantum-1.0.8rc4.dist-info}/licenses/NOTICE +0 -0
luna_quantum/__init__.py
CHANGED
|
@@ -21,6 +21,9 @@ from luna_quantum.solve.usecases import (
|
|
|
21
21
|
SolveJobFetchUpdatesUseCase,
|
|
22
22
|
SolveJobGetResultUseCase,
|
|
23
23
|
)
|
|
24
|
+
from luna_quantum.solve.usecases.solve_job_get_by_id_usecase import (
|
|
25
|
+
SolveJobGetByIdUseCase,
|
|
26
|
+
)
|
|
24
27
|
from luna_quantum.util.debug_info import debug_info
|
|
25
28
|
from luna_quantum.util.log_utils import Logging
|
|
26
29
|
|
|
@@ -83,6 +86,7 @@ UseCaseFactory.set_solve_job_create_class(SolveJobCreateUseCase)
|
|
|
83
86
|
UseCaseFactory.set_solve_job_delete_class(SolveJobDeleteUseCase)
|
|
84
87
|
UseCaseFactory.set_solve_job_get_result_class(SolveJobGetResultUseCase)
|
|
85
88
|
UseCaseFactory.set_solve_job_fetch_updates_class(SolveJobFetchUpdatesUseCase)
|
|
89
|
+
UseCaseFactory.set_solve_job_get_id_class(SolveJobGetByIdUseCase)
|
|
86
90
|
LunaSolveClientFactory.set_client_class(client_class=LunaSolve)
|
|
87
91
|
__all__ = [
|
|
88
92
|
"Bounds",
|
|
Binary file
|
|
@@ -3,6 +3,7 @@ from typing import ClassVar
|
|
|
3
3
|
from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
|
|
4
4
|
from luna_quantum.solve.interfaces.usecases import (
|
|
5
5
|
IModelLoadMetadataByHashUseCase,
|
|
6
|
+
ISolveJobGetByIdUseCase,
|
|
6
7
|
)
|
|
7
8
|
from luna_quantum.solve.interfaces.usecases.model_delete_usecase_i import (
|
|
8
9
|
IModelDeleteUseCase,
|
|
@@ -64,6 +65,7 @@ class UseCaseFactory:
|
|
|
64
65
|
_solve_job_delete_class: ClassVar[type[ISolveJobDeleteUseCase]]
|
|
65
66
|
_solve_job_get_result_class: ClassVar[type[ISolveJobGetResultUseCase]]
|
|
66
67
|
_solve_job_fetch_updates_class: ClassVar[type[ISolveJobFetchUpdatesUseCase]]
|
|
68
|
+
_solve_job_get_by_id_class: ClassVar[type[ISolveJobGetByIdUseCase]]
|
|
67
69
|
|
|
68
70
|
@classmethod
|
|
69
71
|
def set_model_fetch_class(
|
|
@@ -232,6 +234,19 @@ class UseCaseFactory:
|
|
|
232
234
|
"""
|
|
233
235
|
cls._solve_job_fetch_updates_class = solve_job_fetch_updates_class
|
|
234
236
|
|
|
237
|
+
@classmethod
|
|
238
|
+
def set_solve_job_get_id_class(
|
|
239
|
+
cls, solve_job_get_by_id_class: type[ISolveJobGetByIdUseCase]
|
|
240
|
+
) -> None:
|
|
241
|
+
"""Set the implementation class for fetching solve job updates.
|
|
242
|
+
|
|
243
|
+
Parameters
|
|
244
|
+
----------
|
|
245
|
+
solve_job_get_by_id_class : Type[ISolveJobGetByIdUseCase]
|
|
246
|
+
The class implementing ISolveJobGetByIdUseCase
|
|
247
|
+
"""
|
|
248
|
+
cls._solve_job_get_by_id_class = solve_job_get_by_id_class
|
|
249
|
+
|
|
235
250
|
@classmethod
|
|
236
251
|
def model_load_by_id(cls, client: ILunaSolve) -> IModelLoadByIdUseCase:
|
|
237
252
|
"""
|
|
@@ -437,6 +452,23 @@ class UseCaseFactory:
|
|
|
437
452
|
"""
|
|
438
453
|
return cls._solve_job_fetch_updates_class(client=client)
|
|
439
454
|
|
|
455
|
+
@classmethod
|
|
456
|
+
def solve_job_get_by_id(cls, client: ILunaSolve) -> ISolveJobGetByIdUseCase:
|
|
457
|
+
"""
|
|
458
|
+
Get the use-case to retrieve a solve-job by its id.
|
|
459
|
+
|
|
460
|
+
Parameters
|
|
461
|
+
----------
|
|
462
|
+
client : ILunaSolve
|
|
463
|
+
The client used to retrieve a solve-job.
|
|
464
|
+
|
|
465
|
+
Returns
|
|
466
|
+
-------
|
|
467
|
+
ISolveJobGetByIdUseCase
|
|
468
|
+
An instance of the class responsible for retrieving a solve job by its id.
|
|
469
|
+
"""
|
|
470
|
+
return cls._solve_job_get_by_id_class(client=client)
|
|
471
|
+
|
|
440
472
|
@classmethod
|
|
441
473
|
def model_load_metadata_by_hash(
|
|
442
474
|
cls, client: ILunaSolve
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
from
|
|
2
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Literal
|
|
3
4
|
|
|
4
5
|
from pydantic import BaseModel, PrivateAttr
|
|
5
6
|
|
|
6
|
-
from luna_quantum._core import Solution
|
|
7
|
-
from luna_quantum.aqm_overwrites.model import Model
|
|
8
|
-
from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
|
|
9
7
|
from luna_quantum.client.schemas.enums.call_style import CallStyle
|
|
10
|
-
from luna_quantum.client.schemas.enums.model_format import ModelFormat
|
|
11
|
-
from luna_quantum.client.schemas.enums.status import StatusEnum
|
|
12
|
-
from luna_quantum.client.schemas.wrappers import PydanticDatetimeWrapper
|
|
8
|
+
from luna_quantum.client.schemas.enums.model_format import ModelFormat # noqa: TC001
|
|
9
|
+
from luna_quantum.client.schemas.enums.status import StatusEnum # noqa: TC001
|
|
10
|
+
from luna_quantum.client.schemas.wrappers import PydanticDatetimeWrapper # noqa: TC001
|
|
13
11
|
from luna_quantum.factories.luna_solve_client_factory import LunaSolveClientFactory
|
|
14
12
|
from luna_quantum.util.log_utils import Logging
|
|
15
13
|
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from logging import Logger
|
|
16
|
+
|
|
17
|
+
from luna_quantum._core import Solution
|
|
18
|
+
from luna_quantum.aqm_overwrites.model import Model
|
|
19
|
+
from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
|
|
20
|
+
|
|
16
21
|
|
|
17
22
|
class SolveJob(BaseModel):
|
|
18
23
|
"""A model to represent a job for solving model problems."""
|
|
@@ -194,3 +199,32 @@ class SolveJob(BaseModel):
|
|
|
194
199
|
)
|
|
195
200
|
|
|
196
201
|
UseCaseFactory.solve_job_delete(client=c).__call__(solve_job_id=self.id)
|
|
202
|
+
|
|
203
|
+
@staticmethod
|
|
204
|
+
def get_by_id(solve_job_id: str, client: ILunaSolve | None = None) -> SolveJob:
|
|
205
|
+
"""
|
|
206
|
+
Retrieve a solve-job by its ID.
|
|
207
|
+
|
|
208
|
+
Para>meters
|
|
209
|
+
----------
|
|
210
|
+
solve_job_id: str
|
|
211
|
+
Get the solve-job id for which a SolveJob should be retrieved.
|
|
212
|
+
client : Optional[ILunaSolve], optional
|
|
213
|
+
The client to be used for job deletion. If not provided, a default client
|
|
214
|
+
is retrieved using `ClientFactory`.
|
|
215
|
+
|
|
216
|
+
Returns
|
|
217
|
+
-------
|
|
218
|
+
SolveJob
|
|
219
|
+
The solve-job object.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
"""
|
|
223
|
+
c: ILunaSolve = LunaSolveClientFactory.get_client(client)
|
|
224
|
+
from luna_quantum.factories.usecase_factory import ( # noqa: PLC0415
|
|
225
|
+
UseCaseFactory,
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
return UseCaseFactory.solve_job_get_by_id(client=c).__call__(
|
|
229
|
+
solve_job_id=solve_job_id
|
|
230
|
+
)
|
|
@@ -34,6 +34,9 @@ from .solve_job_delete_usecase_i import (
|
|
|
34
34
|
from .solve_job_fetch_updates_usecase_i import (
|
|
35
35
|
ISolveJobFetchUpdatesUseCase,
|
|
36
36
|
)
|
|
37
|
+
from .solve_job_get_by_id_usecase_i import (
|
|
38
|
+
ISolveJobGetByIdUseCase,
|
|
39
|
+
)
|
|
37
40
|
from .solve_job_get_result_usecase_i import (
|
|
38
41
|
ISolveJobGetResultUseCase,
|
|
39
42
|
)
|
|
@@ -51,5 +54,6 @@ __all__ = [
|
|
|
51
54
|
"ISolveJobCreateUseCase",
|
|
52
55
|
"ISolveJobDeleteUseCase",
|
|
53
56
|
"ISolveJobFetchUpdatesUseCase",
|
|
57
|
+
"ISolveJobGetByIdUseCase",
|
|
54
58
|
"ISolveJobGetResultUseCase",
|
|
55
59
|
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
|
|
8
|
+
from luna_quantum.solve.domain.solve_job import SolveJob
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ISolveJobGetByIdUseCase(ABC):
|
|
12
|
+
"""Represent an abstract base to retrieve a solve-job by its id."""
|
|
13
|
+
|
|
14
|
+
@abstractmethod
|
|
15
|
+
def __init__(self, client: ILunaSolve) -> None:
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
@abstractmethod
|
|
19
|
+
def __call__(self, solve_job_id: str) -> SolveJob:
|
|
20
|
+
"""
|
|
21
|
+
Represent an abstract base for callable objects to retrieve solve jobs.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
solve_job_id : str
|
|
26
|
+
The id of the solve-job to retrieve.
|
|
27
|
+
"""
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
from .flex_qaoa import FlexQAOA
|
|
3
|
-
from .optimizers import (
|
|
4
|
-
CombinedOptimizerParams,
|
|
5
|
-
InterpolateOptimizerParams,
|
|
6
|
-
LinearOptimizerParams,
|
|
7
|
-
)
|
|
8
|
-
from .pipeline import (
|
|
9
|
-
IndicatorFunctionParams,
|
|
10
|
-
OneHotParams,
|
|
11
|
-
PipelineParams,
|
|
12
|
-
QuadraticPenaltyParams,
|
|
13
|
-
)
|
|
1
|
+
import warnings
|
|
14
2
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"PipelineParams",
|
|
24
|
-
"QuadraticPenaltyParams",
|
|
25
|
-
"XYMixer",
|
|
26
|
-
]
|
|
3
|
+
from luna_quantum.solve.parameters.algorithms.quantum_gate.flexqaoa import * # noqa: F403
|
|
4
|
+
|
|
5
|
+
warnings.warn(
|
|
6
|
+
"The module `flex_qaoa` is deprecated and will be removed in the future. "
|
|
7
|
+
"Use 'flexqaoa' instead.",
|
|
8
|
+
DeprecationWarning,
|
|
9
|
+
stacklevel=2,
|
|
10
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from .config import CustomConfig
|
|
2
|
+
from .flexqaoa import FlexQAOA
|
|
3
|
+
from .optimizers import (
|
|
4
|
+
CombinedOptimizerParams,
|
|
5
|
+
InterpolateOptimizerParams,
|
|
6
|
+
)
|
|
7
|
+
from .pipeline import (
|
|
8
|
+
IndicatorFunctionConfig,
|
|
9
|
+
InequalityToEqualityConfig,
|
|
10
|
+
PenaltySetting,
|
|
11
|
+
PipelineParams,
|
|
12
|
+
QuadraticPenaltyConfig,
|
|
13
|
+
SetpackingAsOnehotConfig,
|
|
14
|
+
XYMixerConfig,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"CombinedOptimizerParams",
|
|
19
|
+
"CustomConfig",
|
|
20
|
+
"FlexQAOA",
|
|
21
|
+
"IndicatorFunctionConfig",
|
|
22
|
+
"InequalityToEqualityConfig",
|
|
23
|
+
"InterpolateOptimizerParams",
|
|
24
|
+
"PenaltySetting",
|
|
25
|
+
"PipelineParams",
|
|
26
|
+
"QuadraticPenaltyConfig",
|
|
27
|
+
"SetpackingAsOnehotConfig",
|
|
28
|
+
"XYMixerConfig",
|
|
29
|
+
]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field, PositiveInt
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CustomConfig(BaseModel):
|
|
7
|
+
"""Additional FlexQAOA circuit configuration.
|
|
8
|
+
|
|
9
|
+
Attributes
|
|
10
|
+
----------
|
|
11
|
+
max_qubits : PositiveInt | None
|
|
12
|
+
Maximum number of qubits allowed for the circuit. If `None`, no limit is
|
|
13
|
+
applied. Default: `None`.
|
|
14
|
+
minimize_qubits : bool
|
|
15
|
+
Minimize the number of used qubits in the circuit if set to `True`. Otherwise,
|
|
16
|
+
minimize circuit depth. Default: `False`.
|
|
17
|
+
wstate : Literal["log", "bilinear", "linear"]
|
|
18
|
+
WState generation cricuit. Choice between:
|
|
19
|
+
|
|
20
|
+
- `"log"`: Logarithmic-depth binary tree circuit.
|
|
21
|
+
- `"linear"`: Linear circuit construction.
|
|
22
|
+
- `"bilinear"`: Bi-linear circuit construction, starts in the middle and
|
|
23
|
+
linearly constructs the circuit outwards.
|
|
24
|
+
|
|
25
|
+
Default: `"log"`
|
|
26
|
+
qft_synth : Literal["line", "full"]
|
|
27
|
+
QFT synthesis method. Choice between:
|
|
28
|
+
|
|
29
|
+
- `"full"`: Shorter circuit depth implementation that requires all-to-all
|
|
30
|
+
connectivity.
|
|
31
|
+
- `"line"`: Longer circuit depth implementation that requires linear
|
|
32
|
+
connectivity.
|
|
33
|
+
|
|
34
|
+
Default: `"full"`
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
max_qubits: PositiveInt | None = Field(
|
|
38
|
+
default=None,
|
|
39
|
+
description="Maximum number of qubits allowed for the circuit. If `None`, no "
|
|
40
|
+
"limit is applied.",
|
|
41
|
+
)
|
|
42
|
+
minimize_qubits: bool = Field(
|
|
43
|
+
default=False,
|
|
44
|
+
description="Minimize the number of used qubits in the circuit "
|
|
45
|
+
"if set to `True`. Otherwise, minimize circuit depth.",
|
|
46
|
+
)
|
|
47
|
+
wstate: Literal["log", "bilinear", "linear"] = Field(
|
|
48
|
+
default="log",
|
|
49
|
+
description="WState generation cricuit. Choice between: Logarithmic-depth (log)"
|
|
50
|
+
" binary tree circuit and linear or bilinear construction. bilinear places the "
|
|
51
|
+
"start in the middle and linearly constructs the circuit outwards.",
|
|
52
|
+
)
|
|
53
|
+
qft_synth: Literal["line", "full"] = Field(
|
|
54
|
+
default="full",
|
|
55
|
+
description="QFT synthesis method. Shorter depth (full) implementation requires"
|
|
56
|
+
" all-to-all connectivity. Longer (line) implementation requires only linear "
|
|
57
|
+
"connectivity.",
|
|
58
|
+
)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
3
5
|
from pydantic import BaseModel, Field, model_validator
|
|
4
6
|
|
|
5
7
|
from luna_quantum.solve.domain.abstract.luna_algorithm import LunaAlgorithm
|
|
6
|
-
from luna_quantum.solve.errors.solve_base_error import SolveBaseError
|
|
7
8
|
from luna_quantum.solve.parameters.algorithms.base_params.qaoa_circuit_params import (
|
|
8
9
|
BasicQAOAParams,
|
|
9
10
|
LinearQAOAParams,
|
|
@@ -13,51 +14,20 @@ from luna_quantum.solve.parameters.algorithms.base_params.scipy_optimizer import
|
|
|
13
14
|
ScipyOptimizerParams,
|
|
14
15
|
)
|
|
15
16
|
from luna_quantum.solve.parameters.backends.aqarios import Aqarios
|
|
16
|
-
|
|
17
|
-
from .
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
LinearOptimizerParams,
|
|
17
|
+
from luna_quantum.solve.parameters.backends.aqarios_gpu import AqariosGpu
|
|
18
|
+
from luna_quantum.solve.parameters.errors import (
|
|
19
|
+
InterpolateOptimizerError,
|
|
20
|
+
QAOAParameterOptimizerError,
|
|
21
|
+
QAOAParameterRepsMismatchError,
|
|
22
22
|
)
|
|
23
|
-
from .pipeline import PipelineParams
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class QAOAParameterOptimizerError(SolveBaseError):
|
|
27
|
-
"""QAOA cirucit parameters mismatch with optimizer exception."""
|
|
28
|
-
|
|
29
|
-
def __init__(
|
|
30
|
-
self,
|
|
31
|
-
optimizer: ScipyOptimizerParams
|
|
32
|
-
| LinearOptimizerParams
|
|
33
|
-
| CombinedOptimizerParams
|
|
34
|
-
| InterpolateOptimizerParams
|
|
35
|
-
| None,
|
|
36
|
-
params: BasicQAOAParams | LinearQAOAParams | RandomQAOAParams,
|
|
37
|
-
extra: str = "",
|
|
38
|
-
) -> None:
|
|
39
|
-
super().__init__(
|
|
40
|
-
f"Parameter Mismatch of {optimizer.__class__} and {params.__class__}"
|
|
41
|
-
+ ((". " + extra) if extra else "")
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class InterpolateOptimizerError(SolveBaseError):
|
|
46
|
-
"""Interpolate optimizer error when final number of reps is too small."""
|
|
47
|
-
|
|
48
|
-
def __init__(self, reps_end: int, reps_start: int) -> None:
|
|
49
|
-
super().__init__(f"{reps_end=} needs to be larger than {reps_start=}.")
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class QAOAParameterDepthMismatchError(SolveBaseError):
|
|
53
|
-
"""QAOA circuit params mismatch the specified reps."""
|
|
54
23
|
|
|
55
|
-
|
|
56
|
-
|
|
24
|
+
from .config import CustomConfig
|
|
25
|
+
from .optimizers import CombinedOptimizerParams, InterpolateOptimizerParams
|
|
26
|
+
from .pipeline import PipelineParams
|
|
57
27
|
|
|
58
28
|
|
|
59
|
-
class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
60
|
-
"""The FlexQAOA
|
|
29
|
+
class FlexQAOA(LunaAlgorithm[Aqarios | AqariosGpu], BaseModel):
|
|
30
|
+
"""The FlexQAOA algorithm for constrained quantum optimization.
|
|
61
31
|
|
|
62
32
|
The FlexQAOA is an extension to the default QAOA with the capabilities to encode
|
|
63
33
|
inequality constriants with indicator functions as well as one-hot constraints
|
|
@@ -73,18 +43,11 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
73
43
|
Central to this is the pipeline parameter which allows for different configurations.
|
|
74
44
|
|
|
75
45
|
For instance, if one likes to explore ordinary QUBO simulation with all constraints
|
|
76
|
-
represented as quadratic penalties, the `
|
|
46
|
+
represented as quadratic penalties, the `xy_mixers` and `indicator_function` options
|
|
77
47
|
need to be manually disabled
|
|
78
48
|
```
|
|
79
|
-
pipeline =
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
If no indicator function is employed, but the input problem contains inequality
|
|
83
|
-
constraints, slack variables are added to the optimization problem. FlexQAOA allows
|
|
84
|
-
for a configuration that discards slack variables as their assignment is not
|
|
85
|
-
necessarily of interest. This option can be enbled by setting
|
|
86
|
-
```
|
|
87
|
-
qaoa_config = {"discard_slack": True}
|
|
49
|
+
pipeline.xy_mixer.enable = False
|
|
50
|
+
pipeline.indicator_function.enable = False
|
|
88
51
|
```
|
|
89
52
|
|
|
90
53
|
Following the standard protocol for QAOA, a classical optimizer is required that
|
|
@@ -100,24 +63,35 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
100
63
|
Number of sampled shots.
|
|
101
64
|
reps: int
|
|
102
65
|
Number of QAOA layer repetitions
|
|
103
|
-
pipeline: PipelineParams
|
|
66
|
+
pipeline: PipelineParams
|
|
104
67
|
The pipeline defines the selected features for QAOA circuit generation. By
|
|
105
68
|
default, all supported features are enabled (one-hot constraints, inequality
|
|
106
69
|
constraints and quadratic penalties).
|
|
107
|
-
optimizer: ScipyOptimizerParams |
|
|
108
|
-
InterpolateOptimizerParams | None
|
|
109
|
-
The classical optimizer for parameter tuning.
|
|
70
|
+
optimizer: ScipyOptimizerParams | CombinedOptimizerParams |\
|
|
71
|
+
InterpolateOptimizerParams | None
|
|
72
|
+
The classical optimizer for parameter tuning. Setting
|
|
110
73
|
to `None` disables the optimization, leading to an evaluation of the initial
|
|
111
74
|
parameters.
|
|
112
|
-
qaoa_config: AdvancedConfig | Dict
|
|
113
|
-
Additional options for the QAOA circuit and evalutation
|
|
114
75
|
initial_params: LinearQAOAParams | BasicQAOAParams | RandomQAOAParams | Dict
|
|
115
76
|
Custom QAOA variational circuit parameters. By default linear
|
|
116
77
|
increasing/decreasing parameters for the selected `reps` are generated.
|
|
78
|
+
param_conversion: None | Literal["basic"] = "basic"
|
|
79
|
+
Parameter conversion after initialization. This option set to `None` means the
|
|
80
|
+
parameters, as specified are used. This parameter set to `"basic"` means the
|
|
81
|
+
parameters are converted to basic parameters before optimization. This is useful
|
|
82
|
+
if one only wants to optimize the linear schedule of parameters: Then the option
|
|
83
|
+
`None` needs to be selected alongside LinearQAOAParams. This
|
|
84
|
+
option is ignored when CombinedOptimizer is also selected.
|
|
85
|
+
custom_config: CustomConfig
|
|
86
|
+
Additional options for the FlexQAOA circuit.
|
|
117
87
|
"""
|
|
118
88
|
|
|
119
|
-
shots: int = Field(
|
|
120
|
-
|
|
89
|
+
shots: int = Field(
|
|
90
|
+
default=1024, ge=1, lt=1 << 16, description="Number of sampled shots."
|
|
91
|
+
)
|
|
92
|
+
reps: int = Field(
|
|
93
|
+
default=1, ge=1, lt=1000, description="Number of QAOA layer repetitions"
|
|
94
|
+
)
|
|
121
95
|
pipeline: PipelineParams = Field(
|
|
122
96
|
default_factory=lambda: PipelineParams(),
|
|
123
97
|
description="The pipeline defines the selected features for QAOA circuit "
|
|
@@ -126,7 +100,6 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
126
100
|
)
|
|
127
101
|
optimizer: (
|
|
128
102
|
ScipyOptimizerParams
|
|
129
|
-
| LinearOptimizerParams
|
|
130
103
|
| CombinedOptimizerParams
|
|
131
104
|
| InterpolateOptimizerParams
|
|
132
105
|
| None
|
|
@@ -134,36 +107,25 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
134
107
|
default_factory=lambda: ScipyOptimizerParams(),
|
|
135
108
|
description="The classical optimizer. Default: ScipyOptimizer",
|
|
136
109
|
)
|
|
137
|
-
qaoa_config: AdvancedConfig = Field(
|
|
138
|
-
default_factory=lambda: AdvancedConfig(),
|
|
139
|
-
description="Additional options for the QAOA circuit and evalutation",
|
|
140
|
-
)
|
|
141
110
|
initial_params: LinearQAOAParams | BasicQAOAParams | RandomQAOAParams = Field(
|
|
142
111
|
default_factory=lambda: LinearQAOAParams(delta_beta=0.5, delta_gamma=0.5),
|
|
143
112
|
description="Custom QAOA circuit parameters. By default linear "
|
|
144
113
|
"increasing/decreasing parameters for the selected `reps` are generated.",
|
|
145
114
|
)
|
|
115
|
+
param_conversion: None | Literal["basic"] = "basic"
|
|
116
|
+
custom_config: CustomConfig = Field(
|
|
117
|
+
default_factory=lambda: CustomConfig(),
|
|
118
|
+
description="Additional configuration options for the FlexQAOA circuit.",
|
|
119
|
+
)
|
|
146
120
|
|
|
147
121
|
@model_validator(mode="after")
|
|
148
122
|
def _check_param_type(self) -> FlexQAOA:
|
|
149
|
-
if isinstance(self.optimizer,
|
|
150
|
-
self.initial_params, BasicQAOAParams
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
self.
|
|
155
|
-
):
|
|
156
|
-
raise QAOAParameterOptimizerError(self.optimizer, self.initial_params)
|
|
157
|
-
if (
|
|
158
|
-
isinstance(self.optimizer, InterpolateOptimizerParams)
|
|
159
|
-
and isinstance(self.optimizer.optimizer, LinearOptimizerParams)
|
|
160
|
-
and isinstance(self.initial_params, BasicQAOAParams)
|
|
161
|
-
):
|
|
162
|
-
raise QAOAParameterOptimizerError(
|
|
163
|
-
self.optimizer,
|
|
164
|
-
self.initial_params,
|
|
165
|
-
extra="LinearOptimizer used in InterpolateOptimizer.",
|
|
166
|
-
)
|
|
123
|
+
if isinstance(self.optimizer, CombinedOptimizerParams):
|
|
124
|
+
if isinstance(self.initial_params, (BasicQAOAParams, RandomQAOAParams)):
|
|
125
|
+
optim = self.optimizer.__class__.__name__
|
|
126
|
+
params = self.initial_params.__class__.__name__
|
|
127
|
+
raise QAOAParameterOptimizerError(optim, params)
|
|
128
|
+
self.param_conversion = None
|
|
167
129
|
if (
|
|
168
130
|
isinstance(self.optimizer, InterpolateOptimizerParams)
|
|
169
131
|
and self.optimizer.reps_end < self.reps
|
|
@@ -177,7 +139,7 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
177
139
|
isinstance(self.initial_params, BasicQAOAParams)
|
|
178
140
|
and self.initial_params.reps != self.reps
|
|
179
141
|
):
|
|
180
|
-
raise
|
|
142
|
+
raise QAOAParameterRepsMismatchError(self.initial_params.reps, self.reps)
|
|
181
143
|
return self
|
|
182
144
|
|
|
183
145
|
@property
|
|
@@ -213,7 +175,7 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
213
175
|
return Aqarios()
|
|
214
176
|
|
|
215
177
|
@classmethod
|
|
216
|
-
def get_compatible_backends(cls) -> tuple[type[Aqarios]]:
|
|
178
|
+
def get_compatible_backends(cls) -> tuple[type[Aqarios], type[AqariosGpu]]:
|
|
217
179
|
"""
|
|
218
180
|
Check at runtime if the used backend is compatible with the solver.
|
|
219
181
|
|
|
@@ -223,4 +185,4 @@ class FlexQAOA(LunaAlgorithm[Aqarios], BaseModel):
|
|
|
223
185
|
True if the backend is compatible with the solver, False otherwise.
|
|
224
186
|
|
|
225
187
|
"""
|
|
226
|
-
return (Aqarios,)
|
|
188
|
+
return (Aqarios, AqariosGpu)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.parameters.algorithms.base_params.scipy_optimizer import (
|
|
6
|
+
ScipyOptimizerParams,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class CombinedOptimizerParams(BaseModel):
|
|
11
|
+
"""Combination of LinearOptimizer and ScipyOptimizer.
|
|
12
|
+
|
|
13
|
+
Optimizer that first performs an optimization of the linear schedule and then
|
|
14
|
+
fine tunes individual parameters. Only works in conjunction with `LinearQAOAParams`.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Attributes
|
|
18
|
+
----------
|
|
19
|
+
linear: ScipyOptimizerParams
|
|
20
|
+
Parameters of the linear optimizer.
|
|
21
|
+
fine_tune: ScipyOptimizerParams | None
|
|
22
|
+
Parameters of the fine tuning optimizer. If `None`, the same optimizer is used.
|
|
23
|
+
Default: `None`.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
optimizer_type: Literal["combined"] = "combined"
|
|
27
|
+
linear: ScipyOptimizerParams = Field(default_factory=lambda: ScipyOptimizerParams())
|
|
28
|
+
fine_tune: ScipyOptimizerParams | None = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class InterpolateOptimizerParams(BaseModel):
|
|
32
|
+
"""Optimizer with sequentially increasing number of QAOA layers.
|
|
33
|
+
|
|
34
|
+
Optimizer that starts with `reps` iteration and interpolates sequentially in
|
|
35
|
+
`reps_step` steps to `reps_end`. In between it performs a full optimization routine
|
|
36
|
+
tunes individual parameters.
|
|
37
|
+
|
|
38
|
+
Attributes
|
|
39
|
+
----------
|
|
40
|
+
optimizer: ScipyOptimizerParams
|
|
41
|
+
Parameters of the optimizer.
|
|
42
|
+
reps_step: int
|
|
43
|
+
Number of QAOA layers added for one interpolation.
|
|
44
|
+
reps_end: int
|
|
45
|
+
Final number of QAOA layers to be reached.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
optimizer_type: Literal["interpolate"] = "interpolate"
|
|
49
|
+
optimizer: ScipyOptimizerParams = Field(
|
|
50
|
+
default_factory=lambda: ScipyOptimizerParams()
|
|
51
|
+
)
|
|
52
|
+
reps_step: int = Field(default=1, ge=1)
|
|
53
|
+
reps_end: int = Field(default=10, ge=1, lt=1000)
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field, PositiveFloat
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class _EnableMixin:
|
|
7
|
+
enable: bool = True
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PenaltySetting(BaseModel):
|
|
11
|
+
"""Penalty factor settings.
|
|
12
|
+
|
|
13
|
+
Attributes
|
|
14
|
+
----------
|
|
15
|
+
override: PositiveFloat | None
|
|
16
|
+
Overrides the automatically evaluated penalty factor.
|
|
17
|
+
scaling: PositiveFloat
|
|
18
|
+
Scales the automatically evaluated penalty factor.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
override: PositiveFloat | None = None
|
|
22
|
+
scaling: PositiveFloat = 1.0
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class IndicatorFunctionConfig(BaseModel, _EnableMixin):
|
|
26
|
+
"""Configuration for indicator functions to implement inequality constraints.
|
|
27
|
+
|
|
28
|
+
Attributes
|
|
29
|
+
----------
|
|
30
|
+
penalty: PenaltySetting
|
|
31
|
+
Custom penalty setting for indicator functions.
|
|
32
|
+
method: Literal["const", "str"]
|
|
33
|
+
Indicator function implementation method. Default: `"const"`
|
|
34
|
+
Two options are available:
|
|
35
|
+
|
|
36
|
+
- `"const"`: Applies a constant penalty for every constraint violation.
|
|
37
|
+
- `"if"`: Applies the objective function only if all constraints are satisfied.
|
|
38
|
+
Automatically ensures objective to be negative.
|
|
39
|
+
|
|
40
|
+
enable : bool
|
|
41
|
+
Toggle to enable or disable this method. Default: True.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
penalty: PenaltySetting = Field(
|
|
45
|
+
default_factory=lambda: PenaltySetting(scaling=1),
|
|
46
|
+
description="Penalty setting for indicator functions.",
|
|
47
|
+
)
|
|
48
|
+
method: Literal["if", "const"] = Field(
|
|
49
|
+
default="const",
|
|
50
|
+
description="Method of indicator function implementation. Constant Penalty "
|
|
51
|
+
"(const) or conditional application of cost function (if).",
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class XYMixerConfig(BaseModel, _EnableMixin):
|
|
56
|
+
"""Configuration for XY-mixers to implement one-hot constraints.
|
|
57
|
+
|
|
58
|
+
Attributes
|
|
59
|
+
----------
|
|
60
|
+
trotter : int
|
|
61
|
+
Number of trotter steps for XY-mixer implementation. Default: 1.
|
|
62
|
+
types: list[Literal["even", "odd", "last"]]
|
|
63
|
+
Mixer types in XY-ring-mixer. Default: `["even", "odd", "last"]`.
|
|
64
|
+
enable : bool
|
|
65
|
+
Toggle to enable or disable this method. Default: True.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
trotter: int = Field(
|
|
69
|
+
default=1,
|
|
70
|
+
lt=1000,
|
|
71
|
+
ge=1,
|
|
72
|
+
description="Number of trotter steps for XY-mixer implementation.",
|
|
73
|
+
)
|
|
74
|
+
types: list[Literal["even", "odd", "last"]] = Field(
|
|
75
|
+
default=["even", "odd", "last"],
|
|
76
|
+
description='Mixer types in XY-ring-mixer. Default: `["even", "odd", "last"]`',
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class QuadraticPenaltyConfig(BaseModel, _EnableMixin):
|
|
81
|
+
"""Configuration for quadratic penalties.
|
|
82
|
+
|
|
83
|
+
Adds penalty terms to the objective. Adds slack variables for inequality constraints
|
|
84
|
+
if neccessaray.
|
|
85
|
+
|
|
86
|
+
Attributes
|
|
87
|
+
----------
|
|
88
|
+
penalty : PenaltySetting
|
|
89
|
+
Custom penalty setting for quadratic penalty terms.
|
|
90
|
+
enable : bool
|
|
91
|
+
Toggle to enable or disable this method. Default: True.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
penalty: PenaltySetting = Field(
|
|
95
|
+
default_factory=lambda: PenaltySetting(scaling=2.0),
|
|
96
|
+
description="Penalty setting for quadratic penalties.",
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class SetpackingAsOnehotConfig(BaseModel, _EnableMixin):
|
|
101
|
+
"""Configuration for set-packing to one-hot constraint transformation.
|
|
102
|
+
|
|
103
|
+
Attributes
|
|
104
|
+
----------
|
|
105
|
+
enable : bool
|
|
106
|
+
Toggle to enable or disable this method. Default: True.
|
|
107
|
+
"""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class InequalityToEqualityConfig(BaseModel, _EnableMixin):
|
|
111
|
+
"""Configuration for inequality to equality constraint transformation.
|
|
112
|
+
|
|
113
|
+
Attributes
|
|
114
|
+
----------
|
|
115
|
+
max_slack : int
|
|
116
|
+
Maximum number of slack bits to add for each constraint. Default: 10.
|
|
117
|
+
enable : bool
|
|
118
|
+
Toggle to enable or disable this method. Default: True.
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
max_slack: int = Field(
|
|
122
|
+
default=10,
|
|
123
|
+
description="Maximum number of slack bits to add for each constraint.",
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class PipelineParams(BaseModel):
|
|
128
|
+
"""Define the modular FlexQAOA Pipeline.
|
|
129
|
+
|
|
130
|
+
Attributes
|
|
131
|
+
----------
|
|
132
|
+
penalty : PenaltySetting
|
|
133
|
+
General penalty factor settings.
|
|
134
|
+
inequality_to_equality : InequalityToEqualityConfig
|
|
135
|
+
Configuration of the "inequality to equality" transformation.
|
|
136
|
+
setpacking_as_onehot : SetpackingAsOnehotConfig
|
|
137
|
+
Configuration of the "setpacking to onehot" transformation.
|
|
138
|
+
xy_mixer : XYMixerConfig
|
|
139
|
+
Configuration of the XY-mixers.
|
|
140
|
+
indicator_function : IndicatorFunctionConfig
|
|
141
|
+
Configuration of the indicator functions.
|
|
142
|
+
sp_quadratic_penalty : QuadraticPenaltyConfig
|
|
143
|
+
Configuration of the setpacking quadratic penalty function.
|
|
144
|
+
quadratic_penalty : QuadraticPenaltyConfig
|
|
145
|
+
Configuration of the general quadratic penalty function.
|
|
146
|
+
"""
|
|
147
|
+
|
|
148
|
+
penalty: PenaltySetting = Field(default_factory=lambda: PenaltySetting(scaling=2.0))
|
|
149
|
+
inequality_to_equality: InequalityToEqualityConfig = Field(
|
|
150
|
+
default_factory=InequalityToEqualityConfig
|
|
151
|
+
)
|
|
152
|
+
setpacking_as_onehot: SetpackingAsOnehotConfig = Field(
|
|
153
|
+
default_factory=SetpackingAsOnehotConfig
|
|
154
|
+
)
|
|
155
|
+
xy_mixer: XYMixerConfig = Field(default_factory=XYMixerConfig)
|
|
156
|
+
indicator_function: IndicatorFunctionConfig = Field(
|
|
157
|
+
default_factory=IndicatorFunctionConfig
|
|
158
|
+
)
|
|
159
|
+
sp_quadratic_penalty: QuadraticPenaltyConfig = Field(
|
|
160
|
+
default_factory=QuadraticPenaltyConfig
|
|
161
|
+
)
|
|
162
|
+
quadratic_penalty: QuadraticPenaltyConfig = Field(
|
|
163
|
+
default_factory=QuadraticPenaltyConfig
|
|
164
|
+
)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from .aqarios import Aqarios
|
|
2
|
+
from .aqarios_gpu import AqariosGpu
|
|
2
3
|
from .aws import AWS, IQM, IonQ, Rigetti
|
|
3
4
|
from .dwave import DWave
|
|
4
5
|
from .dwave_qpu import DWaveQpu
|
|
@@ -13,6 +14,7 @@ __all__: list[str] = [
|
|
|
13
14
|
"IQM",
|
|
14
15
|
"ZIB",
|
|
15
16
|
"Aqarios",
|
|
17
|
+
"AqariosGpu",
|
|
16
18
|
"DWave",
|
|
17
19
|
"DWaveQpu",
|
|
18
20
|
"Fujitsu",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from luna_quantum.solve.interfaces.backend_i import IBackend
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AqariosGpu(IBackend):
|
|
5
|
+
"""Configuration class for the Aqarios GPU backend."""
|
|
6
|
+
|
|
7
|
+
@property
|
|
8
|
+
def provider(self) -> str:
|
|
9
|
+
"""
|
|
10
|
+
Retrieve the name of the provider.
|
|
11
|
+
|
|
12
|
+
Returns
|
|
13
|
+
-------
|
|
14
|
+
str
|
|
15
|
+
The name of the provider.
|
|
16
|
+
"""
|
|
17
|
+
return "aqarios-gpu"
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from luna_quantum.solve.errors.solve_base_error import SolveBaseError
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class QAOAParameterOptimizerError(SolveBaseError):
|
|
5
|
+
"""QAOA cirucit parameters mismatch with optimizer exception."""
|
|
6
|
+
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
optimizer: str,
|
|
10
|
+
params: str,
|
|
11
|
+
extra: str = "",
|
|
12
|
+
) -> None:
|
|
13
|
+
super().__init__(
|
|
14
|
+
f"Parameter Mismatch of '{optimizer}' and '{params}'"
|
|
15
|
+
+ ((": " + extra) if extra else ".")
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class InterpolateOptimizerError(SolveBaseError):
|
|
20
|
+
"""Interpolate optimizer error when final number of reps is too small."""
|
|
21
|
+
|
|
22
|
+
def __init__(self, reps_end: int, reps_start: int) -> None:
|
|
23
|
+
super().__init__(f"{reps_end=} needs to be larger than {reps_start=}.")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class QAOAParameterRepsMismatchError(SolveBaseError):
|
|
27
|
+
"""QAOA circuit params mismatch the specified reps."""
|
|
28
|
+
|
|
29
|
+
def __init__(self, params_reps: int, reps: int) -> None:
|
|
30
|
+
super().__init__(f"{params_reps=} needs to match {reps=}.")
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from luna_quantum.client.interfaces.services.luna_solve_i import ILunaSolve
|
|
4
|
+
from luna_quantum.solve.domain.solve_job import SolveJob
|
|
5
|
+
from luna_quantum.solve.interfaces.usecases.solve_job_get_by_id_usecase_i import (
|
|
6
|
+
ISolveJobGetByIdUseCase,
|
|
7
|
+
)
|
|
8
|
+
from luna_quantum.util.log_utils import Logging, progress
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from luna_quantum.client.schemas.solve_job import SolveJobSchema
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SolveJobGetByIdUseCase(ISolveJobGetByIdUseCase):
|
|
15
|
+
"""
|
|
16
|
+
Represent an abstract base to retrieve a solve-job by its id.
|
|
17
|
+
|
|
18
|
+
This class interacts with a backend client to retrieve a solve job by its id.
|
|
19
|
+
|
|
20
|
+
Attributes
|
|
21
|
+
----------
|
|
22
|
+
client : ILunaSolve
|
|
23
|
+
Client used to retrieve the solve job.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
client: ILunaSolve
|
|
27
|
+
logger = Logging.get_logger(__name__)
|
|
28
|
+
|
|
29
|
+
def __init__(self, client: ILunaSolve) -> None:
|
|
30
|
+
self.client = client
|
|
31
|
+
|
|
32
|
+
@progress(total=None, desc="Retrieving solve job by id...")
|
|
33
|
+
def __call__(self, solve_job_id: str) -> SolveJob:
|
|
34
|
+
"""
|
|
35
|
+
Retive a solve-job by its id.
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
solve_job_id : str
|
|
40
|
+
The id of the solve-job to retrieve.
|
|
41
|
+
"""
|
|
42
|
+
solve_job: SolveJobSchema = self.client.solve_job.get(solve_job_id=solve_job_id)
|
|
43
|
+
|
|
44
|
+
return SolveJob.model_validate(solve_job.model_dump())
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
luna_quantum-1.0.
|
|
2
|
-
luna_quantum-1.0.
|
|
3
|
-
luna_quantum-1.0.
|
|
4
|
-
luna_quantum-1.0.
|
|
5
|
-
luna_quantum/__init__.py,sha256=
|
|
1
|
+
luna_quantum-1.0.8rc4.dist-info/METADATA,sha256=cxEL3-ylYkSr5yiFx4tzrfiQZ6AQzJCTG1QhmezVNbg,1585
|
|
2
|
+
luna_quantum-1.0.8rc4.dist-info/WHEEL,sha256=OVlAaljgWPhfhJRVM6VsLWLOev5VbYFkuMRMXaOVkcY,108
|
|
3
|
+
luna_quantum-1.0.8rc4.dist-info/licenses/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
|
4
|
+
luna_quantum-1.0.8rc4.dist-info/licenses/NOTICE,sha256=noPOS8eDj5XoyRO8ZrCxIOh5fSjk0RildIrrqxQlepY,588
|
|
5
|
+
luna_quantum/__init__.py,sha256=uvustvqwnorIgsREJjCG4O6qjzjKeZDZmwfhfotAQZ4,3780
|
|
6
6
|
luna_quantum/__init__.pyi,sha256=s2RfcxcRc0antqQnZvD7kKTwpbshkOM85F4d58dDKOE,2005
|
|
7
|
-
luna_quantum/_core.cpython-311-x86_64-linux-gnu.so,sha256=
|
|
7
|
+
luna_quantum/_core.cpython-311-x86_64-linux-gnu.so,sha256=wbK2oxRoEcGOi_WZo9seQ1F1lDwXWez600drhRzfb7Q,6717640
|
|
8
8
|
luna_quantum/_core.pyi,sha256=ICnplN_bc5ScyMOSIW65YqkZzWQP_8BWLDquOGVemRY,121598
|
|
9
9
|
luna_quantum/_utility.py,sha256=6BbCJ2HDA92NtcUuVhnyUcG40-_FB1m21h-M3Z06v-8,6031
|
|
10
10
|
luna_quantum/_utility.pyi,sha256=DAZeMbhjaRf10adPv8QKt8GGOlaHjnfndDcbGmu-qUA,487
|
|
@@ -92,7 +92,7 @@ luna_quantum/exceptions/luna_quantum_call_type_error.py,sha256=mPXghYDBjSWGpodr8
|
|
|
92
92
|
luna_quantum/exceptions/patch_class_field_exists_error.py,sha256=3TGKb-MNyjwntrJkbRaBKEvlsj68ROTwCltDt6Zg7Gg,398
|
|
93
93
|
luna_quantum/factories/__init__.py,sha256=XT0vIcm65KVpYSLbqXdeoPd7yypSj36o1IC55CTaoj4,162
|
|
94
94
|
luna_quantum/factories/luna_solve_client_factory.py,sha256=Y5vqDe8F0HMj3WluHxPl0KbB8KDWRTgWgbZ1igzt3hM,3284
|
|
95
|
-
luna_quantum/factories/usecase_factory.py,sha256=
|
|
95
|
+
luna_quantum/factories/usecase_factory.py,sha256=OgYie8dfV3pJh-W3dojxRJLFzjsNAcE5dAHekNiobsg,16067
|
|
96
96
|
luna_quantum/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
97
97
|
luna_quantum/solve/__init__.py,sha256=Qu363Ci54FhrhRvuLm6WIFAsyxMwtza8n7ImHPQfxj0,307
|
|
98
98
|
luna_quantum/solve/default_token.py,sha256=JpMrRtQsczmBYFeMvDOsbabpBfUubGWNVLlwFn2O4Ew,8691
|
|
@@ -101,7 +101,7 @@ luna_quantum/solve/domain/abstract/__init__.py,sha256=My23tGRFFJYVe6vwgUM4RAFr26
|
|
|
101
101
|
luna_quantum/solve/domain/abstract/luna_algorithm.py,sha256=f24R-c8dEkLtT_UeGAMGV6RlqeBTrR_gtCAlk_-HjaE,7045
|
|
102
102
|
luna_quantum/solve/domain/abstract/qpu_token_backend.py,sha256=2vLMzDrrJsi2ejVMdNOEuhf9x1e7zGijkIn2GCH--j8,1229
|
|
103
103
|
luna_quantum/solve/domain/model_metadata.py,sha256=KqbZ59cKjfl9TrIy8L3BLT0qeqiWYRYNxgLgvQxh0Xo,1686
|
|
104
|
-
luna_quantum/solve/domain/solve_job.py,sha256=
|
|
104
|
+
luna_quantum/solve/domain/solve_job.py,sha256=k0N6c2ZoR8PgwAeAaJDBhqv6Q89i8blf_8BoxD-qH2U,7792
|
|
105
105
|
luna_quantum/solve/errors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
106
106
|
luna_quantum/solve/errors/incompatible_backend_error.py,sha256=PVhyMTIUShy1IJqc_FiYxxY5SzLs791Wfey-JHu6xoA,604
|
|
107
107
|
luna_quantum/solve/errors/model_metadata_missing_error.py,sha256=TBTokypD8drCFPFeMWsUn7mt7aCmKMqKweyzshqf3Bg,363
|
|
@@ -110,7 +110,7 @@ luna_quantum/solve/errors/token_missing_error.py,sha256=PK3n0fe4a57rdSm6gj0qbeh8
|
|
|
110
110
|
luna_quantum/solve/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
111
111
|
luna_quantum/solve/interfaces/algorithm_i.py,sha256=dTWDW1CoFElIbVxjnSnA9lPIcrKDV1YJlySTR_p02xI,1665
|
|
112
112
|
luna_quantum/solve/interfaces/backend_i.py,sha256=dNszKrHSFjBb66ABHPjUUGiENBP3jVN9nGSHJr2R0co,602
|
|
113
|
-
luna_quantum/solve/interfaces/usecases/__init__.py,sha256=
|
|
113
|
+
luna_quantum/solve/interfaces/usecases/__init__.py,sha256=xvcPJC6mX47qZ3TyqaZh4rPx0lLn7bt3938rJ8DyMHc,1521
|
|
114
114
|
luna_quantum/solve/interfaces/usecases/model_delete_usecase_i.py,sha256=wQL0nE2d5UF9_cRpC-sbeHqKrA_46j9wGtO0_FI4gX8,648
|
|
115
115
|
luna_quantum/solve/interfaces/usecases/model_fetch_metadata_usecase_i.py,sha256=MYtx7GHPpSBHF9uLp04UvrguM5U0tkUIexs1Ik3pvVY,890
|
|
116
116
|
luna_quantum/solve/interfaces/usecases/model_get_solutions_usecase_i.py,sha256=xuFbGUST2B3SZLWZXehaTBUu4ruIt77RS_6HFUOr3a0,840
|
|
@@ -123,6 +123,7 @@ luna_quantum/solve/interfaces/usecases/solve_job_cancel_usecase_i.py,sha256=KwF3
|
|
|
123
123
|
luna_quantum/solve/interfaces/usecases/solve_job_create_usecase_i.py,sha256=cCthq9Qq7FezrEL71aeVR1oIMsrEdRKrFuMU-zqKsIc,1334
|
|
124
124
|
luna_quantum/solve/interfaces/usecases/solve_job_delete_usecase_i.py,sha256=8JyNotccE9439GgAifyVcT1TQmAaoXEPMxFwDJFX404,783
|
|
125
125
|
luna_quantum/solve/interfaces/usecases/solve_job_fetch_updates_usecase_i.py,sha256=2ldduW0f3qB74wlf-eIU5Od_jhzBPVgJSw53I49wGmM,1078
|
|
126
|
+
luna_quantum/solve/interfaces/usecases/solve_job_get_by_id_usecase_i.py,sha256=pNctNaf5LT-fMAG-vakg3dHuEZnrWzJp9ihIJVKKTAM,756
|
|
126
127
|
luna_quantum/solve/interfaces/usecases/solve_job_get_result_usecase_i.py,sha256=eXMTO9J7c018kam-iVmkXmBhSTyU2ER9k_oQHJ5pmm0,2040
|
|
127
128
|
luna_quantum/solve/parameters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
128
129
|
luna_quantum/solve/parameters/algorithms/__init__.py,sha256=a4PwA87TLkZUB0_1cwH9_evgdjiyRaAKtQVP7L1CfVw,1298
|
|
@@ -152,12 +153,13 @@ luna_quantum/solve/parameters/algorithms/quantum_annealing/population_annealing_
|
|
|
152
153
|
luna_quantum/solve/parameters/algorithms/quantum_annealing/qbsolv_like_qpu.py,sha256=KaEePKVwjnU5Oab-Tdgl4kM500ccb_I30KdllsmcJW0,4077
|
|
153
154
|
luna_quantum/solve/parameters/algorithms/quantum_annealing/quantum_annealing.py,sha256=rtrBQKi4DMzMtXS2Yy-m8rw6IxF7OxxllQK9OrVnT5c,4898
|
|
154
155
|
luna_quantum/solve/parameters/algorithms/quantum_annealing/repeated_reverse_quantum_annealing.py,sha256=elQ-t4R_N9PTdZiWlMuPgtTNo3V4PA8CW0BAfZIP8s0,8440
|
|
155
|
-
luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py,sha256=
|
|
156
|
-
luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py,sha256=
|
|
157
|
-
luna_quantum/solve/parameters/algorithms/quantum_gate/
|
|
158
|
-
luna_quantum/solve/parameters/algorithms/quantum_gate/
|
|
159
|
-
luna_quantum/solve/parameters/algorithms/quantum_gate/
|
|
160
|
-
luna_quantum/solve/parameters/algorithms/quantum_gate/
|
|
156
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py,sha256=ts1Aiq40KaIPJZQ5J3wMHPao4bmEG4ZOrDpKyKtgG14,154
|
|
157
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py,sha256=1xKPEUmKs14hgDKYjsFNiqcMAcCyFVjRVArI-yyaOO4,278
|
|
158
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/__init__.py,sha256=TGABcymqSfH6gKXN6bjfUg4LKbPXhObtHRfAYaol6Kc,665
|
|
159
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/config.py,sha256=TPrsao2cwmVGB7PHAsl74hq7JoPi9CeSiwCKM748DTE,2252
|
|
160
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/flexqaoa.py,sha256=bPtgnkkSbXP2kvgfFHCXOJ6qmIdDzMQhtcHYVa6Ry68,7901
|
|
161
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/optimizers.py,sha256=NsnxR4cPeZg-tyTHr5uOtNE2IKXsng7sTgKDWqmz1lU,1759
|
|
162
|
+
luna_quantum/solve/parameters/algorithms/quantum_gate/flexqaoa/pipeline.py,sha256=Y9WUC1JKwpygPMI0W3pjt47avc2zeBLF2LcmQrtA2qA,5304
|
|
161
163
|
luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa.py,sha256=n6mRNslrN1AAKOi0wEbxhEdlpmWgxL_42oi7OD19Y4k,3843
|
|
162
164
|
luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa_fo.py,sha256=pBVOvxB48Y1LlMUObrm5s_mJLqp6SQNLaaGZGwFinuE,2587
|
|
163
165
|
luna_quantum/solve/parameters/algorithms/quantum_gate/vqe.py,sha256=ifXcgOw4bari3tebHkuIAnZ1xONGQRp9BnMuXCTGcKI,3875
|
|
@@ -171,8 +173,9 @@ luna_quantum/solve/parameters/algorithms/simulated_annealing/population_annealin
|
|
|
171
173
|
luna_quantum/solve/parameters/algorithms/simulated_annealing/qbsolv_like_simulated_annealing.py,sha256=roq_msa4EQrRpvFze23EnY7iQ-SDpu6ifSP9Thxn_6E,6583
|
|
172
174
|
luna_quantum/solve/parameters/algorithms/simulated_annealing/repeated_reverse_simulated_annealing.py,sha256=phLC27T7vcMCi2f82LaaAObMEqoiAZJXRK38dl-3rBY,8220
|
|
173
175
|
luna_quantum/solve/parameters/algorithms/simulated_annealing/simulated_annealing.py,sha256=urMh0DLN5iuj1uAoyXt7IzwMpNZWciTlq3GhApuNgFE,5660
|
|
174
|
-
luna_quantum/solve/parameters/backends/__init__.py,sha256=
|
|
176
|
+
luna_quantum/solve/parameters/backends/__init__.py,sha256=l-rXUsdJsWv9sJwzd0w-s-Ygftnb_uaxn40qx6cT18U,442
|
|
175
177
|
luna_quantum/solve/parameters/backends/aqarios.py,sha256=4qa9en_-IhFgs4NDGUDJ6XWNevuIGOWCPrp5DcSvwiw,364
|
|
178
|
+
luna_quantum/solve/parameters/backends/aqarios_gpu.py,sha256=SvCZZ4bHxpo0fReaHiUkHwh1RyrWrkd8OOgUS9szJQQ,375
|
|
176
179
|
luna_quantum/solve/parameters/backends/aws/__init__.py,sha256=2o6R9htZHM6mvUSi94S14Q3HdfMgyg_nMTTBzhYdwXY,158
|
|
177
180
|
luna_quantum/solve/parameters/backends/aws/aws.py,sha256=snFW6vY1xJsJuM84xZCmHPrpZBr469N3hIJ-3Im9ybQ,1119
|
|
178
181
|
luna_quantum/solve/parameters/backends/aws/aws_backend_base.py,sha256=XqSzblRhMNJ_tDk54xxF6emhhUVA7XjpA6VCvSH3hMc,2365
|
|
@@ -186,6 +189,7 @@ luna_quantum/solve/parameters/backends/ibm.py,sha256=pDw-0sifu_dfJS4zH2INu6txPh0
|
|
|
186
189
|
luna_quantum/solve/parameters/backends/qctrl.py,sha256=BADuXCvZzFNS9d6MNQIKdPixeQM_2q-dBoRVwEglG7c,3503
|
|
187
190
|
luna_quantum/solve/parameters/backends/zib.py,sha256=SqlLFYWCBHiPkxiCJGb1MH5JNtdKApllpd2f8lzn_D8,352
|
|
188
191
|
luna_quantum/solve/parameters/constants.py,sha256=N1_p4zBN_a_rbdnNPxyinN5FygO8Sd7iVPN3vCTwtYA,510
|
|
192
|
+
luna_quantum/solve/parameters/errors.py,sha256=WsT0yoGMGvyJik7QWFHlCgRirCO39j4NvsWYapdctxU,980
|
|
189
193
|
luna_quantum/solve/parameters/mixins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
190
194
|
luna_quantum/solve/parameters/mixins/fujitsu_common_params_mixin.py,sha256=aAk8A9c3pUVT7XrTHjOIdXR9KpLZXHccTSm8Cj_8mvw,10859
|
|
191
195
|
luna_quantum/solve/parameters/mixins/fujitsu_v2_mixin.py,sha256=isgIOQYMliM8YL1vzoK2f18IAno3LGL9pNc7VqsrKog,3482
|
|
@@ -250,6 +254,7 @@ luna_quantum/solve/usecases/solve_job_cancel_usecase.py,sha256=_FEUTfM4nq5iug3nT
|
|
|
250
254
|
luna_quantum/solve/usecases/solve_job_create_usecase.py,sha256=IcKN2VWTGw3J3Wgnt5QolHYWjk__9tRi-KTf-pBmsT0,3934
|
|
251
255
|
luna_quantum/solve/usecases/solve_job_delete_usecase.py,sha256=hUOLeFLU9NCggWMGuIJG7WYShQjP4H_iZJnPvBJgTpA,1128
|
|
252
256
|
luna_quantum/solve/usecases/solve_job_fetch_updates_usecase.py,sha256=W-Z6Q7IuyodjZmFKEsJGaa9V2fnGMPWj9FRN9gEdPNc,1686
|
|
257
|
+
luna_quantum/solve/usecases/solve_job_get_by_id_usecase.py,sha256=Asvz8PCUtNsJHsFHwAV9nRp2AZ8tec9LmaaBjc0MNjQ,1349
|
|
253
258
|
luna_quantum/solve/usecases/solve_job_get_result_usecase.py,sha256=OeujfR_SgYnO0lvgk1oqoGjsZfLN85ooSXZ9DazCQ74,3907
|
|
254
259
|
luna_quantum/transformations.py,sha256=AZtGBaJ0PTWsr4mpONoJq5BpNOXPcM85CnWDhPgXx_I,902
|
|
255
260
|
luna_quantum/transformations.pyi,sha256=wajxfV6QiD6R_7lUfk5kjAXp-ZHhOvLjtPqZCCX3UuU,10963
|
|
@@ -264,4 +269,4 @@ luna_quantum/util/pretty_base.py,sha256=QUNFiyz5MPsMCZB-wv622oeZ1uLkZ-_0xepNbuzQ
|
|
|
264
269
|
luna_quantum/util/pydantic_utils.py,sha256=nhl_SdLJVAizrtLVHvnbco84g8CdBVdVxN_jlXiv82w,1263
|
|
265
270
|
luna_quantum/utils.py,sha256=pBOkGXNJXlOzxAwTJv8nCj32Q6WNeh3t6Ka3lmTgy9c,134
|
|
266
271
|
luna_quantum/utils.pyi,sha256=yHHPluEJArUltZ2jJ9bPtTugj59E9TOTmYdyH35EHtU,1934
|
|
267
|
-
luna_quantum-1.0.
|
|
272
|
+
luna_quantum-1.0.8rc4.dist-info/RECORD,,
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
from typing import Literal
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel, Field, field_validator
|
|
4
|
-
|
|
5
|
-
from luna_quantum.solve.errors.solve_base_error import SolveBaseError
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class MixerTypeError(SolveBaseError):
|
|
9
|
-
"""Custom Mixer type exception."""
|
|
10
|
-
|
|
11
|
-
def __init__(self) -> None:
|
|
12
|
-
super().__init__("XY-mixer type can only occur once.")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class XYMixer(BaseModel):
|
|
16
|
-
"""XY-mixer configuration.
|
|
17
|
-
|
|
18
|
-
Attributes
|
|
19
|
-
----------
|
|
20
|
-
types: list[Literal["even", "odd", "last"]]
|
|
21
|
-
XY-ring-mixer pipeline
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
types: list[Literal["even", "odd", "last"]] = Field(
|
|
25
|
-
default=["even", "odd", "last"],
|
|
26
|
-
description="XY-ring-mixer types and order.",
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
@field_validator("types")
|
|
30
|
-
@classmethod
|
|
31
|
-
def _validate_type_once(
|
|
32
|
-
cls, v: list[Literal["even", "odd", "last"]]
|
|
33
|
-
) -> list[Literal["even", "odd", "last"]]:
|
|
34
|
-
if len(set(v)) < len(v):
|
|
35
|
-
raise MixerTypeError
|
|
36
|
-
return v
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class AdvancedConfig(BaseModel):
|
|
40
|
-
"""Additional FlexQAOA algorithm configuration.
|
|
41
|
-
|
|
42
|
-
Attributes
|
|
43
|
-
----------
|
|
44
|
-
mixer: XYMixer | Dict
|
|
45
|
-
Mixer types in XY-ring-mixer. Default: `["even", "odd", "last"]`
|
|
46
|
-
parallel_indicators: bool
|
|
47
|
-
Toggle to apply indicator functions in parallel. Does not affect sampling
|
|
48
|
-
performance of QAOA, but only circuit metrics, like number of qubits and
|
|
49
|
-
circuit depth.
|
|
50
|
-
discard_slack: bool
|
|
51
|
-
Discard slack qubits in evaluation, i.e. only measure on the binary variables of
|
|
52
|
-
the initial problem. This requires an auxilary cost function that penalizes
|
|
53
|
-
infeasible solutions.
|
|
54
|
-
infeas_penalty: float | None
|
|
55
|
-
Penalty for infeasible solutions if `discard_slack` is activated. By defalt,
|
|
56
|
-
10 times the max absolute intial bias is chosen.
|
|
57
|
-
"""
|
|
58
|
-
|
|
59
|
-
mixer: XYMixer = Field(
|
|
60
|
-
default_factory=lambda: XYMixer(),
|
|
61
|
-
description='Mixer types in XY-ring-mixer. Default: `["even", "odd", "last"]`',
|
|
62
|
-
)
|
|
63
|
-
parallel_indicators: bool = Field(
|
|
64
|
-
default=True,
|
|
65
|
-
description="Toggle to apply indicator functions in parallel. Does not affect "
|
|
66
|
-
"sampling performance of QAOA, but only circuit metrics, "
|
|
67
|
-
"like number of qubits and circuit depth.",
|
|
68
|
-
)
|
|
69
|
-
discard_slack: bool = Field(
|
|
70
|
-
default=False,
|
|
71
|
-
description="Discard slack qubits in evaluation, i.e. only measure on the "
|
|
72
|
-
"binary variables of the initial problem. This requires an auxilary cost "
|
|
73
|
-
"function that penalizes infeasible solutions.",
|
|
74
|
-
)
|
|
75
|
-
infeas_penalty: float | None = Field(
|
|
76
|
-
default=None,
|
|
77
|
-
ge=0,
|
|
78
|
-
description="Penalty for infeasible solutions if `discard_slack` is activated."
|
|
79
|
-
"By defalt, 10 times the max absolute intial bias is chosen.",
|
|
80
|
-
)
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
from typing import Literal
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel, Field
|
|
4
|
-
|
|
5
|
-
from luna_quantum.solve.parameters.algorithms.base_params.scipy_optimizer import (
|
|
6
|
-
ScipyOptimizerParams,
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class LinearOptimizerParams(ScipyOptimizerParams):
|
|
11
|
-
"""Optimizer for tuning a linear schedule of QAOA parameters.
|
|
12
|
-
|
|
13
|
-
Optimizes onyl two parameters: `delta_beta` and `delta_gamma` with the default
|
|
14
|
-
ScipyOptimizer.
|
|
15
|
-
|
|
16
|
-
Wrapper for scipy.optimize.minimize. See
|
|
17
|
-
[SciPy minimize documentation](
|
|
18
|
-
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html)
|
|
19
|
-
for more information of the available methods and parameters.
|
|
20
|
-
|
|
21
|
-
Attributes
|
|
22
|
-
----------
|
|
23
|
-
method: ScipyOptimizerMethod
|
|
24
|
-
Type of solver. See
|
|
25
|
-
[SciPy minimize documentation](
|
|
26
|
-
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html)
|
|
27
|
-
for supported methods.
|
|
28
|
-
tol: float | None
|
|
29
|
-
Tolerance for termination.
|
|
30
|
-
bounds: None | tuple[float, float] | list[tuple[float, float]]
|
|
31
|
-
Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,
|
|
32
|
-
trust-constr, COBYLA, and COBYQA methods. None is used to specify no bounds,
|
|
33
|
-
`(min, max)` is used to specify bounds for all variables. A sequence of
|
|
34
|
-
`(min, max)` can be used to specify bounds for each parameter individually.
|
|
35
|
-
jac: None | Literal["2-point", "3-point", "cs"]
|
|
36
|
-
Method for computing the gradient vector. Only for CG, BFGS, Newton-CG,
|
|
37
|
-
L-BFGS-B, TNC, SLSQP, dogleg, trust-ncg, trust-krylov, trust-exact and
|
|
38
|
-
trust-constr.
|
|
39
|
-
hess: None | Literal["2-point", "3-point", "cs"]
|
|
40
|
-
Method for computing the Hessian matrix. Only for Newton-CG, dogleg, trust-ncg,
|
|
41
|
-
trust-krylov, trust-exact and trust-constr.
|
|
42
|
-
maxiter: int
|
|
43
|
-
Maximum number of iterations to perform. Depending on the method
|
|
44
|
-
each iteration may use several function evaluations. Will be ignored for TNC
|
|
45
|
-
optimizer. Default: 100
|
|
46
|
-
options: dict[str, float]
|
|
47
|
-
A dictionary of solver options.
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
optimizer_type: Literal["linear"] = "linear"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class CombinedOptimizerParams(BaseModel):
|
|
54
|
-
"""Combination of LinearOptimizer and ScipyOptimizer.
|
|
55
|
-
|
|
56
|
-
Optimizer that first performs an optimization of the linear schedule and then
|
|
57
|
-
fine tunes individual parameters.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Attributes
|
|
61
|
-
----------
|
|
62
|
-
linear: LinearOptimizerParams | Dict
|
|
63
|
-
Parameters of the linear optimizer.
|
|
64
|
-
fine_tune: ScipyOptimizerParams | Dict
|
|
65
|
-
Parameters of the fine tuning optimizer.
|
|
66
|
-
"""
|
|
67
|
-
|
|
68
|
-
optimizer_type: Literal["combined"] = "combined"
|
|
69
|
-
linear: LinearOptimizerParams = Field(
|
|
70
|
-
default_factory=lambda: LinearOptimizerParams()
|
|
71
|
-
)
|
|
72
|
-
fine_tune: ScipyOptimizerParams = Field(
|
|
73
|
-
default_factory=lambda: ScipyOptimizerParams()
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class InterpolateOptimizerParams(BaseModel):
|
|
78
|
-
"""Optimizer with sequentially increasing number of QAOA layers.
|
|
79
|
-
|
|
80
|
-
Optimizer that starts with `reps` iteration and interpolates sequentially in
|
|
81
|
-
`reps_step` steps to `reps_end`. In between it performs a full optimization routine
|
|
82
|
-
tunes individual parameters.
|
|
83
|
-
|
|
84
|
-
Attributes
|
|
85
|
-
----------
|
|
86
|
-
optimiezr: LinearOptimizerParams | ScipyOptimizerParams | Dict
|
|
87
|
-
Parameters of the optimizer.
|
|
88
|
-
reps_step: int
|
|
89
|
-
Number of QAOA layers added for one interpolation.
|
|
90
|
-
reps_end: int
|
|
91
|
-
Final number of QAOA layers to be reached.
|
|
92
|
-
"""
|
|
93
|
-
|
|
94
|
-
optimizer_type: Literal["interpolate"] = "interpolate"
|
|
95
|
-
optimizer: ScipyOptimizerParams | LinearOptimizerParams = Field(
|
|
96
|
-
default_factory=lambda: ScipyOptimizerParams()
|
|
97
|
-
)
|
|
98
|
-
reps_step: int = Field(default=1, ge=1)
|
|
99
|
-
reps_end: int = Field(default=10, ge=1)
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
from pydantic import BaseModel, Field
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class OneHotParams(BaseModel):
|
|
5
|
-
"""Implements one-hot constraints through XY-mixers."""
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class IndicatorFunctionParams(BaseModel):
|
|
9
|
-
"""Implements inequality constraints via indicator functions.
|
|
10
|
-
|
|
11
|
-
Attributes
|
|
12
|
-
----------
|
|
13
|
-
penalty: float | None
|
|
14
|
-
Custom penalty factor for indicator functions. If none set, automatically
|
|
15
|
-
determined through upper and lower bounds.
|
|
16
|
-
penalty_scaling: float
|
|
17
|
-
Scaling of automatically determined penalty factor. Default: 2
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
penalty: float | None = Field(
|
|
21
|
-
default=None,
|
|
22
|
-
ge=0,
|
|
23
|
-
description="Custom penalty factor for indicator functions. If none set, "
|
|
24
|
-
"automatically determined through upper and lower bounds.",
|
|
25
|
-
)
|
|
26
|
-
penalty_scaling: float = Field(
|
|
27
|
-
default=2,
|
|
28
|
-
ge=0,
|
|
29
|
-
description="Scaling of automatically determined penalty factor. Default: 2",
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class QuadraticPenaltyParams(BaseModel):
|
|
34
|
-
"""Implements all constraints through quadratic penalties.
|
|
35
|
-
|
|
36
|
-
Adds penalty terms to the objective. Adds slack variables for inequality constraints
|
|
37
|
-
if neccessaray.
|
|
38
|
-
|
|
39
|
-
Attributes
|
|
40
|
-
----------
|
|
41
|
-
penalty: float | None
|
|
42
|
-
Custom penalty factor for quadratic penalty terms. If none is set, it is
|
|
43
|
-
automatically determined by taking 10 times the maximum absolute initial bias.
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
penalty: float | None = Field(
|
|
47
|
-
default=None,
|
|
48
|
-
ge=0,
|
|
49
|
-
description="Custom penalty factor for quadratic penalty terms. If none set, "
|
|
50
|
-
"automatically determined by taking 10 times the maximum absolute initial "
|
|
51
|
-
"bias.",
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class PipelineParams(BaseModel):
|
|
56
|
-
"""Defines the modular Constrained QAOA Pipeline.
|
|
57
|
-
|
|
58
|
-
By default all features are enabled.
|
|
59
|
-
|
|
60
|
-
Attributes
|
|
61
|
-
----------
|
|
62
|
-
indicator_function: IndicatorFunctionParams | Dict | None
|
|
63
|
-
Whether to implement inequality constraints with indicator functions. Disable
|
|
64
|
-
with setting to `None`.
|
|
65
|
-
one_hot: OneHotParams | Dict | None
|
|
66
|
-
Whether to implement inequality constraints with indicator functions. Disable
|
|
67
|
-
with setting to `None`.
|
|
68
|
-
quadratic_penalty: QuadraticPenaltyParams | Dict | None
|
|
69
|
-
Whether to implement inequality constraints with indicator functions. Disable
|
|
70
|
-
with setting to `None`.
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
indicator_function: IndicatorFunctionParams | None = Field(
|
|
74
|
-
default_factory=lambda: IndicatorFunctionParams(),
|
|
75
|
-
description="Whether to implement inequality constraints with indicator "
|
|
76
|
-
"functions. Disable with setting to `None`.",
|
|
77
|
-
)
|
|
78
|
-
one_hot: OneHotParams | None = Field(
|
|
79
|
-
default_factory=lambda: OneHotParams(),
|
|
80
|
-
description="Whether to implement inequality constraints with indicator "
|
|
81
|
-
"functions. Disable with setting to `None`.",
|
|
82
|
-
)
|
|
83
|
-
quadratic_penalty: QuadraticPenaltyParams | None = Field(
|
|
84
|
-
default_factory=lambda: QuadraticPenaltyParams(),
|
|
85
|
-
description="Whether to implement inequality constraints with indicator "
|
|
86
|
-
"functions. Disable with setting to `None`.",
|
|
87
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|