luna-quantum 1.0.8rc2__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of luna-quantum might be problematic. Click here for more details.
- luna_quantum/__init__.py +121 -0
- luna_quantum/__init__.pyi +85 -0
- luna_quantum/_core.cp314-win_amd64.pyd +0 -0
- luna_quantum/_core.pyi +4185 -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/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 +457 -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 +196 -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 +55 -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_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 +26 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/config.py +80 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/flex_qaoa.py +226 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/optimizers.py +99 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/flex_qaoa/pipeline.py +87 -0
- luna_quantum/solve/parameters/algorithms/quantum_gate/qaoa.py +102 -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 +22 -0
- luna_quantum/solve/parameters/backends/aqarios.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/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/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_result_usecase.py +95 -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.0.8rc2.dist-info/METADATA +36 -0
- luna_quantum-1.0.8rc2.dist-info/RECORD +264 -0
- luna_quantum-1.0.8rc2.dist-info/WHEEL +4 -0
- luna_quantum-1.0.8rc2.dist-info/licenses/LICENSE +176 -0
- luna_quantum-1.0.8rc2.dist-info/licenses/NOTICE +13 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
|
|
7
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MinimumVertexCover(UseCase):
|
|
11
|
+
r"""
|
|
12
|
+
# Minimum Vertex Cover.
|
|
13
|
+
|
|
14
|
+
Description
|
|
15
|
+
-----------
|
|
16
|
+
|
|
17
|
+
A vertex cover of an undirected graph is a set of vertices that includes at least
|
|
18
|
+
one endpoint of every edge of this graph. The Minimum Vertex Cover problem tries to
|
|
19
|
+
find the smallest vertex cover in a given graph. The smallest vertex cover is the
|
|
20
|
+
one that contains the least amount of nodes.
|
|
21
|
+
|
|
22
|
+
Links
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Vertex_cover)
|
|
26
|
+
|
|
27
|
+
[Transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
28
|
+
|
|
29
|
+
Attributes
|
|
30
|
+
----------
|
|
31
|
+
### graph: Dict[int, Dict[int, Dict[str, float]]]
|
|
32
|
+
\n Problem graph for the minimum vertex cover problem in form of nested
|
|
33
|
+
dictionaries.
|
|
34
|
+
\n (e.g. fully connected graph with 3 nodes:
|
|
35
|
+
\n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
|
|
36
|
+
\n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
|
|
37
|
+
|
|
38
|
+
### P: int
|
|
39
|
+
\n Positive, scalar penalty value to penalize edges that are not covered.
|
|
40
|
+
\n Default: _8_
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
name: Literal["MVC"] = "MVC"
|
|
44
|
+
graph: dict[str, dict[str, dict[str, float]]] = Field(name="graph") # type: ignore[call-overload]
|
|
45
|
+
P: int = 8
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class NumberPartitioning(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Number Partitioning.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
The Number Partitioning problem partitions a set of numbers into two subsets such
|
|
16
|
+
that the difference of the subset sums is minimized.
|
|
17
|
+
|
|
18
|
+
Links
|
|
19
|
+
-----
|
|
20
|
+
|
|
21
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Partition_problem)
|
|
22
|
+
|
|
23
|
+
[Transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
24
|
+
|
|
25
|
+
Attributes
|
|
26
|
+
----------
|
|
27
|
+
### numbers: List[int]
|
|
28
|
+
\n The set of numbers which has to be partitioned.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
name: Literal["NP"] = "NP"
|
|
32
|
+
numbers: list[int]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PortfolioOptimization(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Portfolio Optimization.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
The Portfolio Optimization problem tries to find the optimal portfolio of assets
|
|
16
|
+
which achieves an equal or higher return than the target return with the lowest
|
|
17
|
+
risk possible. The optimal portfolio is defined by the binary choices whether to
|
|
18
|
+
invest in a specific asset or not.
|
|
19
|
+
|
|
20
|
+
Links
|
|
21
|
+
-----
|
|
22
|
+
|
|
23
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Portfolio_optimization)
|
|
24
|
+
|
|
25
|
+
[Transformation](https://arxiv.org/pdf/2012.01121.pdf)
|
|
26
|
+
|
|
27
|
+
Attributes
|
|
28
|
+
----------
|
|
29
|
+
### returns: List[List[float]]
|
|
30
|
+
\n Returns matrix which contains time-series of returns per asset i.
|
|
31
|
+
|
|
32
|
+
### R: float
|
|
33
|
+
\n Target for overall return of portfolio.
|
|
34
|
+
|
|
35
|
+
### n: int
|
|
36
|
+
\n Number of wanted assets in set.
|
|
37
|
+
|
|
38
|
+
### lambda0: int = 1
|
|
39
|
+
\n Default lagrange multiplier.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
name: Literal["PO"] = "PO"
|
|
43
|
+
returns: list[list[float]]
|
|
44
|
+
R: float
|
|
45
|
+
n: int
|
|
46
|
+
lambda0: int = 1
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PortfolioOptimizationInvestmentBandsTargetVolatility(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Portfolio Optimization with Investment Bands and Target Volatility.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
The Portfolio Optimization problem tries to find the optimal portfolio of assets
|
|
16
|
+
which achieves an equal or higher return than the target return with the lowest
|
|
17
|
+
risk possible. The optimal portfolio is defined by the binary choices whether to
|
|
18
|
+
invest in a specific asset or not.
|
|
19
|
+
|
|
20
|
+
This special case of portfolio optimization handles to additional constraints. On
|
|
21
|
+
the one hand, it tries to find optimal investment portfolios with a fixed
|
|
22
|
+
volatility. On the other hand, it imposes investment bands in the computed
|
|
23
|
+
portfolios, i.e. the investment for each asset is between a minimum and a maximum.
|
|
24
|
+
|
|
25
|
+
Links
|
|
26
|
+
-----
|
|
27
|
+
|
|
28
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Portfolio_optimization)
|
|
29
|
+
|
|
30
|
+
[Transformation](https://arxiv.org/pdf/2106.06735.pdf)
|
|
31
|
+
|
|
32
|
+
Attributes
|
|
33
|
+
----------
|
|
34
|
+
### log_returns: List[float]
|
|
35
|
+
\n Log return of each asset.
|
|
36
|
+
|
|
37
|
+
### sigma: List[List[float]]
|
|
38
|
+
\n Risk matrix.
|
|
39
|
+
|
|
40
|
+
### investment_bands: List[Tuple[float, float]]
|
|
41
|
+
\n Investment bands for each asset.
|
|
42
|
+
|
|
43
|
+
### target_volatility: float
|
|
44
|
+
\n Target volatility of portfolio.
|
|
45
|
+
|
|
46
|
+
### max_budget: int
|
|
47
|
+
\n Maximum budget.
|
|
48
|
+
|
|
49
|
+
### budget_weight: float
|
|
50
|
+
\n Budget penalty factor.
|
|
51
|
+
|
|
52
|
+
### volatility_weight: float
|
|
53
|
+
\n Volatility penalty factor.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
name: Literal["POIBTV"] = "POIBTV"
|
|
57
|
+
log_returns: list[float]
|
|
58
|
+
sigma: list[list[float]]
|
|
59
|
+
investment_bands: list[tuple[float, float]]
|
|
60
|
+
target_volatility: float
|
|
61
|
+
max_budget: int
|
|
62
|
+
budget_weight: float = 5.0
|
|
63
|
+
volatility_weight: float = 50.0
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class QuadraticAssignment(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Quadratic Assignment.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
There are a set of _n_ facilities and a set of _n_ locations. For each pair of
|
|
16
|
+
locations, a distance is specified and for each pair of facilities a weight or flow
|
|
17
|
+
is specified. The Quadratic Assignment problem assigns all facilities to different
|
|
18
|
+
locations with the goal of minimizing the sum of products of the distances and the
|
|
19
|
+
corresponding flows.
|
|
20
|
+
|
|
21
|
+
Links
|
|
22
|
+
-----
|
|
23
|
+
|
|
24
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Quadratic_assignment_problem)
|
|
25
|
+
|
|
26
|
+
[Transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
27
|
+
|
|
28
|
+
Attributes
|
|
29
|
+
----------
|
|
30
|
+
### flow_matrix: List[List]
|
|
31
|
+
\n A matrix denoting the flow (or weight) between the facilities.
|
|
32
|
+
\n e.g. for two facilities with a flow of 3, the flow_matrix will be
|
|
33
|
+
_[[0, 3], [3, 0]]_.
|
|
34
|
+
|
|
35
|
+
### distance_matrix: List[List]
|
|
36
|
+
\n A matrix denoting the distance between the locations.
|
|
37
|
+
\n e.g. for two places with a distance of 8, the flow_matrix will be
|
|
38
|
+
_[[0, 8], [8, 0]]_.
|
|
39
|
+
|
|
40
|
+
### P: int
|
|
41
|
+
\n Positive, scalar penalty value to penalize when a facility is mapped to two
|
|
42
|
+
different locations or vice versa.
|
|
43
|
+
\n Default: _200_
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
name: Literal["QA"] = "QA"
|
|
47
|
+
flow_matrix: list[list[float]]
|
|
48
|
+
distance_matrix: list[list[float]]
|
|
49
|
+
P: int = 200
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class QuadraticKnapsack(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Quadratic Knapsack.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
Given an upper bound of budget and a set of potential projects, each having a
|
|
16
|
+
certain cost, a certain value, and value interactions with the other projects, the
|
|
17
|
+
Quadratic Knapsack problem selects the combination of projects with the highest
|
|
18
|
+
total value, without exceeding the budget restraint.
|
|
19
|
+
|
|
20
|
+
Links
|
|
21
|
+
-----
|
|
22
|
+
|
|
23
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Quadratic_knapsack_problem)
|
|
24
|
+
|
|
25
|
+
[Transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
26
|
+
|
|
27
|
+
Attributes
|
|
28
|
+
----------
|
|
29
|
+
### projects: List[List[float]]
|
|
30
|
+
\n A double nested list with entries _projects[i][j]_ corresponding to the value
|
|
31
|
+
gain of choosing both projects i and j at the same time.
|
|
32
|
+
|
|
33
|
+
### costs: List[float]
|
|
34
|
+
\n The individual costs of each project.
|
|
35
|
+
|
|
36
|
+
### budget: float
|
|
37
|
+
\n Budget restraint (upper bound) on projects.
|
|
38
|
+
|
|
39
|
+
### P: int
|
|
40
|
+
\n The weight of the penalty term.
|
|
41
|
+
\n Default: _10_
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
name: Literal["QK"] = "QK"
|
|
45
|
+
projects: list[list[float]]
|
|
46
|
+
costs: list[float]
|
|
47
|
+
budget: float
|
|
48
|
+
P: float = 10
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SatelliteScheduling(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Satellite Scheduling.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
We assume a satellite can occupy three states: charging (*c*), downlink (*d*) and
|
|
16
|
+
experiment (*e*). We discretize the time and assume time steps *t ∈ {0,1,...,T}*.
|
|
17
|
+
The variable *x_st* tells us if the satellite is in the state *s ∈ {c,d,e}* at time
|
|
18
|
+
*t*. With this, the time sequence of these variables represents the schedule we want
|
|
19
|
+
to optimize. The optimization goal is to record as much data as possible during the
|
|
20
|
+
mission. [1]
|
|
21
|
+
|
|
22
|
+
There are two satellite variables which may change over time: The charge of the
|
|
23
|
+
battery *C* and the data stored on the memory *D*. The rate with which these
|
|
24
|
+
variables are changing depending on state *s* are denoted by *c_s* and *d_s*
|
|
25
|
+
respectively. [1]
|
|
26
|
+
|
|
27
|
+
For example the experiment state will increase the data *dd > 0* and decrease the
|
|
28
|
+
charge *dc < 0*. Both the battery and the memory define an upper and lower limit
|
|
29
|
+
for the charge and the data, respectively. Not every state can be occupied at each
|
|
30
|
+
instance in time. For example, the charging through solar panels is only possible
|
|
31
|
+
in sunlight, or the downlink is only possible in the vicinity of a ground station.
|
|
32
|
+
Therefore for each state s there is a subset of times `τ_s ⊆ {0,1,...,T}* at which
|
|
33
|
+
the satellite can occupy this state. To enforce this constraint, we remove all
|
|
34
|
+
variables *x_st ∈ {x_st |t ∈ τ_s}*. [1]
|
|
35
|
+
|
|
36
|
+
For the sake of simplicity, we assume that each state has minimum duration of *1*.
|
|
37
|
+
|
|
38
|
+
Links
|
|
39
|
+
-----
|
|
40
|
+
|
|
41
|
+
[Transformation (Experiences with Scheduling Problems on Adiabatic Quantum Computers)](https://elib.dlr.de/110044/1/43.pdf)
|
|
42
|
+
|
|
43
|
+
Attributes
|
|
44
|
+
----------
|
|
45
|
+
### T: int
|
|
46
|
+
\n T is the latest included time step. Note that the earliest included time step
|
|
47
|
+
is always *0*.
|
|
48
|
+
|
|
49
|
+
### P: Tuple[int, int, int, int, int, int]
|
|
50
|
+
\n The penalties for each constraint.
|
|
51
|
+
|
|
52
|
+
### Tau: List[List[int]]
|
|
53
|
+
\n Times to be removed for each state.
|
|
54
|
+
|
|
55
|
+
### d: Dict
|
|
56
|
+
\n Dict describing downlink state which includes entries *rate*, *initial*,
|
|
57
|
+
*max*, *min*.
|
|
58
|
+
|
|
59
|
+
### c: Dict
|
|
60
|
+
\n Dict describing charging state which includes entries *rate*, *initial*,
|
|
61
|
+
*max*, *min*.
|
|
62
|
+
|
|
63
|
+
### S: int
|
|
64
|
+
\n *S* is the total number of possible states.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
name: Literal["SSC"] = "SSC"
|
|
68
|
+
T: int
|
|
69
|
+
P: tuple[int, int, int, int, int, int]
|
|
70
|
+
Tau: list[list[int]]
|
|
71
|
+
d: dict[str, float]
|
|
72
|
+
c: dict[str, float]
|
|
73
|
+
S: int = 3
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
|
|
7
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SensorPlacement(UseCase):
|
|
11
|
+
r"""
|
|
12
|
+
# Sensor Placement.
|
|
13
|
+
|
|
14
|
+
Description
|
|
15
|
+
-----------
|
|
16
|
+
|
|
17
|
+
The Sensor Placement problem finds the optimal placement of pressure sensors on a
|
|
18
|
+
water distribution network, which is modelled by a graph where the edges have
|
|
19
|
+
weights assigned to them. A higher weight corresponds to a higher importance that a
|
|
20
|
+
sensor is placed on one of the nodes of the edge. Placing a sensor at a given node
|
|
21
|
+
has a cost attached to it. The total cost of placing the sensors should also be
|
|
22
|
+
minimized. As a constraint, there is a predetermined number of sensors s, which
|
|
23
|
+
should be placed on the network.
|
|
24
|
+
|
|
25
|
+
Links
|
|
26
|
+
-----
|
|
27
|
+
|
|
28
|
+
[Transformation](https://arxiv.org/pdf/2108.04075.pdf)
|
|
29
|
+
|
|
30
|
+
Attributes
|
|
31
|
+
----------
|
|
32
|
+
### graph: Dict[int, Dict[int, Dict[str, float]]]
|
|
33
|
+
\n Problem graph for the sensor placement problem in form of nested
|
|
34
|
+
dictionaries.
|
|
35
|
+
\n (e.g. network with 3 nodes:
|
|
36
|
+
\n _{0: {2: {'weight': 1.0}}, 1: {2: {'weight': 6.0}},
|
|
37
|
+
2: {0: {'weight': 1.0}, 1: {'weight': 6.0}}}_
|
|
38
|
+
\n or _networkx.to_dict_of_dicts(networkx.Graph(...))_ )
|
|
39
|
+
|
|
40
|
+
### costs: List[float]
|
|
41
|
+
\n Cost of placing a sensor on specific node.
|
|
42
|
+
|
|
43
|
+
### s: int
|
|
44
|
+
\n Number of sensors.
|
|
45
|
+
|
|
46
|
+
### A: float
|
|
47
|
+
\n Lagrange multiplier in front of constraint in eq. (15).
|
|
48
|
+
|
|
49
|
+
### B: float
|
|
50
|
+
\n Lagrange multiplier in front of constraint in eq. (13).
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
name: Literal["SPL"] = "SPL"
|
|
54
|
+
graph: dict[str, dict[str, dict[str, float]]] = Field(name="graph") # type: ignore[call-overload]
|
|
55
|
+
costs: list[float]
|
|
56
|
+
s: int
|
|
57
|
+
A: float = 1
|
|
58
|
+
B: float = 30
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SetCover(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Set Cover.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
Given a set _S_ and a list of subsets of _S_, so that each element of _S_ is
|
|
16
|
+
contained in at least one of the subsets, the Set Cover problem tries to find the
|
|
17
|
+
smallest possible family _C_ of these subsets so that all elements of _S_ are
|
|
18
|
+
contained in at least one subset of _C_.
|
|
19
|
+
|
|
20
|
+
Q-Bit Interpretation
|
|
21
|
+
--------------------
|
|
22
|
+
|
|
23
|
+
Let _n_ be the number of elements of _S_ and let _N_ be the number of subsets of
|
|
24
|
+
_S_. Then, the qubit vector _x_ will have length _N + N * n_. For _x[:N]_,
|
|
25
|
+
_x[i] = 1_, iff. subset _i_ is contained in the set cover. For _x[N:]_, _x[i] = 1_,
|
|
26
|
+
iff. the number of subsets which include element _a_ is _m > 0_ and
|
|
27
|
+
_i = N + a * N + m_.
|
|
28
|
+
|
|
29
|
+
Links
|
|
30
|
+
-----
|
|
31
|
+
|
|
32
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Set_cover_problem)
|
|
33
|
+
|
|
34
|
+
[Transformation](https://arxiv.org/pdf/1302.5843.pdf)
|
|
35
|
+
|
|
36
|
+
Attributes
|
|
37
|
+
----------
|
|
38
|
+
### subset_matrix: List[List[float]]
|
|
39
|
+
\n A matrix containing all subsets.
|
|
40
|
+
\n e.g. for the set _{1, 2, 3}_ and the subsets _{1, 2}_, _{2, 3}_, and _{3}_:
|
|
41
|
+
\n _[[1, 1, 0], [0, 1, 1], [0, 0, 1]]_
|
|
42
|
+
\n or:
|
|
43
|
+
\n _SetCover.gen_subsets_matrix([1, 2, 3], [[1, 2], [2, 3], [3]])_
|
|
44
|
+
|
|
45
|
+
### A: int
|
|
46
|
+
\n A positive constant enforcing that each element of _S_ is contained in at
|
|
47
|
+
least one subset.
|
|
48
|
+
|
|
49
|
+
### B: int
|
|
50
|
+
\n A constant (_0 < B < A) minimizing the number of subsets included.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
name: Literal["SC"] = "SC"
|
|
54
|
+
subset_matrix: list[list[int]]
|
|
55
|
+
A: int = 4
|
|
56
|
+
B: int = 2
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SetPacking(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Set Packing.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
Given a set _S_ and a list of subsets of _S_, a packing is a family _C_ of these
|
|
16
|
+
subsets so that all sets in _C_ are pairwise disjoint. For a set _S_ and a list of
|
|
17
|
+
subsets of _S_, the Set Packing problem assigns a weight to each set and tries to
|
|
18
|
+
find a packing so that the sum of the weights of the used sets is maximized.
|
|
19
|
+
|
|
20
|
+
Note that, in contrast to the [transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
21
|
+
mentioned below, our QUBO formulation searches for _min x^t Q x_ instead of
|
|
22
|
+
_max x^t Q x_ and thus all signs are flipped.
|
|
23
|
+
|
|
24
|
+
Q-Bit Interpretation
|
|
25
|
+
--------------------
|
|
26
|
+
|
|
27
|
+
Subset _i_ is part of the packing iff. qubit _i_ is 1.
|
|
28
|
+
|
|
29
|
+
Links
|
|
30
|
+
-----
|
|
31
|
+
|
|
32
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Set_packing)
|
|
33
|
+
|
|
34
|
+
[Transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
35
|
+
|
|
36
|
+
Attributes
|
|
37
|
+
----------
|
|
38
|
+
### subset_matrix: List[List[int]]
|
|
39
|
+
\n A matrix containing all subsets.
|
|
40
|
+
\n e.g. for the set _{1, 2, 3}_ and the subsets _{1, 2}_, _{2, 3}_, and _{3}_:
|
|
41
|
+
\n _[[1, 1, 0], [0, 1, 1], [0, 0, 1]]_
|
|
42
|
+
|
|
43
|
+
### weights: List[int]
|
|
44
|
+
\n An array of length n_subsets which assigns a weight to each subset.
|
|
45
|
+
|
|
46
|
+
### P: int
|
|
47
|
+
\n Positive, scalar penalty value to penalize subsets that are not disjoint.
|
|
48
|
+
\n Default: _6_
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
name: Literal["SP"] = "SP"
|
|
52
|
+
subset_matrix: list[list[int]]
|
|
53
|
+
weights: list[float]
|
|
54
|
+
P: int = 6
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SetPartitioning(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Set Partitioning.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
The Set Partitioning problem partitions a set of items into a selection of possible
|
|
16
|
+
subsets so that each item of the set occurs in one and only one subset and the cost
|
|
17
|
+
of the chosen subsets is minimized.
|
|
18
|
+
|
|
19
|
+
Q-Bit Interpretation
|
|
20
|
+
--------------------
|
|
21
|
+
|
|
22
|
+
Subset _i_ is part of the partitioning iff. qubit _i_ is 1.
|
|
23
|
+
|
|
24
|
+
Links
|
|
25
|
+
-----
|
|
26
|
+
|
|
27
|
+
[Description and Transformation](https://arxiv.org/pdf/1811.11538.pdf)
|
|
28
|
+
|
|
29
|
+
Attributes
|
|
30
|
+
----------
|
|
31
|
+
### set_: List[int]
|
|
32
|
+
\n The set of items which has to be partitioned.
|
|
33
|
+
|
|
34
|
+
### subsets: List[List[int]]
|
|
35
|
+
\n The possible subsets of set_.
|
|
36
|
+
\n e.g. for _set=[1, 2, 3]_ and the possible subsets _{1, 2}_ and _{3}_ one
|
|
37
|
+
has to specify _subsets=[[1, 2], [3]]_.
|
|
38
|
+
|
|
39
|
+
### costs: List[int]
|
|
40
|
+
\n The cost of each possible subset. Has to be of the same length as _subsets_.
|
|
41
|
+
|
|
42
|
+
### P: int
|
|
43
|
+
\n Positive, scalar penalty value to penalize items that occur in more than one
|
|
44
|
+
subset.
|
|
45
|
+
\n Default: _10_
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
name: Literal["SPP"] = "SPP"
|
|
49
|
+
set_: list[int]
|
|
50
|
+
subsets: list[list[int]]
|
|
51
|
+
costs: list[int]
|
|
52
|
+
P: int = 10
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
from luna_quantum.solve.use_cases.type_aliases import NestedDictIntGraph
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SubGraphIsomorphism(UseCase):
|
|
10
|
+
r"""
|
|
11
|
+
# Subgraph Isomorphism.
|
|
12
|
+
|
|
13
|
+
Description
|
|
14
|
+
-----------
|
|
15
|
+
|
|
16
|
+
The Subgraph Isomorphism problem tries to find out whether, for two graphs _G1_ and
|
|
17
|
+
_G2_, _G2_ contains a subgraph _G3_ that is isomorphic to _G1_, i.e. there exists a
|
|
18
|
+
bijective, edge-invariant vertex mapping from _G1_ to _G3_. It returns the best such
|
|
19
|
+
mapping it is able to find.
|
|
20
|
+
|
|
21
|
+
Links
|
|
22
|
+
-----
|
|
23
|
+
|
|
24
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Subgraph_isomorphism_problem)
|
|
25
|
+
|
|
26
|
+
[Transformation](https://researchspace.auckland.ac.nz/bitstream/handle/2292/31756/CDMTCS499.pdf?sequence=1)
|
|
27
|
+
|
|
28
|
+
Attributes
|
|
29
|
+
----------
|
|
30
|
+
### graph1: Dict[int, Dict[int, Dict[str, float]]]
|
|
31
|
+
\n The graph (in form of nested dictionaries) for which to check whether it is
|
|
32
|
+
isomorphic to a subgraph of graph2.
|
|
33
|
+
\n (e.g. fully connected graph with 3 nodes:
|
|
34
|
+
\n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
|
|
35
|
+
\n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
|
|
36
|
+
|
|
37
|
+
### graph2: Dict[int, Dict[int, Dict[str, float]]]
|
|
38
|
+
\n The graph (in form of nested dictionaries) for which to check whether it
|
|
39
|
+
contains a subgraph that is isomorphic to graph1.
|
|
40
|
+
\n (e.g. fully connected graph with 3 nodes:
|
|
41
|
+
\n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
|
|
42
|
+
\n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
|
|
43
|
+
|
|
44
|
+
### a: float = 1
|
|
45
|
+
\n A penalty value enforcing the bijectivity of the isomorphism.
|
|
46
|
+
|
|
47
|
+
### b: float = 2
|
|
48
|
+
\n A penalty value (b > a) enforcing the edge-invariance of the isomorphism.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
name: Literal["SGI"] = "SGI"
|
|
52
|
+
graph1: NestedDictIntGraph = Field(name="graph") # type: ignore[call-overload]
|
|
53
|
+
graph2: NestedDictIntGraph = Field(name="graph") # type: ignore[call-overload]
|
|
54
|
+
a: float = 1
|
|
55
|
+
b: float = 2
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from luna_quantum.solve.use_cases.base import UseCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SubsetSum(UseCase):
|
|
9
|
+
r"""
|
|
10
|
+
# Subset Sum.
|
|
11
|
+
|
|
12
|
+
Description
|
|
13
|
+
-----------
|
|
14
|
+
|
|
15
|
+
The Subset Sum problem finds a subset of numbers from a given set of integers where
|
|
16
|
+
the total sum over the subset is equal or maximally close to a target value t.
|
|
17
|
+
Example: Set _{5, 8, 4, 6}_ and Target _9_ returns the Subset _{5, 4}_
|
|
18
|
+
|
|
19
|
+
Links
|
|
20
|
+
-----
|
|
21
|
+
|
|
22
|
+
[Wikipedia](https://en.wikipedia.org/wiki/Subset_sum_problem)
|
|
23
|
+
|
|
24
|
+
[Transformation](https://arxiv.org/pdf/1911.08043.pdf) (section 3.2.3)
|
|
25
|
+
|
|
26
|
+
Attributes
|
|
27
|
+
----------
|
|
28
|
+
### numbers: List[int]
|
|
29
|
+
\n Set of integers from which the subset is chosen.
|
|
30
|
+
|
|
31
|
+
### t: int
|
|
32
|
+
\n Target value for sum over all numbers in subset.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
name: Literal["SS"] = "SS"
|
|
36
|
+
numbers: list[int]
|
|
37
|
+
t: int
|