Skip to content

Commit cf80e1d

Browse files
Expose z argument
1 parent ec63e58 commit cf80e1d

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

PyQrackIsing/_pyqrack_ising.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ static inline double expected_closeness_weight(size_t n_rows, size_t n_cols, siz
6363
return 2.0 * mu_k - 1.0;
6464
}
6565

66-
static inline std::vector<double> probability_by_hamming_weight(double J, double h, double theta, double t, size_t n_qubits)
66+
static inline std::vector<double> probability_by_hamming_weight(double J, double h, size_t z, double theta, double t, size_t n_qubits)
6767
{
6868
// critical angle
69-
const size_t z = 4U;
7069
const double theta_c = std::asin(h / (z * J));
7170
const double delta_theta = theta - theta_c;
7271
std::vector<double> bias;
@@ -103,7 +102,7 @@ static inline std::vector<double> probability_by_hamming_weight(double J, double
103102
return bias;
104103
}
105104

106-
std::vector<std::string> generate_tfim_samples_cpp(double J, double h, double theta, double t, size_t n_qubits, size_t shots) {
105+
std::vector<std::string> generate_tfim_samples_cpp(double J, double h, size_t z, double theta, double t, size_t n_qubits, size_t shots) {
107106
// lattice dimensions
108107
size_t n_rows = 1U;
109108
size_t n_cols = n_qubits;
@@ -115,7 +114,7 @@ std::vector<std::string> generate_tfim_samples_cpp(double J, double h, double th
115114
}
116115
}
117116

118-
const std::vector<double> bias = probability_by_hamming_weight(J, h, theta, t, n_qubits);
117+
const std::vector<double> bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits);
119118

120119
// thresholds
121120
std::vector<double> thresholds(n_qubits + 1);
@@ -189,8 +188,8 @@ std::vector<std::string> generate_tfim_samples_cpp(double J, double h, double th
189188
return output;
190189
}
191190

192-
double tfim_magnetization(double J, double h, double theta, double t, size_t n_qubits) {
193-
const std::vector<double> bias = probability_by_hamming_weight(J, h, theta, t, n_qubits);
191+
double tfim_magnetization(double J, double h, size_t z, double theta, double t, size_t n_qubits) {
192+
const std::vector<double> bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits);
194193
double magnetization = 0.0;
195194
for (size_t q = 0U; q < bias.size(); ++q) {
196195
const double mag = (n_qubits - 2.0 * q) / n_qubits;
@@ -200,8 +199,8 @@ double tfim_magnetization(double J, double h, double theta, double t, size_t n_q
200199
return magnetization;
201200
}
202201

203-
double tfim_square_magnetization(double J, double h, double theta, double t, size_t n_qubits) {
204-
const std::vector<double> bias = probability_by_hamming_weight(J, h, theta, t, n_qubits);
202+
double tfim_square_magnetization(double J, double h, size_t z, double theta, double t, size_t n_qubits) {
203+
const std::vector<double> bias = probability_by_hamming_weight(J, h, z, theta, t, n_qubits);
205204
double square_magnetization = 0.0;
206205
for (size_t q = 0U; q < bias.size(); ++q) {
207206
const double mag = (n_qubits - 2.0 * q) / n_qubits;
@@ -214,13 +213,13 @@ double tfim_square_magnetization(double J, double h, double theta, double t, siz
214213
PYBIND11_MODULE(tfim_sampler, m) {
215214
m.doc() = "PyQrackIsing TFIM sample generator";
216215
m.def("_generate_tfim_samples", &generate_tfim_samples_cpp,
217-
py::arg("J"), py::arg("h"), py::arg("theta"), py::arg("t"),
218-
py::arg("n_qubits"), py::arg("shots"));
216+
py::arg("J"), py::arg("h"), py::arg("z"), py::arg("theta"),
217+
py::arg("t"), py::arg("n_qubits"), py::arg("shots"));
219218
m.def("_tfim_magnetization", &tfim_magnetization,
220-
py::arg("J"), py::arg("h"), py::arg("theta"), py::arg("t"),
221-
py::arg("n_qubits"));
219+
py::arg("J"), py::arg("h"), py::arg("z"), py::arg("theta"),
220+
py::arg("t"), py::arg("n_qubits"));
222221
m.def("_tfim_square_magnetization", &tfim_square_magnetization,
223-
py::arg("J"), py::arg("h"), py::arg("theta"), py::arg("t"),
224-
py::arg("n_qubits"));
222+
py::arg("J"), py::arg("h"), py::arg("z"), py::arg("theta"),
223+
py::arg("t"), py::arg("n_qubits"));
225224
}
226225

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tfim_sampler
22

33

4-
def generate_tfim_samples(J=-1.0, h=2.0, theta=0.174532925199432957, t=5, n_qubits=56, shots=100):
5-
return [int(s) for s in tfim_sampler._generate_tfim_samples(J, h, theta, t, n_qubits, shots)]
4+
def generate_tfim_samples(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56, shots=100):
5+
return [int(s) for s in tfim_sampler._generate_tfim_samples(J, h, z, theta, t, n_qubits, shots)]

PyQrackIsing/tfim_magnetization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tfim_sampler
22

33

4-
def tfim_magnetization(J=-1.0, h=2.0, theta=0.174532925199432957, t=5, n_qubits=56):
5-
return tfim_sampler._tfim_magnetization(J, h, theta, t, n_qubits)
4+
def tfim_magnetization(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
5+
return tfim_sampler._tfim_magnetization(J, h, z, theta, t, n_qubits)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tfim_sampler
22

33

4-
def tfim_square_magnetization(J=-1.0, h=2.0, theta=0.174532925199432957, t=5, n_qubits=56):
5-
return tfim_sampler._tfim_square_magnetization(J, h, theta, t, n_qubits)
4+
def tfim_square_magnetization(J=-1.0, h=2.0, z=4, theta=0.174532925199432957, t=5, n_qubits=56):
5+
return tfim_sampler._tfim_square_magnetization(J, h, z, theta, t, n_qubits)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88

99
[project]
1010
name = "PyQrackIsing"
11-
version = "1.1.0"
11+
version = "1.2.0"
1212
requires-python = ">=3.8"
1313
description = "Near-ideal closed-form solutions for transverse field Ising model (TFIM)"
1414
readme = {file = "README.txt", content-type = "text/markdown"}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def build_extension(self, ext):
4040

4141
setup(
4242
name='PyQrackIsing',
43-
version='1.1.0',
43+
version='1.2.0',
4444
author='Dan Strano',
4545
author_email='stranoj@gmail.com',
4646
description='Near-ideal closed-form solutions for transverse field Ising model (TFIM)',

0 commit comments

Comments
 (0)