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

Sparse graph: two-body intereactions with O(1) connectivity The Hamiltonian is like. More...

#include <sparse.hpp>

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

Public Types

using Interactions
 interaction type
using value_type = FloatType
 float type

Public Member Functions

 Sparse (std::size_t num_spins, std::size_t num_edges)
 Sparse constructor.
 Sparse (std::size_t num_spins)
 Sparse delegate constructor.
 Sparse (const json &j, std::size_t num_edges)
 Sparse constructor (from nlohmann::json).
 Sparse (const json &j)
 Sparse constructor (from nlohmann::json).
 Sparse (const Sparse< FloatType > &)=default
 Sparse copy constructor.
 Sparse (Sparse< FloatType > &&)=default
 Sparse move constructor.
const Nodes & adj_nodes (Index ind) const
 list of adjacent nodes
std::size_t get_num_edges () const
 get number of edges
FloatType calc_energy (const Spins &spins) const
 calculate total energy
FloatType calc_energy (const Eigen::Matrix< FloatType, Eigen::Dynamic, 1, Eigen::ColMajor > &spins) const
FloatType energy (const Spins &spins) const
 calculate total energy
FloatType energy (const Eigen::Matrix< FloatType, Eigen::Dynamic, 1, Eigen::ColMajor > &spins) const
FloatType & J (Index i, Index j)
 access J_{ij}
const FloatType & J (Index i, Index j) const
 access J_{ij}
FloatType & h (Index i)
 access h_{i} (local field)
const FloatType & h (Index i) const
 access h_{i} (local field)
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

bool set_adj_node (Index from, Index to)
 add adjacent node from "from" Index to "to" Index

Private Attributes

Interactions _J
 interactions (the number of intereactions is num_spins*(num_spins+1)/2)
std::size_t _num_edges
 the uppder limit of the number of edges per site
std::vector< Nodes > _list_adj_nodes
 the list of the indices of adjacent nodes

Detailed Description

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

Sparse graph: two-body intereactions with O(1) connectivity The Hamiltonian is like.

\[H = \sum_{i<j}J_{ij} \sigma_i \sigma_j + \sum_{i}h_{i} \sigma_i \]

Template Parameters
FloatTypefloating-point type

Member Typedef Documentation

◆ Interactions

template<typename FloatType>
using openjij::graph::Sparse< FloatType >::Interactions
Initial value:
std::unordered_map<std::pair<Index, Index>, FloatType, utility::PairHash>
double FloatType
Note:
Definition compile_config.hpp:37
hash class for std::pair
Definition pairhash.hpp:30

interaction type

◆ value_type

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

float type

Constructor & Destructor Documentation

◆ Sparse() [1/6]

template<typename FloatType>
openjij::graph::Sparse< FloatType >::Sparse ( std::size_t num_spins,
std::size_t num_edges )
inline

Sparse constructor.

Parameters
num_spinsnumber of spins
num_edgesnumber of edges

References _list_adj_nodes, _num_edges, and openjij::graph::Graph::Graph().

Referenced by Sparse(), Sparse(), Sparse(), Sparse(), Sparse(), and openjij::graph::Square< FloatType >::Square().

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

◆ Sparse() [2/6]

template<typename FloatType>
openjij::graph::Sparse< FloatType >::Sparse ( std::size_t num_spins)
inlineexplicit

Sparse delegate constructor.

Parameters
num_spinsnumber of spins

References Sparse().

Here is the call graph for this function:

◆ Sparse() [3/6]

template<typename FloatType>
openjij::graph::Sparse< FloatType >::Sparse ( const json & j,
std::size_t num_edges )
inline

Sparse constructor (from nlohmann::json).

Parameters
jJSON object
num_edgesnumber of edges

References h(), J(), openjij::graph::json_parse(), and Sparse().

Here is the call graph for this function:

◆ Sparse() [4/6]

template<typename FloatType>
openjij::graph::Sparse< FloatType >::Sparse ( const json & j)
inline

Sparse constructor (from nlohmann::json).

Parameters
jJSON object

References Sparse().

Here is the call graph for this function:

◆ Sparse() [5/6]

template<typename FloatType>
openjij::graph::Sparse< FloatType >::Sparse ( const Sparse< FloatType > & )
default

Sparse copy constructor.

References Sparse().

Here is the call graph for this function:

◆ Sparse() [6/6]

template<typename FloatType>
openjij::graph::Sparse< FloatType >::Sparse ( Sparse< FloatType > && )
default

Sparse move constructor.

References Sparse().

Here is the call graph for this function:

Member Function Documentation

◆ adj_nodes()

template<typename FloatType>
const Nodes & openjij::graph::Sparse< FloatType >::adj_nodes ( Index ind) const
inline

list of adjacent nodes

Parameters
indNode index
Returns
corresponding list of adjacent nodes

References _list_adj_nodes.

Referenced by openjij::declare_Sparse().

Here is the caller graph for this function:

◆ calc_energy() [1/2]

template<typename FloatType>
FloatType openjij::graph::Sparse< FloatType >::calc_energy ( const Eigen::Matrix< FloatType, Eigen::Dynamic, 1, Eigen::ColMajor > & spins) const
inline

References energy().

Here is the call graph for this function:

◆ calc_energy() [2/2]

template<typename FloatType>
FloatType openjij::graph::Sparse< FloatType >::calc_energy ( const Spins & spins) const
inline

calculate total energy

Parameters
spins
Deprecated
use energy(spins)
Returns
corresponding energy

References energy().

Referenced by openjij::declare_Sparse().

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

◆ energy() [1/2]

template<typename FloatType>
FloatType openjij::graph::Sparse< FloatType >::energy ( const Eigen::Matrix< FloatType, Eigen::Dynamic, 1, Eigen::ColMajor > & spins) const
inline

References energy(), and openjij::graph::Graph::get_num_spins().

Here is the call graph for this function:

◆ energy() [2/2]

template<typename FloatType>
FloatType openjij::graph::Sparse< FloatType >::energy ( const Spins & spins) const
inline

calculate total energy

Parameters
spins
Returns
corresponding energy

References _list_adj_nodes, openjij::graph::Graph::get_num_spins(), h(), and J().

Referenced by calc_energy(), calc_energy(), and energy().

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

◆ get_num_edges()

template<typename FloatType>
std::size_t openjij::graph::Sparse< FloatType >::get_num_edges ( ) const
inline

get number of edges

Returns
number of edges

References _num_edges.

Referenced by openjij::declare_Sparse().

Here is the caller graph for this function:

◆ h() [1/2]

◆ h() [2/2]

template<typename FloatType>
const FloatType & openjij::graph::Sparse< FloatType >::h ( Index i) const
inline

access h_{i} (local field)

Parameters
iIndex i
Returns
h_{i}

References _J, and openjij::graph::Graph::get_num_spins().

Here is the call graph for this function:

◆ J() [1/2]

◆ J() [2/2]

template<typename FloatType>
const FloatType & openjij::graph::Sparse< FloatType >::J ( Index i,
Index j ) const
inline

access J_{ij}

Parameters
iIndex i
jIndex j
Returns
J_{ij}

References _J, and openjij::graph::Graph::get_num_spins().

Here is the call graph for this function:

◆ set_adj_node()

template<typename FloatType>
bool openjij::graph::Sparse< FloatType >::set_adj_node ( Index from,
Index to )
inlineprivate

add adjacent node from "from" Index to "to" Index

Parameters
from"from" Index
to"to" Index
Returns
true if nodes is successfully added, false if this function failed.

References _list_adj_nodes, _num_edges, openjij::graph::Graph::get_num_spins(), and set_adj_node().

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

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

Member Data Documentation

◆ _J

template<typename FloatType>
Interactions openjij::graph::Sparse< FloatType >::_J
private

interactions (the number of intereactions is num_spins*(num_spins+1)/2)

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

◆ _list_adj_nodes

template<typename FloatType>
std::vector<Nodes> openjij::graph::Sparse< FloatType >::_list_adj_nodes
private

the list of the indices of adjacent nodes

Referenced by adj_nodes(), energy(), set_adj_node(), and Sparse().

◆ _num_edges

template<typename FloatType>
std::size_t openjij::graph::Sparse< FloatType >::_num_edges
private

the uppder limit of the number of edges per site

Referenced by get_num_edges(), set_adj_node(), and Sparse().


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