luna-quantum 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of luna-quantum might be problematic. Click here for more details.
- luna_quantum-0.0.16.dist-info/LICENSE +201 -0
- luna_quantum-0.0.16.dist-info/METADATA +46 -0
- luna_quantum-0.0.16.dist-info/RECORD +160 -0
- luna_quantum-0.0.16.dist-info/WHEEL +4 -0
- luna_sdk/__init__.py +2 -0
- luna_sdk/constants.py +1 -0
- luna_sdk/controllers/__init__.py +2 -0
- luna_sdk/controllers/custom_login_client.py +61 -0
- luna_sdk/controllers/luna_platform_client.py +62 -0
- luna_sdk/controllers/luna_q.py +36 -0
- luna_sdk/controllers/luna_solve.py +49 -0
- luna_sdk/controllers/luna_transform.py +41 -0
- luna_sdk/error/__init__.py +0 -0
- luna_sdk/error/http_error_utils.py +100 -0
- luna_sdk/exceptions/__init__.py +1 -0
- luna_sdk/exceptions/encryption_exception.py +6 -0
- luna_sdk/exceptions/luna_exception.py +7 -0
- luna_sdk/exceptions/luna_server_exception.py +18 -0
- luna_sdk/exceptions/timeout_exception.py +10 -0
- luna_sdk/exceptions/transformation.py +11 -0
- luna_sdk/interfaces/__init__.py +5 -0
- luna_sdk/interfaces/circuit_repo_i.py +62 -0
- luna_sdk/interfaces/clients/__init__.py +0 -0
- luna_sdk/interfaces/clients/client_i.py +10 -0
- luna_sdk/interfaces/clients/luna_q_i.py +39 -0
- luna_sdk/interfaces/clients/luna_solve_i.py +37 -0
- luna_sdk/interfaces/clients/luna_transform_i.py +33 -0
- luna_sdk/interfaces/cplex_repo_i.py +121 -0
- luna_sdk/interfaces/info_repo_i.py +40 -0
- luna_sdk/interfaces/lp_repo_i.py +106 -0
- luna_sdk/interfaces/optimization_repo_i.py +262 -0
- luna_sdk/interfaces/qpu_token_repo_i.py +151 -0
- luna_sdk/interfaces/repository_i.py +14 -0
- luna_sdk/interfaces/solutions_repo_i.py +219 -0
- luna_sdk/py.typed +0 -0
- luna_sdk/repositories/__init__.py +4 -0
- luna_sdk/repositories/circuit_repo.py +104 -0
- luna_sdk/repositories/cplex_repo.py +118 -0
- luna_sdk/repositories/info_repo.py +45 -0
- luna_sdk/repositories/lp_repo.py +105 -0
- luna_sdk/repositories/optimization_repo.py +358 -0
- luna_sdk/repositories/qpu_token_repo.py +226 -0
- luna_sdk/repositories/solutions_repo.py +347 -0
- luna_sdk/schemas/__init__.py +4 -0
- luna_sdk/schemas/circuit.py +43 -0
- luna_sdk/schemas/create/__init__.py +3 -0
- luna_sdk/schemas/create/circuit.py +29 -0
- luna_sdk/schemas/create/optimization.py +22 -0
- luna_sdk/schemas/create/qpu_token.py +26 -0
- luna_sdk/schemas/create/qubo.py +19 -0
- luna_sdk/schemas/create/solution.py +15 -0
- luna_sdk/schemas/enums/__init__.py +0 -0
- luna_sdk/schemas/enums/circuit.py +14 -0
- luna_sdk/schemas/enums/optimization.py +10 -0
- luna_sdk/schemas/enums/problem.py +48 -0
- luna_sdk/schemas/enums/qpu_token_type.py +6 -0
- luna_sdk/schemas/enums/solution.py +8 -0
- luna_sdk/schemas/enums/status.py +10 -0
- luna_sdk/schemas/enums/timeframe.py +11 -0
- luna_sdk/schemas/error_message.py +12 -0
- luna_sdk/schemas/optimization.py +75 -0
- luna_sdk/schemas/optimization_formats/__init__.py +0 -0
- luna_sdk/schemas/optimization_formats/bqm.py +34 -0
- luna_sdk/schemas/optimization_formats/cqm.py +127 -0
- luna_sdk/schemas/optimization_formats/lp.py +9 -0
- luna_sdk/schemas/optimization_formats/qm.py +30 -0
- luna_sdk/schemas/pretty_base.py +49 -0
- luna_sdk/schemas/qpu_token.py +60 -0
- luna_sdk/schemas/representation.py +19 -0
- luna_sdk/schemas/rest/__init__.py +0 -0
- luna_sdk/schemas/rest/qpu_token/__init__.py +0 -0
- luna_sdk/schemas/rest/qpu_token/token_provider.py +45 -0
- luna_sdk/schemas/solution.py +227 -0
- luna_sdk/schemas/solver_info.py +11 -0
- luna_sdk/schemas/solver_parameters/aws/__init__.py +1 -0
- luna_sdk/schemas/solver_parameters/aws/qaoa.py +24 -0
- luna_sdk/schemas/solver_parameters/dwave/__init__.py +72 -0
- luna_sdk/schemas/solver_parameters/dwave/base.py +409 -0
- luna_sdk/schemas/solver_parameters/dwave/dialectic_search.py +31 -0
- luna_sdk/schemas/solver_parameters/dwave/kerberos.py +71 -0
- luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_bqm.py +19 -0
- luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_cqm.py +22 -0
- luna_sdk/schemas/solver_parameters/dwave/parallel_tempering.py +30 -0
- luna_sdk/schemas/solver_parameters/dwave/parallel_tempering_qpu.py +37 -0
- luna_sdk/schemas/solver_parameters/dwave/population_annealing.py +25 -0
- luna_sdk/schemas/solver_parameters/dwave/population_annealing_qpu.py +35 -0
- luna_sdk/schemas/solver_parameters/dwave/qaga.py +56 -0
- luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_qpu.py +19 -0
- luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_simulated_annealing.py +22 -0
- luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_tabu_search.py +21 -0
- luna_sdk/schemas/solver_parameters/dwave/quantum_annealing.py +20 -0
- luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_quantum_annealing.py +82 -0
- luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_simulated_annealing.py +89 -0
- luna_sdk/schemas/solver_parameters/dwave/saga.py +61 -0
- luna_sdk/schemas/solver_parameters/dwave/simulated_annealing.py +74 -0
- luna_sdk/schemas/solver_parameters/dwave/tabu_search.py +72 -0
- luna_sdk/schemas/solver_parameters/fujitsu/__init__.py +20 -0
- luna_sdk/schemas/solver_parameters/fujitsu/base.py +47 -0
- luna_sdk/schemas/solver_parameters/fujitsu/digital_annealer_cpu.py +129 -0
- luna_sdk/schemas/solver_parameters/fujitsu/digital_annealer_v2.py +149 -0
- luna_sdk/schemas/solver_parameters/fujitsu/digital_annealer_v3.py +150 -0
- luna_sdk/schemas/solver_parameters/fujitsu/partial_config.py +177 -0
- luna_sdk/schemas/solver_parameters/ibm/__init__.py +4 -0
- luna_sdk/schemas/solver_parameters/ibm/qaoa.py +64 -0
- luna_sdk/schemas/solver_parameters/ibm/standard_parameters.py +27 -0
- luna_sdk/schemas/solver_parameters/ibm/vqe.py +49 -0
- luna_sdk/schemas/solver_parameters/qctrl/__init__.py +1 -0
- luna_sdk/schemas/solver_parameters/qctrl/qaoa.py +47 -0
- luna_sdk/schemas/transformations/__init__.py +2 -0
- luna_sdk/schemas/transformations/bqm.py +33 -0
- luna_sdk/schemas/transformations/matrix.py +12 -0
- luna_sdk/schemas/use_cases/__init__.py +54 -0
- luna_sdk/schemas/use_cases/arbitrage_edge_based.py +49 -0
- luna_sdk/schemas/use_cases/arbitrage_node_based.py +54 -0
- luna_sdk/schemas/use_cases/base.py +5 -0
- luna_sdk/schemas/use_cases/binary_integer_linear_programming.py +53 -0
- luna_sdk/schemas/use_cases/binary_paint_shop_problem.py +36 -0
- luna_sdk/schemas/use_cases/credit_scoring_feature_selection.py +39 -0
- luna_sdk/schemas/use_cases/dynamic_portfolio_optimization.py +63 -0
- luna_sdk/schemas/use_cases/exact_cover.py +50 -0
- luna_sdk/schemas/use_cases/flight_gate_assignment.py +78 -0
- luna_sdk/schemas/use_cases/graph_coloring.py +41 -0
- luna_sdk/schemas/use_cases/graph_isomorphism.py +53 -0
- luna_sdk/schemas/use_cases/graph_partitioning.py +45 -0
- luna_sdk/schemas/use_cases/hamiltonian_cycle.py +48 -0
- luna_sdk/schemas/use_cases/induced_subgraph_isomorphism.py +49 -0
- luna_sdk/schemas/use_cases/job_shop_scheduling.py +43 -0
- luna_sdk/schemas/use_cases/k_medoids_clustering.py +48 -0
- luna_sdk/schemas/use_cases/knapsack_integer_weights.py +55 -0
- luna_sdk/schemas/use_cases/linear_regression.py +59 -0
- luna_sdk/schemas/use_cases/lmwcs.py +80 -0
- luna_sdk/schemas/use_cases/longest_path.py +49 -0
- luna_sdk/schemas/use_cases/market_graph_clustering.py +60 -0
- luna_sdk/schemas/use_cases/max2sat.py +51 -0
- luna_sdk/schemas/use_cases/max3sat.py +52 -0
- luna_sdk/schemas/use_cases/max_clique.py +59 -0
- luna_sdk/schemas/use_cases/max_cut.py +47 -0
- luna_sdk/schemas/use_cases/max_independent_set.py +36 -0
- luna_sdk/schemas/use_cases/minimal_maximal_matching.py +53 -0
- luna_sdk/schemas/use_cases/minimal_spanning_tree.py +87 -0
- luna_sdk/schemas/use_cases/minimum_vertex_cover.py +44 -0
- luna_sdk/schemas/use_cases/number_partitioning.py +31 -0
- luna_sdk/schemas/use_cases/portfolio_optimization.py +45 -0
- luna_sdk/schemas/use_cases/portfolio_optimization_ib_tv.py +62 -0
- luna_sdk/schemas/use_cases/quadratic_assignment.py +48 -0
- luna_sdk/schemas/use_cases/quadratic_knapsack.py +47 -0
- luna_sdk/schemas/use_cases/satellite_scheduling.py +72 -0
- luna_sdk/schemas/use_cases/sensor_placement.py +57 -0
- luna_sdk/schemas/use_cases/set_cover.py +55 -0
- luna_sdk/schemas/use_cases/set_packing.py +53 -0
- luna_sdk/schemas/use_cases/set_partitioning.py +51 -0
- luna_sdk/schemas/use_cases/subgraph_isomorphism.py +56 -0
- luna_sdk/schemas/use_cases/subset_sum.py +36 -0
- luna_sdk/schemas/use_cases/support_vector_machine.py +63 -0
- luna_sdk/schemas/use_cases/traffic_flow.py +34 -0
- luna_sdk/schemas/use_cases/travelling_salesman_problem.py +52 -0
- luna_sdk/schemas/use_cases/type_aliases.py +11 -0
- luna_sdk/schemas/use_cases/weighted_max_cut.py +36 -0
- luna_sdk/utils/__init__.py +0 -0
- luna_sdk/utils/qpu_tokens.py +52 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from luna_sdk.controllers.luna_platform_client import LunaPlatformClient
|
|
2
|
+
from luna_sdk.interfaces.clients.luna_transform_i import ILunaTransform
|
|
3
|
+
from luna_sdk.interfaces.cplex_repo_i import ICplexRepo
|
|
4
|
+
from luna_sdk.interfaces.lp_repo_i import ILPRepo
|
|
5
|
+
from luna_sdk.repositories.cplex_repo import CplexRepo
|
|
6
|
+
from luna_sdk.repositories.lp_repo import LPRepo
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class LunaTransform(LunaPlatformClient, ILunaTransform):
|
|
10
|
+
cplex: ICplexRepo = None # type: ignore
|
|
11
|
+
lp: ILPRepo = None # type: ignore
|
|
12
|
+
|
|
13
|
+
def __init__(
|
|
14
|
+
self,
|
|
15
|
+
email: str,
|
|
16
|
+
password: str,
|
|
17
|
+
timeout: float = 10.0,
|
|
18
|
+
):
|
|
19
|
+
"""
|
|
20
|
+
LunaSolve is the main entrypoint for all LunaSolve related tasks.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
email: str
|
|
25
|
+
User's email
|
|
26
|
+
password: str
|
|
27
|
+
User's password
|
|
28
|
+
timeout: float
|
|
29
|
+
Timeout for the requests. Default value 10.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
"""
|
|
34
|
+
super().__init__(
|
|
35
|
+
email=email,
|
|
36
|
+
password=password,
|
|
37
|
+
timeout=timeout,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
self.cplex = CplexRepo(self._client)
|
|
41
|
+
self.lp = LPRepo(self._client)
|
|
File without changes
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from httpx import HTTPStatusError, RequestError, Response
|
|
5
|
+
|
|
6
|
+
from luna_sdk.exceptions.luna_server_exception import LunaServerException
|
|
7
|
+
from luna_sdk.schemas.error_message import ErrorMessage
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class HttpErrorUtils:
|
|
11
|
+
@staticmethod
|
|
12
|
+
def __sdk_custom_request_errors(
|
|
13
|
+
response: Response,
|
|
14
|
+
) -> Optional[LunaServerException]:
|
|
15
|
+
"""
|
|
16
|
+
Check if the response needs a custom error message from the SDK.
|
|
17
|
+
|
|
18
|
+
This is the place to add other custom error messages.
|
|
19
|
+
This is helpful then the default http error messages are not enough for the user.
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
response:
|
|
24
|
+
Response object from the request
|
|
25
|
+
|
|
26
|
+
Returns
|
|
27
|
+
-------
|
|
28
|
+
Optional[LunaServerException]
|
|
29
|
+
If the response needs a custom error message, return the exception.
|
|
30
|
+
Otherwise, return None.
|
|
31
|
+
"""
|
|
32
|
+
exception: Optional[LunaServerException] = None
|
|
33
|
+
|
|
34
|
+
def create_error_message(
|
|
35
|
+
internal_code: str, message: str
|
|
36
|
+
) -> LunaServerException:
|
|
37
|
+
return LunaServerException(
|
|
38
|
+
response.status_code,
|
|
39
|
+
ErrorMessage(
|
|
40
|
+
internal_code=f"SDK-{internal_code}",
|
|
41
|
+
message=message,
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
if response.status_code == 502:
|
|
46
|
+
# Catch error when upload was too long
|
|
47
|
+
exception = create_error_message(
|
|
48
|
+
"LUNA_GATEWAY_TIMEOUT",
|
|
49
|
+
"The Luna server did not respond within time,"
|
|
50
|
+
" leading to a timeout. Try reducing the size of the optimization.",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
return exception
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def check_for_error(response: Response) -> None:
|
|
57
|
+
"""
|
|
58
|
+
Check if an error occurred and rais the error if so.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
response: Response
|
|
63
|
+
Response object from the request
|
|
64
|
+
|
|
65
|
+
Raises
|
|
66
|
+
------
|
|
67
|
+
LunaServerException
|
|
68
|
+
If an error occurred with the request. The error message is in the exception.
|
|
69
|
+
RequestError
|
|
70
|
+
If an error occurred with the request outside the http status codes 4xx and 5xx.
|
|
71
|
+
"""
|
|
72
|
+
try:
|
|
73
|
+
response.raise_for_status()
|
|
74
|
+
except HTTPStatusError as e:
|
|
75
|
+
exception: Optional[LunaServerException]
|
|
76
|
+
|
|
77
|
+
try:
|
|
78
|
+
error_msg: ErrorMessage = ErrorMessage.model_validate_json(
|
|
79
|
+
response.text
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# Convert the error message to the correct exception
|
|
83
|
+
exception = LunaServerException(response.status_code, error_msg)
|
|
84
|
+
|
|
85
|
+
except ValueError:
|
|
86
|
+
# The server can generate errors that are in a different format, and we
|
|
87
|
+
# have less to no control how they look like.
|
|
88
|
+
# In this case, we will try to create a custom error messages.
|
|
89
|
+
exception = HttpErrorUtils.__sdk_custom_request_errors(response)
|
|
90
|
+
|
|
91
|
+
if exception:
|
|
92
|
+
logging.error(exception, exc_info=False)
|
|
93
|
+
raise exception
|
|
94
|
+
else:
|
|
95
|
+
logging.error(exception, exc_info=True)
|
|
96
|
+
raise e
|
|
97
|
+
|
|
98
|
+
except RequestError as e:
|
|
99
|
+
logging.error(e, exc_info=True)
|
|
100
|
+
raise e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .transformation import TransformationException
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from luna_sdk.exceptions.luna_exception import LunaException
|
|
2
|
+
from luna_sdk.schemas.error_message import ErrorMessage
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class LunaServerException(LunaException):
|
|
6
|
+
http_status_code: int
|
|
7
|
+
error_message: ErrorMessage
|
|
8
|
+
|
|
9
|
+
def __init__(self, http_status_code: int, error_message: ErrorMessage):
|
|
10
|
+
self.http_status_code = http_status_code
|
|
11
|
+
self.error_message = error_message
|
|
12
|
+
super().__init__(error_message.message)
|
|
13
|
+
|
|
14
|
+
def __str__(self):
|
|
15
|
+
return (
|
|
16
|
+
f"The Luna-Server reported the error '{self.error_message.internal_code}' "
|
|
17
|
+
f"with the message:\n {self.error_message.message}"
|
|
18
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from luna_sdk.exceptions.luna_exception import LunaException
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TimeoutException(LunaException):
|
|
5
|
+
def __init__(self):
|
|
6
|
+
super().__init__(
|
|
7
|
+
"Luna Timeout. The request took too long to complete."
|
|
8
|
+
" Please increase timeout value or try again later."
|
|
9
|
+
" If the problem persists, please contact our support team."
|
|
10
|
+
)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from luna_sdk.exceptions.luna_exception import LunaException
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class TransformationException(LunaException):
|
|
5
|
+
def __str__(self):
|
|
6
|
+
return "An unexpected error occurred during transformation, please contact support or open an issue."
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WeightedConstraintException(LunaException):
|
|
10
|
+
def __str__(self):
|
|
11
|
+
return "Weighted constraints for CQM are not supported"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any, Dict, Optional
|
|
3
|
+
|
|
4
|
+
from luna_sdk.interfaces.repository_i import IRepository
|
|
5
|
+
from luna_sdk.schemas.circuit import CircuitJob, CircuitResult
|
|
6
|
+
from luna_sdk.schemas.enums.circuit import CircuitProviderEnum
|
|
7
|
+
from luna_sdk.schemas.qpu_token import TokenProvider
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ICircuitRepo(IRepository, ABC):
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def create(
|
|
13
|
+
self,
|
|
14
|
+
circuit: str,
|
|
15
|
+
provider: CircuitProviderEnum,
|
|
16
|
+
params: Dict[str, Any] = {},
|
|
17
|
+
qpu_tokens: Optional[TokenProvider] = None,
|
|
18
|
+
timeout: Optional[float] = 10800.0,
|
|
19
|
+
encryption_key: Optional[str] = None,
|
|
20
|
+
) -> CircuitJob:
|
|
21
|
+
"""
|
|
22
|
+
Create a circuit solution.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
circuit: str
|
|
27
|
+
The circuit which to create a solution for.
|
|
28
|
+
provider: CircuitProviderEnum
|
|
29
|
+
Which provider to use to solve the circuit.
|
|
30
|
+
params: Dict[str, Any]
|
|
31
|
+
Additional parameters of the circuit.
|
|
32
|
+
qpu_tokens: Optional[TokenProvider]
|
|
33
|
+
The tokens to be used for the QPU.
|
|
34
|
+
timeout: Optional[float]
|
|
35
|
+
Default = 10800.0. Timeout for the api request. If set to None,
|
|
36
|
+
there won't be any timeout. Increase or disable the timeout if you face
|
|
37
|
+
issues uploading big Problems.
|
|
38
|
+
encryption_key: Optional[str]
|
|
39
|
+
Encryption key to be used for encryption of QPU tokens.
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
CircuitJob
|
|
43
|
+
The created circuit job.
|
|
44
|
+
"""
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
|
|
47
|
+
@abstractmethod
|
|
48
|
+
def get(
|
|
49
|
+
self, job: CircuitJob, encryption_key: Optional[str] = None
|
|
50
|
+
) -> CircuitResult:
|
|
51
|
+
"""
|
|
52
|
+
Attributes:
|
|
53
|
+
choices: A list containing a string or `AliasPath`.
|
|
54
|
+
encryption_key: Optional[str]
|
|
55
|
+
Encryption key to be used for encryption of QPU tokens.
|
|
56
|
+
|
|
57
|
+
This is equivalent to Python ``sum`` of :meth:`time.time`.
|
|
58
|
+
:time.time: 1.0
|
|
59
|
+
`CircuitResult`
|
|
60
|
+
Some sections are omitted here for simplicity.
|
|
61
|
+
"""
|
|
62
|
+
raise NotImplementedError
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
from luna_sdk.interfaces import ICircuitRepo
|
|
4
|
+
from luna_sdk.interfaces.clients.client_i import IClient
|
|
5
|
+
from luna_sdk.interfaces.qpu_token_repo_i import IQpuTokenRepo
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ILunaQ(IClient, ABC):
|
|
9
|
+
"""
|
|
10
|
+
Interface for the LunaQ client
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
@abstractmethod
|
|
17
|
+
def qpu_token(self) -> IQpuTokenRepo:
|
|
18
|
+
"""
|
|
19
|
+
Returns a QPU token repository
|
|
20
|
+
|
|
21
|
+
Examples
|
|
22
|
+
--------
|
|
23
|
+
>>> add(4.0, 2.0)
|
|
24
|
+
6.0
|
|
25
|
+
>>> add(4, 2)
|
|
26
|
+
6.0
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
raise NotImplementedError
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
@abstractmethod
|
|
35
|
+
def circuit(self) -> ICircuitRepo:
|
|
36
|
+
"""
|
|
37
|
+
Returns a circuit :py:class: repository
|
|
38
|
+
"""
|
|
39
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
from luna_sdk.interfaces.clients.client_i import IClient
|
|
4
|
+
from luna_sdk.interfaces.info_repo_i import IInfoRepo
|
|
5
|
+
from luna_sdk.interfaces.optimization_repo_i import IOptimizationRepo
|
|
6
|
+
from luna_sdk.interfaces.qpu_token_repo_i import IQpuTokenRepo
|
|
7
|
+
from luna_sdk.interfaces.solutions_repo_i import ISolutionsRepo
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ILunaSolve(IClient, ABC):
|
|
11
|
+
@property
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def optimization(self) -> IOptimizationRepo:
|
|
14
|
+
"""
|
|
15
|
+
Returns an optimization repository
|
|
16
|
+
|
|
17
|
+
Returns
|
|
18
|
+
----------
|
|
19
|
+
IOptimizationRepo]
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
raise NotImplementedError
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def solution(self) -> ISolutionsRepo:
|
|
27
|
+
raise NotImplementedError
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def qpu_token(self) -> IQpuTokenRepo:
|
|
32
|
+
raise NotImplementedError
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
@abstractmethod
|
|
36
|
+
def info(self) -> IInfoRepo:
|
|
37
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from abc import abstractmethod, ABC
|
|
2
|
+
|
|
3
|
+
from luna_sdk.interfaces import IClient, IOptimizationRepo
|
|
4
|
+
from luna_sdk.interfaces.cplex_repo_i import ICplexRepo
|
|
5
|
+
from luna_sdk.interfaces.lp_repo_i import ILPRepo
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ILunaTransform(IClient, ABC):
|
|
9
|
+
@property
|
|
10
|
+
@abstractmethod
|
|
11
|
+
def cplex(self) -> ICplexRepo:
|
|
12
|
+
"""
|
|
13
|
+
Returns an docplex repository
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
----------
|
|
17
|
+
ICplexRepo
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
raise NotImplementedError
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def lp(self) -> ILPRepo:
|
|
25
|
+
"""
|
|
26
|
+
Returns a lp repository
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
----------
|
|
30
|
+
ILPRepo
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from functools import partial
|
|
3
|
+
from typing import Tuple, List
|
|
4
|
+
|
|
5
|
+
import dimod
|
|
6
|
+
from dimod import ConstrainedQuadraticModel
|
|
7
|
+
from docplex.mp.model import Model as DOCplexModel # type: ignore
|
|
8
|
+
from qiskit_optimization import QuadraticProgram
|
|
9
|
+
|
|
10
|
+
from luna_sdk.interfaces import IRepository # type: ignore
|
|
11
|
+
from dimod.constrained.constrained import CQMToBQMInverter
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ICplexRepo(IRepository, ABC):
|
|
15
|
+
@staticmethod
|
|
16
|
+
def inverter(sample, var_indices, inverter_bqm) -> CQMToBQMInverter:
|
|
17
|
+
sample_list = list(sample.values())
|
|
18
|
+
var_sample = {name: sample_list[index] for name, index in var_indices.items()}
|
|
19
|
+
return inverter_bqm(var_sample)
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def to_qubo_qiskit(self, docplex_model: DOCplexModel) -> QuadraticProgram:
|
|
23
|
+
"""
|
|
24
|
+
Transform DOCplex model to QUBO Qiskit
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
docplex_model: docplex.mp.model.Model
|
|
29
|
+
DOCplex problem description
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
QuadraticProgram
|
|
34
|
+
QUBO Qiskit representation
|
|
35
|
+
"""
|
|
36
|
+
raise NotImplementedError
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def to_lp_file(self, docplex_model: DOCplexModel, filepath: str) -> None:
|
|
40
|
+
"""
|
|
41
|
+
Transform DOCplex to LP representation
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
docplex_model: docplex.mp.model.Model
|
|
46
|
+
DOCplex problem description
|
|
47
|
+
filepath: str
|
|
48
|
+
.lp file path where result should be stored
|
|
49
|
+
"""
|
|
50
|
+
raise NotImplementedError
|
|
51
|
+
|
|
52
|
+
@abstractmethod
|
|
53
|
+
def to_lp_string(self, docplex_model: DOCplexModel) -> str:
|
|
54
|
+
"""
|
|
55
|
+
Transform DOCplex to LP representation
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
docplex_model: docplex.mp.model.Model
|
|
60
|
+
DOCplex problem description
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
str
|
|
64
|
+
LP representation
|
|
65
|
+
"""
|
|
66
|
+
raise NotImplementedError
|
|
67
|
+
|
|
68
|
+
@abstractmethod
|
|
69
|
+
def to_qubo_matrix(
|
|
70
|
+
self, docplex_model: DOCplexModel
|
|
71
|
+
) -> Tuple[List[List[float]], partial]:
|
|
72
|
+
"""
|
|
73
|
+
Transform DOCplex model to QUBO matrix
|
|
74
|
+
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
docplex_model: docplex.mp.model.Model
|
|
78
|
+
DOCplex problem description
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
Tuple[List[List[float]], partial]
|
|
83
|
+
QUBO matrix representation and inverter
|
|
84
|
+
"""
|
|
85
|
+
raise NotImplementedError
|
|
86
|
+
|
|
87
|
+
@abstractmethod
|
|
88
|
+
def to_bqm(
|
|
89
|
+
self, docplex_model: DOCplexModel
|
|
90
|
+
) -> Tuple[dimod.BinaryQuadraticModel, CQMToBQMInverter]:
|
|
91
|
+
"""
|
|
92
|
+
Transform DOCplex model to BQM model
|
|
93
|
+
|
|
94
|
+
Parameters
|
|
95
|
+
----------
|
|
96
|
+
docplex_model: docplex.mp.model.Model
|
|
97
|
+
DOCplex problem description
|
|
98
|
+
|
|
99
|
+
Returns
|
|
100
|
+
-------
|
|
101
|
+
Tuple[dimod.BinaryQuadraticModel, CQMToBQMInverter]
|
|
102
|
+
BQM representation and inverter
|
|
103
|
+
"""
|
|
104
|
+
raise NotImplementedError
|
|
105
|
+
|
|
106
|
+
@abstractmethod
|
|
107
|
+
def to_cqm(self, docplex_model: DOCplexModel) -> ConstrainedQuadraticModel:
|
|
108
|
+
"""
|
|
109
|
+
Transform DOCplex model to CQM model
|
|
110
|
+
|
|
111
|
+
Parameters
|
|
112
|
+
----------
|
|
113
|
+
docplex_model: docplex.mp.model.Model
|
|
114
|
+
DOCplex problem description
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
ConstrainedQuadraticModel
|
|
119
|
+
CQM representation
|
|
120
|
+
"""
|
|
121
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
from luna_sdk.interfaces.repository_i import IRepository
|
|
5
|
+
from luna_sdk.schemas.solver_info import SolverInfo
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class IInfoRepo(IRepository, ABC):
|
|
9
|
+
@abstractmethod
|
|
10
|
+
def solvers_available(
|
|
11
|
+
self, solver_name: Optional[str] = None
|
|
12
|
+
) -> Dict[str, Dict[str, SolverInfo]]:
|
|
13
|
+
"""
|
|
14
|
+
Get list of available solvers.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
solver_name: Optional[str]
|
|
19
|
+
Name of the solver that should be retrieved. If not specified, all solvers
|
|
20
|
+
will be returned.
|
|
21
|
+
|
|
22
|
+
Returns
|
|
23
|
+
-------
|
|
24
|
+
Dict[str, Dict[str, SolverInfo]]
|
|
25
|
+
Dictionary containing the provider name as the key, and a dictionary of
|
|
26
|
+
the solver name and solver-specific information as the value.
|
|
27
|
+
"""
|
|
28
|
+
raise NotImplementedError
|
|
29
|
+
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def providers_available(self) -> List[str]:
|
|
32
|
+
"""
|
|
33
|
+
Get list of available providers.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
List[str]
|
|
38
|
+
List of available QPU providers.
|
|
39
|
+
"""
|
|
40
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from functools import partial
|
|
3
|
+
from typing import Tuple, List
|
|
4
|
+
|
|
5
|
+
import dimod
|
|
6
|
+
from dimod import ConstrainedQuadraticModel
|
|
7
|
+
from dimod.constrained.constrained import CQMToBQMInverter
|
|
8
|
+
from docplex.mp.model import Model as DOCplexModel # type: ignore
|
|
9
|
+
from qiskit_optimization import QuadraticProgram
|
|
10
|
+
|
|
11
|
+
from luna_sdk.interfaces import IRepository # type: ignore
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ILPRepo(IRepository, ABC):
|
|
15
|
+
@staticmethod
|
|
16
|
+
def inverter(sample, var_indices, inverter_bqm) -> CQMToBQMInverter:
|
|
17
|
+
sample_list = list(sample.values())
|
|
18
|
+
var_sample = {name: sample_list[index] for name, index in var_indices.items()}
|
|
19
|
+
return inverter_bqm(var_sample)
|
|
20
|
+
|
|
21
|
+
@abstractmethod
|
|
22
|
+
def to_qubo_qiskit(self, lp_string: str) -> QuadraticProgram:
|
|
23
|
+
"""
|
|
24
|
+
Transform LP to QUBO Qiskit
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
----------
|
|
28
|
+
lp_string: str
|
|
29
|
+
LP problem description
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
QuadraticProgram
|
|
34
|
+
QUBO Qiskit representation
|
|
35
|
+
"""
|
|
36
|
+
raise NotImplementedError
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def to_docplex(self, lp_string: str) -> DOCplexModel:
|
|
40
|
+
"""
|
|
41
|
+
Transform LP to DOCplex
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
lp_string: str
|
|
46
|
+
LP problem description
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
DOCplexModel
|
|
51
|
+
DOCplex representation
|
|
52
|
+
"""
|
|
53
|
+
raise NotImplementedError
|
|
54
|
+
|
|
55
|
+
@abstractmethod
|
|
56
|
+
def to_qubo_matrix(self, lp_string: str) -> Tuple[List[List[float]], partial]:
|
|
57
|
+
"""
|
|
58
|
+
Transform LP to QUBO matrix
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
lp_string: str
|
|
63
|
+
LP problem description
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
Tuple[List[List[float]], partial]
|
|
68
|
+
QUBO matrix representation and inverter
|
|
69
|
+
"""
|
|
70
|
+
raise NotImplementedError
|
|
71
|
+
|
|
72
|
+
@abstractmethod
|
|
73
|
+
def to_bqm(
|
|
74
|
+
self, lp_string: str
|
|
75
|
+
) -> Tuple[dimod.BinaryQuadraticModel, CQMToBQMInverter]:
|
|
76
|
+
"""
|
|
77
|
+
Transform LP to BQM model
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
lp_string: str
|
|
82
|
+
LP problem description
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
Tuple[dimod.BinaryQuadraticModel, CQMToBQMInverter]
|
|
87
|
+
BQM representation and inverter
|
|
88
|
+
"""
|
|
89
|
+
raise NotImplementedError
|
|
90
|
+
|
|
91
|
+
@abstractmethod
|
|
92
|
+
def to_cqm(self, lp_string: str) -> ConstrainedQuadraticModel:
|
|
93
|
+
"""
|
|
94
|
+
Transform LP to CQM model
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
lp_string: str
|
|
99
|
+
LP problem description
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
103
|
+
ConstrainedQuadraticModel
|
|
104
|
+
CQM representation
|
|
105
|
+
"""
|
|
106
|
+
raise NotImplementedError
|