21#include <unordered_map>
41 static_assert(std::is_floating_point<FloatType>::value,
42 "FloatType must be floating-point type.");
122 explicit Sparse(std::size_t num_spins) :
Sparse(num_spins, num_spins) {}
134 using SparseMatrix = Eigen::SparseMatrix<FloatType, Eigen::RowMajor>;
135 using SpIter =
typename SparseMatrix::InnerIterator;
154 size_t num_variables =
quadmat.rows() - 1;
155 for (
int k = 0;
k <
quadmat.outerSize();
k++) {
161 if (
r == num_variables &&
c == num_variables)
164 if (
c == num_variables) {
219 return this->
energy(spins);
223 Eigen::ColMajor> &
spins)
const {
235 if (!(
spins.size() ==
this->get_num_spins())) {
236 std::out_of_range(
"Out of range in energy in Sparse graph.");
253 Eigen::ColMajor> &
spins)
const {
255 for (
size_t i = 0; i <
temp_spins.size(); i++) {
276 return _J[std::make_pair(std::min(i,
j), std::max(i,
j))];
290 return _J.at(std::make_pair(std::min(i,
j), std::max(i,
j)));
303 return _J[std::make_pair(i, i)];
315 return _J.at(std::make_pair(i, i));
Abstract graph class.
Definition graph.hpp:37
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
Sparse(const json &j)
Sparse constructor (from nlohmann::json)
Definition sparse.hpp:180
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
const FloatType & J(Index i, Index j) const
access J_{ij}
Definition sparse.hpp:287
std::size_t get_num_edges() const
get number of edges
Definition sparse.hpp:208
Sparse(const json &j, std::size_t num_edges)
Sparse constructor (from nlohmann::json)
Definition sparse.hpp:130
std::unordered_map< std::pair< Index, Index >, FloatType, utility::PairHash > Interactions
interaction type
Definition sparse.hpp:49
Interactions _J
interactions (the number of intereactions is num_spins*(num_spins+1)/2)
Definition sparse.hpp:61
Sparse(const Sparse< FloatType > &)=default
Sparse copy constructor.
Sparse(std::size_t num_spins)
Sparse delegate constructor.
Definition sparse.hpp:122
bool set_adj_node(Index from, Index to)
add adjacent node from "from" Index to "to" Index
Definition sparse.hpp:81
FloatType value_type
float type
Definition sparse.hpp:54
FloatType & J(Index i, Index j)
access J_{ij}
Definition sparse.hpp:269
FloatType calc_energy(const Eigen::Matrix< FloatType, Eigen::Dynamic, 1, Eigen::ColMajor > &spins) const
Definition sparse.hpp:222
Sparse(Sparse< FloatType > &&)=default
Sparse move constructor.
const Nodes & adj_nodes(Index ind) const
list of adjacent nodes
Definition sparse.hpp:201
FloatType energy(const Eigen::Matrix< FloatType, Eigen::Dynamic, 1, Eigen::ColMajor > &spins) const
Definition sparse.hpp:252
std::size_t _num_edges
the uppder limit of the number of edges per site
Definition sparse.hpp:66
const FloatType & h(Index i) const
access h_{i} (local field)
Definition sparse.hpp:313
Sparse(std::size_t num_spins, std::size_t num_edges)
Sparse constructor.
Definition sparse.hpp:113
std::vector< Nodes > _list_adj_nodes
the list of the indices of adjacent nodes
Definition sparse.hpp:71
FloatType energy(const Spins &spins) const
calculate total energy
Definition sparse.hpp:234
auto json_parse(const json &obj, bool relabel=true)
parse json object from bqm.to_serializable
Definition parse.hpp:50
std::vector< Index > Nodes
Definition graph.hpp:32
std::vector< Spin > Spins
Definition graph.hpp:27
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
hash class for std::pair
Definition pairhash.hpp:30