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 = std::unordered_map< std::pair< Index, Index >, FloatType, utility::PairHash >
 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 Nodesadj_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
 
FloatTypeJ (Index i, Index j)
 access J_{ij}
 
const FloatTypeJ (Index i, Index j) const
 access J_{ij}
 
FloatTypeh (Index i)
 access h_{i} (local field)
 
const FloatTypeh (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 = std::unordered_map<std::pair<Index, Index>, FloatType, utility::PairHash>

interaction type

◆ value_type

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

◆ 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

◆ 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 openjij::graph::Sparse< FloatType >::h(), openjij::graph::Sparse< FloatType >::J(), and openjij::graph::json_parse().

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

◆ Sparse() [5/6]

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

Sparse copy constructor.

◆ Sparse() [6/6]

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

Sparse move constructor.

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 openjij::graph::Sparse< FloatType >::_list_adj_nodes, and openjij::graph::json_parse().

Referenced by openjij::utility::gen_matrix_from_graph().

Here is the call graph for this function:
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 openjij::graph::Sparse< FloatType >::energy(), and openjij::graph::json_parse().

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 openjij::graph::Sparse< FloatType >::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

◆ 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 openjij::graph::Graph::get_num_spins(), openjij::graph::Sparse< FloatType >::h(), openjij::graph::Sparse< FloatType >::J(), and openjij::graph::json_parse().

Referenced by openjij::graph::Sparse< FloatType >::calc_energy(), openjij::graph::Sparse< FloatType >::calc_energy(), and openjij::graph::Sparse< FloatType >::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 openjij::graph::Sparse< FloatType >::_num_edges.

◆ 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 openjij::graph::Sparse< FloatType >::_J, openjij::graph::Graph::get_num_spins(), and openjij::graph::json_parse().

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 openjij::graph::Sparse< FloatType >::_J, openjij::graph::Graph::get_num_spins(), and openjij::graph::json_parse().

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 openjij::graph::Sparse< FloatType >::_list_adj_nodes, openjij::graph::Sparse< FloatType >::_num_edges, openjij::graph::Graph::get_num_spins(), openjij::graph::json_parse(), and openjij::graph::Sparse< FloatType >::set_adj_node().

Referenced by openjij::graph::Sparse< FloatType >::h(), openjij::graph::Sparse< FloatType >::J(), and openjij::graph::Sparse< FloatType >::set_adj_node().

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

Member Data Documentation

◆ _J

◆ _list_adj_nodes

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

◆ _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 openjij::graph::Sparse< FloatType >::get_num_edges(), and openjij::graph::Sparse< FloatType >::set_adj_node().


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