luna-quantum 1.1.0__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- luna_quantum/__init__.py +139 -0
- luna_quantum/__init__.pyi +98 -0
- luna_quantum/_core.cp312-win_amd64.pyd +0 -0
- luna_quantum/_core.pyi +4286 -0
- luna_quantum/_utility.py +148 -0
- luna_quantum/_utility.pyi +20 -0
- luna_quantum/algorithms/__init__.py +1 -0
- luna_quantum/aqm_overwrites/__init__.py +3 -0
- luna_quantum/aqm_overwrites/model.py +184 -0
- luna_quantum/backends/__init__.py +1 -0
- luna_quantum/client/__init__.py +0 -0
- luna_quantum/client/controllers/__init__.py +4 -0
- luna_quantum/client/controllers/luna_http_client.py +37 -0
- luna_quantum/client/controllers/luna_platform_client.py +256 -0
- luna_quantum/client/controllers/luna_q.py +67 -0
- luna_quantum/client/controllers/luna_solve.py +129 -0
- luna_quantum/client/error/__init__.py +0 -0
- luna_quantum/client/error/luna_api_key_invalid_error.py +10 -0
- luna_quantum/client/error/luna_api_key_missing_error.py +10 -0
- luna_quantum/client/error/luna_error.py +2 -0
- luna_quantum/client/error/luna_server_error.py +20 -0
- luna_quantum/client/error/timeout_error.py +12 -0
- luna_quantum/client/error/transformation_error.py +18 -0
- luna_quantum/client/error/utils/__init__.py +0 -0
- luna_quantum/client/error/utils/http_error_utils.py +112 -0
- luna_quantum/client/interfaces/__init__.py +4 -0
- luna_quantum/client/interfaces/clients/__init__.py +25 -0
- luna_quantum/client/interfaces/clients/circuit_rest_client_i.py +68 -0
- luna_quantum/client/interfaces/clients/info_rest_client_i.py +53 -0
- luna_quantum/client/interfaces/clients/model_rest_client_i.py +139 -0
- luna_quantum/client/interfaces/clients/qpu_token_rest_client_i.py +364 -0
- luna_quantum/client/interfaces/clients/rest_client_i.py +21 -0
- luna_quantum/client/interfaces/clients/solve_job_rest_client_i.py +201 -0
- luna_quantum/client/interfaces/clients/users_rest_client_i.py +29 -0
- luna_quantum/client/interfaces/services/__init__.py +0 -0
- luna_quantum/client/interfaces/services/luna_q_i.py +34 -0
- luna_quantum/client/interfaces/services/luna_solve_i.py +72 -0
- luna_quantum/client/interfaces/services/service_i.py +56 -0
- luna_quantum/client/rest_client/__init__.py +15 -0
- luna_quantum/client/rest_client/circuit_rest_client.py +107 -0
- luna_quantum/client/rest_client/info_rest_client.py +74 -0
- luna_quantum/client/rest_client/model_rest_client.py +216 -0
- luna_quantum/client/rest_client/qpu_token_rest_client.py +508 -0
- luna_quantum/client/rest_client/solve_job_rest_client.py +286 -0
- luna_quantum/client/rest_client/users_rest_client.py +35 -0
- luna_quantum/client/schemas/__init__.py +26 -0
- luna_quantum/client/schemas/circuit.py +48 -0
- luna_quantum/client/schemas/create/__init__.py +15 -0
- luna_quantum/client/schemas/create/circuit.py +30 -0
- luna_quantum/client/schemas/create/optimization.py +39 -0
- luna_quantum/client/schemas/create/qpu_token.py +22 -0
- luna_quantum/client/schemas/create/qpu_token_time_quota.py +35 -0
- luna_quantum/client/schemas/create/qpu_token_time_quota_update.py +24 -0
- luna_quantum/client/schemas/create/qubo.py +19 -0
- luna_quantum/client/schemas/create/solve_job_create.py +43 -0
- luna_quantum/client/schemas/enums/__init__.py +0 -0
- luna_quantum/client/schemas/enums/call_style.py +13 -0
- luna_quantum/client/schemas/enums/circuit.py +42 -0
- luna_quantum/client/schemas/enums/model_format.py +11 -0
- luna_quantum/client/schemas/enums/problem.py +50 -0
- luna_quantum/client/schemas/enums/qpu_token_type.py +20 -0
- luna_quantum/client/schemas/enums/sense.py +8 -0
- luna_quantum/client/schemas/enums/status.py +40 -0
- luna_quantum/client/schemas/enums/timeframe.py +11 -0
- luna_quantum/client/schemas/error_message.py +14 -0
- luna_quantum/client/schemas/model_metadata.py +35 -0
- luna_quantum/client/schemas/qpu_token/__init__.py +0 -0
- luna_quantum/client/schemas/qpu_token/qpu_token.py +154 -0
- luna_quantum/client/schemas/qpu_token/qpu_token_source.py +19 -0
- luna_quantum/client/schemas/qpu_token/qpu_token_time_quota.py +30 -0
- luna_quantum/client/schemas/qpu_token/token_provider.py +132 -0
- luna_quantum/client/schemas/representation.py +19 -0
- luna_quantum/client/schemas/solution.py +106 -0
- luna_quantum/client/schemas/solve_job.py +50 -0
- luna_quantum/client/schemas/solver_info.py +11 -0
- luna_quantum/client/schemas/user.py +11 -0
- luna_quantum/client/schemas/wrappers/__init__.py +5 -0
- luna_quantum/client/schemas/wrappers/datetime_wrapper.py +32 -0
- luna_quantum/client/utils/__init__.py +0 -0
- luna_quantum/client/utils/qpu_token_utils.py +147 -0
- luna_quantum/config.py +11 -0
- luna_quantum/decorators.py +248 -0
- luna_quantum/errors.py +34 -0
- luna_quantum/errors.pyi +287 -0
- luna_quantum/exceptions/__init__.py +0 -0
- luna_quantum/exceptions/base_luna_quantum_error.py +2 -0
- luna_quantum/exceptions/luna_quantum_call_type_error.py +9 -0
- luna_quantum/exceptions/patch_class_field_exists_error.py +10 -0
- luna_quantum/factories/__init__.py +4 -0
- luna_quantum/factories/luna_solve_client_factory.py +100 -0
- luna_quantum/factories/usecase_factory.py +489 -0
- luna_quantum/py.typed +0 -0
- luna_quantum/solve/__init__.py +13 -0
- luna_quantum/solve/default_token.py +304 -0
- luna_quantum/solve/domain/__init__.py +0 -0
- luna_quantum/solve/domain/abstract/__init__.py +4 -0
- luna_quantum/solve/domain/abstract/luna_algorithm.py +205 -0
- luna_quantum/solve/domain/abstract/qpu_token_backend.py +34 -0
- luna_quantum/solve/domain/model_metadata.py +56 -0
- luna_quantum/solve/domain/solve_job.py +230 -0
- luna_quantum/solve/errors/__init__.py +0 -0
- luna_quantum/solve/errors/incompatible_backend_error.py +15 -0
- luna_quantum/solve/errors/model_metadata_missing_error.py +11 -0
- luna_quantum/solve/errors/solve_base_error.py +5 -0
- luna_quantum/solve/errors/token_missing_error.py +11 -0
- luna_quantum/solve/interfaces/__init__.py +0 -0
- luna_quantum/solve/interfaces/algorithm_i.py +49 -0
- luna_quantum/solve/interfaces/backend_i.py +28 -0
- luna_quantum/solve/interfaces/usecases/__init__.py +59 -0
- luna_quantum/solve/interfaces/usecases/model_delete_usecase_i.py +27 -0
- luna_quantum/solve/interfaces/usecases/model_fetch_metadata_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/model_get_solutions_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/model_get_solve_jobs_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/model_load_by_id_usecase_i.py +32 -0
- luna_quantum/solve/interfaces/usecases/model_load_by_metadata_usecase_i.py +37 -0
- luna_quantum/solve/interfaces/usecases/model_load_metadata_by_hash_usecase_i.py +38 -0
- luna_quantum/solve/interfaces/usecases/model_save_usecase_i.py +36 -0
- luna_quantum/solve/interfaces/usecases/solve_job_cancel_usecase_i.py +33 -0
- luna_quantum/solve/interfaces/usecases/solve_job_create_usecase_i.py +44 -0
- luna_quantum/solve/interfaces/usecases/solve_job_delete_usecase_i.py +32 -0
- luna_quantum/solve/interfaces/usecases/solve_job_fetch_updates_usecase_i.py +38 -0
- luna_quantum/solve/interfaces/usecases/solve_job_get_by_id_usecase_i.py +27 -0
- luna_quantum/solve/interfaces/usecases/solve_job_get_result_usecase_i.py +63 -0
- luna_quantum/solve/parameters/__init__.py +0 -0
- luna_quantum/solve/parameters/algorithms/__init__.py +51 -0
- luna_quantum/solve/parameters/algorithms/base_params/__init__.py +24 -0
- luna_quantum/solve/parameters/algorithms/base_params/decomposer.py +57 -0
- luna_quantum/solve/parameters/algorithms/base_params/qaoa_circuit_params.py +95 -0
- luna_quantum/solve/parameters/algorithms/base_params/quantum_annealing_params.py +79 -0
- luna_quantum/solve/parameters/algorithms/base_params/scipy_optimizer.py +122 -0
- luna_quantum/solve/parameters/algorithms/base_params/simulated_annealing_params.py +106 -0
- luna_quantum/solve/parameters/algorithms/base_params/tabu_kerberos_params.py +39 -0
- luna_quantum/solve/parameters/algorithms/base_params/tabu_search_params.py +129 -0
- luna_quantum/solve/parameters/algorithms/flexible_parameter_algorithm.py +59 -0
- luna_quantum/solve/parameters/algorithms/genetic_algorithms/__init__.py +4 -0
- luna_quantum/solve/parameters/algorithms/genetic_algorithms/qaga.py +131 -0
- luna_quantum/solve/parameters/algorithms/genetic_algorithms/saga.py +139 -0
- luna_quantum/solve/parameters/algorithms/lq_fda/__init__.py +3 -0
- luna_quantum/solve/parameters/algorithms/lq_fda/fujits_da_base.py +85 -0
- luna_quantum/solve/parameters/algorithms/lq_fda/fujitsu_da_v3c.py +155 -0
- luna_quantum/solve/parameters/algorithms/optimization_solvers/__init__.py +3 -0
- luna_quantum/solve/parameters/algorithms/optimization_solvers/scip.py +51 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/__init__.py +19 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/kerberos.py +149 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_bqm.py +75 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/leap_hybrid_cqm.py +75 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/parallel_tempering_qpu.py +139 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/population_annealing_qpu.py +109 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/qbsolv_like_qpu.py +111 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/quantum_annealing.py +121 -0
- luna_quantum/solve/parameters/algorithms/quantum_annealing/repeated_reverse_quantum_annealing.py +174 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/__init__.py +6 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/__init__.py +10 -0
- 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/flexqaoa/flexqaoa.py +188 -0
- 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/algorithms/quantum_gate/qaoa.py +112 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa_fo.py +69 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/vqe.py +108 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/__init__.py +5 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/dialectic_search.py +136 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/qbsolv_like_tabu_search.py +117 -0
- luna_quantum/solve/parameters/algorithms/search_algorithms/tabu_search.py +126 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/__init__.py +13 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/parallel_tempering.py +131 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/population_annealing.py +95 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/qbsolv_like_simulated_annealing.py +141 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/repeated_reverse_simulated_annealing.py +172 -0
- luna_quantum/solve/parameters/algorithms/simulated_annealing/simulated_annealing.py +126 -0
- luna_quantum/solve/parameters/backends/__init__.py +27 -0
- luna_quantum/solve/parameters/backends/aqarios.py +17 -0
- luna_quantum/solve/parameters/backends/aqarios_gpu.py +17 -0
- luna_quantum/solve/parameters/backends/aws/__init__.py +11 -0
- luna_quantum/solve/parameters/backends/aws/aws.py +36 -0
- luna_quantum/solve/parameters/backends/aws/aws_backend_base.py +74 -0
- luna_quantum/solve/parameters/backends/aws/ionq.py +43 -0
- luna_quantum/solve/parameters/backends/aws/iqm.py +31 -0
- luna_quantum/solve/parameters/backends/aws/rigetti.py +31 -0
- luna_quantum/solve/parameters/backends/cudaq/__init__.py +5 -0
- luna_quantum/solve/parameters/backends/cudaq/cudaq_base.py +16 -0
- luna_quantum/solve/parameters/backends/cudaq/cudaq_cpu.py +30 -0
- luna_quantum/solve/parameters/backends/cudaq/cudaq_gpu.py +32 -0
- luna_quantum/solve/parameters/backends/dwave.py +17 -0
- luna_quantum/solve/parameters/backends/dwave_qpu.py +166 -0
- luna_quantum/solve/parameters/backends/fda.py +17 -0
- luna_quantum/solve/parameters/backends/ibm.py +138 -0
- luna_quantum/solve/parameters/backends/qctrl.py +103 -0
- luna_quantum/solve/parameters/backends/zib.py +17 -0
- luna_quantum/solve/parameters/constants.py +11 -0
- luna_quantum/solve/parameters/errors.py +30 -0
- luna_quantum/solve/parameters/mixins/__init__.py +0 -0
- luna_quantum/solve/parameters/mixins/fujitsu_common_params_mixin.py +239 -0
- luna_quantum/solve/parameters/mixins/fujitsu_v2_mixin.py +70 -0
- luna_quantum/solve/parameters/mixins/qbsolv_like_mixin.py +60 -0
- luna_quantum/solve/use_cases/__init__.py +119 -0
- luna_quantum/solve/use_cases/arbitrage_edge_based.py +50 -0
- luna_quantum/solve/use_cases/arbitrage_node_based.py +55 -0
- luna_quantum/solve/use_cases/base.py +7 -0
- luna_quantum/solve/use_cases/binary_integer_linear_programming.py +54 -0
- luna_quantum/solve/use_cases/binary_paint_shop_problem.py +37 -0
- luna_quantum/solve/use_cases/credit_scoring_feature_selection.py +40 -0
- luna_quantum/solve/use_cases/dynamic_portfolio_optimization.py +64 -0
- luna_quantum/solve/use_cases/exact_cover.py +51 -0
- luna_quantum/solve/use_cases/flight_gate_assignment.py +79 -0
- luna_quantum/solve/use_cases/graph_coloring.py +42 -0
- luna_quantum/solve/use_cases/graph_isomorphism.py +52 -0
- luna_quantum/solve/use_cases/graph_partitioning.py +46 -0
- luna_quantum/solve/use_cases/hamiltonian_cycle.py +49 -0
- luna_quantum/solve/use_cases/induced_subgraph_isomorphism.py +50 -0
- luna_quantum/solve/use_cases/job_shop_scheduling.py +44 -0
- luna_quantum/solve/use_cases/k_medoids_clustering.py +49 -0
- luna_quantum/solve/use_cases/knapsack_integer_weights.py +56 -0
- luna_quantum/solve/use_cases/linear_regression.py +60 -0
- luna_quantum/solve/use_cases/lmwcs.py +84 -0
- luna_quantum/solve/use_cases/longest_path.py +50 -0
- luna_quantum/solve/use_cases/market_graph_clustering.py +61 -0
- luna_quantum/solve/use_cases/max2sat.py +54 -0
- luna_quantum/solve/use_cases/max3sat.py +55 -0
- luna_quantum/solve/use_cases/max_clique.py +60 -0
- luna_quantum/solve/use_cases/max_cut.py +48 -0
- luna_quantum/solve/use_cases/max_independent_set.py +37 -0
- luna_quantum/solve/use_cases/minimal_maximal_matching.py +54 -0
- luna_quantum/solve/use_cases/minimal_spanning_tree.py +90 -0
- luna_quantum/solve/use_cases/minimum_vertex_cover.py +45 -0
- luna_quantum/solve/use_cases/number_partitioning.py +32 -0
- luna_quantum/solve/use_cases/portfolio_optimization.py +46 -0
- luna_quantum/solve/use_cases/portfolio_optimization_ib_tv.py +63 -0
- luna_quantum/solve/use_cases/quadratic_assignment.py +49 -0
- luna_quantum/solve/use_cases/quadratic_knapsack.py +48 -0
- luna_quantum/solve/use_cases/satellite_scheduling.py +73 -0
- luna_quantum/solve/use_cases/sensor_placement.py +58 -0
- luna_quantum/solve/use_cases/set_cover.py +56 -0
- luna_quantum/solve/use_cases/set_packing.py +54 -0
- luna_quantum/solve/use_cases/set_partitioning.py +52 -0
- luna_quantum/solve/use_cases/subgraph_isomorphism.py +55 -0
- luna_quantum/solve/use_cases/subset_sum.py +37 -0
- luna_quantum/solve/use_cases/support_vector_machine.py +64 -0
- luna_quantum/solve/use_cases/traffic_flow.py +35 -0
- luna_quantum/solve/use_cases/travelling_salesman_problem.py +53 -0
- luna_quantum/solve/use_cases/type_aliases.py +9 -0
- luna_quantum/solve/use_cases/weighted_max_cut.py +37 -0
- luna_quantum/solve/usecases/__init__.py +45 -0
- luna_quantum/solve/usecases/model_delete_usecase.py +49 -0
- luna_quantum/solve/usecases/model_fetch_metadata_usecase.py +50 -0
- luna_quantum/solve/usecases/model_get_solution_usecase.py +59 -0
- luna_quantum/solve/usecases/model_get_solve_jobs_usecase.py +62 -0
- luna_quantum/solve/usecases/model_load_by_id_usecase.py +47 -0
- luna_quantum/solve/usecases/model_load_by_metadata_usecase.py +52 -0
- luna_quantum/solve/usecases/model_load_metadata_by_hash_usecase.py +51 -0
- luna_quantum/solve/usecases/model_save_usecase.py +63 -0
- luna_quantum/solve/usecases/solve_job_cancel_usecase.py +51 -0
- luna_quantum/solve/usecases/solve_job_create_usecase.py +112 -0
- luna_quantum/solve/usecases/solve_job_delete_usecase.py +38 -0
- luna_quantum/solve/usecases/solve_job_fetch_updates_usecase.py +49 -0
- luna_quantum/solve/usecases/solve_job_get_by_id_usecase.py +44 -0
- luna_quantum/solve/usecases/solve_job_get_result_usecase.py +105 -0
- luna_quantum/transformations.py +18 -0
- luna_quantum/transformations.pyi +371 -0
- luna_quantum/translator.py +23 -0
- luna_quantum/translator.pyi +869 -0
- luna_quantum/util/__init__.py +0 -0
- luna_quantum/util/active_waiting.py +79 -0
- luna_quantum/util/class_patcher.py +164 -0
- luna_quantum/util/debug_info.py +52 -0
- luna_quantum/util/log_utils.py +187 -0
- luna_quantum/util/pretty_base.py +67 -0
- luna_quantum/util/pydantic_utils.py +38 -0
- luna_quantum/utils.py +3 -0
- luna_quantum/utils.pyi +67 -0
- luna_quantum-1.1.0.dist-info/METADATA +36 -0
- luna_quantum-1.1.0.dist-info/RECORD +276 -0
- luna_quantum-1.1.0.dist-info/WHEEL +4 -0
- luna_quantum-1.1.0.dist-info/licenses/LICENSE +176 -0
- luna_quantum-1.1.0.dist-info/licenses/NOTICE +13 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from luna_quantum.client.interfaces.clients.info_rest_client_i import IInfoRestClient
|
|
5
|
+
from luna_quantum.client.interfaces.clients.model_rest_client_i import (
|
|
6
|
+
IModelRestClient,
|
|
7
|
+
)
|
|
8
|
+
from luna_quantum.client.interfaces.clients.qpu_token_rest_client_i import (
|
|
9
|
+
IQpuTokenRestClient,
|
|
10
|
+
)
|
|
11
|
+
from luna_quantum.client.interfaces.clients.solve_job_rest_client_i import (
|
|
12
|
+
ISolveJobRestClient,
|
|
13
|
+
)
|
|
14
|
+
from luna_quantum.client.interfaces.services.service_i import IService
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ILunaSolve(IService, ABC):
|
|
18
|
+
"""Inteface for luna solve service."""
|
|
19
|
+
|
|
20
|
+
@abstractmethod
|
|
21
|
+
def __init__(self, api_key: str | None = None, *args: Any, **kwargs: Any) -> None:
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
@abstractmethod
|
|
26
|
+
def model(self) -> IModelRestClient:
|
|
27
|
+
"""
|
|
28
|
+
Returns a model rest client.
|
|
29
|
+
|
|
30
|
+
Returns
|
|
31
|
+
-------
|
|
32
|
+
IModelRestClient
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
raise NotImplementedError
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def solve_job(self) -> ISolveJobRestClient:
|
|
40
|
+
"""
|
|
41
|
+
Returns a solve job rest client.
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
ISolveJobRestClient
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
raise NotImplementedError
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
@abstractmethod
|
|
52
|
+
def qpu_token(self) -> IQpuTokenRestClient:
|
|
53
|
+
"""
|
|
54
|
+
Returns a qpu token rest client.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
IQpuTokenRestClient
|
|
59
|
+
"""
|
|
60
|
+
raise NotImplementedError
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
@abstractmethod
|
|
64
|
+
def info(self) -> IInfoRestClient:
|
|
65
|
+
"""
|
|
66
|
+
Returns an info rest client.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
IInfoRestClient
|
|
71
|
+
"""
|
|
72
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from abc import ABC, abstractmethod
|
|
2
|
+
|
|
3
|
+
from httpx import Client
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IService(ABC):
|
|
7
|
+
"""Interface for luna services."""
|
|
8
|
+
|
|
9
|
+
@property
|
|
10
|
+
@abstractmethod
|
|
11
|
+
def client(self) -> Client:
|
|
12
|
+
"""
|
|
13
|
+
Return the httpx client.
|
|
14
|
+
|
|
15
|
+
Returns
|
|
16
|
+
-------
|
|
17
|
+
Client
|
|
18
|
+
A httpx client.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def authenticate(cls, api_key: str) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Authenticate the client with the given API key.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
api_key : str
|
|
30
|
+
The API key used to authenticate the client.
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
None
|
|
35
|
+
This method does not return any value.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def is_same(
|
|
40
|
+
self,
|
|
41
|
+
api_key: str | None = None,
|
|
42
|
+
) -> bool:
|
|
43
|
+
"""
|
|
44
|
+
Whether the service is created with the current environment variables.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
api_key: str
|
|
49
|
+
User's API key
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
bool:
|
|
54
|
+
True if the service is created with the current environment variables.
|
|
55
|
+
False otherwise.
|
|
56
|
+
"""
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from luna_quantum.client.rest_client.circuit_rest_client import CircuitRestClient
|
|
2
|
+
from luna_quantum.client.rest_client.info_rest_client import InfoRestClient
|
|
3
|
+
from luna_quantum.client.rest_client.model_rest_client import (
|
|
4
|
+
ModelRestClient,
|
|
5
|
+
)
|
|
6
|
+
from luna_quantum.client.rest_client.qpu_token_rest_client import QpuTokenRestClient
|
|
7
|
+
from luna_quantum.client.rest_client.solve_job_rest_client import SolveJobRestClient
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"CircuitRestClient",
|
|
11
|
+
"InfoRestClient",
|
|
12
|
+
"ModelRestClient",
|
|
13
|
+
"QpuTokenRestClient",
|
|
14
|
+
"SolveJobRestClient",
|
|
15
|
+
]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from luna_quantum.client.interfaces.clients.circuit_rest_client_i import (
|
|
6
|
+
ICircuitRestClient,
|
|
7
|
+
)
|
|
8
|
+
from luna_quantum.client.schemas.circuit import CircuitJob, CircuitResult
|
|
9
|
+
from luna_quantum.client.schemas.create.circuit import CircuitIn
|
|
10
|
+
from luna_quantum.client.schemas.qpu_token.qpu_token import TokenProvider
|
|
11
|
+
from luna_quantum.client.schemas.qpu_token.token_provider import RestAPITokenProvider
|
|
12
|
+
from luna_quantum.client.utils.qpu_token_utils import QpuTokenUtils
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from luna_quantum.client.schemas.enums.circuit import CircuitProviderEnum
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CircuitRestClient(ICircuitRestClient):
|
|
19
|
+
"""Implementation for circuit rest client."""
|
|
20
|
+
|
|
21
|
+
_endpoint = "/circuits"
|
|
22
|
+
|
|
23
|
+
def create(
|
|
24
|
+
self,
|
|
25
|
+
circuit: str,
|
|
26
|
+
provider: CircuitProviderEnum,
|
|
27
|
+
params: dict[str, Any] | None = None,
|
|
28
|
+
qpu_tokens: TokenProvider | None = None,
|
|
29
|
+
**kwargs: Any,
|
|
30
|
+
) -> CircuitJob:
|
|
31
|
+
"""
|
|
32
|
+
Create a circuit solution.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
circuit: str
|
|
37
|
+
The circuit which to create a solution for.
|
|
38
|
+
provider: CircuitProviderEnum
|
|
39
|
+
Which provider to use to solve the circuit.
|
|
40
|
+
params: Dict[str, Any]
|
|
41
|
+
Additional parameters of the circuit.
|
|
42
|
+
qpu_tokens: Optional[TokenProvider]
|
|
43
|
+
The tokens to be used for the QPU.
|
|
44
|
+
**kwargs
|
|
45
|
+
Parameters to pass to `httpx.request`.
|
|
46
|
+
|
|
47
|
+
Returns
|
|
48
|
+
-------
|
|
49
|
+
CircuitJob
|
|
50
|
+
The created circuit job.
|
|
51
|
+
"""
|
|
52
|
+
if params is None:
|
|
53
|
+
params = {}
|
|
54
|
+
if qpu_tokens is not None:
|
|
55
|
+
rest_qpu_tokens = RestAPITokenProvider.from_sdk_token_provider(
|
|
56
|
+
TokenProvider.model_validate(qpu_tokens)
|
|
57
|
+
)
|
|
58
|
+
else:
|
|
59
|
+
rest_qpu_tokens = None
|
|
60
|
+
|
|
61
|
+
# try to retrieve qpu tokens from env variables
|
|
62
|
+
if rest_qpu_tokens is None:
|
|
63
|
+
qpu_tokens = QpuTokenUtils.patch_qpu_tokens_from_env()
|
|
64
|
+
if qpu_tokens is not None:
|
|
65
|
+
rest_qpu_tokens = RestAPITokenProvider.from_sdk_token_provider(
|
|
66
|
+
qpu_tokens
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
circuit_in: CircuitIn = CircuitIn(
|
|
70
|
+
provider=provider,
|
|
71
|
+
circuit=circuit,
|
|
72
|
+
params=params,
|
|
73
|
+
qpu_tokens=rest_qpu_tokens,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
response = self._client.post(
|
|
77
|
+
self._endpoint, content=circuit_in.model_dump_json(), **kwargs
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
response.raise_for_status()
|
|
81
|
+
return CircuitJob(id=response.json(), provider=provider, params=params)
|
|
82
|
+
|
|
83
|
+
def get(
|
|
84
|
+
self,
|
|
85
|
+
job: CircuitJob,
|
|
86
|
+
**kwargs: Any,
|
|
87
|
+
) -> CircuitResult:
|
|
88
|
+
"""
|
|
89
|
+
Get the result of a circuit.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
**kwargs
|
|
94
|
+
Parameters to pass to `httpx.request`.
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
CircuitResult
|
|
99
|
+
The result of solving the circuit.
|
|
100
|
+
"""
|
|
101
|
+
url = f"{self._endpoint}/{job.id}/{job.provider.value}"
|
|
102
|
+
if job.params is None:
|
|
103
|
+
job.params = {}
|
|
104
|
+
response = self._client.get(url, params=job.params, **kwargs)
|
|
105
|
+
|
|
106
|
+
response.raise_for_status()
|
|
107
|
+
return CircuitResult.model_validate(response.json())
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from luna_quantum.client.interfaces.clients.info_rest_client_i import IInfoRestClient
|
|
6
|
+
from luna_quantum.client.schemas.solver_info import SolverInfo
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class InfoRestClient(IInfoRestClient):
|
|
10
|
+
"""Implementation of the info rest client."""
|
|
11
|
+
|
|
12
|
+
_endpoint = "/"
|
|
13
|
+
|
|
14
|
+
_endpoint_solvers = "/solvers"
|
|
15
|
+
_endpoint_providers = "/providers"
|
|
16
|
+
|
|
17
|
+
def solvers_available(
|
|
18
|
+
self, solver_name: str | None = None, **kwargs: Any
|
|
19
|
+
) -> dict[str, dict[str, SolverInfo]]:
|
|
20
|
+
"""
|
|
21
|
+
Get list of available solvers.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
solver_name: Optional[str]
|
|
26
|
+
Name of the solver that should be retrieved. If not specified, all solvers
|
|
27
|
+
will be returned.
|
|
28
|
+
**kwargs
|
|
29
|
+
Parameters to pass to `httpx.request`.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
Dict[str, Dict[str, SolverInfo]]
|
|
34
|
+
Dictionary containing the provider name as the key, and a dictionary of
|
|
35
|
+
the solver name and solver-specific information as the value.
|
|
36
|
+
"""
|
|
37
|
+
params = {}
|
|
38
|
+
if solver_name:
|
|
39
|
+
params["solver_name"] = solver_name
|
|
40
|
+
|
|
41
|
+
response = self._client.get(
|
|
42
|
+
f"{self._endpoint_solvers}/available", params=params, **kwargs
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
response.raise_for_status()
|
|
46
|
+
|
|
47
|
+
json: dict[str, dict[str, Any]] = response.json()
|
|
48
|
+
to_return: dict[str, dict[str, SolverInfo]] = {}
|
|
49
|
+
for provider, solvers in json.items():
|
|
50
|
+
to_return[provider] = {}
|
|
51
|
+
for solver in solvers:
|
|
52
|
+
to_return[provider][solver] = SolverInfo.model_validate(solvers[solver])
|
|
53
|
+
|
|
54
|
+
return to_return
|
|
55
|
+
|
|
56
|
+
def providers_available(self, **kwargs: Any) -> list[str]:
|
|
57
|
+
"""
|
|
58
|
+
Get list of available providers.
|
|
59
|
+
|
|
60
|
+
Parameters
|
|
61
|
+
----------
|
|
62
|
+
**kwargs
|
|
63
|
+
Parameters to pass to `httpx.request`.
|
|
64
|
+
|
|
65
|
+
Returns
|
|
66
|
+
-------
|
|
67
|
+
List[str]
|
|
68
|
+
List of available QPU providers.
|
|
69
|
+
"""
|
|
70
|
+
response = self._client.get(f"{self._endpoint_providers}/available", **kwargs)
|
|
71
|
+
|
|
72
|
+
response.raise_for_status()
|
|
73
|
+
|
|
74
|
+
return list(response.json())
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any
|
|
4
|
+
|
|
5
|
+
from luna_quantum.aqm_overwrites.model import Model
|
|
6
|
+
from luna_quantum.client.interfaces.clients.model_rest_client_i import (
|
|
7
|
+
IModelRestClient,
|
|
8
|
+
)
|
|
9
|
+
from luna_quantum.client.schemas.create.optimization import OptimizationUseCaseIn
|
|
10
|
+
from luna_quantum.client.schemas.enums.timeframe import TimeframeEnum
|
|
11
|
+
from luna_quantum.client.schemas.model_metadata import ModelMetadataSchema
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from httpx import Response
|
|
15
|
+
|
|
16
|
+
from luna_quantum.solve.use_cases import UseCase
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ModelRestClient(IModelRestClient):
|
|
20
|
+
"""Implementation of the model rest client."""
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def _endpoint(self) -> str:
|
|
24
|
+
return "/models"
|
|
25
|
+
|
|
26
|
+
def get_all(
|
|
27
|
+
self,
|
|
28
|
+
timeframe: TimeframeEnum | None = None,
|
|
29
|
+
limit: int = 50,
|
|
30
|
+
offset: int = 0,
|
|
31
|
+
**kwargs: Any,
|
|
32
|
+
) -> list[ModelMetadataSchema]:
|
|
33
|
+
"""
|
|
34
|
+
Retrieve a list of model metadata.
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
timeframe: Optional[TimeframeEnum]
|
|
39
|
+
Only return optimizations created within a specified timeframe.
|
|
40
|
+
Default None.
|
|
41
|
+
limit:
|
|
42
|
+
Limit the number of optimizations to be returned. Default value 50.
|
|
43
|
+
offset:
|
|
44
|
+
Offset the list of optimizations by this amount. Default value 0.
|
|
45
|
+
**kwargs
|
|
46
|
+
Parameters to pass to `httpx.request`.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
List[ModelMetadataSchema]:
|
|
51
|
+
List of model metadata.
|
|
52
|
+
"""
|
|
53
|
+
params = {}
|
|
54
|
+
if timeframe and timeframe != TimeframeEnum.all_time: # no value == all_time
|
|
55
|
+
params["timeframe"] = timeframe.value
|
|
56
|
+
|
|
57
|
+
limit = max(limit, 1)
|
|
58
|
+
|
|
59
|
+
params["limit"] = str(limit)
|
|
60
|
+
params["offset"] = str(offset)
|
|
61
|
+
response: Response = self._client.get(
|
|
62
|
+
f"{self._endpoint}/metadata", params=params, **kwargs
|
|
63
|
+
)
|
|
64
|
+
response.raise_for_status()
|
|
65
|
+
return [ModelMetadataSchema.model_validate(item) for item in response.json()]
|
|
66
|
+
|
|
67
|
+
def get_model(self, model_id: str, **kwargs: Any) -> Model:
|
|
68
|
+
"""
|
|
69
|
+
Retrieve a model by the id.
|
|
70
|
+
|
|
71
|
+
Parameters
|
|
72
|
+
----------
|
|
73
|
+
model_id: str
|
|
74
|
+
Id of the model to be retrieved.
|
|
75
|
+
**kwargs
|
|
76
|
+
Parameters to pass to `httpx.request`.
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
Model:
|
|
81
|
+
The model.
|
|
82
|
+
|
|
83
|
+
"""
|
|
84
|
+
response: Response = self._client.get(
|
|
85
|
+
f"{self._endpoint}/data/{model_id}", **kwargs
|
|
86
|
+
)
|
|
87
|
+
response.raise_for_status()
|
|
88
|
+
|
|
89
|
+
return Model.deserialize(response.content)
|
|
90
|
+
|
|
91
|
+
def get_metadata_by_hash(
|
|
92
|
+
self, model_hash: int, **kwargs: Any
|
|
93
|
+
) -> ModelMetadataSchema:
|
|
94
|
+
"""
|
|
95
|
+
Retrieve metadata for a model using its hash.
|
|
96
|
+
|
|
97
|
+
This method fetches metadata associated with a given model hash.
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
model_hash : int
|
|
102
|
+
The hash identifier of the model.
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
ModelMetadataSchema
|
|
107
|
+
Metadata information of the model.
|
|
108
|
+
"""
|
|
109
|
+
params = {}
|
|
110
|
+
params["model_hash"] = model_hash
|
|
111
|
+
response: Response = self._client.get(
|
|
112
|
+
f"{self._endpoint}/metadata", params=params, **kwargs
|
|
113
|
+
)
|
|
114
|
+
response.raise_for_status()
|
|
115
|
+
models = [ModelMetadataSchema.model_validate(item) for item in response.json()]
|
|
116
|
+
if len(models) != 1:
|
|
117
|
+
raise ValueError( # TODO(@Llewellyn) better error here # noqa: E501, FIX002, TD004, TRY003
|
|
118
|
+
f"Expected exactly one model with hash {model_hash}, got {len(models)}"
|
|
119
|
+
)
|
|
120
|
+
return models[0]
|
|
121
|
+
|
|
122
|
+
def create(self, model: Model, **kwargs: Any) -> ModelMetadataSchema: # noqa: ARG002
|
|
123
|
+
"""
|
|
124
|
+
Create a model based on the provided Model instance.
|
|
125
|
+
|
|
126
|
+
This function saves the model and returns metadata about it.
|
|
127
|
+
|
|
128
|
+
Parameters
|
|
129
|
+
----------
|
|
130
|
+
model : Model
|
|
131
|
+
Instance of the Model which should be saved.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
ModelMetadataSchema
|
|
136
|
+
Metadata of the created model containing information about its
|
|
137
|
+
configuration and properties.
|
|
138
|
+
|
|
139
|
+
"""
|
|
140
|
+
response: Response = self._client.post(
|
|
141
|
+
f"{self._endpoint}",
|
|
142
|
+
content=model.serialize(), # Send raw bytes directly
|
|
143
|
+
headers={"Content-Type": "application/octet-stream"},
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
response.raise_for_status()
|
|
147
|
+
|
|
148
|
+
return ModelMetadataSchema.model_validate(response.json())
|
|
149
|
+
|
|
150
|
+
def get(self, model_id: str, **kwargs: Any) -> ModelMetadataSchema:
|
|
151
|
+
"""
|
|
152
|
+
Retrieve the model metadata by its id.
|
|
153
|
+
|
|
154
|
+
Parameters
|
|
155
|
+
----------
|
|
156
|
+
model_id: str
|
|
157
|
+
Id of the model to be retrieved.
|
|
158
|
+
**kwargs
|
|
159
|
+
Parameters to pass to `httpx.request`.
|
|
160
|
+
|
|
161
|
+
Returns
|
|
162
|
+
-------
|
|
163
|
+
ModelMetadataSchema:
|
|
164
|
+
Metadata of the model.
|
|
165
|
+
"""
|
|
166
|
+
response: Response = self._client.get(
|
|
167
|
+
f"{self._endpoint}/metadata/{model_id}", **kwargs
|
|
168
|
+
)
|
|
169
|
+
response.raise_for_status()
|
|
170
|
+
|
|
171
|
+
return ModelMetadataSchema.model_validate(response.json())
|
|
172
|
+
|
|
173
|
+
def create_from_use_case(
|
|
174
|
+
self, name: str, use_case: UseCase, **kwargs: Any
|
|
175
|
+
) -> ModelMetadataSchema:
|
|
176
|
+
"""
|
|
177
|
+
Create a model from a use case.
|
|
178
|
+
|
|
179
|
+
Parameters
|
|
180
|
+
----------
|
|
181
|
+
name: str
|
|
182
|
+
Name of the use case to be created.
|
|
183
|
+
use_case: UseCase
|
|
184
|
+
A use case instance that defines the optimization problem.
|
|
185
|
+
**kwargs
|
|
186
|
+
Parameters to pass to `httpx.request`.
|
|
187
|
+
"""
|
|
188
|
+
optimization_in = OptimizationUseCaseIn(
|
|
189
|
+
name=name, use_case=use_case, params=None
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
response: Response = self._client.post(
|
|
193
|
+
f"{self._endpoint}/use-case",
|
|
194
|
+
content=optimization_in.model_dump_json(),
|
|
195
|
+
**kwargs,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
response.raise_for_status()
|
|
199
|
+
|
|
200
|
+
return ModelMetadataSchema.model_validate(response.json())
|
|
201
|
+
|
|
202
|
+
def delete(self, model_id: str, **kwargs: Any) -> None:
|
|
203
|
+
"""
|
|
204
|
+
Delete a model and the model metadata by its id.
|
|
205
|
+
|
|
206
|
+
Parameters
|
|
207
|
+
----------
|
|
208
|
+
model_id: str
|
|
209
|
+
Id of the model to be deleted.
|
|
210
|
+
**kwargs
|
|
211
|
+
Parameters to pass to `httpx.request`.
|
|
212
|
+
"""
|
|
213
|
+
response: Response = self._client.delete(
|
|
214
|
+
f"{self._endpoint}/{model_id}", **kwargs
|
|
215
|
+
)
|
|
216
|
+
response.raise_for_status()
|