luna-quantum 0.0.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of luna-quantum might be problematic. Click here for more details.

Files changed (160) hide show
  1. luna_quantum-0.0.16.dist-info/LICENSE +201 -0
  2. luna_quantum-0.0.16.dist-info/METADATA +46 -0
  3. luna_quantum-0.0.16.dist-info/RECORD +160 -0
  4. luna_quantum-0.0.16.dist-info/WHEEL +4 -0
  5. luna_sdk/__init__.py +2 -0
  6. luna_sdk/constants.py +1 -0
  7. luna_sdk/controllers/__init__.py +2 -0
  8. luna_sdk/controllers/custom_login_client.py +61 -0
  9. luna_sdk/controllers/luna_platform_client.py +62 -0
  10. luna_sdk/controllers/luna_q.py +36 -0
  11. luna_sdk/controllers/luna_solve.py +49 -0
  12. luna_sdk/controllers/luna_transform.py +41 -0
  13. luna_sdk/error/__init__.py +0 -0
  14. luna_sdk/error/http_error_utils.py +100 -0
  15. luna_sdk/exceptions/__init__.py +1 -0
  16. luna_sdk/exceptions/encryption_exception.py +6 -0
  17. luna_sdk/exceptions/luna_exception.py +7 -0
  18. luna_sdk/exceptions/luna_server_exception.py +18 -0
  19. luna_sdk/exceptions/timeout_exception.py +10 -0
  20. luna_sdk/exceptions/transformation.py +11 -0
  21. luna_sdk/interfaces/__init__.py +5 -0
  22. luna_sdk/interfaces/circuit_repo_i.py +62 -0
  23. luna_sdk/interfaces/clients/__init__.py +0 -0
  24. luna_sdk/interfaces/clients/client_i.py +10 -0
  25. luna_sdk/interfaces/clients/luna_q_i.py +39 -0
  26. luna_sdk/interfaces/clients/luna_solve_i.py +37 -0
  27. luna_sdk/interfaces/clients/luna_transform_i.py +33 -0
  28. luna_sdk/interfaces/cplex_repo_i.py +121 -0
  29. luna_sdk/interfaces/info_repo_i.py +40 -0
  30. luna_sdk/interfaces/lp_repo_i.py +106 -0
  31. luna_sdk/interfaces/optimization_repo_i.py +262 -0
  32. luna_sdk/interfaces/qpu_token_repo_i.py +151 -0
  33. luna_sdk/interfaces/repository_i.py +14 -0
  34. luna_sdk/interfaces/solutions_repo_i.py +219 -0
  35. luna_sdk/py.typed +0 -0
  36. luna_sdk/repositories/__init__.py +4 -0
  37. luna_sdk/repositories/circuit_repo.py +104 -0
  38. luna_sdk/repositories/cplex_repo.py +118 -0
  39. luna_sdk/repositories/info_repo.py +45 -0
  40. luna_sdk/repositories/lp_repo.py +105 -0
  41. luna_sdk/repositories/optimization_repo.py +358 -0
  42. luna_sdk/repositories/qpu_token_repo.py +226 -0
  43. luna_sdk/repositories/solutions_repo.py +347 -0
  44. luna_sdk/schemas/__init__.py +4 -0
  45. luna_sdk/schemas/circuit.py +43 -0
  46. luna_sdk/schemas/create/__init__.py +3 -0
  47. luna_sdk/schemas/create/circuit.py +29 -0
  48. luna_sdk/schemas/create/optimization.py +22 -0
  49. luna_sdk/schemas/create/qpu_token.py +26 -0
  50. luna_sdk/schemas/create/qubo.py +19 -0
  51. luna_sdk/schemas/create/solution.py +15 -0
  52. luna_sdk/schemas/enums/__init__.py +0 -0
  53. luna_sdk/schemas/enums/circuit.py +14 -0
  54. luna_sdk/schemas/enums/optimization.py +10 -0
  55. luna_sdk/schemas/enums/problem.py +48 -0
  56. luna_sdk/schemas/enums/qpu_token_type.py +6 -0
  57. luna_sdk/schemas/enums/solution.py +8 -0
  58. luna_sdk/schemas/enums/status.py +10 -0
  59. luna_sdk/schemas/enums/timeframe.py +11 -0
  60. luna_sdk/schemas/error_message.py +12 -0
  61. luna_sdk/schemas/optimization.py +75 -0
  62. luna_sdk/schemas/optimization_formats/__init__.py +0 -0
  63. luna_sdk/schemas/optimization_formats/bqm.py +34 -0
  64. luna_sdk/schemas/optimization_formats/cqm.py +127 -0
  65. luna_sdk/schemas/optimization_formats/lp.py +9 -0
  66. luna_sdk/schemas/optimization_formats/qm.py +30 -0
  67. luna_sdk/schemas/pretty_base.py +49 -0
  68. luna_sdk/schemas/qpu_token.py +60 -0
  69. luna_sdk/schemas/representation.py +19 -0
  70. luna_sdk/schemas/rest/__init__.py +0 -0
  71. luna_sdk/schemas/rest/qpu_token/__init__.py +0 -0
  72. luna_sdk/schemas/rest/qpu_token/token_provider.py +45 -0
  73. luna_sdk/schemas/solution.py +227 -0
  74. luna_sdk/schemas/solver_info.py +11 -0
  75. luna_sdk/schemas/solver_parameters/aws/__init__.py +1 -0
  76. luna_sdk/schemas/solver_parameters/aws/qaoa.py +24 -0
  77. luna_sdk/schemas/solver_parameters/dwave/__init__.py +72 -0
  78. luna_sdk/schemas/solver_parameters/dwave/base.py +409 -0
  79. luna_sdk/schemas/solver_parameters/dwave/dialectic_search.py +31 -0
  80. luna_sdk/schemas/solver_parameters/dwave/kerberos.py +71 -0
  81. luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_bqm.py +19 -0
  82. luna_sdk/schemas/solver_parameters/dwave/leap_hybrid_cqm.py +22 -0
  83. luna_sdk/schemas/solver_parameters/dwave/parallel_tempering.py +30 -0
  84. luna_sdk/schemas/solver_parameters/dwave/parallel_tempering_qpu.py +37 -0
  85. luna_sdk/schemas/solver_parameters/dwave/population_annealing.py +25 -0
  86. luna_sdk/schemas/solver_parameters/dwave/population_annealing_qpu.py +35 -0
  87. luna_sdk/schemas/solver_parameters/dwave/qaga.py +56 -0
  88. luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_qpu.py +19 -0
  89. luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_simulated_annealing.py +22 -0
  90. luna_sdk/schemas/solver_parameters/dwave/qbsolv_like_tabu_search.py +21 -0
  91. luna_sdk/schemas/solver_parameters/dwave/quantum_annealing.py +20 -0
  92. luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_quantum_annealing.py +82 -0
  93. luna_sdk/schemas/solver_parameters/dwave/repeated_reverse_simulated_annealing.py +89 -0
  94. luna_sdk/schemas/solver_parameters/dwave/saga.py +61 -0
  95. luna_sdk/schemas/solver_parameters/dwave/simulated_annealing.py +74 -0
  96. luna_sdk/schemas/solver_parameters/dwave/tabu_search.py +72 -0
  97. luna_sdk/schemas/solver_parameters/fujitsu/__init__.py +20 -0
  98. luna_sdk/schemas/solver_parameters/fujitsu/base.py +47 -0
  99. luna_sdk/schemas/solver_parameters/fujitsu/digital_annealer_cpu.py +129 -0
  100. luna_sdk/schemas/solver_parameters/fujitsu/digital_annealer_v2.py +149 -0
  101. luna_sdk/schemas/solver_parameters/fujitsu/digital_annealer_v3.py +150 -0
  102. luna_sdk/schemas/solver_parameters/fujitsu/partial_config.py +177 -0
  103. luna_sdk/schemas/solver_parameters/ibm/__init__.py +4 -0
  104. luna_sdk/schemas/solver_parameters/ibm/qaoa.py +64 -0
  105. luna_sdk/schemas/solver_parameters/ibm/standard_parameters.py +27 -0
  106. luna_sdk/schemas/solver_parameters/ibm/vqe.py +49 -0
  107. luna_sdk/schemas/solver_parameters/qctrl/__init__.py +1 -0
  108. luna_sdk/schemas/solver_parameters/qctrl/qaoa.py +47 -0
  109. luna_sdk/schemas/transformations/__init__.py +2 -0
  110. luna_sdk/schemas/transformations/bqm.py +33 -0
  111. luna_sdk/schemas/transformations/matrix.py +12 -0
  112. luna_sdk/schemas/use_cases/__init__.py +54 -0
  113. luna_sdk/schemas/use_cases/arbitrage_edge_based.py +49 -0
  114. luna_sdk/schemas/use_cases/arbitrage_node_based.py +54 -0
  115. luna_sdk/schemas/use_cases/base.py +5 -0
  116. luna_sdk/schemas/use_cases/binary_integer_linear_programming.py +53 -0
  117. luna_sdk/schemas/use_cases/binary_paint_shop_problem.py +36 -0
  118. luna_sdk/schemas/use_cases/credit_scoring_feature_selection.py +39 -0
  119. luna_sdk/schemas/use_cases/dynamic_portfolio_optimization.py +63 -0
  120. luna_sdk/schemas/use_cases/exact_cover.py +50 -0
  121. luna_sdk/schemas/use_cases/flight_gate_assignment.py +78 -0
  122. luna_sdk/schemas/use_cases/graph_coloring.py +41 -0
  123. luna_sdk/schemas/use_cases/graph_isomorphism.py +53 -0
  124. luna_sdk/schemas/use_cases/graph_partitioning.py +45 -0
  125. luna_sdk/schemas/use_cases/hamiltonian_cycle.py +48 -0
  126. luna_sdk/schemas/use_cases/induced_subgraph_isomorphism.py +49 -0
  127. luna_sdk/schemas/use_cases/job_shop_scheduling.py +43 -0
  128. luna_sdk/schemas/use_cases/k_medoids_clustering.py +48 -0
  129. luna_sdk/schemas/use_cases/knapsack_integer_weights.py +55 -0
  130. luna_sdk/schemas/use_cases/linear_regression.py +59 -0
  131. luna_sdk/schemas/use_cases/lmwcs.py +80 -0
  132. luna_sdk/schemas/use_cases/longest_path.py +49 -0
  133. luna_sdk/schemas/use_cases/market_graph_clustering.py +60 -0
  134. luna_sdk/schemas/use_cases/max2sat.py +51 -0
  135. luna_sdk/schemas/use_cases/max3sat.py +52 -0
  136. luna_sdk/schemas/use_cases/max_clique.py +59 -0
  137. luna_sdk/schemas/use_cases/max_cut.py +47 -0
  138. luna_sdk/schemas/use_cases/max_independent_set.py +36 -0
  139. luna_sdk/schemas/use_cases/minimal_maximal_matching.py +53 -0
  140. luna_sdk/schemas/use_cases/minimal_spanning_tree.py +87 -0
  141. luna_sdk/schemas/use_cases/minimum_vertex_cover.py +44 -0
  142. luna_sdk/schemas/use_cases/number_partitioning.py +31 -0
  143. luna_sdk/schemas/use_cases/portfolio_optimization.py +45 -0
  144. luna_sdk/schemas/use_cases/portfolio_optimization_ib_tv.py +62 -0
  145. luna_sdk/schemas/use_cases/quadratic_assignment.py +48 -0
  146. luna_sdk/schemas/use_cases/quadratic_knapsack.py +47 -0
  147. luna_sdk/schemas/use_cases/satellite_scheduling.py +72 -0
  148. luna_sdk/schemas/use_cases/sensor_placement.py +57 -0
  149. luna_sdk/schemas/use_cases/set_cover.py +55 -0
  150. luna_sdk/schemas/use_cases/set_packing.py +53 -0
  151. luna_sdk/schemas/use_cases/set_partitioning.py +51 -0
  152. luna_sdk/schemas/use_cases/subgraph_isomorphism.py +56 -0
  153. luna_sdk/schemas/use_cases/subset_sum.py +36 -0
  154. luna_sdk/schemas/use_cases/support_vector_machine.py +63 -0
  155. luna_sdk/schemas/use_cases/traffic_flow.py +34 -0
  156. luna_sdk/schemas/use_cases/travelling_salesman_problem.py +52 -0
  157. luna_sdk/schemas/use_cases/type_aliases.py +11 -0
  158. luna_sdk/schemas/use_cases/weighted_max_cut.py +36 -0
  159. luna_sdk/utils/__init__.py +0 -0
  160. luna_sdk/utils/qpu_tokens.py +52 -0
@@ -0,0 +1,31 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class NumberPartitioning(UseCase):
7
+ """
8
+ # Number Partitioning
9
+
10
+ Description
11
+ -----------
12
+
13
+ The Number Partitioning problem partitions a set of numbers into two subsets such
14
+ that the difference of the subset sums is minimized.
15
+
16
+ Links
17
+ -----
18
+
19
+ [Wikipedia](https://en.wikipedia.org/wiki/Partition_problem)
20
+
21
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
22
+
23
+ Attributes
24
+ ----------
25
+
26
+ ### numbers: List[int]
27
+ \n The set of numbers which has to be partitioned.
28
+ """
29
+
30
+ name: Literal["NP"] = "NP"
31
+ numbers: List[int]
@@ -0,0 +1,45 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class PortfolioOptimization(UseCase):
7
+ """
8
+ # Portfolio Optimization
9
+
10
+ Description
11
+ -----------
12
+
13
+ The Portfolio Optimization problem tries to find the optimal portfolio of assets
14
+ which achieves an equal or higher return than the target return with the lowest
15
+ risk possible. The optimal portfolio is defined by the binary choices whether to
16
+ invest in a specific asset or not.
17
+
18
+ Links
19
+ -----
20
+
21
+ [Wikipedia](https://en.wikipedia.org/wiki/Portfolio_optimization)
22
+
23
+ [Transformation](https://arxiv.org/pdf/2012.01121.pdf)
24
+
25
+ Attributes
26
+ ----------
27
+
28
+ ### returns: List[List[float]]
29
+ \n Returns matrix which contains time-series of returns per asset i.
30
+
31
+ ### R: float
32
+ \n Target for overall return of portfolio.
33
+
34
+ ### n: int
35
+ \n Number of wanted assets in set.
36
+
37
+ ### lambda0: int = 1
38
+ \n Default lagrange multiplier.
39
+ """
40
+
41
+ name: Literal["PO"] = "PO"
42
+ returns: List[List[float]]
43
+ R: float
44
+ n: int
45
+ lambda0: int = 1
@@ -0,0 +1,62 @@
1
+ from typing import List, Literal, Tuple
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class PortfolioOptimizationInvestmentBandsTargetVolatility(UseCase):
7
+ """
8
+ # Portfolio Optimization with Investment Bands and Target Volatility
9
+
10
+ Description
11
+ -----------
12
+
13
+ The Portfolio Optimization problem tries to find the optimal portfolio of assets
14
+ which achieves an equal or higher return than the target return with the lowest
15
+ risk possible. The optimal portfolio is defined by the binary choices whether to
16
+ invest in a specific asset or not.
17
+
18
+ This special case of portfolio optimization handles to additional constraints. On
19
+ the one hand, it tries to find optimal investment portfolios with a fixed
20
+ volatility. On the other hand, it imposes investment bands in the computed
21
+ portfolios, i.e. the investment for each asset is between a minimum and a maximum.
22
+
23
+ Links
24
+ -----
25
+
26
+ [Wikipedia](https://en.wikipedia.org/wiki/Portfolio_optimization)
27
+
28
+ [Transformation](https://arxiv.org/pdf/2106.06735.pdf)
29
+
30
+ Attributes
31
+ ----------
32
+
33
+ ### log_returns: List[float]
34
+ \n Log return of each asset.
35
+
36
+ ### sigma: List[List[float]]
37
+ \n Risk matrix.
38
+
39
+ ### investment_bands: List[Tuple[float, float]]
40
+ \n Investment bands for each asset.
41
+
42
+ ### target_volatility: float
43
+ \n Target volatility of portfolio.
44
+
45
+ ### max_budget: int
46
+ \n Maximum budget.
47
+
48
+ ### budget_weight: float
49
+ \n Budget penalty factor.
50
+
51
+ ### volatility_weight: float
52
+ \n Volatility penalty factor.
53
+ """
54
+
55
+ name: Literal["POIBTV"] = "POIBTV"
56
+ log_returns: List[float]
57
+ sigma: List[List[float]]
58
+ investment_bands: List[Tuple[float, float]]
59
+ target_volatility: float
60
+ max_budget: int
61
+ budget_weight: float = 5.0
62
+ volatility_weight: float = 50.0
@@ -0,0 +1,48 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class QuadraticAssignment(UseCase):
7
+ """
8
+ # Quadratic Assignment
9
+
10
+ Description
11
+ -----------
12
+
13
+ There are a set of _n_ facilities and a set of _n_ locations. For each pair of
14
+ locations, a distance is specified and for each pair of facilities a weight or flow
15
+ is specified. The Quadratic Assignment problem assigns all facilities to different
16
+ locations with the goal of minimizing the sum of products of the distances and the
17
+ corresponding flows.
18
+
19
+ Links
20
+ -----
21
+
22
+ [Wikipedia](https://en.wikipedia.org/wiki/Quadratic_assignment_problem)
23
+
24
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
25
+
26
+ Attributes
27
+ ----------
28
+
29
+ ### flow_matrix: List[List]
30
+ \n A matrix denoting the flow (or weight) between the facilities.
31
+ \n e.g. for two facilities with a flow of 3, the flow_matrix will be
32
+ _[[0, 3], [3, 0]]_.
33
+
34
+ ### distance_matrix: List[List]
35
+ \n A matrix denoting the distance between the locations.
36
+ \n e.g. for two places with a distance of 8, the flow_matrix will be
37
+ _[[0, 8], [8, 0]]_.
38
+
39
+ ### P: int
40
+ \n Positive, scalar penalty value to penalize when a facility is mapped to two
41
+ different locations or vice versa.
42
+ \n Default: _200_
43
+ """
44
+
45
+ name: Literal["QA"] = "QA"
46
+ flow_matrix: List[List]
47
+ distance_matrix: List[List]
48
+ P: int = 200
@@ -0,0 +1,47 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class QuadraticKnapsack(UseCase):
7
+ """
8
+ # Quadratic Knapsack
9
+
10
+ Description
11
+ -----------
12
+
13
+ Given an upper bound of budget and a set of potential projects, each having a
14
+ certain cost, a certain value, and value interactions with the other projects, the
15
+ Quadratic Knapsack problem selects the combination of projects with the highest
16
+ total value, without exceeding the budget restraint.
17
+
18
+ Links
19
+ -----
20
+
21
+ [Wikipedia](https://en.wikipedia.org/wiki/Quadratic_knapsack_problem)
22
+
23
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
24
+
25
+ Attributes
26
+ ----------
27
+
28
+ ### projects: List[List[float]]
29
+ \n A double nested list with entries _projects[i][j]_ corresponding to the value
30
+ gain of choosing both projects i and j at the same time.
31
+
32
+ ### costs: List[float]
33
+ \n The individual costs of each project.
34
+
35
+ ### budget: float
36
+ \n Budget restraint (upper bound) on projects.
37
+
38
+ ### P: int
39
+ \n The weight of the penalty term.
40
+ \n Default: _10_
41
+ """
42
+
43
+ name: Literal["QK"] = "QK"
44
+ projects: List[List[float]]
45
+ costs: List[float]
46
+ budget: float
47
+ P: float = 10
@@ -0,0 +1,72 @@
1
+ from typing import Dict, List, Literal, Tuple
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class SatelliteScheduling(UseCase):
7
+ """
8
+ # Satellite Scheduling
9
+
10
+ Description
11
+ -----------
12
+
13
+ We assume a satellite can occupy three states: charging (*c*), downlink (*d*) and
14
+ experiment (*e*). We discretize the time and assume time steps *t ∈ {0,1,...,T}*.
15
+ The variable *x_st* tells us if the satellite is in the state *s ∈ {c,d,e}* at time
16
+ *t*. With this, the time sequence of these variables represents the schedule we want
17
+ to optimize. The optimization goal is to record as much data as possible during the
18
+ mission. [1]
19
+
20
+ There are two satellite variables which may change over time: The charge of the
21
+ battery *C* and the data stored on the memory *D*. The rate with which these
22
+ variables are changing depending on state *s* are denoted by *c_s* and *d_s*
23
+ respectively. [1]
24
+
25
+ For example the experiment state will increase the data *dd > 0* and decrease the
26
+ charge *dc < 0*. Both the battery and the memory define an upper and lower limit
27
+ for the charge and the data, respectively. Not every state can be occupied at each
28
+ instance in time. For example, the charging through solar panels is only possible
29
+ in sunlight, or the downlink is only possible in the vicinity of a ground station.
30
+ Therefore for each state s there is a subset of times `τ_s ⊆ {0,1,...,T}* at which
31
+ the satellite can occupy this state. To enforce this constraint, we remove all
32
+ variables *x_st ∈ {x_st |t ∈ τ_s}*. [1]
33
+
34
+ For the sake of simplicity, we assume that each state has minimum duration of *1*.
35
+
36
+ Links
37
+ -----
38
+
39
+ [Transformation (Experiences with Scheduling Problems on Adiabatic Quantum Computers)](https://elib.dlr.de/110044/1/43.pdf)
40
+
41
+ Attributes
42
+ ----------
43
+
44
+ ### T: int
45
+ \n T is the latest included time step. Note that the earliest included time step
46
+ is always *0*.
47
+
48
+ ### P: Tuple[int, int, int, int, int, int]
49
+ \n The penalties for each constraint.
50
+
51
+ ### Tau: List[List[int]]
52
+ \n Times to be removed for each state.
53
+
54
+ ### d: Dict
55
+ \n Dict describing downlink state which includes entries *rate*, *initial*,
56
+ *max*, *min*.
57
+
58
+ ### c: Dict
59
+ \n Dict describing charging state which includes entries *rate*, *initial*,
60
+ *max*, *min*.
61
+
62
+ ### S: int
63
+ \n *S* is the total number of possible states.
64
+ """
65
+
66
+ name: Literal["SSC"] = "SSC"
67
+ T: int
68
+ P: Tuple[int, int, int, int, int, int]
69
+ Tau: List[List[int]]
70
+ d: Dict
71
+ c: Dict
72
+ S: int = 3
@@ -0,0 +1,57 @@
1
+ from typing import Dict, List, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class SensorPlacement(UseCase):
9
+ """
10
+ # Sensor Placement
11
+
12
+ Description
13
+ -----------
14
+
15
+ The Sensor Placement problem finds the optimal placement of pressure sensors on a
16
+ water distribution network, which is modelled by a graph where the edges have
17
+ weights assigned to them. A higher weight corresponds to a higher importance that a
18
+ sensor is placed on one of the nodes of the edge. Placing a sensor at a given node
19
+ has a cost attached to it. The total cost of placing the sensors should also be
20
+ minimized. As a constraint, there is a predetermined number of sensors s, which
21
+ should be placed on the network.
22
+
23
+ Links
24
+ -----
25
+
26
+ [Transformation](https://arxiv.org/pdf/2108.04075.pdf)
27
+
28
+ Attributes
29
+ ----------
30
+
31
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
32
+ \n Problem graph for the sensor placement problem in form of nested
33
+ dictionaries.
34
+ \n (e.g. network with 3 nodes:
35
+ \n _{0: {2: {'weight': 1.0}}, 1: {2: {'weight': 6.0}},
36
+ 2: {0: {'weight': 1.0}, 1: {'weight': 6.0}}}_
37
+ \n or _networkx.to_dict_of_dicts(networkx.Graph(...))_ )
38
+
39
+ ### costs: List[float]
40
+ \n Cost of placing a sensor on specific node.
41
+
42
+ ### s: int
43
+ \n Number of sensors.
44
+
45
+ ### A: float
46
+ \n Lagrange multiplier in front of constraint in eq. (15).
47
+
48
+ ### B: float
49
+ \n Lagrange multiplier in front of constraint in eq. (13).
50
+ """
51
+
52
+ name: Literal["SPL"] = "SPL"
53
+ graph: Dict[str, Dict[str, Dict[str, float]]] = Field(name="graph") # type: ignore
54
+ costs: List[float]
55
+ s: int
56
+ A: float = 1
57
+ B: float = 30
@@ -0,0 +1,55 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class SetCover(UseCase):
7
+ """
8
+ # Set Cover
9
+
10
+ Description
11
+ -----------
12
+
13
+ Given a set _S_ and a list of subsets of _S_, so that each element of _S_ is
14
+ contained in at least one of the subsets, the Set Cover problem tries to find the
15
+ smallest possible family _C_ of these subsets so that all elements of _S_ are
16
+ contained in at least one subset of _C_.
17
+
18
+ Q-Bit Interpretation
19
+ --------------------
20
+
21
+ Let _n_ be the number of elements of _S_ and let _N_ be the number of subsets of
22
+ _S_. Then, the qubit vector _x_ will have length _N + N * n_. For _x[:N]_,
23
+ _x[i] = 1_, iff. subset _i_ is contained in the set cover. For _x[N:]_, _x[i] = 1_,
24
+ iff. the number of subsets which include element _a_ is _m > 0_ and
25
+ _i = N + a * N + m_.
26
+
27
+ Links
28
+ -----
29
+
30
+ [Wikipedia](https://en.wikipedia.org/wiki/Set_cover_problem)
31
+
32
+ [Transformation](https://arxiv.org/pdf/1302.5843.pdf)
33
+
34
+ Attributes
35
+ ----------
36
+
37
+ ### subset_matrix: List[List[float]]
38
+ \n A matrix containing all subsets.
39
+ \n e.g. for the set _{1, 2, 3}_ and the subsets _{1, 2}_, _{2, 3}_, and _{3}_:
40
+ \n _[[1, 1, 0], [0, 1, 1], [0, 0, 1]]_
41
+ \n or:
42
+ \n _SetCover.gen_subsets_matrix([1, 2, 3], [[1, 2], [2, 3], [3]])_
43
+
44
+ ### A: int
45
+ \n A positive constant enforcing that each element of _S_ is contained in at
46
+ least one subset.
47
+
48
+ ### B: int
49
+ \n A constant (_0 < B < A) minimizing the number of subsets included.
50
+ """
51
+
52
+ name: Literal["SC"] = "SC"
53
+ subset_matrix: List[List[int]]
54
+ A: int = 4
55
+ B: int = 2
@@ -0,0 +1,53 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class SetPacking(UseCase):
7
+ """
8
+ # Set Packing
9
+
10
+ Description
11
+ -----------
12
+
13
+ Given a set _S_ and a list of subsets of _S_, a packing is a family _C_ of these
14
+ subsets so that all sets in _C_ are pairwise disjoint. For a set _S_ and a list of
15
+ subsets of _S_, the Set Packing problem assigns a weight to each set and tries to
16
+ find a packing so that the sum of the weights of the used sets is maximized.
17
+
18
+ Note that, in contrast to the [transformation](https://arxiv.org/pdf/1811.11538.pdf)
19
+ mentioned below, our QUBO formulation searches for _min x^t Q x_ instead of
20
+ _max x^t Q x_ and thus all signs are flipped.
21
+
22
+ Q-Bit Interpretation
23
+ --------------------
24
+
25
+ Subset _i_ is part of the packing iff. qubit _i_ is 1.
26
+
27
+ Links
28
+ -----
29
+
30
+ [Wikipedia](https://en.wikipedia.org/wiki/Set_packing)
31
+
32
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
33
+
34
+ Attributes
35
+ ----------
36
+
37
+ ### subset_matrix: List[List[int]]
38
+ \n A matrix containing all subsets.
39
+ \n e.g. for the set _{1, 2, 3}_ and the subsets _{1, 2}_, _{2, 3}_, and _{3}_:
40
+ \n _[[1, 1, 0], [0, 1, 1], [0, 0, 1]]_
41
+
42
+ ### weights: List[int]
43
+ \n An array of length n_subsets which assigns a weight to each subset.
44
+
45
+ ### P: int
46
+ \n Positive, scalar penalty value to penalize subsets that are not disjoint.
47
+ \n Default: _6_
48
+ """
49
+
50
+ name: Literal["SP"] = "SP"
51
+ subset_matrix: List[List[int]]
52
+ weights: List[float]
53
+ P: int = 6
@@ -0,0 +1,51 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class SetPartitioning(UseCase):
7
+ """
8
+ # Set Partitioning
9
+
10
+ Description
11
+ -----------
12
+
13
+ The Set Partitioning problem partitions a set of items into a selection of possible
14
+ subsets so that each item of the set occurs in one and only one subset and the cost
15
+ of the chosen subsets is minimized.
16
+
17
+ Q-Bit Interpretation
18
+ --------------------
19
+
20
+ Subset _i_ is part of the partitioning iff. qubit _i_ is 1.
21
+
22
+ Links
23
+ -----
24
+
25
+ [Description and Transformation](https://arxiv.org/pdf/1811.11538.pdf)
26
+
27
+ Attributes
28
+ ----------
29
+
30
+ ### set_: List[int]
31
+ \n The set of items which has to be partitioned.
32
+
33
+ ### subsets: List[List[int]]
34
+ \n The possible subsets of set_.
35
+ \n e.g. for _set=[1, 2, 3]_ and the possible subsets _{1, 2}_ and _{3}_ one
36
+ has to specify _subsets=[[1, 2], [3]]_.
37
+
38
+ ### costs: List[int]
39
+ \n The cost of each possible subset. Has to be of the same length as _subsets_.
40
+
41
+ ### P: int
42
+ \n Positive, scalar penalty value to penalize items that occur in more than one
43
+ subset.
44
+ \n Default: _10_
45
+ """
46
+
47
+ name: Literal["SPP"] = "SPP"
48
+ set_: List[int]
49
+ subsets: List[List[int]]
50
+ costs: List[int]
51
+ P: int = 10
@@ -0,0 +1,56 @@
1
+ from typing import Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+ from luna_sdk.schemas.use_cases.graph_isomorphism import NestedDictIntGraph
7
+
8
+
9
+ class SubGraphIsomorphism(UseCase):
10
+ """
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
+
31
+ ### graph1: Dict[int, Dict[int, Dict[str, float]]]
32
+ \n The graph (in form of nested dictionaries) for which to check whether it is
33
+ isomorphic to a subgraph of graph2.
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
+ ### graph2: Dict[int, Dict[int, Dict[str, float]]]
39
+ \n The graph (in form of nested dictionaries) for which to check whether it
40
+ contains a subgraph that is isomorphic to graph1.
41
+ \n (e.g. fully connected graph with 3 nodes:
42
+ \n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
43
+ \n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
44
+
45
+ ### a: float = 1
46
+ \n A penalty value enforcing the bijectivity of the isomorphism.
47
+
48
+ ### b: float = 2
49
+ \n A penalty value (b > a) enforcing the edge-invariance of the isomorphism.
50
+ """
51
+
52
+ name: Literal["SGI"] = "SGI"
53
+ graph1: NestedDictIntGraph = Field(name="graph") # type: ignore
54
+ graph2: NestedDictIntGraph = Field(name="graph") # type: ignore
55
+ a: float = 1
56
+ b: float = 2
@@ -0,0 +1,36 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class SubsetSum(UseCase):
7
+ """
8
+ # Subset Sum
9
+
10
+ Description
11
+ -----------
12
+
13
+ The Subset Sum problem finds a subset of numbers from a given set of integers where
14
+ the total sum over the subset is equal or maximally close to a target value t.
15
+ Example: Set _{5, 8, 4, 6}_ and Target _9_ returns the Subset _{5, 4}_
16
+
17
+ Links
18
+ -----
19
+
20
+ [Wikipedia](https://en.wikipedia.org/wiki/Subset_sum_problem)
21
+
22
+ [Transformation](https://arxiv.org/pdf/1911.08043.pdf) (section 3.2.3)
23
+
24
+ Attributes
25
+ ----------
26
+
27
+ ### numbers: List[int]
28
+ \n Set of integers from which the subset is chosen.
29
+
30
+ ### t: int
31
+ \n Target value for sum over all numbers in subset.
32
+ """
33
+
34
+ name: Literal["SS"] = "SS"
35
+ numbers: List[int]
36
+ t: int
@@ -0,0 +1,63 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class SupportVectorMachine(UseCase):
7
+ """
8
+ # Support Vector Machine
9
+
10
+ Description
11
+ -----------
12
+
13
+ In machine learning, support vector machines are supervised learning models that
14
+ perform linear classification in such a way that the seperating hyperplane is as far
15
+ away from each data point as possible.
16
+
17
+ Note that, in this implementation, the model always assumes the separating
18
+ hyperplane to be unbiased, i.e. it goes through the origin.
19
+
20
+ Q-Bit Interpretation
21
+ --------------------
22
+
23
+ For interpretation, the qubit vector has to be cut into N sublists of length K
24
+ (specified below). The sum of each of the products of each of these sublists and the
25
+ precision vector gives a lagrangian multiplier for each data point.
26
+
27
+ Links
28
+ -----
29
+
30
+ [Wikipedia](https://en.wikipedia.org/wiki/Support-vector_machine)
31
+
32
+ [Transformation](https://doi.org/10.1038/s41598-021-89461-4)
33
+
34
+ Attributes
35
+ ----------
36
+
37
+ ### X: List[List[float]]
38
+ \n Training data set in form of a nested list.
39
+ \n All inner lists have to be of the same length.
40
+ \n (e.g. 3 data points with 2 features:
41
+ \n _[[1.1, 4.23], [0.1, -2.4], [-2.3, 1.11]]_
42
+
43
+ ### Y: List[int]
44
+ \n Classification labels of the training data set.
45
+ \n e.g. for 3 data points:
46
+ \n _[-1, 1, 1]_
47
+
48
+ ### K: int
49
+ \n Length of the precision vector.
50
+ \n As the problem outputs are supposed to be real values but the qubo only
51
+ gives a binary vector, we need a precision vector, consisting of positive powers
52
+ of 2, to simulate real values. This parameter determines the length of this
53
+ vector.
54
+ \n (e.g. for K = 5, the precision vector is _[0.25, 0.5, 1, 2, 4]_)
55
+ \n This parameter also determines the size of the qubo matrix together with the
56
+ number of data points _N_:
57
+ \n _size = N * K_
58
+ """
59
+
60
+ name: Literal["SVM"] = "SVM"
61
+ X: List[List[float]]
62
+ Y: List[int]
63
+ K: int = 5