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,59 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class LinearRegression(UseCase):
7
+ """
8
+ # Linear Regression
9
+
10
+ Description
11
+ -----------
12
+
13
+ In statistics, linear regression is a linear approach to modelling the relationship
14
+ between a real-valued dependent variable and one or more real-valued independent
15
+ variables.
16
+
17
+ Q-Bit Interpretation
18
+ --------------------
19
+
20
+ For interpretation, the qubit vector has to be cut into (n_features + 1) sublists of
21
+ length K (specified below). The sum of each of the product of each of these sublists
22
+ and the precision vector gives an estimated feature weight.
23
+
24
+ Links
25
+ -----
26
+
27
+ [Wikipedia](https://en.wikipedia.org/wiki/Linear_regression)
28
+
29
+ [Transformation](https://doi.org/10.1038/s41598-021-89461-4)
30
+
31
+ Attributes
32
+ ----------
33
+
34
+ ### X: List[List[float]]
35
+ \n Training data set in form of a nested list.
36
+ \n All inner lists have to be of the same length.
37
+ \n (e.g. 3 data points with 2 features:
38
+ \n _[[1.1, 4.23], [0.1, -2.4], [-2.3, 1.11]]_ )
39
+
40
+ ### Y: List[int]
41
+ \n Regression labels of the training data set.
42
+ \n (e.g. for 3 data points:
43
+ \n _[1.2, -3.4, 2.41]_ )
44
+
45
+ ### K: int
46
+ \n Length of the precision vector.
47
+ \n As the problem outputs are supposed to be real values but the qubo only gives
48
+ a binary vector, we need a precision vector, consisting of powers of 2, to
49
+ simulate real values. This parameter determines the length of this vector.
50
+ \n (e.g. for K = 6, the precision vector is _[-2, -1, -0.5, 0.5, 1, 2]_)
51
+ \n This parameter also determines the size of the qubo matrix together with the
52
+ number of features _d_:
53
+ \n _size = (d + 1) * K_
54
+ """
55
+
56
+ name: Literal["LR"] = "LR"
57
+ X: List[List[float]]
58
+ Y: List[float]
59
+ K: int = 24
@@ -0,0 +1,80 @@
1
+ from typing import List, Literal, Optional, Tuple
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+ from luna_sdk.schemas.use_cases.type_aliases import NestedDictGraph
7
+
8
+
9
+ class LabeledMaxWeightedCommonSubgraph(UseCase):
10
+ """
11
+ # Labeled Maximum Weighted Common Subgraph
12
+
13
+ Description
14
+ -----------
15
+
16
+ The Labeled Maximum Weighted Common Subgraph (LMWCS) problem finds, given two graphs
17
+ _G1_ and _G2_, the largest subgraph of _G1_ that is isomorphic to a subgraph of
18
+ _G2_. A weight is associated with each possible mapping between a node in _G1_ and a
19
+ node in _G2_ to model a difference in importance for different mappings between
20
+ nodes in the first graph and the second graph. The vertex pairs with assigned value
21
+ _1_ form the common subgraph. Besides the constraint on the mappings which follow
22
+ from requiring bijectivity, one can also define user-defined constraints.
23
+
24
+ Notes:
25
+ There is an error in definition of _C_ (bijectivity constraint): condition one
26
+ should be: _((i == m)_ or _(j == n))_ and not _((i == j)_ and _(j == n))_.
27
+
28
+ We need to map the binary vector elements _b_{i, j}_, where _i_ and _j_ describe a
29
+ node in the graphs 1 and 2 respectively, to an entry in a
30
+ _(graph1.order() * graph2.order())_ dimensional vector. Here, we say that the
31
+ element _b_{i, j}_ is mapped to the _(i * graph2.order() + j)_th entry of the
32
+ vector.
33
+
34
+ Generally, we have to fulfill _a_{(i, j), (m, n)} > min(w_{i, j}, w_{m, n})_ with
35
+ _w_ being the weights for the pairs _(i, j)_. Here, we choose _a > max(weights)_ as
36
+ if _a_ fulfills this condition for all _a_{(i, j), (m, n)}_.
37
+
38
+ Q-Bit Interpretation
39
+ --------------------
40
+
41
+ The tuple _(i, j)_ is part of the mapping iff. qubit _i * graph2.order() + j_ is 1.
42
+
43
+ Links
44
+ -----
45
+
46
+ [Transformation](https://arxiv.org/pdf/1601.06693.pdf)
47
+
48
+ Attributes
49
+ ----------
50
+
51
+ ### graph1: Dict[int, Dict[int, Dict[str, float]]]
52
+ \n First problem graph for the lmwcs problem in form of nested dictionaries.
53
+ \n (e.g. fully connected graph with 3 nodes:
54
+ \n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
55
+ \n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
56
+
57
+ ### graph2: Dict[int, Dict[int, Dict[str, float]]]
58
+ \n Second problem graph for the lmwcs problem in form of nested dictionaries.
59
+ \n (e.g. fully connected graph with 3 nodes:
60
+ \n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
61
+ \n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
62
+
63
+ ### weigths: List[float]
64
+ \n Weights for all pairs _(i, j)_ in _graph1.nodes x graph2.nodes_.
65
+
66
+ ### a: float
67
+ \n Penalty for mapping violating bijectivity or user constraints.
68
+
69
+ ### user_constraints: List[Tuple[Tuple[int, int], Tuple[int, int]]]
70
+ \n User given constraints on the vertex mapping.
71
+ \n _((i, j), (m, n))_ being part of the user constraints means that _(i, j)_ and
72
+ _(m, n)_ must not be part of the mapping at the same time.
73
+ """
74
+
75
+ name: Literal["LMWCS"] = "LMWCS"
76
+ graph1: NestedDictGraph = Field(name="graph") # type: ignore
77
+ graph2: NestedDictGraph = Field(name="graph") # type: ignore
78
+ weights: List[float]
79
+ a: float
80
+ user_constraints: Optional[List[Tuple[Tuple[int, int], Tuple[int, int]]]] = None
@@ -0,0 +1,49 @@
1
+ from typing import Dict, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class LongestPath(UseCase):
9
+ """
10
+ # Longest Path
11
+
12
+ Description
13
+ -----------
14
+
15
+ The longest path problem is the problem of finding a simple path of maximum length
16
+ from a given start node to a given terminal node in a given graph. A path is called
17
+ simple if it does not have any repeated vertices.
18
+
19
+ Links
20
+ -----
21
+
22
+ [Wikipedia](https://en.wikipedia.org/wiki/Longest_path_problem)
23
+
24
+ [Transformation](https://www.sciencedirect.com/science/article/abs/pii/S030439752100092X#!)
25
+
26
+ Attributes
27
+ ----------
28
+
29
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
30
+ \n Problem graph for the longest path problem in form of nested dictionaries.
31
+ \n (e.g. fully connected graph with 3 nodes:
32
+ \n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
33
+ \n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
34
+
35
+ ### start_node:
36
+ \n At which node to start.
37
+
38
+ ### terminal_node:
39
+ \n At which node to stop.
40
+
41
+ ### steps:
42
+ \n How many nodes to include in the path.
43
+ """
44
+
45
+ name: Literal["LP"] = "LP"
46
+ graph: Dict[str, Dict[str, Dict[str, float]]] = Field(name="graph") # type: ignore
47
+ start_node: str
48
+ terminal_node: str
49
+ steps: int
@@ -0,0 +1,60 @@
1
+ from typing import List, Literal
2
+
3
+ from luna_sdk.schemas.use_cases.base import UseCase
4
+
5
+
6
+ class MarketGraphClustering(UseCase):
7
+ """
8
+ # Market Graph Clustering
9
+
10
+ Description
11
+ -----------
12
+
13
+ The authors formulate the index-tracking problem as a QUBO graph-clustering problem.
14
+ Their formulation restricts the number of assets while identifying the most
15
+ representative exemplars of an index. Their thesis is that a portfolio consisting of
16
+ the most representative set of exemplars will minimize tracking-error.
17
+ Initial results are very encouraging. Their tests show they accurately replicate the
18
+ returns of broad market indices, using only a small subset of their constituent
19
+ assets. Moreover, their QUBO formulation allows us to take advantage of recent
20
+ hardware advances to overcome the NP-hard nature of the clustering problem.
21
+ Using these novel architectures they obtain better solutions within small fractions
22
+ of the time required to solve equivalent problems formulated in traditional
23
+ constrained form and solved on traditional hardware. Their initial results certainly
24
+ offer hope and set the stage for larger-scale problems, in finance and beyond.
25
+
26
+ Their implementation is based on the work of *Bauckhage et al.*.
27
+
28
+ Q-Bit Interpretation
29
+ --------------------
30
+
31
+ "The qubit vector at index _k_ is 1 iff. stock _k_ from matrix _G_ (see below) is
32
+ chosen as medoid of a cluster. The step of assigning the remaining stocks to
33
+ clusters is not covered in this problem but can be easily done in linear time with
34
+ respect to the number of data points."
35
+
36
+ Links
37
+ -----
38
+
39
+ [Transformation (Market Graph Clustering via QUBO and Digital Annealing)](https://www.mdpi.com/1911-8074/14/1/34)
40
+
41
+ [Bauckhage et al. (A QUBO Formulation of the k-Medoids Problem)](http://ceur-ws.org/Vol-2454/paper_39.pdf)
42
+
43
+ Attributes
44
+ ----------
45
+
46
+ ### G: List[List[float]]
47
+ \n An *n x m* matrix, where *n* is the number of stocks and *m* is the number of
48
+ time units with returns for the respective stock at this time.
49
+
50
+ ### k: int
51
+ \n The number of representatives desired.
52
+
53
+ ### gamma: float
54
+ \n Penalty coefficient to enforce feasibility of the solution.
55
+ """
56
+
57
+ name: Literal["MGC"] = "MGC"
58
+ G: List[List[float]]
59
+ k: int
60
+ gamma: float
@@ -0,0 +1,51 @@
1
+ """Provides the Max2SAT class"""
2
+
3
+ from typing import List, Literal, Optional
4
+
5
+ from pydantic import Field
6
+
7
+ from luna_sdk.schemas.use_cases.base import UseCase
8
+ from luna_sdk.schemas.use_cases.type_aliases import Clause
9
+
10
+
11
+ class Max2SAT(UseCase):
12
+ """
13
+ # Maximum 2-SAT
14
+
15
+ Description
16
+ -----------
17
+
18
+ For a formula in conjunctive normal form (CNF) with two literals per clause, the
19
+ Maximum 2-SAT problem determines the maximum number of clauses that can be
20
+ simultaneously satisfied by an assignment.
21
+
22
+ Q-Bit Interpretation
23
+ --------------------
24
+
25
+ Each qubit corresponds to the truth value of one of the variables, to be precise:
26
+ _sorted(variables)[i] == True_ iff. _qubits[i] == 1_.
27
+
28
+ Links
29
+ -----
30
+
31
+ [Wikipedia](https://en.wikipedia.org/wiki/2-satisfiability#Maximum-2-satisfiability)
32
+
33
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
34
+
35
+ Attributes
36
+ ----------
37
+
38
+ ### clauses: List[Tuple[Tuple[int, bool], Tuple[int, bool]]]
39
+ \n A list containing all clauses of the formula in CNF in form of tuples.
40
+ \n (e.g. the formula _x0 * x1 + -x1 * x2_:
41
+ \n _[((0, True), (1, True)), ((1, False), (2, True))]_ )
42
+ \n It is possible to use arbitrary variable indices.
43
+
44
+ ### n_vars: Optional[int]
45
+ \n The number of different variables. Can be used to check whether the input
46
+ clauses have the desired number of different variables.
47
+ """
48
+
49
+ name: Literal["M2SAT"] = "M2SAT"
50
+ clauses: List[Clause] = Field(name="clauses") # type: ignore
51
+ n_vars: Optional[int] = None
@@ -0,0 +1,52 @@
1
+ from typing import List, Literal, Optional
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+ from luna_sdk.schemas.use_cases.type_aliases import Clause
7
+
8
+
9
+ class Max3SAT(UseCase):
10
+ """
11
+ # Maximum 3-SAT
12
+
13
+ Description
14
+ -----------
15
+
16
+ For a formula in conjunctive normal form (CNF) with three literals per clause, the
17
+ Maximum 3-SAT problem determines the maximum number of clauses that can be
18
+ simultaneously satisfied by an assignment.
19
+
20
+ Q-Bit Interpretation
21
+ --------------------
22
+
23
+ Let _n_ be the number of different variables and let _m_ be the number of clauses.
24
+ Then, each of the first _n_ qubits corresponds to the truth value of one of the
25
+ variables, to be precise: _sorted(variables)[i] == True_ iff. _qubits[i] == 1_. Each
26
+ of the last _m_ qubits tells whether the corresponding clause is fulfilled,
27
+ formally: _clauses[i]_ is fulfilled iff. _qubits[n + i] == 1_.
28
+
29
+ Links
30
+ -----
31
+
32
+ [Wikipedia](https://en.wikipedia.org/wiki/MAX-3SAT)
33
+
34
+ [Transformation](https://canvas.auckland.ac.nz/courses/14782/files/574983/download?verifier=1xqRikUjTEBwm8PnObD8YVmKdeEhZ9Ui8axW8HwP&wrap=1)
35
+
36
+ Attributes
37
+ ----------
38
+
39
+ ### clauses: List[Tuple[Tuple[int, bool], Tuple[int, bool], Tuple[int, bool]]]
40
+ \n A list containing all clauses of the formula in CNF in form of tuples.
41
+ \n (e.g. the formula _x0 * x1 * -x2 + -x1 * x2 * x3_:
42
+ \n _[((0, True), (1, True), (2, False)), ((1, False), (2, True), (3, True))]_ )
43
+ \n It is possible to use arbitrary variable indices.
44
+
45
+ ### n_vars: Optional[int]
46
+ \n The number of different variables. Can be used to check whether the input
47
+ clauses have the desired number of different variables.
48
+ """
49
+
50
+ name: Literal["M3SAT"] = "M3SAT"
51
+ clauses: List[Clause] = Field(name="clauses") # type: ignore
52
+ n_vars: Optional[int] = None
@@ -0,0 +1,59 @@
1
+ from typing import Dict, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class MaxClique(UseCase):
9
+ """
10
+ # Maximum Clique
11
+
12
+ Description
13
+ -----------
14
+
15
+ The Maximum Clique problem describes the task of finding the largest sized clique in
16
+ a given graph. A clique is a set of nodes in a graph, where every node has an edge
17
+ to every other node in the clique. A k-clique denotes a clique with exactly k nodes.
18
+ The maximum clique of a graph is the clique with the highest possible k value.
19
+
20
+ There is a closely related problem, the decisional clique problem, which describes
21
+ the challenge of determining whether a clique of at least size k exists in the given
22
+ graph.
23
+
24
+ Math
25
+ ----
26
+
27
+ ![Formula](https://www.matthiasknoll.net/storage/img/max_clique.svg)
28
+
29
+
30
+ Links
31
+ -----
32
+
33
+ [Wikipedia](https://en.wikipedia.org/wiki/Clique_problem#Finding_a_single_maximal_clique)
34
+
35
+ [Transformation](https://arxiv.org/pdf/1801.08649.pdf)
36
+
37
+ Attributes
38
+ ----------
39
+
40
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
41
+ \n Problem graph for the maximum clique problem in form of nested dictionaries.
42
+ \n (e.g. fully connected graph with 3 nodes:
43
+ \n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
44
+ \n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
45
+
46
+ ### hard_constraints: Dict
47
+ \n Hard constraints that must be fulfilled by any valid instance. They are
48
+ defined in _aqcore.transformator.specifications.graph_specifications_.
49
+
50
+ ### soft_constraints: Optional[Dict]
51
+ \n Desirable traits that instances should fulfill.
52
+
53
+ ### check_soft_constraints: bool
54
+ \n Defines whether soft constraints should also be fulfilled. Default is
55
+ _False_.
56
+ """
57
+
58
+ name: Literal["MCQ"] = "MCQ"
59
+ graph: Dict[str, Dict[str, Dict[str, float]]] = Field(name="graph") # type: ignore
@@ -0,0 +1,47 @@
1
+ from typing import Dict, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class MaxCut(UseCase):
9
+ """
10
+ # Maximum Cut
11
+
12
+ Description
13
+ -----------
14
+
15
+ The Maximum Cut problem tries to find a cut that maximizes the number of
16
+ intersecting edges in an undirected graph.
17
+
18
+ Q-Bit Interpretation
19
+ --------------------
20
+ A cut defines two sets of nodes, 0 and 1.
21
+ The qubits x = (x_0, x_1, ..., x_n) can be interpreted like this:
22
+ x_i = 0 iff. node i belongs to set 0 and x_i = 1 iff. it belongs to set 1.
23
+
24
+ Math
25
+ ----
26
+
27
+ ![Formula](https://drive.google.com/uc?id=1D41KIt4S6gVkdOefWkwGDWLoIiTyexai)
28
+
29
+ Links
30
+ -----
31
+
32
+ [Wikipedia](https://en.wikipedia.org/wiki/Maximum_cut)
33
+
34
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
35
+
36
+ Attributes
37
+ ----------
38
+
39
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
40
+ \n Problem graph for the maximum cut problem in form of nested dictionaries.
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
+
46
+ name: Literal["MC"] = "MC"
47
+ graph: Dict[str, Dict[str, Dict[str, float]]] = Field(name="graph") # type: ignore
@@ -0,0 +1,36 @@
1
+ from typing import Dict, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class MaxIndependentSet(UseCase):
9
+ """
10
+ # Maximum Independent Set
11
+
12
+ Description
13
+ -----------
14
+
15
+ An independent set of a graph _G_ is a set of vertices of _G_, where every two
16
+ vertices are not connected by an edge in _G_. The Maximum Independent Set problem
17
+ tries to find the largest independent set of a graph.
18
+
19
+ Links
20
+ -----
21
+
22
+ [Description and Transformation](https://arxiv.org/pdf/1801.08653.pdf)
23
+
24
+ Attributes
25
+ ----------
26
+
27
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
28
+ \n Problem graph for the maximum independent set problem in form of nested
29
+ dictionaries.
30
+ \n (e.g. fully connected graph with 3 nodes:
31
+ \n _{0: {1: {}, 2: {}}, 1: {0: {}, 2: {}}, 2: {0: {}, 1: {}}}_
32
+ \n or _networkx.to_dict_of_dicts(networkx.complete_graph(3))_ )
33
+ """
34
+
35
+ name: Literal["MIS"] = "MIS"
36
+ graph: Dict[int, Dict[int, Dict[str, float]]] = Field(name="graph") # type: ignore
@@ -0,0 +1,53 @@
1
+ from typing import Dict, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class MinimalMaximalMatching(UseCase):
9
+ """
10
+ # Minimal Maximal Matching
11
+
12
+ Description
13
+ -----------
14
+
15
+ For a graph _G = (V, E)_, the Minimal Maximal Matching problem tries to find a
16
+ "coloring" _C ⊆ E_ with the following three constraints:
17
+ \n 1. For each edge in _C_, the incident vertices shall be colored and the union of
18
+ all these vertices shall be called _D_.
19
+ \n 2. No two edges in _C_ share a vertex.
20
+ \n 3. If _u, v ∈ D_, then _(uv) ∉ E_.\n
21
+
22
+ Links
23
+ -----
24
+
25
+ [Description and Transformation](https://arxiv.org/pdf/1302.5843.pdf)
26
+
27
+ Attributes
28
+ ----------
29
+
30
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
31
+ \n Problem graph for the minimal maximal matching problem in form of nested
32
+ dictionaries.
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
+ ### A: int
38
+ \n A positive constant enforcing that no vertex has two colored edges.
39
+
40
+ ### B: int
41
+ \n A constant to penalize when an edge is uncolored although it would not
42
+ violate the coloring condition. For _d_ being the maximal degree in the graph,
43
+ choose _A > (d - 2)B_.
44
+
45
+ ### C: int
46
+ \n A constant (C < B) to minimize the number of colored edges.
47
+ """
48
+
49
+ name: Literal["MMM"] = "MMM"
50
+ graph: Dict[str, Dict[str, Dict[str, float]]] = Field(name="graph") # type: ignore
51
+ A: int = 10
52
+ B: int = 2
53
+ C: int = 1
@@ -0,0 +1,87 @@
1
+ from typing import Literal, Optional
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+ from luna_sdk.schemas.use_cases.type_aliases import NestedDictGraph
7
+
8
+
9
+ class MinimalSpanningTree(UseCase):
10
+ """
11
+ # Minimal Spanning Tree with maximal degree constraint
12
+
13
+ Description
14
+ -----------
15
+
16
+ The Minimal Spanning Tree problem tries to find a spanning tree over all nodes in a
17
+ given input graph such that the cost of the covered edges (the sum of the weights
18
+ inside the tree) is minimal. The addition maximal degree constraint, i.e. limiting
19
+ the degree of the tree at each node to a maximum value, makes this problem NP-hard.
20
+
21
+ Convention on depth index of vertex and edge:
22
+ Zero index is vertex root and all the edges leaving from root, etc.
23
+ That means there are N/2 possible depths for edges and N/2 + 1 possible depths for
24
+ vertices.
25
+
26
+ Q-Bit Interpretation
27
+ --------------------
28
+
29
+ Assume we have a graph with _m_ nodes, _n_ edges, a max degree of _k_, and the qubit
30
+ vector _q_.
31
+ Then, for _i = 0, ..., n-1_, _q[i] = 1_ iff. edge _i_ is included in the tree.
32
+ Variables _n, ..., n + ⌈ m / 2 ⌉_ keep track of the depth of a node in the tree.
33
+ Now, let _a := n + ⌈ m / 2 ⌉_. Variables _a, ..., a + 2 * n_ tell for each edge in
34
+ the graph which vertex is closer to the root of the tree.
35
+ Finally, with _b := a * 2 * n_, the variables
36
+ _b, ..., b + m * ⌊ log2(maxDegree) + 1 ⌋_ count the degree of a node in the tree.
37
+
38
+ Links
39
+ -----
40
+
41
+ [Wikipedia](https://en.wikipedia.org/wiki/Degree-constrained_spanning_tree),
42
+ [Without degree constraint](https://en.wikipedia.org/wiki/Minimum_spanning_tree)
43
+
44
+ [Transformation](https://arxiv.org/abs/1302.5843)
45
+
46
+ Attributes
47
+ ----------
48
+
49
+ ### graph: Dict[int, Dict[int, Dict[str, float]]
50
+ \n Problem graph for the minimal spanning tree problem in form of nested
51
+ dictionaries. Each vertex needs to be weighted.
52
+ \n (e.g. Wikipedia example
53
+ \n _{
54
+ 0: {1: {"weight": 1}, 3: {"weight": 4}, 4: {"weight": 3}},
55
+ 1: {3: {"weight": 4}, 4: {"weight": 2}},
56
+ 2: {4: {"weight": 4}, 5: {"weight": 5}},
57
+ 3: {4: {"weight": 4}},
58
+ 4: {5: {"weight": 7}}
59
+ }_ )
60
+
61
+ ### max_degree : int
62
+ \n The maximum degree at one joint of the tree. (e.g. 2 is a special case of the
63
+ travelling salesman problem).
64
+
65
+ ### A : Optional[float] = None.
66
+ \n The penalty factor for constraints. Can be left _None_ to be estimated from
67
+ the problem graph via the papers suggestion.
68
+ \n Default: _None_
69
+
70
+ ### B : Optional[float] = 1.
71
+ \n The optimization penalty factor.
72
+ \n Deafult: _1_
73
+
74
+ ### ba_ratio : Optional[float] = 0.1
75
+ \n A factor that increases or decreases the ratio between constraint and
76
+ optimization penalty factors in the automatic estimation. If constraints are
77
+ violated, this ratio needs to be decreased as the _A_ penalty needs to be
78
+ increased. _0.1_ is a good starting point.
79
+ \n Default: _0.1_
80
+ """
81
+
82
+ name: Literal["MST"] = "MST"
83
+ graph: NestedDictGraph = Field(name="graph") # type: ignore
84
+ max_degree: int
85
+ A: Optional[float] = None
86
+ B: Optional[float] = 1.0
87
+ ba_ratio: Optional[float] = 0.1
@@ -0,0 +1,44 @@
1
+ from typing import Dict, Literal
2
+
3
+ from pydantic import Field
4
+
5
+ from luna_sdk.schemas.use_cases.base import UseCase
6
+
7
+
8
+ class MinimumVertexCover(UseCase):
9
+ """
10
+ # Minimum Vertex Cover
11
+
12
+ Description
13
+ -----------
14
+
15
+ A vertex cover of an undirected graph is a set of vertices that includes at least
16
+ one endpoint of every edge of this graph. The Minimum Vertex Cover problem tries to
17
+ find the smallest vertex cover in a given graph. The smallest vertex cover is the
18
+ one that contains the least amount of nodes.
19
+
20
+ Links
21
+ -----
22
+
23
+ [Wikipedia](https://en.wikipedia.org/wiki/Vertex_cover)
24
+
25
+ [Transformation](https://arxiv.org/pdf/1811.11538.pdf)
26
+
27
+ Attributes
28
+ ----------
29
+
30
+ ### graph: Dict[int, Dict[int, Dict[str, float]]]
31
+ \n Problem graph for the minimum vertex cover problem in form of nested
32
+ dictionaries.
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
+ ### P: int
38
+ \n Positive, scalar penalty value to penalize edges that are not covered.
39
+ \n Default: _8_
40
+ """
41
+
42
+ name: Literal["MVC"] = "MVC"
43
+ graph: Dict[str, Dict[str, Dict[str, float]]] = Field(name="graph") # type: ignore
44
+ P: int = 8