eqc-models 0.9.9__py3-none-any.whl → 0.10.0__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/platlib/compile_extensions.py +67 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/polyeval.c +127 -123
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/polyeval.cpython-310-darwin.so +0 -0
- eqc_models-0.10.0.data/platlib/eqc_models/base.py +115 -0
- eqc_models-0.10.0.data/platlib/eqc_models/combinatorics/setcover.py +93 -0
- eqc_models-0.10.0.data/platlib/eqc_models/communitydetection.py +25 -0
- eqc_models-0.10.0.data/platlib/eqc_models/eqcdirectsolver.py +61 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/graph/base.py +28 -17
- eqc_models-0.10.0.data/platlib/eqc_models/graph/partition.py +148 -0
- eqc_models-0.10.0.data/platlib/eqc_models/graphs.py +28 -0
- eqc_models-0.10.0.data/platlib/eqc_models/maxcut.py +113 -0
- eqc_models-0.10.0.data/platlib/eqc_models/maxkcut.py +185 -0
- eqc_models-0.10.0.data/platlib/eqc_models/ml/classifierqboost.py +628 -0
- eqc_models-0.10.0.data/platlib/eqc_models/ml/cvqboost_hamiltonian.pyx +83 -0
- eqc_models-0.10.0.data/platlib/eqc_models/ml/cvqboost_hamiltonian_c_func.c +68 -0
- eqc_models-0.10.0.data/platlib/eqc_models/ml/cvqboost_hamiltonian_c_func.h +14 -0
- eqc_models-0.10.0.data/platlib/eqc_models/quadraticmodel.py +131 -0
- eqc_models-0.10.0.data/platlib/eqc_models/solvers/eqcdirect.py +160 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/utilities/polynomial.py +11 -0
- {eqc_models-0.9.9.dist-info → eqc_models-0.10.0.dist-info}/METADATA +2 -1
- eqc_models-0.10.0.dist-info/RECORD +65 -0
- eqc_models-0.9.9.data/platlib/compile_extensions.py +0 -23
- eqc_models-0.9.9.data/platlib/eqc_models/ml/classifierqboost.py +0 -423
- eqc_models-0.9.9.dist-info/RECORD +0 -52
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/algorithms/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/algorithms/base.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/algorithms/penaltymultiplier.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/allocation/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/allocation/allocation.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/allocation/portbase.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/allocation/portmomentum.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/assignment/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/assignment/qap.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/assignment/setpartition.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/base.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/constraints.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/operators.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/polyeval.pyx +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/polynomial.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/base/quadratic.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/decoding.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/graph/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/graph/hypergraph.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/graph/maxcut.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/graph/maxkcut.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/classifierbase.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/classifierqsvm.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/clustering.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/clusteringbase.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/decomposition.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/forecast.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/forecastbase.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/regressor.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/regressorbase.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/ml/reservoir.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/sequence/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/sequence/tsp.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/solvers/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/solvers/qciclient.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/utilities/__init__.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/utilities/fileio.py +0 -0
- {eqc_models-0.9.9.data → eqc_models-0.10.0.data}/platlib/eqc_models/utilities/qplib.py +0 -0
- {eqc_models-0.9.9.dist-info → eqc_models-0.10.0.dist-info}/LICENSE.txt +0 -0
- {eqc_models-0.9.9.dist-info → eqc_models-0.10.0.dist-info}/WHEEL +0 -0
- {eqc_models-0.9.9.dist-info → eqc_models-0.10.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#include <stdlib.h>
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
#include <string.h>
|
|
4
|
+
#include <omp.h>
|
|
5
|
+
#include "cvqboost_hamiltonian_c_func.h"
|
|
6
|
+
|
|
7
|
+
void get_hamiltonian_c(
|
|
8
|
+
float **J,
|
|
9
|
+
float *C,
|
|
10
|
+
float **h_vals,
|
|
11
|
+
float *y,
|
|
12
|
+
float lambda_coef,
|
|
13
|
+
int n_records,
|
|
14
|
+
int n_classifiers
|
|
15
|
+
) {
|
|
16
|
+
float tmp_i, tmp_j;
|
|
17
|
+
|
|
18
|
+
// omp_set_num_threads(8);
|
|
19
|
+
|
|
20
|
+
/*
|
|
21
|
+
#pragma omp parallel
|
|
22
|
+
{
|
|
23
|
+
#pragma omp single
|
|
24
|
+
printf("Number of threads: %d\n", omp_get_num_threads());
|
|
25
|
+
}
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
double start = omp_get_wtime();
|
|
29
|
+
// Compute J matrix
|
|
30
|
+
//#pragma omp parallel for collapse(2) //schedule(static,10)
|
|
31
|
+
for (int i = 0; i < n_classifiers; i++) {
|
|
32
|
+
for (int j = 0; j < n_classifiers; j++) {
|
|
33
|
+
J[i][j] = 0.0f;
|
|
34
|
+
|
|
35
|
+
// Parallelized innermost loop
|
|
36
|
+
#pragma omp parallel for reduction(+:J[i][j]) schedule(dynamic, 10000)
|
|
37
|
+
for (int k = 0; k < n_records; k++) {
|
|
38
|
+
tmp_i = h_vals[i][k];
|
|
39
|
+
tmp_j = h_vals[j][k];
|
|
40
|
+
J[i][j] += tmp_i * tmp_j;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
double end = omp_get_wtime();
|
|
45
|
+
printf("Time J loop: %f seconds\n", end - start);
|
|
46
|
+
|
|
47
|
+
// Compute C vector
|
|
48
|
+
start = omp_get_wtime();
|
|
49
|
+
//#pragma omp parallel for schedule(static,10)
|
|
50
|
+
for (int i = 0; i < n_classifiers; i++) {
|
|
51
|
+
C[i] = 0.0f;
|
|
52
|
+
|
|
53
|
+
// Parallelized innermost loop
|
|
54
|
+
#pragma omp parallel for reduction(+:C[i]) schedule(dynamic, 10000)
|
|
55
|
+
for (int m = 0; m < n_records; m++) {
|
|
56
|
+
tmp_i = -2.0f * y[m] * h_vals[i][m];
|
|
57
|
+
C[i] += tmp_i;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
end = omp_get_wtime();
|
|
61
|
+
printf("Time C loop: %f seconds\n", end - start);
|
|
62
|
+
|
|
63
|
+
// Add lambda_coef to the diagonal of J
|
|
64
|
+
//#pragma omp parallel for schedule(static)
|
|
65
|
+
for (int i = 0; i < n_classifiers; i++) {
|
|
66
|
+
J[i][i] += lambda_coef;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#ifndef CVQBOOST_HAMILTONIAN_C_FUNC_H
|
|
2
|
+
#define CVQBOOST_HAMILTONIAN_C_FUNC_H
|
|
3
|
+
|
|
4
|
+
void get_hamiltonian_c(
|
|
5
|
+
float **J,
|
|
6
|
+
float *C,
|
|
7
|
+
float **h_vals,
|
|
8
|
+
float *y,
|
|
9
|
+
float lambda_coef,
|
|
10
|
+
int n_records,
|
|
11
|
+
int n_classifiers
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
#endif // CVQBOOST_HAMILTONIAN_C_FUNC_H
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
from typing import Tuple
|
|
2
|
+
import numpy as np
|
|
3
|
+
from .base import EqcModel
|
|
4
|
+
|
|
5
|
+
class QuadraticMixIn:
|
|
6
|
+
C = None
|
|
7
|
+
J = None
|
|
8
|
+
|
|
9
|
+
def encode(self, levels:int=200, norm_value:float=None, dtype=np.float32) -> np.ndarray:
|
|
10
|
+
"""
|
|
11
|
+
Encode Hamiltonian into the domain of the device
|
|
12
|
+
|
|
13
|
+
The encoding method can be tuned using levels or norm_value. The parameter
|
|
14
|
+
levels and the member self.domains are used to generate a vector t such that
|
|
15
|
+
$$
|
|
16
|
+
x = ts
|
|
17
|
+
$$
|
|
18
|
+
thus,
|
|
19
|
+
$$
|
|
20
|
+
h^Tx + x^TJx = h^T(ts) + (ts)^TJ(ts) = (th)^Ts + s^T(t\\cross tJ)s
|
|
21
|
+
$$
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
n = max(self.domains.shape)
|
|
26
|
+
J = self.J
|
|
27
|
+
C = self.C
|
|
28
|
+
if norm_value is None:
|
|
29
|
+
max_level = levels - 1
|
|
30
|
+
multipliers = (self.domains) / max_level
|
|
31
|
+
J = np.array(np.outer(multipliers, multipliers) * J)
|
|
32
|
+
# h = np.multiply(h[:,0], multipliers)
|
|
33
|
+
C *= multipliers
|
|
34
|
+
C = C.reshape((n, 1))
|
|
35
|
+
else:
|
|
36
|
+
# normalize the operator
|
|
37
|
+
max_val_J = np.max(np.abs(J))
|
|
38
|
+
max_val_C = np.max(np.abs(C))
|
|
39
|
+
if max_val_J > max_val_C:
|
|
40
|
+
max_val = max_val_J
|
|
41
|
+
else:
|
|
42
|
+
max_val = max_val_C
|
|
43
|
+
C /= max_val
|
|
44
|
+
C *= norm_value
|
|
45
|
+
J /= max_val
|
|
46
|
+
J *= norm_value
|
|
47
|
+
# make J symmetric
|
|
48
|
+
J += J.T
|
|
49
|
+
J /= 2
|
|
50
|
+
# return operator in hJ format
|
|
51
|
+
H = np.hstack([C, J]).astype(dtype)
|
|
52
|
+
|
|
53
|
+
if self.machine_slacks > 0:
|
|
54
|
+
machine_slacks = self.machine_slacks
|
|
55
|
+
n = H.shape[0]
|
|
56
|
+
Hslack = np.zeros((n+machine_slacks, n+machine_slacks+1), dtype=dtype)
|
|
57
|
+
Hslack[:n, :n+1] = H
|
|
58
|
+
H = Hslack
|
|
59
|
+
|
|
60
|
+
return np.array(H)
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def sparse(self) -> Tuple[np.ndarray, np.ndarray]:
|
|
64
|
+
""" Put the linear and quadratic terms in a sparse format
|
|
65
|
+
|
|
66
|
+
:returns: coefficients : List, indices : List
|
|
67
|
+
"""
|
|
68
|
+
C, J = self.H
|
|
69
|
+
n = self.n
|
|
70
|
+
indices = []
|
|
71
|
+
coefficients = []
|
|
72
|
+
# build a key (ordered tuple of indices) of length 2 for each element
|
|
73
|
+
for i in range(n):
|
|
74
|
+
if C[i,0] != 0:
|
|
75
|
+
key = (0, i+1)
|
|
76
|
+
indices.append(key)
|
|
77
|
+
coefficients.append(C[i,0])
|
|
78
|
+
# make J upper triangular
|
|
79
|
+
J = np.triu(J) + np.tril(J, -1).T
|
|
80
|
+
for i in range(n):
|
|
81
|
+
for j in range(i, n):
|
|
82
|
+
val = J[i, j]
|
|
83
|
+
if val != 0:
|
|
84
|
+
key = (i+1, j+1)
|
|
85
|
+
indices.append(key)
|
|
86
|
+
coefficients.append(val)
|
|
87
|
+
return np.array(coefficients, dtype=np.float32), np.array(indices, dtype=np.int32)
|
|
88
|
+
|
|
89
|
+
def evaluate(self, solution: np.ndarray, decode:bool=False, levels:int=200) -> float:
|
|
90
|
+
"""
|
|
91
|
+
Evaluate the solution using the original operator. The decode
|
|
92
|
+
and levels parameters control the decoding of the solution. Without
|
|
93
|
+
specifying decode, the evaluation of the operator is done with the
|
|
94
|
+
solution provided.
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
H = self.H
|
|
98
|
+
h, J = H[:, 0], H[:, 1:]
|
|
99
|
+
if decode:
|
|
100
|
+
sol = self.decode(solution)
|
|
101
|
+
else:
|
|
102
|
+
sol = solution
|
|
103
|
+
return np.squeeze(sol.T@J@sol + h.T@sol)
|
|
104
|
+
|
|
105
|
+
class QuadraticModel(QuadraticMixIn, EqcModel):
|
|
106
|
+
""" Provides a quadratic operator and device sum constraint support """
|
|
107
|
+
|
|
108
|
+
def __init__(self, C : np.ndarray, J : np.ndarray, sum_constraint : float):
|
|
109
|
+
self._C = C
|
|
110
|
+
self._J = J
|
|
111
|
+
self._sum_constraint = sum_constraint
|
|
112
|
+
|
|
113
|
+
@property
|
|
114
|
+
def H(self):
|
|
115
|
+
return self._C, self._J
|
|
116
|
+
|
|
117
|
+
def check_constraint(self, solution: np.array) -> bool:
|
|
118
|
+
""" Evaluate the solution against the original sum constraint """
|
|
119
|
+
return np.sum(solution) == self.sum_constraint
|
|
120
|
+
|
|
121
|
+
@property
|
|
122
|
+
def sum_constraint(self) -> int:
|
|
123
|
+
""" Integer value which all qudits must sum to.
|
|
124
|
+
The value must be less than or equal to n * base for
|
|
125
|
+
the model to make sense. """
|
|
126
|
+
|
|
127
|
+
return self._sum_constraint
|
|
128
|
+
|
|
129
|
+
@sum_constraint.setter
|
|
130
|
+
def sum_constraint(self, value : int):
|
|
131
|
+
self._sum_constraint = value
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# (C) Quantum Computing Inc., 2024.
|
|
2
|
+
from typing import Dict
|
|
3
|
+
import logging
|
|
4
|
+
import numpy as np
|
|
5
|
+
from eqc_direct.client import EqcClient
|
|
6
|
+
from eqc_models.base.base import ModelSolver, EqcModel
|
|
7
|
+
|
|
8
|
+
log = logging.getLogger(name=__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class EqcDirectMixin:
|
|
12
|
+
"""
|
|
13
|
+
This class provides an instance method and property that
|
|
14
|
+
manage the direct connection to a QCi device.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
ip_addr = None
|
|
19
|
+
port = None
|
|
20
|
+
|
|
21
|
+
def connect(self, ip_addr: str, port: str) -> str:
|
|
22
|
+
"""
|
|
23
|
+
Explicitly set device address; if environment is
|
|
24
|
+
configured with the connection, this call is not required.
|
|
25
|
+
|
|
26
|
+
Parameters
|
|
27
|
+
------------
|
|
28
|
+
|
|
29
|
+
ip_addr: The IP address of the device.
|
|
30
|
+
|
|
31
|
+
port: The port number of the device.
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
------------
|
|
35
|
+
The status.
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
self.ip_addr = ip_addr
|
|
39
|
+
self.port = port
|
|
40
|
+
client = self.client
|
|
41
|
+
return client.system_status()["status_desc"]
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def client(self):
|
|
45
|
+
params = {}
|
|
46
|
+
if self.ip_addr is not None:
|
|
47
|
+
params["ip_address"] = self.ip_addr
|
|
48
|
+
if self.port is not None:
|
|
49
|
+
params["port"] = self.port
|
|
50
|
+
return EqcClient(**params)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class EqcDirectSolver(ModelSolver, EqcDirectMixin):
|
|
54
|
+
"""
|
|
55
|
+
This class provides an instance method for direct submission
|
|
56
|
+
of jobs to QCi devices.
|
|
57
|
+
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
def solve(
|
|
61
|
+
self,
|
|
62
|
+
model: EqcModel,
|
|
63
|
+
relaxation_schedule: int = 2,
|
|
64
|
+
precision: float = 1.0,
|
|
65
|
+
) -> Dict:
|
|
66
|
+
"""Parameters
|
|
67
|
+
-------------
|
|
68
|
+
model: An EqcModel instance.
|
|
69
|
+
|
|
70
|
+
relaxation_schedule: A predefined schedule indicator which
|
|
71
|
+
sets parameters on the device to control the sampling through
|
|
72
|
+
photon measurement; default is 2.
|
|
73
|
+
|
|
74
|
+
precision: A value which, when not None, indicates
|
|
75
|
+
the numerical precision desired in the solution: 1 for
|
|
76
|
+
integer, 0.1 for tenths place, 0.01 for hundreths and None for
|
|
77
|
+
raw; default is 1.0.
|
|
78
|
+
|
|
79
|
+
Returns
|
|
80
|
+
---------
|
|
81
|
+
Json response from the solver.
|
|
82
|
+
|
|
83
|
+
"""
|
|
84
|
+
poly_coefficients, poly_indices = model.sparse
|
|
85
|
+
# print(poly_indices)
|
|
86
|
+
if model.machine_slacks > 0:
|
|
87
|
+
# add a single 0 coefficient entry as the next-highest index
|
|
88
|
+
highest_idx = int(np.max(poly_indices))
|
|
89
|
+
# print("POLY HIGHEST", highest_idx)
|
|
90
|
+
for i in range(model.machine_slacks):
|
|
91
|
+
addtl_index = [0 for i in range(len(poly_indices[0]))]
|
|
92
|
+
addtl_index[-1] = highest_idx + i + 1
|
|
93
|
+
poly_indices = poly_indices.tolist() + [addtl_index]
|
|
94
|
+
poly_coefficients = poly_coefficients.tolist() + [0]
|
|
95
|
+
# print(poly_indices)
|
|
96
|
+
scval = model.sum_constraint
|
|
97
|
+
|
|
98
|
+
client = self.client
|
|
99
|
+
lock_id, start_ts, end_ts = client.wait_for_lock()
|
|
100
|
+
log.debug(
|
|
101
|
+
"Got device lock id %s. Wait time %f",
|
|
102
|
+
lock_id,
|
|
103
|
+
end_ts - start_ts,
|
|
104
|
+
)
|
|
105
|
+
resp = None
|
|
106
|
+
try:
|
|
107
|
+
log.debug(
|
|
108
|
+
"Calling device with parameters relaxation_schedule %d sum_constraint %s lock_id %s solution_precision %f",
|
|
109
|
+
relaxation_schedule,
|
|
110
|
+
scval,
|
|
111
|
+
lock_id,
|
|
112
|
+
precision,
|
|
113
|
+
)
|
|
114
|
+
resp = client.process_job(
|
|
115
|
+
poly_coefficients=poly_coefficients,
|
|
116
|
+
poly_indices=poly_indices,
|
|
117
|
+
relaxation_schedule=relaxation_schedule,
|
|
118
|
+
sum_constraint=scval,
|
|
119
|
+
lock_id=lock_id,
|
|
120
|
+
solution_precision=precision,
|
|
121
|
+
)
|
|
122
|
+
log.debug("Received response with status %s", resp["err_desc"])
|
|
123
|
+
log.debug(
|
|
124
|
+
"Runtime %f resulting in energy %f",
|
|
125
|
+
resp["runtime"],
|
|
126
|
+
resp["energy"],
|
|
127
|
+
)
|
|
128
|
+
log.debug(
|
|
129
|
+
"Distillation runtime %s resulting in energy %f",
|
|
130
|
+
resp["distilled_runtime"],
|
|
131
|
+
resp["distilled_energy"],
|
|
132
|
+
)
|
|
133
|
+
finally:
|
|
134
|
+
client.release_lock(lock_id=lock_id)
|
|
135
|
+
if resp is not None:
|
|
136
|
+
solution = resp["solution"]
|
|
137
|
+
energy = resp["energy"]
|
|
138
|
+
runtime = resp["runtime"]
|
|
139
|
+
dirac3_sol = np.array(solution)
|
|
140
|
+
log.debug(
|
|
141
|
+
"Energy %f Runtime %f Solution Size %i Solution Sum %f",
|
|
142
|
+
energy,
|
|
143
|
+
runtime,
|
|
144
|
+
len(dirac3_sol),
|
|
145
|
+
sum(dirac3_sol),
|
|
146
|
+
)
|
|
147
|
+
else:
|
|
148
|
+
raise RuntimeError("FAILED TO GET RESPONSE")
|
|
149
|
+
return resp
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
class Dirac3DirectSolver(EqcDirectSolver):
|
|
153
|
+
|
|
154
|
+
"""
|
|
155
|
+
Naming this for when when other devices are available and have
|
|
156
|
+
different requirements. For instance, Dirac-3 requires the
|
|
157
|
+
summation constraint parameter, but others might not. The same
|
|
158
|
+
could be true for relaxation schedule.
|
|
159
|
+
|
|
160
|
+
"""
|
|
@@ -48,22 +48,33 @@ def convert_hamiltonian_to_polynomial(
|
|
|
48
48
|
assert num_vars >= 1, "Invalid number of variables <%d>!" % num_vars
|
|
49
49
|
|
|
50
50
|
if D is not None:
|
|
51
|
+
assert len(D.shape) == 4, "Incorrect shape!"
|
|
51
52
|
assert D.shape[0] == num_vars, "Inconsistent dimensions!"
|
|
52
53
|
assert D.shape[1] == num_vars, "Inconsistent dimensions!"
|
|
53
54
|
assert D.shape[2] == num_vars, "Inconsistent dimensions!"
|
|
54
55
|
assert D.shape[3] == num_vars, "Inconsistent dimensions!"
|
|
55
56
|
poly_order = 4
|
|
56
57
|
elif C is not None:
|
|
58
|
+
assert len(C.shape) == 3, "Incorrect shape!"
|
|
57
59
|
assert C.shape[0] == num_vars, "Inconsistent dimensions!"
|
|
58
60
|
assert C.shape[1] == num_vars, "Inconsistent dimensions!"
|
|
59
61
|
assert C.shape[2] == num_vars, "Inconsistent dimensions!"
|
|
60
62
|
poly_order = 3
|
|
61
63
|
elif B is not None:
|
|
64
|
+
assert len(B.shape) == 2, "Incorrect shape!"
|
|
62
65
|
assert B.shape[0] == num_vars, "Inconsistent dimensions!"
|
|
63
66
|
assert B.shape[1] == num_vars, "Inconsistent dimensions!"
|
|
64
67
|
poly_order = 2
|
|
65
68
|
elif A is not None:
|
|
69
|
+
assert len(A.shape) in [1, 2], "Incorrect shape!"
|
|
70
|
+
if len(A.shape) == 2:
|
|
71
|
+
if A.shape[1] == 1:
|
|
72
|
+
A = A.reshape((A.shape[0]))
|
|
73
|
+
else:
|
|
74
|
+
assert False, "Incorrect shape!"
|
|
75
|
+
|
|
66
76
|
assert A.shape[0] == num_vars, "Inconsistent dimensions!"
|
|
77
|
+
|
|
67
78
|
poly_order = 1
|
|
68
79
|
else:
|
|
69
80
|
assert False, "No hamiltonian provided!"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: eqc-models
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Optimization and ML modeling package targeting EQC devices
|
|
5
5
|
Author: Quantum Computing Inc.
|
|
6
6
|
Author-email: support@quantumcomputinginc.com
|
|
@@ -13,6 +13,7 @@ License-File: LICENSE.txt
|
|
|
13
13
|
Requires-Dist: numpy<2,>=1.22.1
|
|
14
14
|
Requires-Dist: networkx<3,>=2.6.3
|
|
15
15
|
Requires-Dist: pandas>=2.1.0
|
|
16
|
+
Requires-Dist: scikit-learn>=1.2.1
|
|
16
17
|
Requires-Dist: qci-client<5,>=4.3.0
|
|
17
18
|
Requires-Dist: emucore-direct==1.0.6
|
|
18
19
|
Provides-Extra: direct
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
eqc_models-0.10.0.data/platlib/compile_extensions.py,sha256=ivFZ87WFzBITU7IwK_72C41MDNMortJIF8tKevm2aW4,1946
|
|
2
|
+
eqc_models-0.10.0.data/platlib/eqc_models/__init__.py,sha256=njh-tvfgnAIVBGw9FXFv6XQOAgwrnBG23dU9dipa1Jg,585
|
|
3
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base.py,sha256=YWS9kjmh-ZEZqpByDaik4fLjeGbwKLLlqbVMsHto6Bs,3524
|
|
4
|
+
eqc_models-0.10.0.data/platlib/eqc_models/communitydetection.py,sha256=-zqESm8MFDdaw_a39Kg6Wuu5Tvman3JOeUH4bbPXB48,891
|
|
5
|
+
eqc_models-0.10.0.data/platlib/eqc_models/decoding.py,sha256=G3JgbIFzvZ3DIKW0kZ1JeTMIZmrc8hy9kzdbX2Xv5Og,637
|
|
6
|
+
eqc_models-0.10.0.data/platlib/eqc_models/eqcdirectsolver.py,sha256=zoR8VHD9OFEBxKO9GW8sPLtuqVfWMubg4SDFCQKr3fc,2444
|
|
7
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graphs.py,sha256=8gWGwPKhAFoddYFRiJ770CNHrbudy_UVqgsv2BrHVDA,895
|
|
8
|
+
eqc_models-0.10.0.data/platlib/eqc_models/maxcut.py,sha256=ohD08acRcmDhnxRI5MN1wvY6k81xUs8PRpsAzO5kQXI,2899
|
|
9
|
+
eqc_models-0.10.0.data/platlib/eqc_models/maxkcut.py,sha256=fzittwUftQljSqe9yBS042-SXeyj2AmLTDuW8yc0JFw,5812
|
|
10
|
+
eqc_models-0.10.0.data/platlib/eqc_models/quadraticmodel.py,sha256=vhWMNmKxzxaV6kdb9TTI-SqJMUEvKMLHfAOD6BVYBwc,4242
|
|
11
|
+
eqc_models-0.10.0.data/platlib/eqc_models/algorithms/__init__.py,sha256=lzQoMMSs2QTqp5suEYNvcQaSEN16d0LwIsZ1mRstumU,135
|
|
12
|
+
eqc_models-0.10.0.data/platlib/eqc_models/algorithms/base.py,sha256=qfQQTwuVyewn7Qpg1_SVoD_7TsdA8vdwSKGqOeZSmNI,204
|
|
13
|
+
eqc_models-0.10.0.data/platlib/eqc_models/algorithms/penaltymultiplier.py,sha256=gV48irx3q9yvMsCRqv2fa8DGQEOUkgVNGbZdNzI-3Tc,7057
|
|
14
|
+
eqc_models-0.10.0.data/platlib/eqc_models/allocation/__init__.py,sha256=op_udrapTlWrakTuQId3M0ggo-Y1w4nGJLPcYKOQ-8I,239
|
|
15
|
+
eqc_models-0.10.0.data/platlib/eqc_models/allocation/allocation.py,sha256=PAQn4M75Zegeoy0i6r3hycWs4TKeRglHk05TvwZOoLk,15506
|
|
16
|
+
eqc_models-0.10.0.data/platlib/eqc_models/allocation/portbase.py,sha256=BTnYYduHydPbrE2yQr_Sgv3XJACH_GpIJstuMrfGqCU,3269
|
|
17
|
+
eqc_models-0.10.0.data/platlib/eqc_models/allocation/portmomentum.py,sha256=oMod63rNDC-01dLZjmhUb24SN3_GVgfc6CItgQL_obI,3756
|
|
18
|
+
eqc_models-0.10.0.data/platlib/eqc_models/assignment/__init__.py,sha256=CX_QYl8P1meajV8gcVs6hm07VhoLVe8uu436t7-1XQo,86
|
|
19
|
+
eqc_models-0.10.0.data/platlib/eqc_models/assignment/qap.py,sha256=WMiQQmTORsgi2w7kbmMA1xo-93dESLECWqYTF-zkmTs,2963
|
|
20
|
+
eqc_models-0.10.0.data/platlib/eqc_models/assignment/setpartition.py,sha256=-DJjPgsSMslEjfo3iDdXbKHQ9Lfc3cHlNc-9DtkJnW0,6202
|
|
21
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/__init__.py,sha256=RwZguuucmsuOSVqfPLBqj-wzinBOzcgO-2ifFU-DCqg,2885
|
|
22
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/base.py,sha256=kpnOb1dw0aaQyassIYKNlS6rIH1fNvZMI-NKPosAEMk,4856
|
|
23
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/constraints.py,sha256=KMPyCdt_8GMWLnVEdpzw1T1WqXm2f7Lh629ClUH7XDY,8271
|
|
24
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/operators.py,sha256=9nCeN6fRP-_YBfs-Gm57D-O_376qcOQiqGDuVlSlf00,7392
|
|
25
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/polyeval.c,sha256=4Rbo0snmzpBfk3EL1u5NLsYt_vni5wk_4p9XwsszFkg,445633
|
|
26
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/polyeval.cpython-310-darwin.so,sha256=p9WsRiRpK18WJUHT4-x3s2VPr92_-DF5TLLPOuvwl_o,101024
|
|
27
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/polyeval.pyx,sha256=76Bf99Jt1_rLh5byrZxAjavE2F4_yCysirViqOBFIXw,2547
|
|
28
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/polynomial.py,sha256=dlWqL-PgSzV1UX-1S-MDwEL4sp3vs3h0vdRkv4JYfLo,12981
|
|
29
|
+
eqc_models-0.10.0.data/platlib/eqc_models/base/quadratic.py,sha256=BHZKniUvSq30pZgzguVasdO39BCEYue_wi5AIklPGS8,8062
|
|
30
|
+
eqc_models-0.10.0.data/platlib/eqc_models/combinatorics/setcover.py,sha256=v42_pB2gPF2YkVllCqqjw58t97y5AAddfWITIsESZI8,2730
|
|
31
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graph/__init__.py,sha256=Cpo4jb630U57J0lS_iZddE_W3v9N4ijUb7xZRIYuguo,95
|
|
32
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graph/base.py,sha256=j48OwhorZ5jTlTysTmMiXCeiAdj6jylBREk3NxCpFLI,2072
|
|
33
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graph/hypergraph.py,sha256=ABvutT0NOdIEpUF4TjUzboE4Y_J5iUZyj6-AzKr4R28,13268
|
|
34
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graph/maxcut.py,sha256=o8xVsAwTa9jcpmsIoCQ5z7HSstVdraT8TENomdT519o,4132
|
|
35
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graph/maxkcut.py,sha256=OFZwmC3wWpIJWVHOb9wkUeka0g0bOHrwf-mx0VZvt58,5807
|
|
36
|
+
eqc_models-0.10.0.data/platlib/eqc_models/graph/partition.py,sha256=HMpRRipLp14x8pHucY-g6fU7v0PGoy1pf_KpzbanfD0,5800
|
|
37
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/__init__.py,sha256=CLfraacr0FrD5ynxlNB6cyNy0lpbavcQT45TvkDrNvY,369
|
|
38
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/classifierbase.py,sha256=1yXufiUGpaiBjI2evMiwfYn-Zr-SnWwCnvtREqprtJw,2184
|
|
39
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/classifierqboost.py,sha256=5Dcpd0DjpMmlUULyZFKKWm4UuZpeMaknWKViiIjwc0U,18978
|
|
40
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/classifierqsvm.py,sha256=b6TdwlghR84UoQpfUThwMwNF_wmkABbCqOn6T1uY2dA,6636
|
|
41
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/clustering.py,sha256=yhh6jlgwZiQVn9h2pnYBlzVTCocK7rzsEurSQxCn5FQ,9486
|
|
42
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/clusteringbase.py,sha256=AvQbt6jeocBAGCuAmXHKyr3wLWqYUtBDq9PbsEOSlSc,2632
|
|
43
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/cvqboost_hamiltonian.pyx,sha256=3PMmEJ_xfmmWXGfire0t-WASnmKj6-CblufgQ2NTARo,2111
|
|
44
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/cvqboost_hamiltonian_c_func.c,sha256=ZoKgm_uGjTewhk4W6s-x8QoFuZO0KVkxILIFh6JKsoI,1851
|
|
45
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/cvqboost_hamiltonian_c_func.h,sha256=aOImMG5pziUnZxGpDXyWjLrvcY7ZdsczwwSQ2ay4T88,272
|
|
46
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/decomposition.py,sha256=Nsnq0GmINpbGOszndgCHXqKdECNpiNiampBrHPU_Gjg,8943
|
|
47
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/forecast.py,sha256=fFcBxQK9ZryfEuyvlr9HXicHoZRzLFybimYYttzhI9E,7403
|
|
48
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/forecastbase.py,sha256=s-6nUMvtYqG07r7MmmkFVj8_QqgeGkD-HVoEEDTE2bk,3654
|
|
49
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/regressor.py,sha256=LA1woXCnefG0wfoOxilX1kszgCUmfNcbQgs_WZ4Ai0o,5683
|
|
50
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/regressorbase.py,sha256=H5E8-8pUji1oH5JRdS37LJQoHuKt2JU8eXCZp-ZaEM4,2109
|
|
51
|
+
eqc_models-0.10.0.data/platlib/eqc_models/ml/reservoir.py,sha256=cPRvpCaWLYTBkui35jCssHcOPQgSQZallrG6Ac9djVI,2827
|
|
52
|
+
eqc_models-0.10.0.data/platlib/eqc_models/sequence/__init__.py,sha256=VXlYufO3GYFsM00oii9Cite2WsQEF8XTwRcjLPH_Zlg,92
|
|
53
|
+
eqc_models-0.10.0.data/platlib/eqc_models/sequence/tsp.py,sha256=YM641FTyK5NkgRGxHrU1QmMkEU0gf77nEmIElTqa6Qw,7680
|
|
54
|
+
eqc_models-0.10.0.data/platlib/eqc_models/solvers/__init__.py,sha256=hTjJI4F0FNDgQlK_oRHJxLIkg6of3I1-nEqU_3RL4Gk,542
|
|
55
|
+
eqc_models-0.10.0.data/platlib/eqc_models/solvers/eqcdirect.py,sha256=RzcRz3e3a0nJaR_qZ1td3NRKHT1NKPei_QNYExN3ooI,4898
|
|
56
|
+
eqc_models-0.10.0.data/platlib/eqc_models/solvers/qciclient.py,sha256=Vnfqa1N6JSzigb-mbqXj6g0r-1wOkeYzmEmctId1VCo,26975
|
|
57
|
+
eqc_models-0.10.0.data/platlib/eqc_models/utilities/__init__.py,sha256=SI2U7JKmPWSiq-F1WcSyfd7l9V6nbOZv_p8quMAZaT0,340
|
|
58
|
+
eqc_models-0.10.0.data/platlib/eqc_models/utilities/fileio.py,sha256=alWPTfjGFx6Iio9HZAAWtYcLmZsBBifg6S6_YbFMQhk,1088
|
|
59
|
+
eqc_models-0.10.0.data/platlib/eqc_models/utilities/polynomial.py,sha256=blXfu7Ehz9lT4nEmIinRzJOL27_qUHSbQ57zxmwDJCA,4735
|
|
60
|
+
eqc_models-0.10.0.data/platlib/eqc_models/utilities/qplib.py,sha256=Do-MjmCFdI5HyDOAjfoz4_5lugySLMBlMAWDLUWx2OA,15796
|
|
61
|
+
eqc_models-0.10.0.dist-info/LICENSE.txt,sha256=8eh0oqsNNVR1Jk-13gkqRRSo2axtUU5kp2KzH4f9u3U,11354
|
|
62
|
+
eqc_models-0.10.0.dist-info/METADATA,sha256=vFFt3ENmDo-0sFt3-9V_ffKaZm2y9COhcC0N_AVbUvM,7107
|
|
63
|
+
eqc_models-0.10.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
64
|
+
eqc_models-0.10.0.dist-info/top_level.txt,sha256=9ZfFeKNEvkRlKWoUnfcZ9TzmTdgdsuPEnTPy11Hqf4Q,30
|
|
65
|
+
eqc_models-0.10.0.dist-info/RECORD,,
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
from setuptools import Extension
|
|
2
|
-
from setuptools.command.build_py import build_py as _build_py
|
|
3
|
-
import numpy
|
|
4
|
-
|
|
5
|
-
# Modules to be compiled and include_dirs when necessary
|
|
6
|
-
extensions = [
|
|
7
|
-
Extension(
|
|
8
|
-
"eqc_models.base.polyeval",
|
|
9
|
-
["eqc_models/base/polyeval.pyx"], include_dirs=[numpy.get_include()],
|
|
10
|
-
),
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
class build_py(_build_py):
|
|
14
|
-
def run(self):
|
|
15
|
-
self.run_command("build_ext")
|
|
16
|
-
return super().run()
|
|
17
|
-
|
|
18
|
-
def initialize_options(self):
|
|
19
|
-
super().initialize_options()
|
|
20
|
-
if self.distribution.ext_modules == None:
|
|
21
|
-
self.distribution.ext_modules = []
|
|
22
|
-
|
|
23
|
-
self.distribution.ext_modules.extend(extensions)
|