eqc-models 0.10.0__py3-none-any.whl → 0.10.3__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.
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/__init__.py +2 -1
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/algorithms/penaltymultiplier.py +20 -7
- eqc_models-0.10.3.data/platlib/eqc_models/assignment/setpartition.py +4 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/base.py +44 -4
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/polyeval.c +163 -163
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/polyeval.cpython-310-darwin.so +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/polynomial.py +7 -3
- eqc_models-0.10.3.data/platlib/eqc_models/combinatorics/__init__.py +6 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/combinatorics/setcover.py +35 -17
- {eqc_models-0.10.0.data/platlib/eqc_models/assignment → eqc_models-0.10.3.data/platlib/eqc_models/combinatorics}/setpartition.py +2 -0
- eqc_models-0.10.3.data/platlib/eqc_models/graph/__init__.py +6 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/graph/maxkcut.py +26 -68
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/solvers/qciclient.py +11 -2
- {eqc_models-0.10.0.dist-info → eqc_models-0.10.3.dist-info}/METADATA +3 -2
- eqc_models-0.10.3.dist-info/RECORD +59 -0
- {eqc_models-0.10.0.dist-info → eqc_models-0.10.3.dist-info}/WHEEL +1 -1
- eqc_models-0.10.0.data/platlib/eqc_models/base.py +0 -115
- eqc_models-0.10.0.data/platlib/eqc_models/communitydetection.py +0 -25
- eqc_models-0.10.0.data/platlib/eqc_models/eqcdirectsolver.py +0 -61
- eqc_models-0.10.0.data/platlib/eqc_models/graph/__init__.py +0 -5
- eqc_models-0.10.0.data/platlib/eqc_models/graphs.py +0 -28
- eqc_models-0.10.0.data/platlib/eqc_models/maxcut.py +0 -113
- eqc_models-0.10.0.data/platlib/eqc_models/maxkcut.py +0 -185
- eqc_models-0.10.0.data/platlib/eqc_models/quadraticmodel.py +0 -131
- eqc_models-0.10.0.data/platlib/eqc_models/solvers/eqcdirect.py +0 -160
- eqc_models-0.10.0.dist-info/RECORD +0 -65
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/compile_extensions.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/algorithms/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/algorithms/base.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/allocation/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/allocation/allocation.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/allocation/portbase.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/allocation/portmomentum.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/assignment/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/assignment/qap.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/constraints.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/operators.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/polyeval.pyx +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/base/quadratic.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/decoding.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/graph/base.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/graph/hypergraph.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/graph/maxcut.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/graph/partition.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/classifierbase.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/classifierqboost.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/classifierqsvm.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/clustering.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/clusteringbase.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/cvqboost_hamiltonian.pyx +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/cvqboost_hamiltonian_c_func.c +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/cvqboost_hamiltonian_c_func.h +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/decomposition.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/forecast.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/forecastbase.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/regressor.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/regressorbase.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/ml/reservoir.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/sequence/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/sequence/tsp.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/solvers/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/utilities/__init__.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/utilities/fileio.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/utilities/polynomial.py +0 -0
- {eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/utilities/qplib.py +0 -0
- {eqc_models-0.10.0.dist-info → eqc_models-0.10.3.dist-info/licenses}/LICENSE.txt +0 -0
- {eqc_models-0.10.0.dist-info → eqc_models-0.10.3.dist-info}/top_level.txt +0 -0
|
@@ -8,8 +8,9 @@ from .base import QuadraticModel, PolynomialModel
|
|
|
8
8
|
from .solvers import (Dirac1CloudSolver, Dirac3CloudSolver, Dirac3DirectSolver)
|
|
9
9
|
from .allocation import AllocationModel, AllocationModelX, ResourceRuleEnum
|
|
10
10
|
from .assignment import QAPModel
|
|
11
|
+
from .combinatorics import SetCoverModel, SetPartitionModel
|
|
11
12
|
|
|
12
13
|
__all__ = ["QuadraticModel", "PolynomialModel", "Dirac1CloudSolver",
|
|
13
14
|
"Dirac3CloudSolver", "AllocationModel", "AllocationModelX",
|
|
14
15
|
"Dirac3DirectSolver", "ResourceRuleEnum",
|
|
15
|
-
"QAPModel"]
|
|
16
|
+
"QAPModel", "SetPartitionModel", "SetCoverModel"]
|
{eqc_models-0.10.0.data → eqc_models-0.10.3.data}/platlib/eqc_models/algorithms/penaltymultiplier.py
RENAMED
|
@@ -33,6 +33,14 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
33
33
|
penalties : List
|
|
34
34
|
The values for penalties found at each algorithm iteration. A penalty of 0
|
|
35
35
|
indicates algorithm termination.
|
|
36
|
+
penalty_threshold : float
|
|
37
|
+
This value is the cutoff for penalty values that are threated as 0. Default
|
|
38
|
+
is 1e-6.
|
|
39
|
+
progress_threshold : float
|
|
40
|
+
This value is the cutoff for checking for progress on reducing the penalty
|
|
41
|
+
value. The current penalty is compared to the average of the previous two
|
|
42
|
+
and if the absolute difference is less than this value, then the algorithm
|
|
43
|
+
stops, reporting progress has not been made. The default value is 1e-4.
|
|
36
44
|
dynamic_range : List
|
|
37
45
|
The values for the dynamic range of the unconstrained problem formulation,
|
|
38
46
|
which is useful for identifying difficulty in representation of the problem
|
|
@@ -50,7 +58,7 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
50
58
|
This example uses the quadratic assignment problem and the known multiplier to test
|
|
51
59
|
the implementation of the algorithm.
|
|
52
60
|
|
|
53
|
-
>>> from eqc_models.solvers.qciclient import
|
|
61
|
+
>>> from eqc_models.solvers.qciclient import Dirac3IntegerCloudSolver
|
|
54
62
|
>>> from eqc_models.assignment.qap import QAPModel
|
|
55
63
|
>>> A = np.array([[0, 5, 8, 0, 1],
|
|
56
64
|
... [0, 0, 0, 10, 15],
|
|
@@ -68,10 +76,10 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
68
76
|
... [7, 5, 8, 5, 7],
|
|
69
77
|
... [1, 9, 2, 9, 2.]])
|
|
70
78
|
>>> model = QAPModel(A, B, C)
|
|
71
|
-
>>> solver =
|
|
79
|
+
>>> solver = Dirac3IntegerCloudSolver() # must be configured with environment variables
|
|
72
80
|
>>> algo = PenaltyMultiplierAlgorithm(model, solver)
|
|
73
81
|
>>> algo.upper_bound = 330.64
|
|
74
|
-
>>> algo.run(relaxation_schedule=2,
|
|
82
|
+
>>> algo.run(relaxation_schedule=2, num_samples=5) # doctest: +ELLIPSIS
|
|
75
83
|
2... RUNNING... COMPLETED...
|
|
76
84
|
>>> algo.alphas[-1] # doctest: +SKIP
|
|
77
85
|
106.25
|
|
@@ -80,7 +88,8 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
80
88
|
|
|
81
89
|
"""
|
|
82
90
|
|
|
83
|
-
def __init__(self, model : ConstraintModel, solver : ModelSolver
|
|
91
|
+
def __init__(self, model : ConstraintModel, solver : ModelSolver, penalty_threshold:float=1e-6,
|
|
92
|
+
progress_threshold : float = 1e-4):
|
|
84
93
|
self.model = model
|
|
85
94
|
self.solver = solver
|
|
86
95
|
# ub = np.max(model.quad_objective)
|
|
@@ -95,6 +104,8 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
95
104
|
self.alphas = None
|
|
96
105
|
self.dynamic_range = None
|
|
97
106
|
self.responses = None
|
|
107
|
+
self.penalty_threshold = penalty_threshold
|
|
108
|
+
self.progress_threshold = progress_threshold
|
|
98
109
|
|
|
99
110
|
@property
|
|
100
111
|
def upper_bound(self) -> float:
|
|
@@ -141,7 +152,7 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
141
152
|
else:
|
|
142
153
|
penalty = None
|
|
143
154
|
|
|
144
|
-
while penalty is None or penalty >
|
|
155
|
+
while penalty is None or penalty > self.penalty_threshold:
|
|
145
156
|
log.info("NEW RUN")
|
|
146
157
|
log.info("SETTING MULTIPLIER %f", alpha)
|
|
147
158
|
model.penalty_multiplier = float(alpha)
|
|
@@ -162,8 +173,10 @@ class PenaltyMultiplierAlgorithm(Algorithm):
|
|
|
162
173
|
energies.append(results["energies"][0])
|
|
163
174
|
log.info("NEW SOLUTION OBJECTIVE %f LESS OFFSET %f ENERGY %f PENALTY %f",
|
|
164
175
|
obj_val, less_offset, energies[-1], penalty)
|
|
165
|
-
if
|
|
176
|
+
if penalty < self.penalty_threshold:
|
|
177
|
+
pass
|
|
178
|
+
elif obj_val < ub:
|
|
166
179
|
alpha += (ub - obj_val) / penalty
|
|
167
|
-
if abs(sum(penalties[-2:])/2-penalty) <
|
|
180
|
+
if penalty > self.penalty_threshold and abs(sum(penalties[-2:])/2-penalty) < self.progress_threshold:
|
|
168
181
|
log.warn("SUFFICIENT PROGRESS NOT MADE FOR THREE ITERATIONS, QUITTING")
|
|
169
182
|
break
|
|
@@ -42,12 +42,50 @@ class EqcModel:
|
|
|
42
42
|
_H = None
|
|
43
43
|
_machine_slacks = 0
|
|
44
44
|
|
|
45
|
-
def decode(self, solution : np.ndarray) -> np.ndarray:
|
|
46
|
-
"""
|
|
45
|
+
def decode(self, solution : np.ndarray, from_encoding : str=None) -> np.ndarray:
|
|
46
|
+
"""
|
|
47
|
+
Manipulate the solution to match the variable count. Optionally,
|
|
48
|
+
a log-encoded solution vector can be translated into a vector
|
|
49
|
+
with integral values.
|
|
50
|
+
|
|
51
|
+
Parameters
|
|
52
|
+
-----------
|
|
53
|
+
|
|
54
|
+
solution : np.ndarray
|
|
55
|
+
1d solution vector
|
|
56
|
+
|
|
57
|
+
from_encoding : str
|
|
58
|
+
string indicating if the vector is an encoding of particular type. The
|
|
59
|
+
text 'qubo' is the only option that does anything for now.
|
|
60
|
+
|
|
61
|
+
>>> model = EqcModel()
|
|
62
|
+
>>> ub = np.array([1, 2, 5])
|
|
63
|
+
>>> model.upper_bound = ub
|
|
64
|
+
>>> model.machine_slacks = 1
|
|
65
|
+
>>> solution = np.array([1, 1, 1, 1, 0, 1, 0]) # this solution has a 3, which violates the upper bound, but decode doesn't care
|
|
66
|
+
>>> model.decode(solution, "qubo")
|
|
67
|
+
array([1, 3, 5])
|
|
68
|
+
|
|
69
|
+
"""
|
|
47
70
|
|
|
71
|
+
solution = np.array(solution)
|
|
48
72
|
# ignore any slacks that may have been added during encoding
|
|
49
|
-
|
|
50
|
-
|
|
73
|
+
if self.machine_slacks > 0:
|
|
74
|
+
solution = solution[:-self.machine_slacks]
|
|
75
|
+
if from_encoding == "qubo":
|
|
76
|
+
ub = self.upper_bound
|
|
77
|
+
en = solution.shape[0]
|
|
78
|
+
assert en > 0
|
|
79
|
+
n = ub.shape[0]
|
|
80
|
+
linear_operator = np.zeros((n,en))
|
|
81
|
+
j = 0
|
|
82
|
+
for i in range(self.n):
|
|
83
|
+
m = int(np.floor(np.log2(ub[i]))+1)
|
|
84
|
+
bits = 2**np.arange(m)
|
|
85
|
+
assert j+m <= linear_operator.shape[1]+2, f"Invalid slice for i={i} {j}:{j+m}"
|
|
86
|
+
linear_operator[i,j:j+m] = bits
|
|
87
|
+
j += m
|
|
88
|
+
solution = (linear_operator@solution).astype(np.int64)
|
|
51
89
|
return solution
|
|
52
90
|
|
|
53
91
|
@property
|
|
@@ -64,6 +102,8 @@ class EqcModel:
|
|
|
64
102
|
value = np.array(value)
|
|
65
103
|
if (value != value.astype(np.int64)).any():
|
|
66
104
|
raise ValueError("Upper bound values must be integer")
|
|
105
|
+
if (value==0).any():
|
|
106
|
+
raise ValueError("Zero values are not allowed as an upper_bound.")
|
|
67
107
|
self._upper_bound = value.astype(np.int64)
|
|
68
108
|
|
|
69
109
|
@property
|