27#include <unordered_map>
30#include <cimod/binary_polynomial_model.hpp>
48 static_assert(std::is_floating_point<FloatType>::value,
49 "FloatType must be floating-point type.");
70 throw std::runtime_error(
71 "The sizes of key_list and value_list must match each other");
79#pragma omp parallel for
98 std::sort(
key.begin(),
key.end());
125 std::sort(
key.begin(),
key.end());
170 cimod::Polynomial<Index, FloatType>
poly_map;
180 const cimod::PolynomialKeyList<Index> &
get_keys()
const {
187 const cimod::PolynomialValueList<FloatType> &
get_values()
const {
202 throw std::out_of_range(
"The size of spins/binaries does not equal to "
203 "the size of polynomial graph");
211#pragma omp parallel for reduction(+ : energy)
260 std::unordered_map<std::vector<Index>, std::size_t, cimod::vector_hash>
266 std::stringstream
ss;
267 ss <<
"Too small system size. ";
268 ss <<
"The degree of the input polynomial interaction is " <<
key.size();
270 throw std::runtime_error(
ss.str());
272 if (0 <
key.size()) {
274 for (std::size_t i = 0; i <
key.size() - 1; ++i) {
275 if (
key[i] ==
key[i + 1]) {
276 throw std::runtime_error(
"No self-loops allowed");
279 std::stringstream
ss;
280 ss <<
"Too small system size. ";
281 ss <<
"The index of a interaction: " <<
key[i] <<
" is out of range";
282 throw std::runtime_error(
ss.str());
286 std::stringstream
ss;
287 ss <<
"Too small system size. ";
288 ss <<
"The index of a interaction: " <<
key.back()
289 <<
" is out of range";
290 throw std::runtime_error(
ss.str());
Abstract graph class.
Definition graph.hpp:37
std::size_t size() const noexcept
get number of spins
Definition graph.hpp:96
Polynomial graph class, which can treat many-body interactions.
Definition polynomial.hpp:47
FloatType energy(const Spins &spins, const bool omp_flag=true) const
Return the total energy corresponding to the input variables, Spins or Binaries.
Definition polynomial.hpp:200
Polynomial(const nlohmann::json &j)
Constructor of Polynomial class to initialize num_variables, and interactions from json.
Definition polynomial.hpp:63
FloatType calc_energy(const Spins &spins, const bool omp_flag=true) const
Return the total energy corresponding to the input variables, Spins or Binaries.
Definition polynomial.hpp:243
FloatType & J(std::vector< Index > &key)
Access the interaction corresponding to the input argument to set an interaction.
Definition polynomial.hpp:97
const cimod::PolynomialKeyList< Index > & get_keys() const
Get the PolynomialKeyList object (all the keys of polynomial interactions).
Definition polynomial.hpp:180
FloatType & J(Args... args)
Access the interaction corresponding to the input argument to set an interaction.
Definition polynomial.hpp:150
FloatType J(Args... args) const
Access the interaction corresponding to the input argument to set an interaction.
Definition polynomial.hpp:161
FloatType & J(const std::vector< Index > &key)
Access the interaction corresponding to the input argument to set an interaction.
Definition polynomial.hpp:114
FloatType J(const std::vector< Index > &key) const
Return the interaction corresponding to the input argument.
Definition polynomial.hpp:139
cimod::PolynomialKeyList< Index > poly_key_list_
The list of the indices of the polynomial interactions (namely, the list of key of the polynomial int...
Definition polynomial.hpp:251
const cimod::PolynomialValueList< FloatType > & get_values() const
Get the PolynomialValueList object (all the values of polynomial interactions).
Definition polynomial.hpp:187
std::unordered_map< std::vector< Index >, std::size_t, cimod::vector_hash > poly_key_inv_
The inverse key list, which indicates the index of the poly_key_list_ and poly_value_list_.
Definition polynomial.hpp:261
Polynomial(const std::size_t num_variables)
Constructor of Polynomial class to initialize variables and vartype.
Definition polynomial.hpp:58
void CheckKeyValid(const std::vector< Index > &key) const
Check if the input keys are valid.
Definition polynomial.hpp:264
FloatType J(std::vector< Index > &key) const
Return the interaction corresponding to the input argument.
Definition polynomial.hpp:124
cimod::Polynomial< Index, FloatType > get_polynomial() const
Generate and return all the polynomial interactions as std::unordered_map<std::vector<Index>,...
Definition polynomial.hpp:169
cimod::PolynomialValueList< FloatType > poly_value_list_
The list of the values of the polynomial interactions (namely, the list of value of the polynomial in...
Definition polynomial.hpp:256
FloatType value_type
Floating-point type.
Definition polynomial.hpp:53
std::size_t get_num_interactions() const
Return the number of all the interactions.
Definition polynomial.hpp:193
auto json_parse(const json &obj, bool relabel=true)
parse json object from bqm.to_serializable
Definition parse.hpp:50
std::vector< Spin > Spins
Definition graph.hpp:27
int Spin
Definition graph.hpp:26
std::size_t Index
Definition graph.hpp:30
Definition algorithm.hpp:24
double FloatType
Note:
Definition compile_config.hpp:37