17#include <pybind11/pybind11.h>
18#include <pybind11/stl.h>
19#include <pybind11/functional.h>
20#include <pybind11/eigen.h>
22#include <pybind11_json/pybind11_json.hpp>
24#include <nlohmann/json.hpp>
33namespace py = pybind11;
35using namespace py::literals;
43 py::class_<graph::Graph>(m,
"Graph", py::module_local())
44 .def(py::init<std::size_t>(),
"num_spins"_a)
73template <
typename FloatType>
76 using json = nlohmann::json;
78 auto str = std::string(
"Dense") + suffix;
79 py::class_<graph::Dense<FloatType>,
graph::Graph>(m, str.c_str(),
81 .def(py::init<std::size_t>(),
"num_spins"_a)
82 .def(py::init([](py::object obj) {
83 return std::unique_ptr<graph::Dense<FloatType>>(
88 .def(
"set_interaction_matrix",
93 const Eigen::Matrix<FloatType, Eigen::Dynamic, 1, Eigen::ColMajor>
105 const std::pair<std::size_t, std::size_t> &key,
106 FloatType val) { self.
J(key.first, key.second) = val; },
111 const std::pair<std::size_t, std::size_t> &key) {
112 return self.
J(key.first, key.second);
131template <
typename FloatType>
134 using json = nlohmann::json;
136 auto str = std::string(
"Sparse") + suffix;
137 py::class_<graph::Sparse<FloatType>,
graph::Graph>(m, str.c_str(),
139 .def(py::init<std::size_t, std::size_t>(),
"num_spins"_a,
"num_edges"_a)
140 .def(py::init<std::size_t>(),
"num_spins"_a)
141 .def(py::init([](py::object obj, std::size_t num_edges) {
142 return std::unique_ptr<graph::Sparse<FloatType>>(
146 "obj"_a,
"num_edges"_a)
147 .def(py::init([](py::object obj) {
148 return std::unique_ptr<graph::Sparse<FloatType>>(
158 const Eigen::Matrix<FloatType, Eigen::Dynamic, 1, Eigen::ColMajor>
170 const std::pair<std::size_t, std::size_t> &key,
171 FloatType val) { self.
J(key.first, key.second) = val; },
176 const std::pair<std::size_t, std::size_t> &key) {
177 return self.
J(key.first, key.second);
195template <
typename FloatType>
198 auto str = std::string(
"CSRSparse") + suffix;
199 py::class_<graph::CSRSparse<FloatType>,
graph::Graph>(m, str.c_str(),
201 .def(py::init<
const Eigen::SparseMatrix<FloatType, Eigen::RowMajor> &>(),
"interaction"_a)
206 const Eigen::Matrix<FloatType, Eigen::Dynamic, 1, Eigen::ColMajor>
219template <
typename FloatType>
222 using json = nlohmann::json;
224 auto str = std::string(
"Polynomial") + suffix;
226 py::class_<Poly, graph::Graph>(m, str.c_str(), py::module_local())
227 .def(py::init<const std::size_t>(),
"num_variables"_a)
228 .def(py::init([](
const py::object &obj) {
229 return std::unique_ptr<graph::Polynomial<FloatType>>(
233 .def(
"get_num_interactions", &Poly::get_num_interactions)
234 .def(
"calc_energy", &Poly::calc_energy,
"spins"_a,
"omp_flag"_a =
true)
235 .def(
"energy", &Poly::energy,
"spins"_a,
"omp_flag"_a =
true)
244 [](Poly &self, std::vector<graph::Index> &key,
FloatType val) {
250 [](
const Poly &self, std::vector<graph::Index> &key) {
256 [](
const Poly &self,
graph::Index key) {
return self.J(key); },
258 .def(
"get_polynomial", [](
const Poly &self) {
259 py::dict py_polynomial;
260 for (std::size_t i = 0; i < self.get_keys().size(); ++i) {
262 for (
const auto &it : self.get_keys()[i]) {
263 temp = temp + py::make_tuple(it);
265 py_polynomial[temp] = self.get_values()[i];
267 return py_polynomial;
273 py::enum_<graph::Dir>(m,
"Dir", py::module_local())
281template <
typename FloatType>
284 using json = nlohmann::json;
286 auto str = std::string(
"Square") + suffix;
288 m, str.c_str(), py::module_local())
289 .def(py::init<std::size_t, std::size_t, FloatType>(),
"num_row"_a,
290 "num_column"_a,
"init_val"_a = 0)
292 .def(py::init([](py::object obj, std::size_t num_row,
293 std::size_t num_column,
FloatType init_val) {
294 return std::unique_ptr<graph::Square<FloatType>>(
296 num_column, init_val));
298 "obj"_a,
"num_row"_a,
"num_column"_a,
"init_val"_a = 0)
306 const std::tuple<std::size_t, std::size_t, graph::Dir> &key,
308 self.
J(std::get<0>(key), std::get<1>(key), std::get<2>(key)) = val;
314 const std::tuple<std::size_t, std::size_t, graph::Dir> &key) {
315 return self.
J(std::get<0>(key), std::get<1>(key), std::get<2>(key));
321 const std::pair<std::size_t, std::size_t> &key,
322 FloatType val) { self.
h(key.first, key.second) = val; },
327 const std::pair<std::size_t, std::size_t> &key) {
328 return self.
h(key.first, key.second);
335 py::enum_<graph::ChimeraDir>(m,
"ChimeraDir")
347template <
typename FloatType>
350 using json = nlohmann::json;
352 auto str = std::string(
"Chimera") + suffix;
354 m, str.c_str(), py::module_local())
355 .def(py::init<std::size_t, std::size_t, FloatType>(),
"num_row"_a,
356 "num_column"_a,
"init_val"_a = 0)
358 .def(py::init([](py::object obj, std::size_t num_row,
359 std::size_t num_column,
FloatType init_val) {
360 return std::unique_ptr<graph::Chimera<FloatType>>(
362 num_column, init_val));
364 "obj"_a,
"num_row"_a,
"num_column"_a,
"init_val"_a = 0)
373 const std::tuple<std::size_t, std::size_t, std::size_t,
376 self.
J(std::get<0>(key), std::get<1>(key), std::get<2>(key),
377 std::get<3>(key)) = val;
383 const std::tuple<std::size_t, std::size_t, std::size_t,
385 return self.
J(std::get<0>(key), std::get<1>(key), std::get<2>(key),
392 const std::tuple<std::size_t, std::size_t, std::size_t> &key,
394 self.
h(std::get<0>(key), std::get<1>(key), std::get<2>(key)) = val;
400 const std::tuple<std::size_t, std::size_t, std::size_t> &key) {
401 return self.
h(std::get<0>(key), std::get<1>(key), std::get<2>(key));
409template <
typename GraphType>
411 const std::string >ype_str) {
415 auto str = std::string(
"ClassicalIsing") + gtype_str;
416 py::class_<ClassicalIsing>(m, str.c_str(), py::module_local())
417 .def(py::init<const graph::Spins &, const GraphType &>(),
"init_spin"_a,
418 "init_interaction"_a)
421 [](ClassicalIsing &self,
const graph::Spins &init_spin) {
422 self.reset_spins(init_spin);
425 .def_readwrite(
"spin", &ClassicalIsing::spin)
426 .def_readonly(
"interaction", &ClassicalIsing::interaction)
427 .def_readonly(
"num_spins", &ClassicalIsing::num_spins);
430 auto mkci_str = std::string(
"make_classical_ising");
433 [](
const graph::Spins &init_spin,
const GraphType &init_interaction) {
434 return system::make_classical_ising(init_spin, init_interaction);
436 "init_spin"_a,
"init_interaction"_a);
440template <
typename GraphType>
442 const std::string >ype_str) {
445 auto str = std::string(
"ClassicalIsing") + gtype_str;
447 py::class_<CIP>(m, str.c_str(), py::module_local())
449 const cimod::Vartype>(),
450 "init_variables"_a,
"init_interaction"_a,
"vartype"_a)
452 const std::string>(),
453 "init_variables"_a,
"init_interaction"_a,
"vartype"_a)
454 .def(py::init([](
const graph::Spins &init_spins,
const py::object &obj) {
455 return std::unique_ptr<CIP>(
456 new CIP(init_spins,
static_cast<nlohmann::json
>(obj)));
458 "init_spin"_a,
"obj"_a)
459 .def_readonly(
"variables", &CIP::variables)
460 .def_readonly(
"num_variables", &CIP::num_variables)
461 .def(
"reset_variables", &CIP::reset_variables,
"init_variables"_a)
462 .def(
"reset_spins", &CIP::reset_variables,
"init_spins"_a)
463 .def(
"get_values", &CIP::get_values)
464 .def(
"get_keys", &CIP::get_keys)
465 .def(
"get_adj", &CIP::get_adj)
466 .def(
"get_vartype_to_string", &CIP::get_vartype_string)
467 .def(
"get_max_effective_dE", &CIP::get_max_effective_dE)
468 .def(
"get_min_effective_dE", &CIP::get_min_effective_dE);
471 auto mkcip_str = std::string(
"make_classical_ising_polynomial");
474 [](
const graph::Spins &init_spin,
const GraphType &init_interaction,
475 const cimod::Vartype vartype) {
476 return system::make_classical_ising_polynomial(
477 init_spin, init_interaction, vartype);
479 "init_spin"_a,
"init_interaction"_a,
"vartype"_a);
484 [](
const graph::Spins &init_spin,
const GraphType &init_interaction,
485 const std::string vartype) {
486 return system::make_classical_ising_polynomial(
487 init_spin, init_interaction, vartype);
489 "init_spin"_a,
"init_interaction"_a,
"vartype"_a);
494 [](
const graph::Spins &init_spin,
const py::object &obj) {
495 return system::make_classical_ising_polynomial(
496 init_spin, static_cast<nlohmann::json>(obj));
498 "init_spin"_a,
"obj"_a);
501template <
typename GraphType>
503 const std::string >ype_str) {
506 auto str = std::string(
"KLocal") + gtype_str;
508 py::class_<KLP>(m, str.c_str(), py::module_local())
509 .def(py::init<const graph::Binaries &, const GraphType &>(),
510 "init_spin"_a,
"init_interaction"_a)
513 return std::unique_ptr<KLP>(
514 new KLP(init_binaries,
static_cast<nlohmann::json
>(obj)));
516 "init_binaries"_a,
"obj"_a)
517 .def_readonly(
"binaries", &KLP::binaries)
518 .def_readonly(
"num_binaries", &KLP::num_binaries)
519 .def_readonly(
"count_call_updater", &KLP::count_call_updater)
520 .def_property_readonly(
"num_interactions", &KLP::GetNumInteractions)
521 .def_readwrite(
"rate_call_k_local", &KLP::rate_call_k_local)
522 .def(
"reset_binaries", &KLP::reset_binaries,
"init_binaries"_a)
523 .def(
"reset_spins", &KLP::reset_binaries,
"init_spins"_a)
524 .def(
"reset_dE", &KLP::reset_dE)
525 .def(
"get_active_binaries", &KLP::get_active_binaries)
526 .def(
"get_max_effective_dE", &KLP::get_max_effective_dE)
527 .def(
"get_min_effective_dE", &KLP::get_min_effective_dE)
528 .def(
"get_keys", &KLP::get_keys)
529 .def(
"get_values", &KLP::get_values)
530 .def(
"get_vartype_to_string", &KLP::get_vartype_string)
531 .def(
"get_polynomial",
532 [](
const KLP &self) {
533 py::dict py_polynomial;
534 const auto &poly_key_list = self.get_keys();
535 const auto &poly_value_list = self.get_values();
536 for (std::size_t i = 0; i < poly_key_list.size(); ++i) {
538 for (
const auto &index : poly_key_list[i]) {
539 tuple = tuple + py::make_tuple(index);
541 py_polynomial[tuple] = poly_value_list[i];
543 return py_polynomial;
545 .def(
"get_adj", [](
const KLP &self) {
546 const auto &adj = self.get_adj();
547 const auto &poly_key_list = self.get_keys();
548 const auto &poly_value_list = self.get_values();
550 for (int64_t i = 0; i < self.num_binaries; ++i) {
552 for (
const auto &index_key : adj[i]) {
554 for (
const auto &index_binary : poly_key_list[index_key]) {
555 tuple = tuple + py::make_tuple(index_binary);
557 dict[tuple] = poly_value_list[index_key];
559 py_adj[py::int_(i)] = dict;
565 auto mkcip_str = std::string(
"make_k_local_polynomial");
568 [](
const graph::Spins &init_spin,
const GraphType &init_interaction) {
569 return system::make_k_local_polynomial(init_spin, init_interaction);
571 "init_spin"_a,
"init_interaction"_a);
574 auto mkcip_json_str = std::string(
"make_k_local_polynomial");
576 mkcip_json_str.c_str(),
577 [](
const graph::Spins &init_spin,
const py::object &obj) {
578 return system::make_k_local_polynomial(
579 init_spin, static_cast<nlohmann::json>(obj));
581 "init_spin"_a,
"obj"_a);
585template <
typename GraphType>
587 const std::string >ype_str) {
590 using FloatType =
typename GraphType::value_type;
592 auto str = std::string(
"TransverseIsing") + gtype_str;
593 py::class_<TransverseIsing>(m, str.c_str(), py::module_local())
596 "init_spin"_a,
"init_interaction"_a,
"gamma"_a)
599 "init_classical_spins"_a,
"init_interaction"_a,
"gamma"_a,
600 "num_trotter_slices"_a)
603 [](TransverseIsing &self,
605 self.reset_spins(init_trotter_spins);
607 "init_trotter_spins"_a)
610 [](TransverseIsing &self,
const graph::Spins &classical_spins) {
611 self.reset_spins(classical_spins);
614 .def_readwrite(
"trotter_spins", &TransverseIsing::trotter_spins)
615 .def_readonly(
"interaction", &TransverseIsing::interaction)
616 .def_readonly(
"num_classical_spins",
617 &TransverseIsing::num_classical_spins)
618 .def_readwrite(
"gamma", &TransverseIsing::gamma);
621 auto mkci_str = std::string(
"make_transverse_ising");
625 const GraphType &init_interaction,
double gamma) {
626 return system::make_transverse_ising(init_trotter_spins,
627 init_interaction, gamma);
629 "init_trotter_spins"_a,
"init_interaction"_a,
"gamma"_a);
633 [](
const graph::Spins &classical_spins,
const GraphType &init_interaction,
634 double gamma, std::size_t num_trotter_slices) {
635 return system::make_transverse_ising(classical_spins, init_interaction,
636 gamma, num_trotter_slices);
638 "classical_spins"_a,
"init_interaction"_a,
"gamma"_a,
639 "num_trotter_slices"_a);
643template <
typename GraphType>
645 const std::string >ype_str) {
648 using FloatType =
typename GraphType::value_type;
649 using SpinConfiguration =
typename TransverseIsing::SpinConfiguration;
651 auto str = std::string(
"ContinuousTimeIsing") + gtype_str;
652 py::class_<TransverseIsing>(m, str.c_str(), py::module_local())
653 .def(py::init<const SpinConfiguration &, const GraphType &, FloatType>(),
654 "init_spin_config"_a,
"init_interaction"_a,
"gamma"_a)
655 .def(py::init<const graph::Spins &, const GraphType &, FloatType>(),
656 "init_spins"_a,
"init_interaction"_a,
"gamma"_a)
659 [](TransverseIsing &self,
const SpinConfiguration &init_spin_config) {
660 self.reset_spins(init_spin_config);
662 "init_spin_config"_a)
665 [](TransverseIsing &self,
const graph::Spins &classical_spins) {
666 self.reset_spins(classical_spins);
669 .def_readwrite(
"spin_config", &TransverseIsing::spin_config)
670 .def_readonly(
"interaction", &TransverseIsing::interaction)
671 .def_readonly(
"num_spins", &TransverseIsing::num_spins)
672 .def_readonly(
"gamma", &TransverseIsing::gamma);
675 auto mkci_str = std::string(
"make_continuous_time_ising");
678 [](
const graph::Spins &classical_spins,
const GraphType &init_interaction,
680 return system::make_continuous_time_ising(classical_spins,
681 init_interaction, gamma);
683 "classical_spins"_a,
"init_interaction"_a,
"gamma"_a);
687template <
template <
typename>
class Updater,
typename System,
688 typename RandomNumberEngine>
690 const std::string &updater_str) {
691 auto str = std::string(
"Algorithm_") + updater_str + std::string(
"_run");
696 [](System &system, std::size_t seed,
698 const std::function<
void(
702 py::gil_scoped_release release;
704 using Callback = std::function<void(
705 const System &, const utility::UpdaterParameter<SystemType> &)>;
706 RandomNumberEngine rng(seed);
707 algorithm::Algorithm<Updater>::run(
708 system, rng, schedule_list,
709 callback ? [=](const System &system,
710 const utility::UpdaterParameter<SystemType>
711 ¶m) { callback(system, param.get_tuple()); }
712 : Callback(
nullptr));
714 py::gil_scoped_acquire acquire;
716 "system"_a,
"seed"_a,
"schedule_list"_a,
"callback"_a =
nullptr);
721 [](System &system,
const utility::ScheduleList<SystemType> &schedule_list,
722 const std::function<void(
724 const typename utility::UpdaterParameter<SystemType>::Tuple &)>
726 py::gil_scoped_release release;
728 using Callback = std::function<void(
729 const System &,
const utility::UpdaterParameter<SystemType> &)>;
730 RandomNumberEngine rng(std::random_device{}());
732 system, rng, schedule_list,
733 callback ? [=](
const System &system,
734 const utility::UpdaterParameter<SystemType>
735 ¶m) { callback(system, param.get_tuple()); }
736 : Callback(
nullptr));
738 py::gil_scoped_acquire acquire;
740 "system"_a,
"schedule_list"_a,
"callback"_a =
nullptr);
743 using TupleList = std::vector<std::pair<
744 typename utility::UpdaterParameter<SystemType>::Tuple, std::size_t>>;
749 [](System &system, std::size_t seed,
const TupleList &tuplelist,
750 const std::function<void(
752 const typename utility::UpdaterParameter<SystemType>::Tuple &)>
754 py::gil_scoped_release release;
756 using Callback = std::function<void(
757 const System &,
const utility::UpdaterParameter<SystemType> &)>;
760 system, rng, utility::make_schedule_list<SystemType>(tuplelist),
761 callback ? [=](
const System &system,
762 const utility::UpdaterParameter<SystemType>
763 ¶m) { callback(system, param.get_tuple()); }
764 : Callback(
nullptr));
766 py::gil_scoped_acquire acquire;
768 "system"_a,
"seed"_a,
"tuplelist"_a,
"callback"_a =
nullptr);
773 [](System &system,
const TupleList &tuplelist,
774 const std::function<void(
776 const typename utility::UpdaterParameter<SystemType>::Tuple &)>
778 py::gil_scoped_release release;
779 using Callback = std::function<void(
780 const System &,
const utility::UpdaterParameter<SystemType> &)>;
783 system, rng, utility::make_schedule_list<SystemType>(tuplelist),
784 callback ? [=](
const System &system,
785 const utility::UpdaterParameter<SystemType>
786 ¶m) { callback(system, param.get_tuple()); }
787 : Callback(
nullptr));
789 py::gil_scoped_acquire acquire;
791 "system"_a,
"tuplelist"_a,
"callback"_a =
nullptr);
795template <
typename SystemType>
801 return "(beta: " + std::to_string(obj.beta) +
")";
807 return "(beta: " + std::to_string(obj.beta) +
808 ", lambda: " + std::to_string(obj.lambda) +
")";
814 return "(beta: " + std::to_string(obj.beta) +
815 ", s: " + std::to_string(obj.s) +
")";
819 py::class_<utility::ClassicalUpdaterParameter>(m,
"ClassicalUpdaterParameter",
822 .def(py::init<double>(),
"beta"_a)
823 .def_readwrite(
"beta", &utility::ClassicalUpdaterParameter::beta)
830 py::class_<utility::ClassicalConstraintUpdaterParameter>(
831 m,
"ClassicalConstraintUpdaterParameter", py::module_local())
833 .def(py::init<double, double>(),
"beta"_a,
"lambda"_a)
834 .def(py::init<
const std::pair<double, double> &>(),
"obj"_a)
835 .def_readwrite(
"beta",
836 &utility::ClassicalConstraintUpdaterParameter::beta)
837 .def_readwrite(
"lambda",
838 &utility::ClassicalConstraintUpdaterParameter::lambda)
846 py::class_<utility::TransverseFieldUpdaterParameter>(
847 m,
"TransverseFieldUpdaterParameter", py::module_local())
849 .def(py::init<double, double>(),
"beta"_a,
"s"_a)
850 .def(py::init<
const std::pair<double, double> &>(),
"obj"_a)
851 .def_readwrite(
"beta", &utility::TransverseFieldUpdaterParameter::beta)
852 .def_readwrite(
"s", &utility::TransverseFieldUpdaterParameter::s)
859template <
typename SystemType>
861 auto str = systemtype_str +
"Schedule";
862 py::class_<utility::Schedule<SystemType>>(m, str.c_str(), py::module_local())
864 .def(py::init<
const std::pair<
868 .def_readwrite(
"updater_parameter",
876 m.def(
"make_schedule_list", &utility::make_schedule_list<SystemType>,
885 [](
const System &system) {
return result::get_solution(system); },
890template<
typename FloatType>
894 std::string name = std::string(
"BinaryPolynomialModel");
895 auto py_class = py::class_<BPM>(m, name.c_str(), py::module_local());
897 py_class.def(py::init<
const std::vector<std::vector<typename BPM::IndexType>>&,
898 const std::vector<FloatType>&>(),
899 "key_list"_a,
"value_list"_a);
901 py_class.def(
"get_degree", &BPM::GetDegree);
902 py_class.def(
"get_system_size", &BPM::GetSystemSize);
903 py_class.def(
"get_index_list", &BPM::GetIndexList);
904 py_class.def(
"get_index_map", &BPM::GetIndexMap);
905 py_class.def(
"get_key_value_list", &BPM::GetKeyValueList);
906 py_class.def(
"get_adjacency_list", &BPM::GetAdjacencyList);
907 py_class.def(
"get_estimated_min_energy_difference", &BPM::GetEstimatedMinEnergyDifference);
908 py_class.def(
"get_estimated_max_energy_difference", &BPM::GetEstimatedMaxEnergyDifference);
909 py_class.def(
"calculate_energy", &BPM::CalculateEnergy);
912template<
typename FloatType>
916 std::string name = std::string(
"IsingPolynomialModel");
917 auto py_class = py::class_<IPM>(m, name.c_str(), py::module_local());
919 py_class.def(py::init<std::vector<std::vector<typename IPM::IndexType>>&,
920 std::vector<FloatType>&>(),
921 "key_list"_a,
"value_list"_a);
923 py_class.def(
"get_degree", &IPM::GetDegree);
924 py_class.def(
"get_system_size", &IPM::GetSystemSize);
925 py_class.def(
"get_index_list", &IPM::GetIndexList);
926 py_class.def(
"get_index_map", &IPM::GetIndexMap);
927 py_class.def(
"get_key_value_list", &IPM::GetKeyValueList);
928 py_class.def(
"get_adjacency_list", &IPM::GetAdjacencyList);
929 py_class.def(
"get_estimated_min_energy_difference", &IPM::GetEstimatedMinEnergyDifference);
930 py_class.def(
"get_estimated_max_energy_difference", &IPM::GetEstimatedMaxEnergyDifference);
931 py_class.def(
"calculate_energy", &IPM::CalculateEnergy);
935template<
class ModelType>
939 std::string name = std::string(
"SASampler") + post_name;
941 auto py_class = py::class_<SAS>(m, name.c_str(), py::module_local());
943 py_class.def(py::init<const ModelType&>(),
"model"_a);
945 py_class.def(
"set_num_sweeps", &SAS::SetNumSweeps,
"num_sweeps"_a);
946 py_class.def(
"set_num_reads", &SAS::SetNumReads,
"num_reads"_a);
947 py_class.def(
"set_num_threads", &SAS::SetNumThreads,
"num_threads"_a);
948 py_class.def(
"set_beta_min", &SAS::SetBetaMin,
"beta_min"_a);
949 py_class.def(
"set_beta_max", &SAS::SetBetaMax,
"beta_max"_a);
950 py_class.def(
"set_beta_min_auto", &SAS::SetBetaMinAuto);
951 py_class.def(
"set_beta_max_auto", &SAS::SetBetaMaxAuto);
952 py_class.def(
"set_update_method", &SAS::SetUpdateMethod,
"update_method"_a);
953 py_class.def(
"set_random_number_engine", &SAS::SetRandomNumberEngine,
"random_number_engine"_a);
954 py_class.def(
"set_temperature_schedule", &SAS::SetTemperatureSchedule,
"temperature_schedule"_a);
955 py_class.def(
"get_model", &SAS::GetModel);
956 py_class.def(
"get_num_sweeps", &SAS::GetNumSweeps);
957 py_class.def(
"get_num_reads", &SAS::GetNumReads);
958 py_class.def(
"get_num_threads", &SAS::GetNumThreads);
959 py_class.def(
"get_beta_min", &SAS::GetBetaMin);
960 py_class.def(
"get_beta_max", &SAS::GetBetaMax);
961 py_class.def(
"get_update_method", &SAS::GetUpdateMethod);
962 py_class.def(
"get_random_number_engine", &SAS::GetRandomNumberEngine);
963 py_class.def(
"get_temperature_schedule", &SAS::GetTemperatureSchedule);
964 py_class.def(
"get_seed", &SAS::GetSeed);
965 py_class.def(
"get_index_list", &SAS::GetIndexList);
966 py_class.def(
"get_samples", &SAS::GetSamples);
967 py_class.def(
"calculate_energies", &SAS::CalculateEnergies);
968 py_class.def(
"sample", py::overload_cast<>(&SAS::Sample));
969 py_class.def(
"sample", py::overload_cast<const std::uint64_t>(&SAS::Sample),
"seed"_a);
971 m.def(
"make_sa_sampler", [](
const ModelType &model) {
972 return sampler::make_sa_sampler(model);
978 py::enum_<algorithm::UpdateMethod>(m,
"UpdateMethod")
979 .value(
"METROPOLIS", algorithm::UpdateMethod::METROPOLIS)
980 .value(
"HEAT_BATH", algorithm::UpdateMethod::HEAT_BATH);
984 py::enum_<algorithm::RandomNumberEngine>(m,
"RandomNumberEngine")
985 .value(
"MT", algorithm::RandomNumberEngine::MT)
986 .value(
"MT_64", algorithm::RandomNumberEngine::MT_64)
987 .value(
"XORSHIFT", algorithm::RandomNumberEngine::XORSHIFT);
991 py::enum_<utility::TemperatureSchedule>(m,
"TemperatureSchedule")
992 .value(
"LINEAR", utility::TemperatureSchedule::LINEAR)
993 .value(
"GEOMETRIC", utility::TemperatureSchedule::GEOMETRIC);
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 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:73
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:272
void declare_Chimera(py::module &m, const std::string &suffix)
Definition declare.hpp:348
void declare_IsingPolynomialModel(py::module &m)
Definition declare.hpp:913
void declare_ClassicalConstraintUpdaterParameter(py::module &m)
Definition declare.hpp:829
void declare_ClassicalIsingPolynomial(py::module &m, const std::string >ype_str)
Definition declare.hpp:441
void declare_TransverseFieldUpdaterParameter(py::module &m)
Definition declare.hpp:845
void declare_KLocalPolynomial(py::module &m, const std::string >ype_str)
Definition declare.hpp:502
void declare_Schedule(py::module &m, const std::string &systemtype_str)
Definition declare.hpp:860
void declare_Dense(py::module &m, const std::string &suffix)
Definition declare.hpp:74
void declare_CSRSparse(py::module &m, const std::string &suffix)
Definition declare.hpp:196
void declare_TemperatureSchedule(py::module &m)
Definition declare.hpp:990
void declare_Algorithm_run(py::module &m, const std::string &updater_str)
Definition declare.hpp:689
void declare_ContinuousTimeIsing(py::module &m, const std::string >ype_str)
Definition declare.hpp:644
void declare_ClassicalIsing(py::module &m, const std::string >ype_str)
Definition declare.hpp:410
void declare_TransverseIsing(py::module &m, const std::string >ype_str)
Definition declare.hpp:586
void declare_RandomNumberEngine(py::module &m)
Definition declare.hpp:983
void declare_BinaryPolynomialModel(py::module &m)
Definition declare.hpp:891
void declare_get_solution(py::module &m)
Definition declare.hpp:882
void declare_ClassicalUpdaterParameter(py::module &m)
Definition declare.hpp:818
void declare_ChimeraDir(py::module &m)
Definition declare.hpp:334
void declare_Square(py::module &m, const std::string &suffix)
Definition declare.hpp:282
void declare_Graph(py::module &m)
Definition declare.hpp:42
void declare_UpdateMethod(py::module &m)
Definition declare.hpp:977
double FloatType
Note:
Definition compile_config.hpp:37
void declare_Polynomial(py::module &m, const std::string &suffix)
Definition declare.hpp:220
void declare_Sparse(py::module &m, const std::string &suffix)
Definition declare.hpp:132
std::string repr_impl(const utility::UpdaterParameter< SystemType > &)
void declare_SASampler(py::module &m, const std::string &post_name="")
Definition declare.hpp:936
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