openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
openjij::graph::Polynomial< FloatType > Class Template Reference

Polynomial graph class, which can treat many-body interactions. The Hamiltonian is like. More...

#include <polynomial.hpp>

Inheritance diagram for openjij::graph::Polynomial< FloatType >:
Collaboration diagram for openjij::graph::Polynomial< FloatType >:

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.
Public Member Functions inherited from openjij::graph::Graph
 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_.

Detailed Description

template<typename FloatType>
class openjij::graph::Polynomial< FloatType >

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\} \).

Template Parameters
FloatTypefloating-point type

Member Typedef Documentation

◆ value_type

template<typename FloatType>
using openjij::graph::Polynomial< FloatType >::value_type = FloatType

Floating-point type.

Constructor & Destructor Documentation

◆ Polynomial() [1/2]

template<typename FloatType>
openjij::graph::Polynomial< FloatType >::Polynomial ( const std::size_t num_variables)
inlineexplicit

Constructor of Polynomial class to initialize variables and vartype.

Parameters
num_variablesstd::size_t

References openjij::graph::Graph::Graph().

Here is the call graph for this function:

◆ Polynomial() [2/2]

template<typename FloatType>
openjij::graph::Polynomial< FloatType >::Polynomial ( const nlohmann::json & j)
inlineexplicit

Constructor of Polynomial class to initialize num_variables, and interactions from json.

Parameters
jJSON object

References openjij::graph::Graph::Graph(), openjij::graph::json_parse_polynomial(), poly_key_inv_, poly_key_list_, poly_value_list_, and openjij::graph::Graph::size().

Here is the call graph for this function:

Member Function Documentation

◆ calc_energy()

template<typename FloatType>
FloatType openjij::graph::Polynomial< FloatType >::calc_energy ( const Spins & spins,
const bool omp_flag = true ) const
inline

Return the total energy corresponding to the input variables, Spins or Binaries.

Deprecated
Parameters
spinsconst Spins& or const Binaries& (both are the same type)
omp_flagif true OpenMP is enabled.
Returns
The total energy

References energy().

Here is the call graph for this function:

◆ CheckKeyValid()

template<typename FloatType>
void openjij::graph::Polynomial< FloatType >::CheckKeyValid ( const std::vector< Index > & key) const
inlineprivate

Check if the input keys are valid.

References openjij::graph::Graph::size().

Referenced by J(), and J().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ energy()

template<typename FloatType>
FloatType openjij::graph::Polynomial< FloatType >::energy ( const Spins & spins,
const bool omp_flag = true ) const
inline

Return the total energy corresponding to the input variables, Spins or Binaries.

Parameters
spinsconst Spins& or const Binaries& (both are the same type)
omp_flagif true OpenMP is enabled.
Returns
The total energy

References energy(), poly_key_list_, poly_value_list_, and openjij::graph::Graph::size().

Referenced by calc_energy(), and energy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_keys()

template<typename FloatType>
const cimod::PolynomialKeyList< Index > & openjij::graph::Polynomial< FloatType >::get_keys ( ) const
inline

Get the PolynomialKeyList object (all the keys of polynomial interactions).

Returns
PolynomialKeyList object as std::vector<std::vector<Index>>.

References poly_key_list_.

Referenced by openjij::system::KLocalPolynomial< graph::Polynomial< FloatType > >::KLocalPolynomial(), and openjij::system::ClassicalIsingPolynomial< graph::Polynomial< FloatType > >::SetInteractions().

Here is the caller graph for this function:

◆ get_num_interactions()

template<typename FloatType>
std::size_t openjij::graph::Polynomial< FloatType >::get_num_interactions ( ) const
inline

Return the number of all the interactions.

Returns
The number of all the interactions.

References poly_key_list_.

◆ get_polynomial()

template<typename FloatType>
cimod::Polynomial< Index, FloatType > openjij::graph::Polynomial< FloatType >::get_polynomial ( ) const
inline

Generate and return all the polynomial interactions as std::unordered_map<std::vector<Index>, FloatType>.

Returns
All the interactions

References poly_key_list_, and poly_value_list_.

◆ get_values()

template<typename FloatType>
const cimod::PolynomialValueList< FloatType > & openjij::graph::Polynomial< FloatType >::get_values ( ) const
inline

Get the PolynomialValueList object (all the values of polynomial interactions).

Returns
PolynomialValueList object as std::vector<FloatType>.

References poly_value_list_.

Referenced by openjij::system::KLocalPolynomial< graph::Polynomial< FloatType > >::KLocalPolynomial(), and openjij::system::ClassicalIsingPolynomial< graph::Polynomial< FloatType > >::SetInteractions().

Here is the caller graph for this function:

◆ J() [1/6]

template<typename FloatType>
template<typename... Args>
FloatType & openjij::graph::Polynomial< FloatType >::J ( Args... args)
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.

Parameters
argsparameter pack
Returns
The interaction corresponding to "args".

References J().

Here is the call graph for this function:

◆ J() [2/6]

template<typename FloatType>
template<typename... Args>
FloatType openjij::graph::Polynomial< FloatType >::J ( Args... args) const
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.

Parameters
argsparameter pack
Returns
The interaction corresponding to "args".

References J().

Here is the call graph for this function:

◆ J() [3/6]

template<typename FloatType>
FloatType & openjij::graph::Polynomial< FloatType >::J ( const std::vector< Index > & key)
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.

Parameters
keyconst std::vector<Index>&
Returns
The interaction corresponding to "key".

References J().

Here is the call graph for this function:

◆ J() [4/6]

template<typename FloatType>
FloatType openjij::graph::Polynomial< FloatType >::J ( const std::vector< Index > & key) const
inline

Return the interaction corresponding to the input argument.

If the interaction specified by "key" is empty, this function returns the zero.

Parameters
keyconst std::vector<Index>&
Returns
The interaction corresponding to "key".

References J().

Here is the call graph for this function:

◆ J() [5/6]

template<typename FloatType>
FloatType & openjij::graph::Polynomial< FloatType >::J ( std::vector< Index > & key)
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.

Parameters
keystd::vector<Index>&
Returns
The interaction corresponding to "key".

References CheckKeyValid(), poly_key_inv_, poly_key_list_, and poly_value_list_.

Referenced by J(), J(), J(), and J().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ J() [6/6]

template<typename FloatType>
FloatType openjij::graph::Polynomial< FloatType >::J ( std::vector< Index > & key) const
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.

Parameters
keystd::vector<Index>&
Returns
The interaction corresponding to "key".

References CheckKeyValid(), poly_key_inv_, and poly_value_list_.

Here is the call graph for this function:

Member Data Documentation

◆ poly_key_inv_

template<typename FloatType>
std::unordered_map<std::vector<Index>, std::size_t, cimod::vector_hash> openjij::graph::Polynomial< FloatType >::poly_key_inv_
private

The inverse key list, which indicates the index of the poly_key_list_ and poly_value_list_.

Referenced by J(), J(), and Polynomial().

◆ poly_key_list_

template<typename FloatType>
cimod::PolynomialKeyList<Index> openjij::graph::Polynomial< FloatType >::poly_key_list_
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 energy(), get_keys(), get_num_interactions(), get_polynomial(), J(), and Polynomial().

◆ poly_value_list_

template<typename FloatType>
cimod::PolynomialValueList<FloatType> openjij::graph::Polynomial< FloatType >::poly_value_list_
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 energy(), get_polynomial(), get_values(), J(), J(), and Polynomial().


The documentation for this class was generated from the following file: