luna-quantum 0.0.16__py3-none-any.whl → 0.0.29__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 → luna_quantum-0.0.29.dist-info}/METADATA +2 -1
- {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.29.dist-info}/RECORD +57 -53
- luna_sdk/controllers/custom_login_client.py +8 -3
- luna_sdk/controllers/luna_platform_client.py +9 -9
- luna_sdk/controllers/luna_q.py +7 -10
- luna_sdk/controllers/luna_solve.py +8 -15
- luna_sdk/controllers/luna_transform.py +9 -16
- luna_sdk/interfaces/circuit_repo_i.py +18 -12
- luna_sdk/interfaces/cplex_repo_i.py +25 -10
- luna_sdk/interfaces/info_repo_i.py +10 -3
- luna_sdk/interfaces/lp_repo_i.py +20 -8
- luna_sdk/interfaces/optimization_repo_i.py +31 -57
- luna_sdk/interfaces/qpu_token_repo_i.py +24 -28
- luna_sdk/interfaces/solutions_repo_i.py +44 -24
- luna_sdk/repositories/circuit_repo.py +11 -44
- luna_sdk/repositories/cplex_repo.py +32 -20
- luna_sdk/repositories/info_repo.py +4 -7
- luna_sdk/repositories/lp_repo.py +21 -15
- luna_sdk/repositories/optimization_repo.py +25 -200
- luna_sdk/repositories/qpu_token_repo.py +28 -120
- luna_sdk/repositories/solutions_repo.py +109 -181
- luna_sdk/schemas/create/solution.py +2 -2
- luna_sdk/schemas/optimization.py +9 -11
- luna_sdk/schemas/pretty_base.py +10 -3
- luna_sdk/schemas/qpu_token.py +3 -0
- luna_sdk/schemas/solution.py +7 -6
- luna_sdk/schemas/solver_info.py +31 -1
- luna_sdk/schemas/solver_parameters/aws/optimizer_params.py +40 -0
- luna_sdk/schemas/solver_parameters/aws/qaoa.py +36 -4
- luna_sdk/schemas/solver_parameters/base_parameter.py +5 -0
- luna_sdk/schemas/solver_parameters/dwave/base.py +15 -14
- luna_sdk/schemas/solver_parameters/dwave/dialectic_search.py +3 -2
- luna_sdk/schemas/solver_parameters/dwave/kerberos.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_bqm.py +2 -2
- luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_cqm.py +2 -2
- luna_sdk/schemas/solver_parameters/dwave/parallel_tempering.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/parallel_tempering_qpu.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/population_annealing.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/population_annealing_qpu.py +2 -1
- luna_sdk/schemas/solver_parameters/dwave/qaga.py +4 -2
- luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_qpu.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_simulated_annealing.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_tabu_search.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/quantum_annealing.py +2 -3
- luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_quantum_annealing.py +4 -2
- luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_simulated_annealing.py +3 -2
- luna_sdk/schemas/solver_parameters/dwave/saga.py +1 -1
- luna_sdk/schemas/solver_parameters/dwave/tabu_search.py +3 -1
- luna_sdk/schemas/solver_parameters/fujitsu/base.py +5 -4
- luna_sdk/schemas/solver_parameters/fujitsu/partial_config.py +7 -5
- luna_sdk/schemas/solver_parameters/ibm/standard_parameters.py +121 -7
- luna_sdk/schemas/solver_parameters/qctrl/qaoa.py +2 -2
- luna_sdk/schemas/wrappers/__init__.py +1 -0
- luna_sdk/schemas/wrappers/datetime_wrapper.py +31 -0
- luna_sdk/utils/parameter_finder.py +90 -0
- luna_sdk/constants.py +0 -1
- {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.29.dist-info}/LICENSE +0 -0
- {luna_quantum-0.0.16.dist-info → luna_quantum-0.0.29.dist-info}/WHEEL +0 -0
|
@@ -6,7 +6,7 @@ from luna_sdk.interfaces.circuit_repo_i import ICircuitRepo
|
|
|
6
6
|
from luna_sdk.schemas.circuit import CircuitJob, CircuitResult
|
|
7
7
|
from luna_sdk.schemas.create.circuit import CircuitIn
|
|
8
8
|
from luna_sdk.schemas.enums.circuit import CircuitProviderEnum
|
|
9
|
-
from luna_sdk.schemas.qpu_token import TokenProvider
|
|
9
|
+
from luna_sdk.schemas.qpu_token import TokenProvider
|
|
10
10
|
from luna_sdk.schemas.rest.qpu_token.token_provider import RestAPITokenProvider
|
|
11
11
|
from luna_sdk.utils.qpu_tokens import extract_qpu_tokens_from_env
|
|
12
12
|
|
|
@@ -20,35 +20,13 @@ class CircuitRepo(ICircuitRepo):
|
|
|
20
20
|
provider: CircuitProviderEnum,
|
|
21
21
|
params: Dict[str, Any] = {},
|
|
22
22
|
qpu_tokens: Optional[TokenProvider] = None,
|
|
23
|
-
timeout: Optional[float] = 10800.0,
|
|
24
23
|
encryption_key: Optional[str] = None,
|
|
24
|
+
**kwargs,
|
|
25
25
|
) -> CircuitJob:
|
|
26
|
-
"""
|
|
27
|
-
Create a circuit solution.
|
|
28
|
-
|
|
29
|
-
Parameters
|
|
30
|
-
----------
|
|
31
|
-
circuit: str
|
|
32
|
-
The circuit which to create a solution for.
|
|
33
|
-
provider: CircuitProviderEnum
|
|
34
|
-
Which provider to use to solve the circuit.
|
|
35
|
-
params: Dict[str, Any]
|
|
36
|
-
Additional parameters of the circuit.
|
|
37
|
-
qpu_tokens: Optional[TokenProvider]
|
|
38
|
-
The tokens to be used for the QPU.
|
|
39
|
-
timeout: Optional[float]
|
|
40
|
-
Default = 10800.0. Timeout for the api request. If set to None,
|
|
41
|
-
there won't be any timeout. Increase or disable the timeout if you face
|
|
42
|
-
issues uploading big Problems.
|
|
43
|
-
encryption_key: Optional[str]
|
|
44
|
-
Encryption key to be used for encryption of QPU tokens.
|
|
45
|
-
Returns
|
|
46
|
-
-------
|
|
47
|
-
CircuitJob
|
|
48
|
-
The created circuit job.
|
|
49
|
-
"""
|
|
50
26
|
if qpu_tokens is not None:
|
|
51
|
-
rest_qpu_tokens = RestAPITokenProvider.from_sdk_token_provider(
|
|
27
|
+
rest_qpu_tokens = RestAPITokenProvider.from_sdk_token_provider(
|
|
28
|
+
TokenProvider.model_validate(qpu_tokens)
|
|
29
|
+
)
|
|
52
30
|
else:
|
|
53
31
|
rest_qpu_tokens = None
|
|
54
32
|
|
|
@@ -68,29 +46,18 @@ class CircuitRepo(ICircuitRepo):
|
|
|
68
46
|
)
|
|
69
47
|
|
|
70
48
|
response = self._client.post(
|
|
71
|
-
self._endpoint, content=circuit_in.model_dump_json(),
|
|
49
|
+
self._endpoint, content=circuit_in.model_dump_json(), **kwargs
|
|
72
50
|
)
|
|
73
51
|
|
|
74
52
|
response.raise_for_status()
|
|
75
53
|
return CircuitJob(id=response.json(), provider=provider, params=params)
|
|
76
54
|
|
|
77
55
|
def get(
|
|
78
|
-
self,
|
|
56
|
+
self,
|
|
57
|
+
job: CircuitJob,
|
|
58
|
+
encryption_key: Optional[str] = None,
|
|
59
|
+
**kwargs,
|
|
79
60
|
) -> CircuitResult:
|
|
80
|
-
"""
|
|
81
|
-
Retrieve a circuit result from a job.
|
|
82
|
-
|
|
83
|
-
Parameters
|
|
84
|
-
----------
|
|
85
|
-
job: CircuitJob
|
|
86
|
-
The job received upon circuit creation.
|
|
87
|
-
encryption_key: Optional[str]
|
|
88
|
-
The encryption key to be used for the QPU.
|
|
89
|
-
Returns
|
|
90
|
-
-------
|
|
91
|
-
CircuitResult
|
|
92
|
-
The result of solving the circuit.
|
|
93
|
-
"""
|
|
94
61
|
url = f"{self._endpoint}/{job.id}/{job.provider.value}"
|
|
95
62
|
encryption_key = encryption_key or os.environ.get("LUNA_ENCRYPTION_KEY")
|
|
96
63
|
if encryption_key is None:
|
|
@@ -98,7 +65,7 @@ class CircuitRepo(ICircuitRepo):
|
|
|
98
65
|
if job.params is None:
|
|
99
66
|
job.params = {}
|
|
100
67
|
job.params["encryption_key"] = encryption_key
|
|
101
|
-
response = self._client.get(url, params=job.params,
|
|
68
|
+
response = self._client.get(url, params=job.params, **kwargs)
|
|
102
69
|
|
|
103
70
|
response.raise_for_status()
|
|
104
71
|
return CircuitResult.model_validate(response.json())
|
|
@@ -2,7 +2,7 @@ import os
|
|
|
2
2
|
import pickle
|
|
3
3
|
import tempfile
|
|
4
4
|
from functools import partial
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Dict, List, Tuple
|
|
6
6
|
|
|
7
7
|
import dimod
|
|
8
8
|
from dimod import ConstrainedQuadraticModel
|
|
@@ -12,7 +12,7 @@ from qiskit_optimization import QuadraticProgram
|
|
|
12
12
|
|
|
13
13
|
from luna_sdk.exceptions.transformation import TransformationException
|
|
14
14
|
from luna_sdk.interfaces.cplex_repo_i import ICplexRepo
|
|
15
|
-
from luna_sdk.schemas.transformations.bqm import BQMResultSchema
|
|
15
|
+
from luna_sdk.schemas.transformations.bqm import BQMResultSchema
|
|
16
16
|
from luna_sdk.schemas.transformations.matrix import MatrixSchema
|
|
17
17
|
|
|
18
18
|
|
|
@@ -20,12 +20,14 @@ class CplexRepo(ICplexRepo):
|
|
|
20
20
|
_endpoint = "/transformations/docplex"
|
|
21
21
|
|
|
22
22
|
def _send_request_with_pickle_file_response(
|
|
23
|
-
self, docplex_model: DOCplexModel, endpoint: str
|
|
23
|
+
self, docplex_model: DOCplexModel, endpoint: str, **kwargs
|
|
24
24
|
):
|
|
25
25
|
file = tempfile.NamedTemporaryFile(delete=False)
|
|
26
26
|
with open(file.name, "wb") as tmp:
|
|
27
27
|
pickle.dump(docplex_model, tmp)
|
|
28
|
-
response = self._client.post(
|
|
28
|
+
response = self._client.post(
|
|
29
|
+
endpoint, files={"file": (file.name, file.file)}, **kwargs
|
|
30
|
+
)
|
|
29
31
|
os.remove(file.name)
|
|
30
32
|
try:
|
|
31
33
|
parsed_model = pickle.loads(response.content)
|
|
@@ -33,9 +35,9 @@ class CplexRepo(ICplexRepo):
|
|
|
33
35
|
raise TransformationException()
|
|
34
36
|
return parsed_model
|
|
35
37
|
|
|
36
|
-
def to_qubo_qiskit(self, docplex_model: DOCplexModel) -> QuadraticProgram:
|
|
38
|
+
def to_qubo_qiskit(self, docplex_model: DOCplexModel, **kwargs) -> QuadraticProgram:
|
|
37
39
|
qubo_qiskit_model = self._send_request_with_pickle_file_response(
|
|
38
|
-
docplex_model, f"{self._endpoint}/to-qubo-qiskit"
|
|
40
|
+
docplex_model, f"{self._endpoint}/to-qubo-qiskit", **kwargs
|
|
39
41
|
)
|
|
40
42
|
try:
|
|
41
43
|
assert isinstance(qubo_qiskit_model, QuadraticProgram)
|
|
@@ -43,51 +45,59 @@ class CplexRepo(ICplexRepo):
|
|
|
43
45
|
raise TransformationException()
|
|
44
46
|
return qubo_qiskit_model
|
|
45
47
|
|
|
46
|
-
def to_lp_file(self, docplex_model: DOCplexModel, filepath: str) -> None:
|
|
48
|
+
def to_lp_file(self, docplex_model: DOCplexModel, filepath: str, **kwargs) -> None:
|
|
47
49
|
file = tempfile.NamedTemporaryFile(delete=False)
|
|
48
50
|
with open(file.name, "wb") as tmp:
|
|
49
51
|
pickle.dump(docplex_model, tmp)
|
|
50
52
|
response = self._client.post(
|
|
51
|
-
f"{self._endpoint}/to-lp-file",
|
|
53
|
+
f"{self._endpoint}/to-lp-file",
|
|
54
|
+
files={"file": (file.name, file.file)},
|
|
55
|
+
**kwargs,
|
|
52
56
|
)
|
|
53
57
|
with open(filepath, "w") as file: # type: ignore
|
|
54
58
|
file.write(response.content.decode("utf-8")) # type: ignore
|
|
55
59
|
|
|
56
|
-
def to_lp_string(self, docplex_model: DOCplexModel) -> str:
|
|
60
|
+
def to_lp_string(self, docplex_model: DOCplexModel, **kwargs) -> str:
|
|
57
61
|
file = tempfile.NamedTemporaryFile(delete=False)
|
|
58
62
|
with open(file.name, "wb") as tmp:
|
|
59
63
|
pickle.dump(docplex_model, tmp)
|
|
60
64
|
response = self._client.post(
|
|
61
|
-
f"{self._endpoint}/to-lp-file",
|
|
65
|
+
f"{self._endpoint}/to-lp-file",
|
|
66
|
+
files={"file": (file.name, file.file)},
|
|
67
|
+
**kwargs,
|
|
62
68
|
)
|
|
63
69
|
return response.content.decode("utf-8")
|
|
64
70
|
|
|
65
71
|
def to_qubo_matrix(
|
|
66
|
-
self, docplex_model: DOCplexModel
|
|
72
|
+
self, docplex_model: DOCplexModel, **kwargs
|
|
67
73
|
) -> Tuple[List[List[float]], partial]:
|
|
68
74
|
file = tempfile.NamedTemporaryFile(delete=False)
|
|
69
75
|
with open(file.name, "wb") as tmp:
|
|
70
76
|
pickle.dump(docplex_model, tmp)
|
|
71
77
|
response = self._client.post(
|
|
72
|
-
f"{self._endpoint}/to-qubo-matrix",
|
|
78
|
+
f"{self._endpoint}/to-qubo-matrix",
|
|
79
|
+
files={"file": (file.name, file.file)},
|
|
80
|
+
**kwargs,
|
|
73
81
|
)
|
|
74
|
-
retrieved_matrix = MatrixSchema.
|
|
82
|
+
retrieved_matrix = MatrixSchema.model_validate(response.json())
|
|
75
83
|
return retrieved_matrix.matrix, partial(
|
|
76
84
|
self.inverter,
|
|
77
85
|
var_indices=retrieved_matrix.variable_indices,
|
|
78
|
-
inverter_bqm=CQMToBQMInverter.from_dict(
|
|
86
|
+
inverter_bqm=CQMToBQMInverter.from_dict(
|
|
87
|
+
retrieved_matrix.inverter.model_dump()
|
|
88
|
+
),
|
|
79
89
|
)
|
|
80
90
|
|
|
81
91
|
def to_bqm(
|
|
82
|
-
self, docplex_model: DOCplexModel
|
|
92
|
+
self, docplex_model: DOCplexModel, **kwargs
|
|
83
93
|
) -> Tuple[dimod.BinaryQuadraticModel, CQMToBQMInverter]:
|
|
84
94
|
file = tempfile.NamedTemporaryFile(delete=False)
|
|
85
95
|
with open(file.name, "wb") as tmp:
|
|
86
96
|
pickle.dump(docplex_model, tmp)
|
|
87
97
|
response = self._client.post(
|
|
88
|
-
f"{self._endpoint}/to-bqm", files={"file": (file.name, file.file)}
|
|
98
|
+
f"{self._endpoint}/to-bqm", files={"file": (file.name, file.file)}, **kwargs
|
|
89
99
|
)
|
|
90
|
-
retrieved_bqm = BQMResultSchema.
|
|
100
|
+
retrieved_bqm = BQMResultSchema.model_validate(response.json())
|
|
91
101
|
|
|
92
102
|
quadratic: Dict[Tuple[str, str], float] = {}
|
|
93
103
|
for key, value in retrieved_bqm.bqm.quadratic.items():
|
|
@@ -104,15 +114,17 @@ class CplexRepo(ICplexRepo):
|
|
|
104
114
|
)
|
|
105
115
|
except Exception:
|
|
106
116
|
raise TransformationException()
|
|
107
|
-
inverter = CQMToBQMInverter.from_dict(retrieved_bqm.inverter.
|
|
117
|
+
inverter = CQMToBQMInverter.from_dict(retrieved_bqm.inverter.model_dump())
|
|
108
118
|
return bqm, inverter
|
|
109
119
|
|
|
110
|
-
def to_cqm(
|
|
120
|
+
def to_cqm(
|
|
121
|
+
self, docplex_model: DOCplexModel, **kwargs
|
|
122
|
+
) -> ConstrainedQuadraticModel:
|
|
111
123
|
file = tempfile.NamedTemporaryFile(delete=False)
|
|
112
124
|
with open(file.name, "wb") as tmp:
|
|
113
125
|
pickle.dump(docplex_model, tmp)
|
|
114
126
|
response = self._client.post(
|
|
115
|
-
f"{self._endpoint}/to-cqm", files={"file": (file.name, file.file)}
|
|
127
|
+
f"{self._endpoint}/to-cqm", files={"file": (file.name, file.file)}, **kwargs
|
|
116
128
|
)
|
|
117
129
|
cqm = ConstrainedQuadraticModel.from_file(response.content)
|
|
118
130
|
return cqm
|
|
@@ -11,15 +11,14 @@ class InfoRepo(IInfoRepo):
|
|
|
11
11
|
_endpoint_providers = "/providers"
|
|
12
12
|
|
|
13
13
|
def solvers_available(
|
|
14
|
-
self, solver_name: Optional[str] = None
|
|
14
|
+
self, solver_name: Optional[str] = None, **kwargs
|
|
15
15
|
) -> Dict[str, Dict[str, SolverInfo]]:
|
|
16
16
|
params = {}
|
|
17
17
|
if solver_name:
|
|
18
18
|
params["solver_name"] = solver_name
|
|
19
19
|
|
|
20
20
|
response = self._client.get(
|
|
21
|
-
f"{self._endpoint_solvers}/available",
|
|
22
|
-
params=params,
|
|
21
|
+
f"{self._endpoint_solvers}/available", params=params, **kwargs
|
|
23
22
|
)
|
|
24
23
|
|
|
25
24
|
response.raise_for_status()
|
|
@@ -35,10 +34,8 @@ class InfoRepo(IInfoRepo):
|
|
|
35
34
|
|
|
36
35
|
return to_return
|
|
37
36
|
|
|
38
|
-
def providers_available(self) -> List[str]:
|
|
39
|
-
response = self._client.get(
|
|
40
|
-
f"{self._endpoint_providers}/available",
|
|
41
|
-
)
|
|
37
|
+
def providers_available(self, **kwargs) -> List[str]:
|
|
38
|
+
response = self._client.get(f"{self._endpoint_providers}/available", **kwargs)
|
|
42
39
|
|
|
43
40
|
response.raise_for_status()
|
|
44
41
|
|
luna_sdk/repositories/lp_repo.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
|
2
2
|
import pickle
|
|
3
3
|
import tempfile
|
|
4
4
|
from functools import partial
|
|
5
|
-
from typing import
|
|
5
|
+
from typing import Dict, List, Tuple
|
|
6
6
|
|
|
7
7
|
import dimod
|
|
8
8
|
from dimod import ConstrainedQuadraticModel
|
|
@@ -12,7 +12,7 @@ from qiskit_optimization import QuadraticProgram
|
|
|
12
12
|
|
|
13
13
|
from luna_sdk.exceptions.transformation import TransformationException
|
|
14
14
|
from luna_sdk.interfaces.lp_repo_i import ILPRepo
|
|
15
|
-
from luna_sdk.schemas.transformations.bqm import BQMResultSchema
|
|
15
|
+
from luna_sdk.schemas.transformations.bqm import BQMResultSchema
|
|
16
16
|
from luna_sdk.schemas.transformations.matrix import MatrixSchema
|
|
17
17
|
|
|
18
18
|
|
|
@@ -31,9 +31,9 @@ class LPRepo(ILPRepo):
|
|
|
31
31
|
raise TransformationException()
|
|
32
32
|
return parsed_model
|
|
33
33
|
|
|
34
|
-
def to_qubo_qiskit(self, lp_string: str) -> QuadraticProgram:
|
|
34
|
+
def to_qubo_qiskit(self, lp_string: str, **kwargs) -> QuadraticProgram:
|
|
35
35
|
qubo_qiskit_model = self._send_request_with_pickle_file_response(
|
|
36
|
-
lp_string, f"{self._endpoint}/to-qubo-qiskit"
|
|
36
|
+
lp_string, f"{self._endpoint}/to-qubo-qiskit", **kwargs
|
|
37
37
|
)
|
|
38
38
|
try:
|
|
39
39
|
assert isinstance(qubo_qiskit_model, QuadraticProgram)
|
|
@@ -41,9 +41,9 @@ class LPRepo(ILPRepo):
|
|
|
41
41
|
raise TransformationException()
|
|
42
42
|
return qubo_qiskit_model
|
|
43
43
|
|
|
44
|
-
def to_docplex(self, lp_string: str) -> DOCplexModel:
|
|
44
|
+
def to_docplex(self, lp_string: str, **kwargs) -> DOCplexModel:
|
|
45
45
|
docplex_model = self._send_request_with_pickle_file_response(
|
|
46
|
-
lp_string, f"{self._endpoint}/to-docplex"
|
|
46
|
+
lp_string, f"{self._endpoint}/to-docplex", **kwargs
|
|
47
47
|
)
|
|
48
48
|
try:
|
|
49
49
|
assert isinstance(docplex_model, DOCplexModel)
|
|
@@ -51,30 +51,36 @@ class LPRepo(ILPRepo):
|
|
|
51
51
|
raise TransformationException()
|
|
52
52
|
return docplex_model
|
|
53
53
|
|
|
54
|
-
def to_qubo_matrix(
|
|
54
|
+
def to_qubo_matrix(
|
|
55
|
+
self, lp_string: str, **kwargs
|
|
56
|
+
) -> Tuple[List[List[float]], partial]:
|
|
55
57
|
file = tempfile.NamedTemporaryFile(delete=False, suffix=".lp")
|
|
56
58
|
with open(file.name, "w") as tmp:
|
|
57
59
|
tmp.write(lp_string)
|
|
58
60
|
response = self._client.post(
|
|
59
|
-
f"{self._endpoint}/to-qubo-matrix",
|
|
61
|
+
f"{self._endpoint}/to-qubo-matrix",
|
|
62
|
+
files={"file": (file.name, file.file)},
|
|
63
|
+
**kwargs,
|
|
60
64
|
)
|
|
61
|
-
retrieved_matrix = MatrixSchema.
|
|
65
|
+
retrieved_matrix = MatrixSchema.model_validate(response.json())
|
|
62
66
|
return retrieved_matrix.matrix, partial(
|
|
63
67
|
self.inverter,
|
|
64
68
|
var_indices=retrieved_matrix.variable_indices,
|
|
65
|
-
inverter_bqm=CQMToBQMInverter.from_dict(
|
|
69
|
+
inverter_bqm=CQMToBQMInverter.from_dict(
|
|
70
|
+
retrieved_matrix.inverter.model_dump()
|
|
71
|
+
),
|
|
66
72
|
)
|
|
67
73
|
|
|
68
74
|
def to_bqm(
|
|
69
|
-
self, lp_string: str
|
|
75
|
+
self, lp_string: str, **kwargs
|
|
70
76
|
) -> Tuple[dimod.BinaryQuadraticModel, CQMToBQMInverter]:
|
|
71
77
|
file = tempfile.NamedTemporaryFile(delete=False, suffix=".lp")
|
|
72
78
|
with open(file.name, "w") as tmp:
|
|
73
79
|
tmp.write(lp_string)
|
|
74
80
|
response = self._client.post(
|
|
75
|
-
f"{self._endpoint}/to-bqm", files={"file": (file.name, file.file)}
|
|
81
|
+
f"{self._endpoint}/to-bqm", files={"file": (file.name, file.file)}, **kwargs
|
|
76
82
|
)
|
|
77
|
-
retrieved_bqm = BQMResultSchema.
|
|
83
|
+
retrieved_bqm = BQMResultSchema.model_validate(response.json())
|
|
78
84
|
|
|
79
85
|
quadratic: Dict[Tuple[str, str], float] = {}
|
|
80
86
|
for key, value in retrieved_bqm.bqm.quadratic.items():
|
|
@@ -94,12 +100,12 @@ class LPRepo(ILPRepo):
|
|
|
94
100
|
inverter = CQMToBQMInverter.from_dict(retrieved_bqm.inverter.dict())
|
|
95
101
|
return bqm, inverter
|
|
96
102
|
|
|
97
|
-
def to_cqm(self, lp_string: str) -> ConstrainedQuadraticModel:
|
|
103
|
+
def to_cqm(self, lp_string: str, **kwargs) -> ConstrainedQuadraticModel:
|
|
98
104
|
file = tempfile.NamedTemporaryFile(delete=False, suffix=".lp")
|
|
99
105
|
with open(file.name, "w") as tmp:
|
|
100
106
|
tmp.write(lp_string)
|
|
101
107
|
response = self._client.post(
|
|
102
|
-
f"{self._endpoint}/to-cqm", files={"file": (file.name, file.file)}
|
|
108
|
+
f"{self._endpoint}/to-cqm", files={"file": (file.name, file.file)}, **kwargs
|
|
103
109
|
)
|
|
104
110
|
cqm = ConstrainedQuadraticModel.from_file(response.content)
|
|
105
111
|
return cqm
|
|
@@ -33,26 +33,8 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
33
33
|
input_type: Optional[InputType] = None,
|
|
34
34
|
limit: int = 50,
|
|
35
35
|
offset: int = 0,
|
|
36
|
+
**kwargs,
|
|
36
37
|
) -> List[Optimization]:
|
|
37
|
-
"""
|
|
38
|
-
Get a list of all available Models.
|
|
39
|
-
|
|
40
|
-
Parameters
|
|
41
|
-
----------
|
|
42
|
-
timeframe: Optional[TimeframeEnum]
|
|
43
|
-
Only return QUBOs created within a specified timeframe. Default None.
|
|
44
|
-
input_type: Optional[InputType]
|
|
45
|
-
Only return optimizations of a specified input type. Default None.
|
|
46
|
-
limit: int
|
|
47
|
-
Limit the number of Optimizations to be returned. Default value 50.
|
|
48
|
-
offset: int
|
|
49
|
-
Offset the list of optimizations by this amount. Default value 0.
|
|
50
|
-
|
|
51
|
-
Returns
|
|
52
|
-
-------
|
|
53
|
-
List[Model]
|
|
54
|
-
List of Model instances.
|
|
55
|
-
"""
|
|
56
38
|
params = {}
|
|
57
39
|
if timeframe and timeframe != TimeframeEnum.all_time: # no value == all_time
|
|
58
40
|
params["timeframe"] = timeframe.value
|
|
@@ -66,12 +48,14 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
66
48
|
|
|
67
49
|
params["limit"] = str(limit)
|
|
68
50
|
params["offset"] = str(offset)
|
|
69
|
-
response: Response = self._client.get(self._endpoint, params=params)
|
|
51
|
+
response: Response = self._client.get(self._endpoint, params=params, **kwargs)
|
|
70
52
|
response.raise_for_status()
|
|
71
53
|
return [Optimization.model_validate(item) for item in response.json()]
|
|
72
54
|
|
|
73
|
-
def get(self, optimization_id: str) -> Optimization:
|
|
74
|
-
response: Response = self._client.get(
|
|
55
|
+
def get(self, optimization_id: str, **kwargs) -> Optimization:
|
|
56
|
+
response: Response = self._client.get(
|
|
57
|
+
f"{self._endpoint}/{optimization_id}", **kwargs
|
|
58
|
+
)
|
|
75
59
|
response.raise_for_status()
|
|
76
60
|
response_data = response.json()
|
|
77
61
|
|
|
@@ -97,39 +81,15 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
97
81
|
|
|
98
82
|
response_data.update(optimization_data)
|
|
99
83
|
|
|
100
|
-
return model.
|
|
84
|
+
return model.model_validate(response_data)
|
|
101
85
|
|
|
102
86
|
def create_from_qubo(
|
|
103
|
-
self,
|
|
104
|
-
name: str,
|
|
105
|
-
matrix: List[List[float]],
|
|
106
|
-
timeout: Optional[float] = 10800.0,
|
|
87
|
+
self, name: str, matrix: List[List[float]], **kwargs
|
|
107
88
|
) -> Optimization:
|
|
108
|
-
"""
|
|
109
|
-
Create an optimization from a QUBO matrix.
|
|
110
|
-
|
|
111
|
-
Parameters
|
|
112
|
-
----------
|
|
113
|
-
name: str
|
|
114
|
-
Name of the optimization to be created.
|
|
115
|
-
matrix: List[List[float]]
|
|
116
|
-
QUBO matrix.
|
|
117
|
-
timeout: Optional[float]
|
|
118
|
-
Default = 10800. Timeout for the api request. If set to None,
|
|
119
|
-
there won't be any timeout. Increase or disable the timeout if you face
|
|
120
|
-
issues uploading big QUBO matrices.
|
|
121
|
-
|
|
122
|
-
Returns
|
|
123
|
-
-------
|
|
124
|
-
Optimization:
|
|
125
|
-
Created optimization.
|
|
126
|
-
"""
|
|
127
89
|
data_in: Dict[str, Any] = QUBOIn(name=name, matrix=matrix).model_dump()
|
|
128
90
|
|
|
129
91
|
response: Response = self._client.post(
|
|
130
|
-
f"{self._endpoint}/qubo",
|
|
131
|
-
json=data_in,
|
|
132
|
-
timeout=timeout,
|
|
92
|
+
f"{self._endpoint}/qubo", json=data_in, **kwargs
|
|
133
93
|
)
|
|
134
94
|
|
|
135
95
|
response.raise_for_status()
|
|
@@ -137,30 +97,8 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
137
97
|
return Optimization.model_validate_json(response.text)
|
|
138
98
|
|
|
139
99
|
def create_from_use_case(
|
|
140
|
-
self,
|
|
141
|
-
name: str,
|
|
142
|
-
use_case: UseCase,
|
|
143
|
-
timeout: Optional[float] = 10800.0,
|
|
100
|
+
self, name: str, use_case: UseCase, **kwargs
|
|
144
101
|
) -> Optimization:
|
|
145
|
-
"""
|
|
146
|
-
Create an optimization from a use case.
|
|
147
|
-
|
|
148
|
-
Parameters
|
|
149
|
-
----------
|
|
150
|
-
name: str
|
|
151
|
-
Name of the optimization to be created.
|
|
152
|
-
use_case: UseCase
|
|
153
|
-
Use case.
|
|
154
|
-
timeout: Optional[float]
|
|
155
|
-
Default = 10800.0. Timeout for the api request. If set to None,
|
|
156
|
-
there won't be any timeout. Increase or disable the timeout if you face
|
|
157
|
-
issues uploading big Problems.
|
|
158
|
-
|
|
159
|
-
Returns
|
|
160
|
-
-------
|
|
161
|
-
Optimization:
|
|
162
|
-
Created optimization.
|
|
163
|
-
"""
|
|
164
102
|
optimization_in = OptimizationUseCaseIn(
|
|
165
103
|
name=name, use_case=use_case, params=None
|
|
166
104
|
)
|
|
@@ -168,7 +106,7 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
168
106
|
response: Response = self._client.post(
|
|
169
107
|
f"{self._endpoint}/use_case",
|
|
170
108
|
content=optimization_in.model_dump_json(),
|
|
171
|
-
|
|
109
|
+
**kwargs,
|
|
172
110
|
)
|
|
173
111
|
|
|
174
112
|
response.raise_for_status()
|
|
@@ -176,33 +114,12 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
176
114
|
return Optimization.model_validate_json(response.text)
|
|
177
115
|
|
|
178
116
|
def create_from_bqm(
|
|
179
|
-
self,
|
|
180
|
-
name: str,
|
|
181
|
-
bqm: BinaryQuadraticModel,
|
|
182
|
-
timeout: Optional[float] = 10800.0,
|
|
117
|
+
self, name: str, bqm: BinaryQuadraticModel, **kwargs
|
|
183
118
|
) -> Optimization:
|
|
184
|
-
"""
|
|
185
|
-
Create an optimization from BQM.
|
|
186
|
-
|
|
187
|
-
Parameters
|
|
188
|
-
----------
|
|
189
|
-
name: str
|
|
190
|
-
Name of the optimization to be created.
|
|
191
|
-
bqm: BinaryQuadraticModel
|
|
192
|
-
QUBO in dimod BQM format.
|
|
193
|
-
timeout: Optional[float]
|
|
194
|
-
|
|
195
|
-
Returns
|
|
196
|
-
-------
|
|
197
|
-
Optimization:
|
|
198
|
-
Created optimization.
|
|
199
|
-
"""
|
|
200
119
|
data_in = {"name": name, **BQMSchema.from_bqm(bqm).model_dump()}
|
|
201
120
|
|
|
202
121
|
response: Response = self._client.post(
|
|
203
|
-
f"{self._endpoint}/bqm",
|
|
204
|
-
json=data_in,
|
|
205
|
-
timeout=timeout,
|
|
122
|
+
f"{self._endpoint}/bqm", json=data_in, **kwargs
|
|
206
123
|
)
|
|
207
124
|
|
|
208
125
|
response.raise_for_status()
|
|
@@ -210,34 +127,12 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
210
127
|
return Optimization.model_validate_json(response.text)
|
|
211
128
|
|
|
212
129
|
def create_from_cqm(
|
|
213
|
-
self,
|
|
214
|
-
name: str,
|
|
215
|
-
cqm: ConstrainedQuadraticModel,
|
|
216
|
-
timeout: Optional[float] = 10800.0,
|
|
130
|
+
self, name: str, cqm: ConstrainedQuadraticModel, **kwargs
|
|
217
131
|
) -> Optimization:
|
|
218
|
-
"""
|
|
219
|
-
Create an optimization from CQM.
|
|
220
|
-
|
|
221
|
-
Parameters
|
|
222
|
-
----------
|
|
223
|
-
name: str
|
|
224
|
-
Name of the optimization to be created.
|
|
225
|
-
cqm: ConstrainedQuadraticModel
|
|
226
|
-
in dimod CQM format.
|
|
227
|
-
timeout: Optional[float]
|
|
228
|
-
|
|
229
|
-
Returns
|
|
230
|
-
-------
|
|
231
|
-
Optimization:
|
|
232
|
-
Created optimization.
|
|
233
|
-
"""
|
|
234
|
-
|
|
235
132
|
data_in = {"name": name, **CQMSchema.from_cqm(cqm).model_dump()}
|
|
236
133
|
|
|
237
134
|
response: Response = self._client.post(
|
|
238
|
-
f"{self._endpoint}/cqm",
|
|
239
|
-
json=data_in,
|
|
240
|
-
timeout=timeout,
|
|
135
|
+
f"{self._endpoint}/cqm", json=data_in, **kwargs
|
|
241
136
|
)
|
|
242
137
|
|
|
243
138
|
response.raise_for_status()
|
|
@@ -245,35 +140,13 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
245
140
|
return Optimization.model_validate_json(response.text)
|
|
246
141
|
|
|
247
142
|
def create_from_lp_file(
|
|
248
|
-
self,
|
|
249
|
-
name: str,
|
|
250
|
-
lp_file: BufferedReader,
|
|
251
|
-
timeout: Optional[float] = 10800.0,
|
|
143
|
+
self, name: str, lp_file: BufferedReader, **kwargs
|
|
252
144
|
) -> Optimization:
|
|
253
|
-
"""
|
|
254
|
-
Create an optimization from LP file.
|
|
255
|
-
|
|
256
|
-
Parameters
|
|
257
|
-
----------
|
|
258
|
-
name: str
|
|
259
|
-
Name of the optimization to be created.
|
|
260
|
-
lp_file: buffer reader.
|
|
261
|
-
timeout: Optional[float]
|
|
262
|
-
Default = 10800. Timeout for the api request. If set to None,
|
|
263
|
-
there won't be any timeout. Increase or disable the timeout if you face
|
|
264
|
-
issues uploading big QUBO matrices.
|
|
265
|
-
|
|
266
|
-
Returns
|
|
267
|
-
-------
|
|
268
|
-
Optimization:
|
|
269
|
-
Created optimization.
|
|
270
|
-
"""
|
|
271
|
-
|
|
272
145
|
response: Response = self._client.post(
|
|
273
146
|
f"{self._endpoint}/lp-file",
|
|
274
147
|
data={"optimization_in": json.dumps({"name": name})},
|
|
275
148
|
files={"lp_file": lp_file},
|
|
276
|
-
|
|
149
|
+
**kwargs,
|
|
277
150
|
)
|
|
278
151
|
|
|
279
152
|
response.raise_for_status()
|
|
@@ -281,78 +154,30 @@ class OptimizationRepo(IOptimizationRepo):
|
|
|
281
154
|
return Optimization.model_validate_json(response.text)
|
|
282
155
|
|
|
283
156
|
def create_from_lp_string(
|
|
284
|
-
self,
|
|
285
|
-
name: str,
|
|
286
|
-
lp_string: str,
|
|
287
|
-
timeout: Optional[float] = 10800.0,
|
|
157
|
+
self, name: str, lp_string: str, **kwargs
|
|
288
158
|
) -> Optimization:
|
|
289
|
-
"""
|
|
290
|
-
Create an optimization from LP string.
|
|
291
|
-
|
|
292
|
-
Parameters
|
|
293
|
-
----------
|
|
294
|
-
name: str
|
|
295
|
-
Name of the optimization to be created.
|
|
296
|
-
lp_string: string.
|
|
297
|
-
timeout: Optional[float]
|
|
298
|
-
Default = 10800. Timeout for the api request. If set to None,
|
|
299
|
-
there won't be any timeout. Increase or disable the timeout if you face
|
|
300
|
-
issues uploading big QUBO matrices.
|
|
301
|
-
|
|
302
|
-
Returns
|
|
303
|
-
-------
|
|
304
|
-
Optimization:
|
|
305
|
-
Created optimization.
|
|
306
|
-
"""
|
|
307
159
|
data_in = {"name": name, "lp_string": lp_string}
|
|
308
160
|
|
|
309
161
|
response: Response = self._client.post(
|
|
310
|
-
f"{self._endpoint}/lp-string",
|
|
311
|
-
json=data_in,
|
|
312
|
-
timeout=timeout,
|
|
162
|
+
f"{self._endpoint}/lp-string", json=data_in, **kwargs
|
|
313
163
|
)
|
|
314
164
|
|
|
315
165
|
response.raise_for_status()
|
|
316
166
|
|
|
317
167
|
return Optimization.model_validate_json(response.text)
|
|
318
168
|
|
|
319
|
-
def rename(self, optimization_id: str, name: str) -> Optimization:
|
|
320
|
-
"""
|
|
321
|
-
Update the name of the optimization
|
|
322
|
-
|
|
323
|
-
Parameters
|
|
324
|
-
----------
|
|
325
|
-
optimization_id: str
|
|
326
|
-
Id of the optimization to be updated.
|
|
327
|
-
name: str
|
|
328
|
-
New name of the optimization
|
|
329
|
-
|
|
330
|
-
Returns
|
|
331
|
-
-------
|
|
332
|
-
Optimization:
|
|
333
|
-
Updated optimization.
|
|
334
|
-
"""
|
|
169
|
+
def rename(self, optimization_id: str, name: str, **kwargs) -> Optimization:
|
|
335
170
|
data: Dict[str, str] = {"name": name}
|
|
336
171
|
|
|
337
172
|
response: Response = self._client.put(
|
|
338
|
-
f"{self._endpoint}/{optimization_id}",
|
|
339
|
-
content=json.dumps(data),
|
|
173
|
+
f"{self._endpoint}/{optimization_id}", content=json.dumps(data), **kwargs
|
|
340
174
|
)
|
|
341
175
|
response.raise_for_status()
|
|
342
176
|
|
|
343
177
|
return Optimization.model_validate_json(response.text)
|
|
344
178
|
|
|
345
|
-
def delete(self, optimization_id: str) -> None:
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
Parameters
|
|
350
|
-
----------
|
|
351
|
-
optimization_id: str
|
|
352
|
-
Id of the Model that should be deleted
|
|
353
|
-
|
|
354
|
-
Returns
|
|
355
|
-
-------
|
|
356
|
-
"""
|
|
357
|
-
response: Response = self._client.delete(f"{self._endpoint}/{optimization_id}")
|
|
179
|
+
def delete(self, optimization_id: str, **kwargs) -> None:
|
|
180
|
+
response: Response = self._client.delete(
|
|
181
|
+
f"{self._endpoint}/{optimization_id}", **kwargs
|
|
182
|
+
)
|
|
358
183
|
response.raise_for_status()
|