openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
declare.hpp
Go to the documentation of this file.
1// Copyright 2023 Jij Inc.
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <pybind11/pybind11.h>
18#include <pybind11/stl.h>
19#include <pybind11/functional.h>
20#include <pybind11/eigen.h>
21
22#include <pybind11_json/pybind11_json.hpp>
23
24#include <nlohmann/json.hpp>
25
27#include <openjij/graph/all.hpp>
33
34namespace py = pybind11;
35
36using namespace py::literals;
37
38namespace openjij {
39
40// NOTE: please add `py::module_local()` when defining `py::class_`
41
42// graph
43inline void declare_Graph(py::module &m) {
44 py::class_<graph::Graph>(m, "Graph", py::module_local())
45 .def(py::init<std::size_t>(), "num_spins"_a)
46 .def(
47 "gen_spin",
48 [](const graph::Graph &self, std::size_t seed) {
49 RandomEngine rng(seed);
50 return self.gen_spin(rng);
51 },
52 "seed"_a)
53 .def("gen_spin",
54 [](const graph::Graph &self) {
55 RandomEngine rng(std::random_device{}());
56 return self.gen_spin(rng);
57 })
58 .def(
59 "gen_binary",
60 [](const graph::Graph &self, std::size_t seed) {
61 RandomEngine rng(seed);
62 return self.gen_binary(rng);
63 },
64 "seed"_a)
65 .def("gen_binary",
66 [](const graph::Graph &self) {
67 RandomEngine rng(std::random_device{}());
68 return self.gen_binary(rng);
69 })
70 .def("size", &graph::Graph::size);
71}
72
73// dense
74template <typename FloatType>
75inline void declare_Dense(py::module &m, const std::string &suffix) {
76
77 using json = nlohmann::json;
78
79 auto str = std::string("Dense") + suffix;
80 py::class_<graph::Dense<FloatType>, graph::Graph>(m, str.c_str(),
81 py::module_local())
82 .def(py::init<std::size_t>(), "num_spins"_a)
83 .def(py::init([](py::object obj) {
84 return std::unique_ptr<graph::Dense<FloatType>>(
85 new graph::Dense<FloatType>(static_cast<json>(obj)));
86 }),
87 "obj"_a)
88 .def(py::init<const graph::Dense<FloatType> &>(), "other"_a)
89 .def("set_interaction_matrix",
91 .def(
92 "calc_energy",
93 [](const graph::Dense<FloatType> &self,
94 const Eigen::Matrix<FloatType, Eigen::Dynamic, 1, Eigen::ColMajor>
95 &spins) { return self.calc_energy(spins); },
96 "spins"_a)
97 .def(
98 "calc_energy",
99 [](const graph::Dense<FloatType> &self, const graph::Spins &spins) {
100 return self.calc_energy(spins);
101 },
102 "spins"_a)
103 .def(
104 "__setitem__",
106 const std::pair<std::size_t, std::size_t> &key,
107 FloatType val) { self.J(key.first, key.second) = val; },
108 "key"_a, "val"_a)
109 .def(
110 "__getitem__",
111 [](const graph::Dense<FloatType> &self,
112 const std::pair<std::size_t, std::size_t> &key) {
113 return self.J(key.first, key.second);
114 },
115 "key"_a)
116 .def(
117 "__setitem__",
118 [](graph::Dense<FloatType> &self, std::size_t key, FloatType val) {
119 self.h(key) = val;
120 },
121 "key"_a, "val"_a)
122 .def(
123 "__getitem__",
124 [](const graph::Dense<FloatType> &self, std::size_t key) {
125 return self.h(key);
126 },
127 "key"_a)
128 .def("get_interactions", &graph::Dense<FloatType>::get_interactions);
129}
130
131// sparse
132template <typename FloatType>
133inline void declare_Sparse(py::module &m, const std::string &suffix) {
134
135 using json = nlohmann::json;
136
137 auto str = std::string("Sparse") + suffix;
138 py::class_<graph::Sparse<FloatType>, graph::Graph>(m, str.c_str(),
139 py::module_local())
140 .def(py::init<std::size_t, std::size_t>(), "num_spins"_a, "num_edges"_a)
141 .def(py::init<std::size_t>(), "num_spins"_a)
142 .def(py::init([](py::object obj, std::size_t num_edges) {
143 return std::unique_ptr<graph::Sparse<FloatType>>(
144 new graph::Sparse<FloatType>(static_cast<json>(obj),
145 num_edges));
146 }),
147 "obj"_a, "num_edges"_a)
148 .def(py::init([](py::object obj) {
149 return std::unique_ptr<graph::Sparse<FloatType>>(
150 new graph::Sparse<FloatType>(static_cast<json>(obj)));
151 }),
152 "obj"_a)
153 .def(py::init<const graph::Sparse<FloatType> &>(), "other"_a)
154 .def("adj_nodes", &graph::Sparse<FloatType>::adj_nodes)
155 .def("get_num_edges", &graph::Sparse<FloatType>::get_num_edges)
156 .def(
157 "calc_energy",
158 [](const graph::Sparse<FloatType> &self,
159 const Eigen::Matrix<FloatType, Eigen::Dynamic, 1, Eigen::ColMajor>
160 &spins) { return self.calc_energy(spins); },
161 "spins"_a)
162 .def(
163 "calc_energy",
164 [](const graph::Sparse<FloatType> &self, const graph::Spins &spins) {
165 return self.calc_energy(spins);
166 },
167 "spins"_a)
168 .def(
169 "__setitem__",
171 const std::pair<std::size_t, std::size_t> &key,
172 FloatType val) { self.J(key.first, key.second) = val; },
173 "key"_a, "val"_a)
174 .def(
175 "__getitem__",
176 [](const graph::Sparse<FloatType> &self,
177 const std::pair<std::size_t, std::size_t> &key) {
178 return self.J(key.first, key.second);
179 },
180 "key"_a)
181 .def(
182 "__setitem__",
183 [](graph::Sparse<FloatType> &self, std::size_t key, FloatType val) {
184 self.h(key) = val;
185 },
186 "key"_a, "val"_a)
187 .def(
188 "__getitem__",
189 [](const graph::Sparse<FloatType> &self, std::size_t key) {
190 return self.h(key);
191 },
192 "key"_a);
193}
194
195// csr sparse
196template <typename FloatType>
197inline void declare_CSRSparse(py::module &m, const std::string &suffix) {
198
199 auto str = std::string("CSRSparse") + suffix;
200 py::class_<graph::CSRSparse<FloatType>, graph::Graph>(m, str.c_str(),
201 py::module_local())
202 .def(py::init<const Eigen::SparseMatrix<FloatType, Eigen::RowMajor> &>(), "interaction"_a)
203 .def(py::init<const graph::CSRSparse<FloatType> &>(), "other"_a)
204 .def(
205 "calc_energy",
206 [](const graph::CSRSparse<FloatType> &self,
207 const Eigen::Matrix<FloatType, Eigen::Dynamic, 1, Eigen::ColMajor>
208 &spins) { return self.calc_energy(spins); },
209 "spins"_a)
210 .def(
211 "calc_energy",
212 [](const graph::CSRSparse<FloatType> &self, const graph::Spins &spins) {
213 return self.calc_energy(spins);
214 },
215 "spins"_a)
216 .def("get_interactions", &graph::CSRSparse<FloatType>::get_interactions);
217}
218
219// Polynomial
220template <typename FloatType>
221inline void declare_Polynomial(py::module &m, const std::string &suffix) {
222
223 using json = nlohmann::json;
224 using Poly = graph::Polynomial<FloatType>;
225 auto str = std::string("Polynomial") + suffix;
226
227 py::class_<Poly, graph::Graph>(m, str.c_str(), py::module_local())
228 .def(py::init<const std::size_t>(), "num_variables"_a)
229 .def(py::init([](const py::object &obj) {
230 return std::unique_ptr<graph::Polynomial<FloatType>>(
231 new graph::Polynomial<FloatType>(static_cast<json>(obj)));
232 }),
233 "obj"_a)
234 .def("get_num_interactions", &Poly::get_num_interactions)
235 .def("calc_energy", &Poly::calc_energy, "spins"_a, "omp_flag"_a = true)
236 .def("energy", &Poly::energy, "spins"_a, "omp_flag"_a = true)
237 .def(
238 "__setitem__",
239 [](Poly &self, graph::Index key, FloatType val) {
240 self.J(key) = val;
241 },
242 "key"_a, "val"_a)
243 .def(
244 "__setitem__",
245 [](Poly &self, std::vector<graph::Index> &key, FloatType val) {
246 self.J(key) = val;
247 },
248 "key"_a, "val"_a)
249 .def(
250 "__getitem__",
251 [](const Poly &self, std::vector<graph::Index> &key) {
252 return self.J(key);
253 },
254 "key"_a)
255 .def(
256 "__getitem__",
257 [](const Poly &self, graph::Index key) { return self.J(key); },
258 "key"_a)
259 .def("get_polynomial", [](const Poly &self) {
260 py::dict py_polynomial;
261 for (std::size_t i = 0; i < self.get_keys().size(); ++i) {
262 py::tuple temp;
263 for (const auto &it : self.get_keys()[i]) {
264 temp = temp + py::make_tuple(it);
265 }
266 py_polynomial[temp] = self.get_values()[i];
267 }
268 return py_polynomial;
269 });
270}
271
272// enum class Dir
273inline void declare_Dir(py::module &m) {
274 py::enum_<graph::Dir>(m, "Dir", py::module_local())
275 .value("PLUS_R", graph::Dir::PLUS_R)
276 .value("MINUS_R", graph::Dir::MINUS_R)
277 .value("PLUS_C", graph::Dir::PLUS_C)
278 .value("MINUS_C", graph::Dir::MINUS_C);
279}
280
281// square
282template <typename FloatType>
283inline void declare_Square(py::module &m, const std::string &suffix) {
284
285 using json = nlohmann::json;
286
287 auto str = std::string("Square") + suffix;
288 py::class_<graph::Square<FloatType>, graph::Sparse<FloatType>>(
289 m, str.c_str(), py::module_local())
290 .def(py::init<std::size_t, std::size_t, FloatType>(), "num_row"_a,
291 "num_column"_a, "init_val"_a = 0)
292 .def(py::init<const graph::Square<FloatType> &>(), "other"_a)
293 .def(py::init([](py::object obj, std::size_t num_row,
294 std::size_t num_column, FloatType init_val) {
295 return std::unique_ptr<graph::Square<FloatType>>(
296 new graph::Square<FloatType>(static_cast<json>(obj), num_row,
297 num_column, init_val));
298 }),
299 "obj"_a, "num_row"_a, "num_column"_a, "init_val"_a = 0)
300 .def("to_ind", &graph::Square<FloatType>::to_ind)
301 .def("to_rc", &graph::Square<FloatType>::to_rc)
302 .def("get_num_row", &graph::Square<FloatType>::get_num_row)
303 .def("get_num_column", &graph::Square<FloatType>::get_num_column)
304 .def(
305 "__setitem__",
307 const std::tuple<std::size_t, std::size_t, graph::Dir> &key,
308 FloatType val) {
309 self.J(std::get<0>(key), std::get<1>(key), std::get<2>(key)) = val;
310 },
311 "key"_a, "val"_a)
312 .def(
313 "__getitem__",
314 [](const graph::Square<FloatType> &self,
315 const std::tuple<std::size_t, std::size_t, graph::Dir> &key) {
316 return self.J(std::get<0>(key), std::get<1>(key), std::get<2>(key));
317 },
318 "key"_a)
319 .def(
320 "__setitem__",
322 const std::pair<std::size_t, std::size_t> &key,
323 FloatType val) { self.h(key.first, key.second) = val; },
324 "key"_a, "val"_a)
325 .def(
326 "__getitem__",
327 [](const graph::Square<FloatType> &self,
328 const std::pair<std::size_t, std::size_t> &key) {
329 return self.h(key.first, key.second);
330 },
331 "key"_a);
332}
333
334// enum class ChimeraDir
335inline void declare_ChimeraDir(py::module &m) {
336 py::enum_<graph::ChimeraDir>(m, "ChimeraDir")
337 .value("PLUS_R", graph::ChimeraDir::PLUS_R)
338 .value("MINUS_R", graph::ChimeraDir::MINUS_R)
339 .value("PLUS_C", graph::ChimeraDir::PLUS_C)
340 .value("MINUS_C", graph::ChimeraDir::MINUS_C)
341 .value("IN_0or4", graph::ChimeraDir::IN_0or4)
342 .value("IN_1or5", graph::ChimeraDir::IN_1or5)
343 .value("IN_2or6", graph::ChimeraDir::IN_2or6)
344 .value("IN_3or7", graph::ChimeraDir::IN_3or7);
345}
346
347// chimera
348template <typename FloatType>
349inline void declare_Chimera(py::module &m, const std::string &suffix) {
350
351 using json = nlohmann::json;
352
353 auto str = std::string("Chimera") + suffix;
354 py::class_<graph::Chimera<FloatType>, graph::Sparse<FloatType>>(
355 m, str.c_str(), py::module_local())
356 .def(py::init<std::size_t, std::size_t, FloatType>(), "num_row"_a,
357 "num_column"_a, "init_val"_a = 0)
358 .def(py::init<const graph::Chimera<FloatType> &>(), "other"_a)
359 .def(py::init([](py::object obj, std::size_t num_row,
360 std::size_t num_column, FloatType init_val) {
361 return std::unique_ptr<graph::Chimera<FloatType>>(
362 new graph::Chimera<FloatType>(static_cast<json>(obj), num_row,
363 num_column, init_val));
364 }),
365 "obj"_a, "num_row"_a, "num_column"_a, "init_val"_a = 0)
366 .def("to_ind", &graph::Chimera<FloatType>::to_ind)
367 .def("to_rci", &graph::Chimera<FloatType>::to_rci)
368 .def("get_num_row", &graph::Chimera<FloatType>::get_num_row)
369 .def("get_num_column", &graph::Chimera<FloatType>::get_num_column)
370 .def("get_num_in_chimera", &graph::Chimera<FloatType>::get_num_in_chimera)
371 .def(
372 "__setitem__",
374 const std::tuple<std::size_t, std::size_t, std::size_t,
375 graph::ChimeraDir> &key,
376 FloatType val) {
377 self.J(std::get<0>(key), std::get<1>(key), std::get<2>(key),
378 std::get<3>(key)) = val;
379 },
380 "key"_a, "val"_a)
381 .def(
382 "__getitem__",
383 [](const graph::Chimera<FloatType> &self,
384 const std::tuple<std::size_t, std::size_t, std::size_t,
385 graph::ChimeraDir> &key) {
386 return self.J(std::get<0>(key), std::get<1>(key), std::get<2>(key),
387 std::get<3>(key));
388 },
389 "key"_a)
390 .def(
391 "__setitem__",
393 const std::tuple<std::size_t, std::size_t, std::size_t> &key,
394 FloatType val) {
395 self.h(std::get<0>(key), std::get<1>(key), std::get<2>(key)) = val;
396 },
397 "key"_a, "val"_a)
398 .def(
399 "__getitem__",
400 [](const graph::Chimera<FloatType> &self,
401 const std::tuple<std::size_t, std::size_t, std::size_t> &key) {
402 return self.h(std::get<0>(key), std::get<1>(key), std::get<2>(key));
403 },
404 "key"_a);
405}
406
407// system
408
409// ClassicalIsing
410template <typename GraphType>
411inline void declare_ClassicalIsing(py::module &m,
412 const std::string &gtype_str) {
413 // ClassicalIsing
414 using ClassicalIsing = system::ClassicalIsing<GraphType>;
415
416 auto str = std::string("ClassicalIsing") + gtype_str;
417 py::class_<ClassicalIsing>(m, str.c_str(), py::module_local())
418 .def(py::init<const graph::Spins &, const GraphType &>(), "init_spin"_a,
419 "init_interaction"_a)
420 .def(
421 "reset_spins",
422 [](ClassicalIsing &self, const graph::Spins &init_spin) {
423 self.reset_spins(init_spin);
424 },
425 "init_spin"_a)
426 .def_readwrite("spin", &ClassicalIsing::spin)
427 .def_readonly("interaction", &ClassicalIsing::interaction)
428 .def_readonly("num_spins", &ClassicalIsing::num_spins);
429
430 // make_classical_ising
431 auto mkci_str = std::string("make_classical_ising");
432 m.def(
433 mkci_str.c_str(),
434 [](const graph::Spins &init_spin, const GraphType &init_interaction) {
435 return system::make_classical_ising(init_spin, init_interaction);
436 },
437 "init_spin"_a, "init_interaction"_a);
438}
439
440// ClassicalIsingPolynomial
441template <typename GraphType>
442inline void declare_ClassicalIsingPolynomial(py::module &m,
443 const std::string &gtype_str) {
444
446 auto str = std::string("ClassicalIsing") + gtype_str;
447
448 py::class_<CIP>(m, str.c_str(), py::module_local())
449 .def(py::init<const graph::Spins &, const GraphType &,
450 const cimod::Vartype>(),
451 "init_variables"_a, "init_interaction"_a, "vartype"_a)
452 .def(py::init<const graph::Spins &, const GraphType &,
453 const std::string>(),
454 "init_variables"_a, "init_interaction"_a, "vartype"_a)
455 .def(py::init([](const graph::Spins &init_spins, const py::object &obj) {
456 return std::unique_ptr<CIP>(
457 new CIP(init_spins, static_cast<nlohmann::json>(obj)));
458 }),
459 "init_spin"_a, "obj"_a)
460 .def_readonly("variables", &CIP::variables)
461 .def_readonly("num_variables", &CIP::num_variables)
462 .def("reset_variables", &CIP::reset_variables, "init_variables"_a)
463 .def("reset_spins", &CIP::reset_variables, "init_spins"_a)
464 .def("get_values", &CIP::get_values)
465 .def("get_keys", &CIP::get_keys)
466 .def("get_adj", &CIP::get_adj)
467 .def("get_vartype_to_string", &CIP::get_vartype_string)
468 .def("get_max_effective_dE", &CIP::get_max_effective_dE)
469 .def("get_min_effective_dE", &CIP::get_min_effective_dE);
470
471 // make_classical_ising_polynomial
472 auto mkcip_str = std::string("make_classical_ising_polynomial");
473 m.def(
474 mkcip_str.c_str(),
475 [](const graph::Spins &init_spin, const GraphType &init_interaction,
476 const cimod::Vartype vartype) {
477 return system::make_classical_ising_polynomial(
478 init_spin, init_interaction, vartype);
479 },
480 "init_spin"_a, "init_interaction"_a, "vartype"_a);
481
482 // make_classical_ising_polynomial
483 m.def(
484 mkcip_str.c_str(),
485 [](const graph::Spins &init_spin, const GraphType &init_interaction,
486 const std::string vartype) {
487 return system::make_classical_ising_polynomial(
488 init_spin, init_interaction, vartype);
489 },
490 "init_spin"_a, "init_interaction"_a, "vartype"_a);
491
492 // make_classical_ising_polynomial
493 m.def(
494 mkcip_str.c_str(),
495 [](const graph::Spins &init_spin, const py::object &obj) {
496 return system::make_classical_ising_polynomial(
497 init_spin, static_cast<nlohmann::json>(obj));
498 },
499 "init_spin"_a, "obj"_a);
500}
501
502template <typename GraphType>
503inline void declare_KLocalPolynomial(py::module &m,
504 const std::string &gtype_str) {
505
507 auto str = std::string("KLocal") + gtype_str;
508
509 py::class_<KLP>(m, str.c_str(), py::module_local())
510 .def(py::init<const graph::Binaries &, const GraphType &>(),
511 "init_spin"_a, "init_interaction"_a)
512 .def(py::init(
513 [](const graph::Binaries &init_binaries, const py::object &obj) {
514 return std::unique_ptr<KLP>(
515 new KLP(init_binaries, static_cast<nlohmann::json>(obj)));
516 }),
517 "init_binaries"_a, "obj"_a)
518 .def_readonly("binaries", &KLP::binaries)
519 .def_readonly("num_binaries", &KLP::num_binaries)
520 .def_readonly("count_call_updater", &KLP::count_call_updater)
521 .def_property_readonly("num_interactions", &KLP::GetNumInteractions)
522 .def_readwrite("rate_call_k_local", &KLP::rate_call_k_local)
523 .def("reset_binaries", &KLP::reset_binaries, "init_binaries"_a)
524 .def("reset_spins", &KLP::reset_binaries, "init_spins"_a)
525 .def("reset_dE", &KLP::reset_dE)
526 .def("get_active_binaries", &KLP::get_active_binaries)
527 .def("get_max_effective_dE", &KLP::get_max_effective_dE)
528 .def("get_min_effective_dE", &KLP::get_min_effective_dE)
529 .def("get_keys", &KLP::get_keys)
530 .def("get_values", &KLP::get_values)
531 .def("get_vartype_to_string", &KLP::get_vartype_string)
532 .def("get_polynomial",
533 [](const KLP &self) {
534 py::dict py_polynomial;
535 const auto &poly_key_list = self.get_keys();
536 const auto &poly_value_list = self.get_values();
537 for (std::size_t i = 0; i < poly_key_list.size(); ++i) {
538 py::tuple tuple;
539 for (const auto &index : poly_key_list[i]) {
540 tuple = tuple + py::make_tuple(index);
541 }
542 py_polynomial[tuple] = poly_value_list[i];
543 }
544 return py_polynomial;
545 })
546 .def("get_adj", [](const KLP &self) {
547 const auto &adj = self.get_adj();
548 const auto &poly_key_list = self.get_keys();
549 const auto &poly_value_list = self.get_values();
550 py::dict py_adj;
551 for (int64_t i = 0; i < self.num_binaries; ++i) {
552 py::dict dict;
553 for (const auto &index_key : adj[i]) {
554 py::tuple tuple;
555 for (const auto &index_binary : poly_key_list[index_key]) {
556 tuple = tuple + py::make_tuple(index_binary);
557 }
558 dict[tuple] = poly_value_list[index_key];
559 }
560 py_adj[py::int_(i)] = dict;
561 }
562 return py_adj;
563 });
564
565 // make_classical_ising_polynomial
566 auto mkcip_str = std::string("make_k_local_polynomial");
567 m.def(
568 mkcip_str.c_str(),
569 [](const graph::Spins &init_spin, const GraphType &init_interaction) {
570 return system::make_k_local_polynomial(init_spin, init_interaction);
571 },
572 "init_spin"_a, "init_interaction"_a);
573
574 // make_classical_ising_polynomial
575 auto mkcip_json_str = std::string("make_k_local_polynomial");
576 m.def(
577 mkcip_json_str.c_str(),
578 [](const graph::Spins &init_spin, const py::object &obj) {
579 return system::make_k_local_polynomial(
580 init_spin, static_cast<nlohmann::json>(obj));
581 },
582 "init_spin"_a, "obj"_a);
583}
584
585// TransverseIsing
586template <typename GraphType>
587inline void declare_TransverseIsing(py::module &m,
588 const std::string &gtype_str) {
589 // TransverseIsing
590 using TransverseIsing = system::TransverseIsing<GraphType>;
591 using FloatType = typename GraphType::value_type;
592
593 auto str = std::string("TransverseIsing") + gtype_str;
594 py::class_<TransverseIsing>(m, str.c_str(), py::module_local())
595 .def(py::init<const system::TrotterSpins &, const GraphType &,
596 FloatType>(),
597 "init_spin"_a, "init_interaction"_a, "gamma"_a)
598 .def(py::init<const graph::Spins &, const GraphType &, FloatType,
599 size_t>(),
600 "init_classical_spins"_a, "init_interaction"_a, "gamma"_a,
601 "num_trotter_slices"_a)
602 .def(
603 "reset_spins",
604 [](TransverseIsing &self,
605 const system::TrotterSpins &init_trotter_spins) {
606 self.reset_spins(init_trotter_spins);
607 },
608 "init_trotter_spins"_a)
609 .def(
610 "reset_spins",
611 [](TransverseIsing &self, const graph::Spins &classical_spins) {
612 self.reset_spins(classical_spins);
613 },
614 "classical_spins"_a)
615 .def_readwrite("trotter_spins", &TransverseIsing::trotter_spins)
616 .def_readonly("interaction", &TransverseIsing::interaction)
617 .def_readonly("num_classical_spins",
618 &TransverseIsing::num_classical_spins)
619 .def_readwrite("gamma", &TransverseIsing::gamma);
620
621 // make_transverse_ising
622 auto mkci_str = std::string("make_transverse_ising");
623 m.def(
624 mkci_str.c_str(),
625 [](const system::TrotterSpins &init_trotter_spins,
626 const GraphType &init_interaction, double gamma) {
627 return system::make_transverse_ising(init_trotter_spins,
628 init_interaction, gamma);
629 },
630 "init_trotter_spins"_a, "init_interaction"_a, "gamma"_a);
631
632 m.def(
633 mkci_str.c_str(),
634 [](const graph::Spins &classical_spins, const GraphType &init_interaction,
635 double gamma, std::size_t num_trotter_slices) {
636 return system::make_transverse_ising(classical_spins, init_interaction,
637 gamma, num_trotter_slices);
638 },
639 "classical_spins"_a, "init_interaction"_a, "gamma"_a,
640 "num_trotter_slices"_a);
641}
642
643// Continuous Time Transverse Ising
644template <typename GraphType>
645inline void declare_ContinuousTimeIsing(py::module &m,
646 const std::string &gtype_str) {
647 // TransverseIsing
648 using TransverseIsing = system::ContinuousTimeIsing<GraphType>;
649 using FloatType = typename GraphType::value_type;
650 using SpinConfiguration = typename TransverseIsing::SpinConfiguration;
651
652 auto str = std::string("ContinuousTimeIsing") + gtype_str;
653 py::class_<TransverseIsing>(m, str.c_str(), py::module_local())
654 .def(py::init<const SpinConfiguration &, const GraphType &, FloatType>(),
655 "init_spin_config"_a, "init_interaction"_a, "gamma"_a)
656 .def(py::init<const graph::Spins &, const GraphType &, FloatType>(),
657 "init_spins"_a, "init_interaction"_a, "gamma"_a)
658 .def(
659 "reset_spins",
660 [](TransverseIsing &self, const SpinConfiguration &init_spin_config) {
661 self.reset_spins(init_spin_config);
662 },
663 "init_spin_config"_a)
664 .def(
665 "reset_spins",
666 [](TransverseIsing &self, const graph::Spins &classical_spins) {
667 self.reset_spins(classical_spins);
668 },
669 "classical_spins"_a)
670 .def_readwrite("spin_config", &TransverseIsing::spin_config)
671 .def_readonly("interaction", &TransverseIsing::interaction)
672 .def_readonly("num_spins", &TransverseIsing::num_spins)
673 .def_readonly("gamma", &TransverseIsing::gamma);
674
675 // make_continuous_ising
676 auto mkci_str = std::string("make_continuous_time_ising");
677 m.def(
678 mkci_str.c_str(),
679 [](const graph::Spins &classical_spins, const GraphType &init_interaction,
680 double gamma) {
681 return system::make_continuous_time_ising(classical_spins,
682 init_interaction, gamma);
683 },
684 "classical_spins"_a, "init_interaction"_a, "gamma"_a);
685}
686
687// Algorithm
688template <template <typename> class Updater, typename System,
689 typename RandomNumberEngine>
690inline void declare_Algorithm_run(py::module &m,
691 const std::string &updater_str) {
692 auto str = std::string("Algorithm_") + updater_str + std::string("_run");
693 using SystemType = typename system::get_system_type<System>::type;
694 // with seed
695 m.def(
696 str.c_str(),
697 [](System &system, std::size_t seed,
698 const utility::ScheduleList<SystemType> &schedule_list,
699 const std::function<void(
700 const System &,
702 &callback) {
703 py::gil_scoped_release release;
704
705 using Callback = std::function<void(
706 const System &, const utility::UpdaterParameter<SystemType> &)>;
707 RandomNumberEngine rng(seed);
708 algorithm::Algorithm<Updater>::run(
709 system, rng, schedule_list,
710 callback ? [=](const System &system,
711 const utility::UpdaterParameter<SystemType>
712 &param) { callback(system, param.get_tuple()); }
713 : Callback(nullptr));
714
715 py::gil_scoped_acquire acquire;
716 },
717 "system"_a, "seed"_a, "schedule_list"_a, "callback"_a = nullptr);
718
719 // without seed
720 m.def(
721 str.c_str(),
722 [](System &system, const utility::ScheduleList<SystemType> &schedule_list,
723 const std::function<void(
724 const System &,
725 const typename utility::UpdaterParameter<SystemType>::Tuple &)>
726 &callback) {
727 py::gil_scoped_release release;
728
729 using Callback = std::function<void(
730 const System &, const utility::UpdaterParameter<SystemType> &)>;
731 RandomNumberEngine rng(std::random_device{}());
733 system, rng, schedule_list,
734 callback ? [=](const System &system,
735 const utility::UpdaterParameter<SystemType>
736 &param) { callback(system, param.get_tuple()); }
737 : Callback(nullptr));
738
739 py::gil_scoped_acquire acquire;
740 },
741 "system"_a, "schedule_list"_a, "callback"_a = nullptr);
742
743 // schedule_list can be a list of tuples
744 using TupleList = std::vector<std::pair<
745 typename utility::UpdaterParameter<SystemType>::Tuple, std::size_t>>;
746
747 // with seed
748 m.def(
749 str.c_str(),
750 [](System &system, std::size_t seed, const TupleList &tuplelist,
751 const std::function<void(
752 const System &,
753 const typename utility::UpdaterParameter<SystemType>::Tuple &)>
754 &callback) {
755 py::gil_scoped_release release;
756
757 using Callback = std::function<void(
758 const System &, const utility::UpdaterParameter<SystemType> &)>;
759 RandomNumberEngine rng(seed);
761 system, rng, utility::make_schedule_list<SystemType>(tuplelist),
762 callback ? [=](const System &system,
763 const utility::UpdaterParameter<SystemType>
764 &param) { callback(system, param.get_tuple()); }
765 : Callback(nullptr));
766
767 py::gil_scoped_acquire acquire;
768 },
769 "system"_a, "seed"_a, "tuplelist"_a, "callback"_a = nullptr);
770
771 // without seed
772 m.def(
773 str.c_str(),
774 [](System &system, const TupleList &tuplelist,
775 const std::function<void(
776 const System &,
777 const typename utility::UpdaterParameter<SystemType>::Tuple &)>
778 &callback) {
779 py::gil_scoped_release release;
780 using Callback = std::function<void(
781 const System &, const utility::UpdaterParameter<SystemType> &)>;
782 RandomNumberEngine rng(std::random_device{}());
784 system, rng, utility::make_schedule_list<SystemType>(tuplelist),
785 callback ? [=](const System &system,
786 const utility::UpdaterParameter<SystemType>
787 &param) { callback(system, param.get_tuple()); }
788 : Callback(nullptr));
789
790 py::gil_scoped_acquire acquire;
791 },
792 "system"_a, "tuplelist"_a, "callback"_a = nullptr);
793}
794
795// utility
796template <typename SystemType>
798
799template <>
800inline std::string
802 return "(beta: " + std::to_string(obj.beta) + ")";
803}
804
805template <>
806inline std::string repr_impl(
808 return "(beta: " + std::to_string(obj.beta) +
809 ", lambda: " + std::to_string(obj.lambda) + ")";
810}
811
812template <>
813inline std::string repr_impl(
815 return "(beta: " + std::to_string(obj.beta) +
816 ", s: " + std::to_string(obj.s) + ")";
817}
818
819inline void declare_ClassicalUpdaterParameter(py::module &m) {
820 py::class_<utility::ClassicalUpdaterParameter>(m, "ClassicalUpdaterParameter",
821 py::module_local())
822 .def(py::init<>())
823 .def(py::init<double>(), "beta"_a)
824 .def_readwrite("beta", &utility::ClassicalUpdaterParameter::beta)
825 .def("__repr__", [](const utility::ClassicalUpdaterParameter &self) {
826 return repr_impl(self);
827 });
828}
829
831 py::class_<utility::ClassicalConstraintUpdaterParameter>(
832 m, "ClassicalConstraintUpdaterParameter", py::module_local())
833 .def(py::init<>())
834 .def(py::init<double, double>(), "beta"_a, "lambda"_a)
835 .def(py::init<const std::pair<double, double> &>(), "obj"_a)
836 .def_readwrite("beta",
837 &utility::ClassicalConstraintUpdaterParameter::beta)
838 .def_readwrite("lambda",
839 &utility::ClassicalConstraintUpdaterParameter::lambda)
840 .def("__repr__",
842 return repr_impl(self);
843 });
844}
845
846inline void declare_TransverseFieldUpdaterParameter(py::module &m) {
847 py::class_<utility::TransverseFieldUpdaterParameter>(
848 m, "TransverseFieldUpdaterParameter", py::module_local())
849 .def(py::init<>())
850 .def(py::init<double, double>(), "beta"_a, "s"_a)
851 .def(py::init<const std::pair<double, double> &>(), "obj"_a)
852 .def_readwrite("beta", &utility::TransverseFieldUpdaterParameter::beta)
853 .def_readwrite("s", &utility::TransverseFieldUpdaterParameter::s)
854 .def("__repr__",
856 return repr_impl(self);
857 });
858}
859
860template <typename SystemType>
861inline void declare_Schedule(py::module &m, const std::string &systemtype_str) {
862 auto str = systemtype_str + "Schedule";
863 py::class_<utility::Schedule<SystemType>>(m, str.c_str(), py::module_local())
864 .def(py::init<>())
865 .def(py::init<const std::pair<
866 const utility::UpdaterParameter<SystemType> &, std::size_t> &>(),
867 "obj"_a)
868 .def_readwrite("one_mc_step", &utility::Schedule<SystemType>::one_mc_step)
869 .def_readwrite("updater_parameter",
871 .def("__repr__", [](const utility::Schedule<SystemType> &self) {
872 return "(" + repr_impl(self.updater_parameter) +
873 " mcs: " + std::to_string(self.one_mc_step) + ")";
874 });
875
876 // define make_schedule_list
877 m.def("make_schedule_list", &utility::make_schedule_list<SystemType>,
878 "tuplelist"_a);
879}
880
881// result
882// get_solution
883template <typename System> inline void declare_get_solution(py::module &m) {
884 m.def(
885 "get_solution",
886 [](const System &system) { return result::get_solution(system); },
887 "system"_a);
888}
889
890
891template<typename FloatType>
892void declare_BinaryPolynomialModel(py::module &m) {
894
895 std::string name = std::string("BinaryPolynomialModel");
896 auto py_class = py::class_<BPM>(m, name.c_str(), py::module_local());
897
898 py_class.def(py::init<const std::vector<std::vector<typename BPM::IndexType>>&,
899 const std::vector<FloatType>&>(),
900 "key_list"_a, "value_list"_a);
901
902 py_class.def("get_degree", &BPM::GetDegree);
903 py_class.def("get_system_size", &BPM::GetSystemSize);
904 py_class.def("get_index_list", &BPM::GetIndexList);
905 py_class.def("get_index_map", &BPM::GetIndexMap);
906 py_class.def("get_key_value_list", &BPM::GetKeyValueList);
907 py_class.def("get_adjacency_list", &BPM::GetAdjacencyList);
908 py_class.def("get_estimated_min_energy_difference", &BPM::GetEstimatedMinEnergyDifference);
909 py_class.def("get_estimated_max_energy_difference", &BPM::GetEstimatedMaxEnergyDifference);
910 py_class.def("calculate_energy", &BPM::CalculateEnergy);
911}
912
913template<typename FloatType>
914void declare_IsingPolynomialModel(py::module &m) {
916
917 std::string name = std::string("IsingPolynomialModel");
918 auto py_class = py::class_<IPM>(m, name.c_str(), py::module_local());
919
920 py_class.def(py::init<std::vector<std::vector<typename IPM::IndexType>>&,
921 std::vector<FloatType>&>(),
922 "key_list"_a, "value_list"_a);
923
924 py_class.def("get_degree", &IPM::GetDegree);
925 py_class.def("get_system_size", &IPM::GetSystemSize);
926 py_class.def("get_index_list", &IPM::GetIndexList);
927 py_class.def("get_index_map", &IPM::GetIndexMap);
928 py_class.def("get_key_value_list", &IPM::GetKeyValueList);
929 py_class.def("get_adjacency_list", &IPM::GetAdjacencyList);
930 py_class.def("get_estimated_min_energy_difference", &IPM::GetEstimatedMinEnergyDifference);
931 py_class.def("get_estimated_max_energy_difference", &IPM::GetEstimatedMaxEnergyDifference);
932 py_class.def("calculate_energy", &IPM::CalculateEnergy);
933}
934
935void declare_IntegerQuadraticModel(py::module &m) {
937
938 std::string name = std::string("IntegerQuadraticModel");
939 auto py_class = py::class_<IQM>(m, name.c_str(), py::module_local());
940
941 py_class.def(py::init<std::vector<std::vector<std::int64_t>>&,
942 std::vector<double>&,
943 std::vector<std::pair<std::int64_t, std::int64_t>>&>(),
944 "key_list"_a, "value_list"_a, "bound_list"_a);
945
946 py_class.def("get_max_min_terms", &IQM::GetMaxMinTerms);
947 py_class.def("get_index_list", &IQM::GetIndexList);
948 py_class.def("get_num_variables", &IQM::GetNumVariables);
949 py_class.def("get_quadratic", &IQM::GetQuadratic);
950 py_class.def("get_linear", &IQM::GetLinear);
951 py_class.def("get_squared", &IQM::GetSquared);
952 py_class.def("get_constant", &IQM::GetConstant);
953 py_class.def("get_bound_list", &IQM::GetBounds);
954 py_class.def("get_only_bilinear_index_set", &IQM::GetOnlyBilinearIndexSet);
955}
956
959
960 std::string name = std::string("IntegerPolynomialModel");
961 auto py_class = py::class_<IPM>(m, name.c_str(), py::module_local());
962
963 py_class.def(py::init<std::vector<std::vector<std::int64_t>>&,
964 std::vector<double>&,
965 std::vector<std::pair<std::int64_t, std::int64_t>>&>(),
966 "key_list"_a, "value_list"_a, "bound_list"_a);
967
968 py_class.def("get_max_min_terms", &IPM::GetMaxMinTerms);
969 py_class.def("get_index_list", &IPM::GetIndexList);
970 py_class.def("get_num_variables", &IPM::GetNumVariables);
971 py_class.def("get_bound_list", &IPM::GetBounds);
972 py_class.def("get_constant", &IPM::GetConstant);
973 py_class.def("get_key_value_list", &IPM::GetKeyValueList);
974 py_class.def("get_index_to_interactions", &IPM::GetIndexToInteractions);
975 py_class.def("get_each_variable_degree", &IPM::GetEachVariableDegree);
976}
977
978void declare_IntegerSAResult(py::module &m) {
979 auto py_result = py::class_<sampler::IntegerSAResult>(m, "IntegerSAResult", py::module_local());
980 py_result.def_readonly("energy", &sampler::IntegerSAResult::energy);
981 py_result.def_readonly("solution", &sampler::IntegerSAResult::solution);
982 py_result.def_readonly("energy_history", &sampler::IntegerSAResult::energy_history);
983 py_result.def_readonly("temperature_history", &sampler::IntegerSAResult::temperature_history);
984}
985
986void declare_SampleByIntegerSA(py::module &m) {
987 // SampleByIntegerSA for IntegerQuadraticModel
988 m.def("sample_by_integer_sa_quadratic",
989 &sampler::SampleByIntegerSA<graph::IntegerQuadraticModel>,
990 "model"_a, "num_sweeps"_a, "update_method"_a, "rand_type"_a,
991 "schedule"_a, "num_reads"_a, "seed"_a, "num_threads"_a,
992 "min_T"_a, "max_T"_a, "log_history"_a);
993
994 // SampleByIntegerSA for IntegerPolynomialModel
995 m.def("sample_by_integer_sa_polynomial",
996 &sampler::SampleByIntegerSA<graph::IntegerPolynomialModel>,
997 "model"_a, "num_sweeps"_a, "update_method"_a, "rand_type"_a,
998 "schedule"_a, "num_reads"_a, "seed"_a, "num_threads"_a,
999 "min_T"_a, "max_T"_a, "log_history"_a);
1000}
1001
1002
1003template<class ModelType>
1004void declare_SASampler(py::module &m, const std::string &post_name = "") {
1006
1007 std::string name = std::string("SASampler") + post_name;
1008
1009 auto py_class = py::class_<SAS>(m, name.c_str(), py::module_local());
1010
1011 py_class.def(py::init<const ModelType&>(), "model"_a);
1012
1013 py_class.def("set_num_sweeps", &SAS::SetNumSweeps, "num_sweeps"_a);
1014 py_class.def("set_num_reads", &SAS::SetNumReads, "num_reads"_a);
1015 py_class.def("set_num_threads", &SAS::SetNumThreads, "num_threads"_a);
1016 py_class.def("set_beta_min", &SAS::SetBetaMin, "beta_min"_a);
1017 py_class.def("set_beta_max", &SAS::SetBetaMax, "beta_max"_a);
1018 py_class.def("set_beta_min_auto", &SAS::SetBetaMinAuto);
1019 py_class.def("set_beta_max_auto", &SAS::SetBetaMaxAuto);
1020 py_class.def("set_update_method", &SAS::SetUpdateMethod, "update_method"_a);
1021 py_class.def("set_random_number_engine", &SAS::SetRandomNumberEngine, "random_number_engine"_a);
1022 py_class.def("set_temperature_schedule", &SAS::SetTemperatureSchedule, "temperature_schedule"_a);
1023 py_class.def("get_model", &SAS::GetModel);
1024 py_class.def("get_num_sweeps", &SAS::GetNumSweeps);
1025 py_class.def("get_num_reads", &SAS::GetNumReads);
1026 py_class.def("get_num_threads", &SAS::GetNumThreads);
1027 py_class.def("get_beta_min", &SAS::GetBetaMin);
1028 py_class.def("get_beta_max", &SAS::GetBetaMax);
1029 py_class.def("get_update_method", &SAS::GetUpdateMethod);
1030 py_class.def("get_random_number_engine", &SAS::GetRandomNumberEngine);
1031 py_class.def("get_temperature_schedule", &SAS::GetTemperatureSchedule);
1032 py_class.def("get_seed", &SAS::GetSeed);
1033 py_class.def("get_index_list", &SAS::GetIndexList);
1034 py_class.def("get_samples", &SAS::GetSamples);
1035 py_class.def("calculate_energies", &SAS::CalculateEnergies);
1036 py_class.def("sample", py::overload_cast<>(&SAS::Sample));
1037 py_class.def("sample", py::overload_cast<const std::uint64_t>(&SAS::Sample), "seed"_a);
1038
1039 m.def("make_sa_sampler", [](const ModelType &model) {
1040 return sampler::make_sa_sampler(model);
1041 }, "model"_a);
1042
1043}
1044
1045void declare_UpdateMethod(py::module &m) {
1046 py::enum_<algorithm::UpdateMethod>(m, "UpdateMethod")
1047 .value("METROPOLIS", algorithm::UpdateMethod::METROPOLIS)
1048 .value("HEAT_BATH", algorithm::UpdateMethod::HEAT_BATH)
1049 .value("SUWA_TODO", algorithm::UpdateMethod::SUWA_TODO)
1050 .value("OPT_METROPOLIS", algorithm::UpdateMethod::OPT_METROPOLIS);
1051}
1052
1053void declare_RandomNumberEngine(py::module &m) {
1054 py::enum_<algorithm::RandomNumberEngine>(m, "RandomNumberEngine")
1055 .value("MT", algorithm::RandomNumberEngine::MT)
1056 .value("MT_64", algorithm::RandomNumberEngine::MT_64)
1057 .value("XORSHIFT", algorithm::RandomNumberEngine::XORSHIFT);
1058}
1059
1060void declare_TemperatureSchedule(py::module &m) {
1061 py::enum_<utility::TemperatureSchedule>(m, "TemperatureSchedule")
1062 .value("LINEAR", utility::TemperatureSchedule::LINEAR)
1063 .value("GEOMETRIC", utility::TemperatureSchedule::GEOMETRIC);
1064}
1065
1066
1067} // namespace openjij
Definition binary_polynomial_model.hpp:27
CSRSparse graph: just store CSR Sparse Matrix (Eigen::Sparse) The Hamiltonian is like.
Definition csr_sparse.hpp:42
FloatType calc_energy(const Spins &spins) const
calculate total energy
Definition csr_sparse.hpp:123
chimera lattice graph
Definition chimera.hpp:95
FloatType & h(std::size_t r, std::size_t c, std::size_t i)
access h(row, colum, in-chimera) (local field)
Definition chimera.hpp:458
FloatType & J(std::size_t r, std::size_t c, std::size_t i, ChimeraDir dir)
access J(row, colum, in-chimera, direction)
Definition chimera.hpp:354
two-body all-to-all interactions The Hamiltonian is like
Definition dense.hpp:44
FloatType & J(Index i, Index j)
access J_{ij}
Definition dense.hpp:211
FloatType calc_energy(const Spins &spins) const
calculate total energy
Definition dense.hpp:160
FloatType & h(Index i)
access h_{i} (local field)
Definition dense.hpp:246
Abstract graph class.
Definition graph.hpp:37
const Spins gen_spin(RandomNumberEngine &random_numder_engine) const
generate spins randomly.
Definition graph.hpp:55
const Binaries gen_binary(RandomNumberEngine &random_numder_engine) const
generate spins randomly.
Definition graph.hpp:73
std::size_t size() const noexcept
get number of spins
Definition graph.hpp:96
Definition integer_polynomial_model.hpp:20
Definition integer_quadratic_model.hpp:20
Definition ising_polynomial_model.hpp:23
Polynomial graph class, which can treat many-body interactions.
Definition polynomial.hpp:47
Sparse graph: two-body intereactions with O(1) connectivity The Hamiltonian is like.
Definition sparse.hpp:40
FloatType calc_energy(const Spins &spins) const
calculate total energy
Definition sparse.hpp:218
FloatType & h(Index i)
access h_{i} (local field)
Definition sparse.hpp:300
FloatType & J(Index i, Index j)
access J_{ij}
Definition sparse.hpp:269
square lattice graph
Definition square.hpp:64
FloatType & h(std::size_t r, std::size_t c)
access h(row, colum) (local field)
Definition square.hpp:337
FloatType & J(std::size_t r, std::size_t c, Dir dir)
access J(row, colum, direction)
Definition square.hpp:276
Class for executing simulated annealing.
Definition sa_sampler.hpp:27
ClassicalIsingPolynomial class, which is a system to solve higher order unconstrained binary optimiza...
Definition classical_ising_polynomial.hpp:36
KLocalPolynomial class, which is a system to solve higher order unconstrained binary optimization (HU...
Definition k_local_polynomial.hpp:32
xorshift random generator for c++11 random
Definition random.hpp:39
RandomNumberEngine
Definition algorithm.hpp:78
std::vector< Binary > Binaries
Definition graph.hpp:29
auto json_parse(const json &obj, bool relabel=true)
parse json object from bqm.to_serializable
Definition parse.hpp:50
ChimeraDir
direction in chimera graph
Definition chimera.hpp:46
@ MINUS_C
minus-column direction: (r, c, ind) -> (r, c-1, ind)
@ IN_0or4
inside-chimera 0or4 direction: (r, c, ind) -> (r, c, 0or4)
@ IN_2or6
inside-chimera 2or6 direction: (r, c, ind) -> (r, c, 2or6)
@ MINUS_R
minus-row direction: (r, c, ind) -> (r-1, c, ind)
@ IN_1or5
inside-chimera 1or5 direction: (r, c, ind) -> (r, c, 1or5)
@ IN_3or7
inside-chimera 3or7 direction: (r, c, ind) -> (r, c, 3or7)
@ PLUS_C
plus-column direction: (r, c, ind) -> (r, c+1, ind)
@ PLUS_R
plus-row direction: (r, c, ind) -> (r+1, c, ind)
std::vector< Spin > Spins
Definition graph.hpp:27
@ MINUS_C
minux-column direction: (r, c) -> (r, c-1)
@ MINUS_R
minus-row direction: (r, c) -> (r-1, c)
@ PLUS_C
plus-column direction: (r, c) -> (r, c+1)
@ PLUS_R
plus-row direction: (r, c) -> (r+1, c)
std::size_t Index
Definition graph.hpp:30
std::vector< graph::Spins > TrotterSpins
trotterized spin (std::vector<Spins>) trotter_spins[i][j] -> jth spin in ith trotter slice.
Definition transverse_ising.hpp:32
std::vector< Schedule< SystemType > > ScheduleList
schedule list alias
Definition schedule_list.hpp:135
Definition algorithm.hpp:24
void declare_Dir(py::module &m)
Definition declare.hpp:273
void declare_Chimera(py::module &m, const std::string &suffix)
Definition declare.hpp:349
void declare_IsingPolynomialModel(py::module &m)
Definition declare.hpp:914
void declare_ClassicalConstraintUpdaterParameter(py::module &m)
Definition declare.hpp:830
void declare_ClassicalIsingPolynomial(py::module &m, const std::string &gtype_str)
Definition declare.hpp:442
void declare_TransverseFieldUpdaterParameter(py::module &m)
Definition declare.hpp:846
void declare_KLocalPolynomial(py::module &m, const std::string &gtype_str)
Definition declare.hpp:503
void declare_IntegerSAResult(py::module &m)
Definition declare.hpp:978
void declare_Schedule(py::module &m, const std::string &systemtype_str)
Definition declare.hpp:861
void declare_Dense(py::module &m, const std::string &suffix)
Definition declare.hpp:75
void declare_CSRSparse(py::module &m, const std::string &suffix)
Definition declare.hpp:197
void declare_TemperatureSchedule(py::module &m)
Definition declare.hpp:1060
void declare_Algorithm_run(py::module &m, const std::string &updater_str)
Definition declare.hpp:690
void declare_ContinuousTimeIsing(py::module &m, const std::string &gtype_str)
Definition declare.hpp:645
void declare_ClassicalIsing(py::module &m, const std::string &gtype_str)
Definition declare.hpp:411
void declare_TransverseIsing(py::module &m, const std::string &gtype_str)
Definition declare.hpp:587
void declare_RandomNumberEngine(py::module &m)
Definition declare.hpp:1053
void declare_BinaryPolynomialModel(py::module &m)
Definition declare.hpp:892
void declare_get_solution(py::module &m)
Definition declare.hpp:883
void declare_ClassicalUpdaterParameter(py::module &m)
Definition declare.hpp:819
void declare_ChimeraDir(py::module &m)
Definition declare.hpp:335
void declare_IntegerQuadraticModel(py::module &m)
Definition declare.hpp:935
void declare_Square(py::module &m, const std::string &suffix)
Definition declare.hpp:283
void declare_Graph(py::module &m)
Definition declare.hpp:43
void declare_UpdateMethod(py::module &m)
Definition declare.hpp:1045
void declare_SampleByIntegerSA(py::module &m)
Definition declare.hpp:986
double FloatType
Note:
Definition compile_config.hpp:37
void declare_Polynomial(py::module &m, const std::string &suffix)
Definition declare.hpp:221
void declare_Sparse(py::module &m, const std::string &suffix)
Definition declare.hpp:133
std::string repr_impl(const utility::UpdaterParameter< SystemType > &)
void declare_SASampler(py::module &m, const std::string &post_name="")
Definition declare.hpp:1004
void declare_IntegerPolynomialModel(py::module &m)
Definition declare.hpp:957
static void run(System &system, RandomNumberEngine &random_number_engine, const utility::ScheduleList< typename system::get_system_type< System >::type > &schedule_list, const std::function< void(const System &, const utility::UpdaterParameter< typename system::get_system_type< System >::type > &)> &callback=nullptr)
Definition algorithm.hpp:29
ClassicalIsing structure (system for classical Ising model)
Definition classical_ising.hpp:38
Continuous Time Quantum Ising system.
Definition continuous_time_ising.hpp:34
TransverseIsing structure with discrete-time trotter spins.
Definition transverse_ising.hpp:39
typename System::system_type type
Definition system.hpp:77
schedule struct
Definition schedule_list.hpp:121
std::size_t one_mc_step
Definition schedule_list.hpp:126
UpdaterParameter< SystemType > updater_parameter
Definition schedule_list.hpp:125
updater paramter for classical ising model with a single constraint
Definition schedule_list.hpp:52
updater parameter for classical ising system
Definition schedule_list.hpp:37
updater paramter for transverse ising model
Definition schedule_list.hpp:74
updater parameter for monte carlo simulation
Definition schedule_list.hpp:32