31using RowColumn = std::pair<std::size_t, std::size_t>;
64template <
typename FloatType>
class Square :
public Sparse<FloatType> {
65 static_assert(std::is_floating_point<FloatType>::value,
66 "argument must be an arithmetic type");
91 inline std::size_t
mod_r(std::int64_t a)
const {
102 inline std::size_t
mod_c(std::int64_t a)
const {
117 if (!((
r1 ==
r2 && std::abs(
c1 -
c2) == 1) ||
118 (
c1 ==
c2 && std::abs(
r1 -
r2) == 1) ||
121 throw std::runtime_error(
"invalid index pair " + std::to_string(
idx1) +
122 " " + std::to_string(
idx2) +
123 " inserted in Square");
137 if (!(-1 <=
r &&
r <= (std::int64_t)
_num_row)) {
138 throw std::runtime_error(
"invalid value r=" + std::to_string(
r) +
139 " inserted in Square");
143 throw std::runtime_error(
"invalid value c=" + std::to_string(
c) +
144 " inserted in Square");
159 throw std::runtime_error(
"invalid value index=" + std::to_string(
ind) +
160 " inserted in Square");
165 return std::make_pair(
r,
c);
194 if (
r < num_row - 1) {
199 if (
c < num_column - 1) {
222 throw std::runtime_error(
"number of system size does not match");
227 for (
auto &&
elem :
bqm.get_quadratic()) {
234 for (
auto &&
elem :
bqm.get_linear()) {
std::size_t get_num_spins() const noexcept
get number of spins
Definition graph.hpp:89
Sparse graph: two-body intereactions with O(1) connectivity The Hamiltonian is like.
Definition sparse.hpp:40
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
std::size_t mod_r(std::int64_t a) const
mod function (a mod num_row)
Definition square.hpp:91
const FloatType & h(std::size_t r, std::size_t c) const
access h(row, colum) (local field)
Definition square.hpp:352
void _checkpair(Index idx1, Index idx2) const
check if the pair has a valid connection
Definition square.hpp:113
std::size_t get_num_column() const
get number of columns
Definition square.hpp:265
const FloatType & J(std::size_t r, std::size_t c, Dir dir) const
access J(row, colum, direction)
Definition square.hpp:307
FloatType _init_val
initial value to be set to interactions
Definition square.hpp:72
Square(Square< FloatType > &&)=default
square lattice graph move constructor
FloatType & h(std::size_t r, std::size_t c)
access h(row, colum) (local field)
Definition square.hpp:337
std::size_t _num_row
number of rows
Definition square.hpp:77
FloatType & J(std::size_t r, std::size_t c, Dir dir)
access J(row, colum, direction)
Definition square.hpp:276
RowColumn to_rc(Index ind) const
convert from global index to (row x column) index
Definition square.hpp:157
std::size_t mod_c(std::int64_t a) const
mod function (a mod num_column)
Definition square.hpp:102
const Spin & spin(const Spins &spins, std::size_t r, std::size_t c) const
derive spin value at the index (row x column)
Definition square.hpp:381
Square(std::size_t num_row, std::size_t num_column, FloatType init_val=0)
square lattice graph constructor
Definition square.hpp:175
Spin & spin(Spins &spins, std::size_t r, std::size_t c) const
derive spin value at the index (row x column)
Definition square.hpp:368
Square(const Square< FloatType > &)=default
square lattice graph copy constructor
std::size_t _num_column
number of columns
Definition square.hpp:82
Square(const json &j, std::size_t num_row, std::size_t num_column, FloatType init_val=0)
Square constructor (from nlohmann::json)
Definition square.hpp:218
std::size_t get_num_row() const
get number of rows
Definition square.hpp:258
Index to_ind(std::int64_t r, std::int64_t c) const
convert from (row x column) index to global index
Definition square.hpp:136
auto json_parse(const json &obj, bool relabel=true)
parse json object from bqm.to_serializable
Definition parse.hpp:50
std::pair< std::size_t, std::size_t > RowColumn
Row x Column type.
Definition square.hpp:31
@ MINUS_C
minus-column direction: (r, c, ind) -> (r, c-1, ind)
@ MINUS_R
minus-row direction: (r, c, ind) -> (r-1, c, ind)
@ 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
int Spin
Definition graph.hpp:26
Dir
direction enum class
Definition square.hpp:36
@ 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)
nlohmann::json json
Definition parse.hpp:33
std::size_t Index
Definition graph.hpp:30
Definition algorithm.hpp:24
double FloatType
Note:
Definition compile_config.hpp:37