41using ChimeraIndex = std::tuple<std::size_t, std::size_t, std::size_t>;
94template <
typename FloatType =
double>
96 static_assert(std::is_arithmetic<FloatType>::value,
97 "argument must be an arithmetic type");
127 inline std::size_t
mod_r(std::int64_t a)
const {
139 inline std::size_t
mod_c(std::int64_t a)
const {
152 std::int64_t r1, c1, i1, r2, c2, i2;
153 std::tie(r1, c1, i1) =
to_rci(idx1);
154 std::tie(r2, c2, i2) =
to_rci(idx2);
155 if (!((r1 == r2 && std::abs(c1 - c2) == 1 && i1 == i2 &&
157 (c1 == c2 && std::abs(r1 - r2) == 1 && i1 == i2 &&
159 (r1 == r2 && c1 == c2 && i1 < 4 && 4 <= i2) ||
160 (r1 == r2 && c1 == c2 && i2 < 4 && 4 <= i1) ||
161 (r1 == r2 && c1 == c2 && i1 == i2))
163 throw std::runtime_error(
"invalid index pair " + std::to_string(idx1) +
164 " " + std::to_string(idx2) +
165 " inserted in Chimera");
179 Index to_ind(std::int64_t r, std::int64_t c, std::int64_t i)
const {
182 if (!(-1 <= r && r <=
static_cast<std::int64_t
>(
_num_row))) {
183 throw std::runtime_error(
"invalid value r=" + std::to_string(r) +
184 " inserted in Chimera");
187 if (!(-1 <= c && c <=
static_cast<std::int64_t
>(
_num_column))) {
188 throw std::runtime_error(
"invalid value c=" + std::to_string(c) +
189 " inserted in Chimera");
193 throw std::runtime_error(
"invalid value i=" + std::to_string(i) +
194 " inserted in Chimera");
210 throw std::runtime_error(
"invalid value index=" + std::to_string(ind) +
211 " inserted in Chimera");
218 std::int64_t i = ind;
219 return std::make_tuple(r, c, i);
236 for (std::size_t r = 0; r <
_num_row; r++) {
240 if (r > 0 && i < 4) {
245 if (c > 0 && 4 <= i) {
250 if (r < num_row - 1 && i < 4) {
255 if (c < num_column - 1 && 4 <= i) {
288 Chimera(
const json &j, std::size_t num_row, std::size_t num_column,
292 throw std::runtime_error(
"number of system size does not match");
297 for (
auto &&elem : bqm.get_quadratic()) {
298 const auto &key = elem.first;
299 const auto &val = elem.second;
304 for (
auto &&elem : bqm.get_linear()) {
305 const auto &key = elem.first;
306 const auto &val = elem.second;
363 to_ind(r, c, i),
to_ind(
static_cast<std::int64_t
>(r) - 1, c, i));
367 to_ind(r, c, i),
to_ind(r,
static_cast<std::int64_t
>(c) - 1, i));
371 to_ind(r, c, i),
to_ind(
static_cast<std::int64_t
>(r) + 1, c, i));
375 to_ind(r, c, i),
to_ind(r,
static_cast<std::int64_t
>(c) + 1, i));
379 to_ind(r, c, (i < 4) ? 4 : 0));
382 to_ind(r, c, (i < 4) ? 5 : 1));
385 to_ind(r, c, (i < 4) ? 6 : 2));
388 to_ind(r, c, (i < 4) ? 7 : 3));
406 const FloatType &
J(std::size_t r, std::size_t c, std::size_t i,
416 to_ind(r, c, i),
to_ind(
static_cast<std::int64_t
>(r) - 1, c, i));
420 to_ind(r, c, i),
to_ind(r,
static_cast<std::int64_t
>(c) - 1, i));
424 to_ind(r, c, i),
to_ind(
static_cast<std::int64_t
>(r) + 1, c, i));
428 to_ind(r, c, i),
to_ind(r,
static_cast<std::int64_t
>(c) + 1, i));
432 to_ind(r, c, (i < 4) ? 4 : 0));
435 to_ind(r, c, (i < 4) ? 5 : 1));
438 to_ind(r, c, (i < 4) ? 6 : 2));
441 to_ind(r, c, (i < 4) ? 7 : 3));
475 const FloatType &
h(std::size_t r, std::size_t c, std::size_t i)
const {
493 Spin &
spin(
Spins &spins, std::size_t r, std::size_t c, std::size_t i)
const {
494 return spins[
to_ind(r, c, i)];
508 std::size_t i)
const {
509 return spins[
to_ind(r, c, i)];
std::size_t mod_r(std::int64_t a) const
mod function (a mod num_row)
Definition chimera.hpp:127
static constexpr std::size_t _num_in_chimera
number of spins in each chimera units (8)
Definition chimera.hpp:118
const Spin & spin(const Spins &spins, std::size_t r, std::size_t c, std::size_t i) const
derive spin value at the index (row x column)
Definition chimera.hpp:507
FloatType _init_val
initial value to be set to inreactions
Definition chimera.hpp:103
Chimera(std::size_t num_row, std::size_t num_column, FloatType init_val=0)
chimera lattice graph constructor
Definition chimera.hpp:229
Chimera(const json &j, std::size_t num_row, std::size_t num_column, FloatType init_val=0)
Square constructor (from nlohmann::json).
Definition chimera.hpp:288
std::size_t get_num_column() const
get number of columns
Definition chimera.hpp:335
ChimeraIndex to_rci(Index ind) const
convert from global index to (row x column x in-chimera) index
Definition chimera.hpp:208
std::size_t mod_c(std::int64_t a) const
mod function (a mod num_column)
Definition chimera.hpp:139
void _checkpair(Index idx1, Index idx2) const
check if the pair has a valid connection
Definition chimera.hpp:151
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
Chimera(Chimera< FloatType > &&)=default
chimera lattice graph move constructor
std::size_t get_num_in_chimera() const
get number of spins in each chimera unit
Definition chimera.hpp:342
std::size_t _num_row
number of rows
Definition chimera.hpp:108
std::size_t _num_column
number of columns
Definition chimera.hpp:113
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
const FloatType & J(std::size_t r, std::size_t c, std::size_t i, ChimeraDir dir) const
access J(row, colum, in-chimera, direction)
Definition chimera.hpp:406
const FloatType & h(std::size_t r, std::size_t c, std::size_t i) const
access h(row, colum, in-chimera) (local field)
Definition chimera.hpp:475
Chimera(const Chimera< FloatType > &)=default
chimera lattice graph copy constructor
std::size_t get_num_row() const
get number of rows
Definition chimera.hpp:328
Index to_ind(std::int64_t r, std::int64_t c, std::int64_t i) const
convert from (row x column x in-chimera) index to global index
Definition chimera.hpp:179
Spin & spin(Spins &spins, std::size_t r, std::size_t c, std::size_t i) const
derive spin value at the index (row x column)
Definition chimera.hpp:493
std::size_t get_num_spins() const noexcept
get number of spins
Definition graph.hpp:89
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
Sparse(std::size_t num_spins, std::size_t num_edges)
Definition sparse.hpp:113
Definition binary_polynomial_model.hpp:24
int Spin
Definition graph.hpp:26
std::vector< Spin > Spins
Definition graph.hpp:27
nlohmann::json json
Definition parse.hpp:33
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)
Definition chimera.hpp:66
@ IN_0or4
inside-chimera 0or4 direction: (r, c, ind) -> (r, c, 0or4)
Definition chimera.hpp:71
@ IN_2or6
inside-chimera 2or6 direction: (r, c, ind) -> (r, c, 2or6)
Definition chimera.hpp:81
@ MINUS_R
minus-row direction: (r, c, ind) -> (r-1, c, ind)
Definition chimera.hpp:56
@ IN_1or5
inside-chimera 1or5 direction: (r, c, ind) -> (r, c, 1or5)
Definition chimera.hpp:76
@ IN_3or7
inside-chimera 3or7 direction: (r, c, ind) -> (r, c, 3or7)
Definition chimera.hpp:86
@ PLUS_C
plus-column direction: (r, c, ind) -> (r, c+1, ind)
Definition chimera.hpp:61
@ PLUS_R
plus-row direction: (r, c, ind) -> (r+1, c, ind)
Definition chimera.hpp:51
std::tuple< std::size_t, std::size_t, std::size_t > ChimeraIndex
Chimera index (row, column, in-chimera) The structure of in-chimera is as follows in-chimera index.
Definition chimera.hpp:41
std::size_t Index
Definition graph.hpp:30
Definition algorithm.hpp:24
double FloatType
Note:
Definition compile_config.hpp:37