openjij
Framework for the Ising model and QUBO.
|
Polynomial graph class, which can treat many-body interactions. More...
#include <polynomial.hpp>
Public Types | |
using | value_type = FloatType |
Floating-point type. | |
Public Member Functions | |
Polynomial (const std::size_t num_variables) | |
Constructor of Polynomial class to initialize variables and vartype. | |
Polynomial (const nlohmann::json &j) | |
Constructor of Polynomial class to initialize num_variables, and interactions from json. | |
FloatType & | J (std::vector< Index > &key) |
Access the interaction corresponding to the input argument to set an interaction. | |
FloatType & | J (const std::vector< Index > &key) |
Access the interaction corresponding to the input argument to set an interaction. | |
FloatType | J (std::vector< Index > &key) const |
Return the interaction corresponding to the input argument. | |
FloatType | J (const std::vector< Index > &key) const |
Return the interaction corresponding to the input argument. | |
template<typename... Args> | |
FloatType & | J (Args... args) |
Access the interaction corresponding to the input argument to set an interaction. | |
template<typename... Args> | |
FloatType | J (Args... args) const |
Access the interaction corresponding to the input argument to set an interaction. | |
cimod::Polynomial< Index, FloatType > | get_polynomial () const |
Generate and return all the polynomial interactions as std::unordered_map<std::vector<Index>, FloatType>. | |
const cimod::PolynomialKeyList< Index > & | get_keys () const |
Get the PolynomialKeyList object (all the keys of polynomial interactions). | |
const cimod::PolynomialValueList< FloatType > & | get_values () const |
Get the PolynomialValueList object (all the values of polynomial interactions). | |
std::size_t | get_num_interactions () const |
Return the number of all the interactions. | |
FloatType | energy (const Spins &spins, const bool omp_flag=true) const |
Return the total energy corresponding to the input variables, Spins or Binaries. | |
FloatType | calc_energy (const Spins &spins, const bool omp_flag=true) const |
Return the total energy corresponding to the input variables, Spins or Binaries. | |
![]() | |
Graph (std::size_t num_spins) | |
Graph constructor. | |
template<typename RandomNumberEngine > | |
const Spins | gen_spin (RandomNumberEngine &random_numder_engine) const |
generate spins randomly. | |
template<typename RandomNumberEngine > | |
const Binaries | gen_binary (RandomNumberEngine &random_numder_engine) const |
generate spins randomly. | |
std::size_t | get_num_spins () const noexcept |
get number of spins | |
std::size_t | size () const noexcept |
get number of spins | |
Private Member Functions | |
void | CheckKeyValid (const std::vector< Index > &key) const |
Check if the input keys are valid. | |
Private Attributes | |
cimod::PolynomialKeyList< Index > | poly_key_list_ |
The list of the indices of the polynomial interactions (namely, the list of key of the polynomial interactions as std::unordered_map) as std::vector<std::vector<Index>>. | |
cimod::PolynomialValueList< FloatType > | poly_value_list_ |
The list of the values of the polynomial interactions (namely, the list of value of the polynomial interactions as std::unordered_map) as std::vecto<FloatType>. | |
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_. | |
Polynomial graph class, which can treat many-body interactions.
The Hamiltonian is like
\[ H=\sum_{i \neq j} Q_{ij} x_i x_j + \sum_{i \neq j \neq k} Q_{ijk} x_i x_j x_k + \ldots \]
Note here that \( x_i \in \{0, 1\} \) or \( x_i \in \{-1, +1\} \).
FloatType | floating-point type |
Floating-point type.
|
inlineexplicit |
Constructor of Polynomial class to initialize variables and vartype.
num_variables | std::size_t |
|
inlineexplicit |
Constructor of Polynomial class to initialize num_variables, and interactions from json.
j | JSON object |
References openjij::graph::json_parse(), openjij::graph::Polynomial< FloatType >::poly_key_inv_, openjij::graph::Polynomial< FloatType >::poly_key_list_, and openjij::graph::Polynomial< FloatType >::poly_value_list_.
|
inline |
Return the total energy corresponding to the input variables, Spins or Binaries.
spins | const Spins& or const Binaries& (both are the same type) |
omp_flag | if true OpenMP is enabled. |
References openjij::graph::Polynomial< FloatType >::energy(), and openjij::graph::json_parse().
|
inlineprivate |
Check if the input keys are valid.
References openjij::graph::json_parse(), and openjij::graph::Graph::size().
Referenced by openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::Polynomial< FloatType >::J().
|
inline |
Return the total energy corresponding to the input variables, Spins or Binaries.
spins | const Spins& or const Binaries& (both are the same type) |
omp_flag | if true OpenMP is enabled. |
References openjij::graph::Polynomial< FloatType >::energy(), openjij::graph::json_parse(), openjij::graph::Polynomial< FloatType >::poly_key_list_, openjij::graph::Polynomial< FloatType >::poly_value_list_, and openjij::graph::Graph::size().
Referenced by openjij::graph::Polynomial< FloatType >::calc_energy(), and openjij::graph::Polynomial< FloatType >::energy().
|
inline |
Get the PolynomialKeyList object (all the keys of polynomial interactions).
References openjij::graph::Polynomial< FloatType >::poly_key_list_.
Referenced by openjij::system::KLocalPolynomial< graph::Polynomial< FloatType > >::KLocalPolynomial(), and openjij::system::ClassicalIsingPolynomial< graph::Polynomial< FloatType > >::SetInteractions().
|
inline |
Return the number of all the interactions.
References openjij::graph::Polynomial< FloatType >::poly_key_list_.
|
inline |
Generate and return all the polynomial interactions as std::unordered_map<std::vector<Index>, FloatType>.
References openjij::graph::json_parse(), openjij::graph::Polynomial< FloatType >::poly_key_list_, and openjij::graph::Polynomial< FloatType >::poly_value_list_.
|
inline |
Get the PolynomialValueList object (all the values of polynomial interactions).
References openjij::graph::Polynomial< FloatType >::poly_value_list_.
Referenced by openjij::system::KLocalPolynomial< graph::Polynomial< FloatType > >::KLocalPolynomial(), and openjij::system::ClassicalIsingPolynomial< graph::Polynomial< FloatType > >::SetInteractions().
|
inline |
Access the interaction corresponding to the input argument to set an interaction.
If the interaction specified by "args" is empty, the zero will be added to the polynomial graph.
args | parameter pack |
References openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::json_parse().
|
inline |
Access the interaction corresponding to the input argument to set an interaction.
If the interaction specified by "args" is empty, this function returns the zero.
args | parameter pack |
References openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::json_parse().
|
inline |
Access the interaction corresponding to the input argument to set an interaction.
If the interaction specified by "key" is empty, the zero will be added to the polynomial graph.
key | const std::vector<Index>& |
References openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::json_parse().
|
inline |
Return the interaction corresponding to the input argument.
If the interaction specified by "key" is empty, this function returns the zero.
key | const std::vector<Index>& |
References openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::json_parse().
|
inline |
Access the interaction corresponding to the input argument to set an interaction.
Note that the input argument "key" will be sorted. If the interaction specified by "key" is empty, the zero will be added to the polynomial graph.
key | std::vector<Index>& |
References openjij::graph::Polynomial< FloatType >::CheckKeyValid(), openjij::graph::json_parse(), openjij::graph::Polynomial< FloatType >::poly_key_inv_, openjij::graph::Polynomial< FloatType >::poly_key_list_, and openjij::graph::Polynomial< FloatType >::poly_value_list_.
Referenced by openjij::graph::Polynomial< FloatType >::J(), openjij::graph::Polynomial< FloatType >::J(), openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::Polynomial< FloatType >::J().
|
inline |
Return the interaction corresponding to the input argument.
Note that the input argument "key" will be sorted. If the interaction specified by "key" is empty, this function returns the zero.
key | std::vector<Index>& |
References openjij::graph::Polynomial< FloatType >::CheckKeyValid(), openjij::graph::json_parse(), openjij::graph::Polynomial< FloatType >::poly_key_inv_, and openjij::graph::Polynomial< FloatType >::poly_value_list_.
|
private |
The inverse key list, which indicates the index of the poly_key_list_ and poly_value_list_.
Referenced by openjij::graph::Polynomial< FloatType >::J(), openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::Polynomial< FloatType >::Polynomial().
|
private |
The list of the indices of the polynomial interactions (namely, the list of key of the polynomial interactions as std::unordered_map) as std::vector<std::vector<Index>>.
Referenced by openjij::graph::Polynomial< FloatType >::energy(), openjij::graph::Polynomial< FloatType >::get_keys(), openjij::graph::Polynomial< FloatType >::get_num_interactions(), openjij::graph::Polynomial< FloatType >::get_polynomial(), openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::Polynomial< FloatType >::Polynomial().
|
private |
The list of the values of the polynomial interactions (namely, the list of value of the polynomial interactions as std::unordered_map) as std::vecto<FloatType>.
Referenced by openjij::graph::Polynomial< FloatType >::energy(), openjij::graph::Polynomial< FloatType >::get_polynomial(), openjij::graph::Polynomial< FloatType >::get_values(), openjij::graph::Polynomial< FloatType >::J(), openjij::graph::Polynomial< FloatType >::J(), and openjij::graph::Polynomial< FloatType >::Polynomial().