cimod
C++ library for a binary (and polynomial) quadratic model.
cimod Namespace Reference

Namespaces

 _version
 
 model
 
 utils
 
 vartype
 

Classes

class  BinaryPolynomialModel
 Class for BinaryPolynomialModel. More...
 
struct  Dense
 
struct  Sparse
 
class  BinaryQuadraticModel
 Class for dense binary quadratic model. More...
 
struct  Dict
 
class  BinaryQuadraticModel< IndexType, FloatType, Dict >
 Class for legacy binary quadratic model (dict datastructure). More...
 
struct  pair_hash
 Hash function for std::unordered_map. More...
 
struct  vector_hash
 

Typedefs

template<typename IndexType , typename FloatType >
using Polynomial = std::unordered_map< std::vector< IndexType >, FloatType, vector_hash >
 Type alias for the polynomial interactions as std::unordered_map. More...
 
template<typename IndexType >
using PolynomialKeyList = std::vector< std::vector< IndexType > >
 Type alias for the indices of the polynomial interactions (namely, the list of keys of the polynomial interactions as std::unordered_map) as std::vector<std::vector>>. More...
 
template<typename FloatType >
using PolynomialValueList = std::vector< FloatType >
 Type alias for the values of the polynomial interactions (namely, the list of values of the polynomial interactions as std::unordered_map) as std::vector. More...
 
template<typename IndexType >
using Sample = std::unordered_map< IndexType, int32_t >
 Type alias for sample, which represents the spin or binary configurations. More...
 
template<typename IndexType , typename FloatType >
using Linear = std::unordered_map< IndexType, FloatType >
 Type alias for linear bias. More...
 
template<typename IndexType , typename FloatType >
using Quadratic = std::unordered_map< std::pair< IndexType, IndexType >, FloatType, pair_hash >
 Type alias for quadratic bias. More...
 
template<typename IndexType , typename FloatType >
using Adjacency = std::unordered_map< IndexType, std::unordered_map< IndexType, FloatType > >
 Type alias for adjacency list. More...
 

Enumerations

enum class  Vartype { SPIN = 0 , BINARY , NONE = -1 }
 Enum class for representing problem type. More...
 

Functions

template<class C_key , class C_value , class Hash >
void insert_or_assign (std::unordered_map< C_key, C_value, Hash > &um, const C_key &key, const C_value &val)
 Insert or assign a element of unordered_map (for C++14 or C++11) More...
 
template<typename IndexType >
void FormatPolynomialKey (std::vector< IndexType > *key, const Vartype &vartype)
 Format the input key: for example, {2,1,1}-->{1,2} for BINARY variable and {2,1,1}-->{2} for SPIN variable. More...
 
cimod::Vartype ToCimodVartype (const std::string &vartype_str)
 Convert vartype from string to cimod::Vartype. More...
 
template<typename IntegerType >
void CheckVariables (const std::vector< IntegerType > &configurations, const Vartype &vartype)
 Convert vartype from string to cimod::Vartype. More...
 
void CheckVartypeNotNONE (const Vartype &vartype)
 Check if the input vartype is not Vartype::NONE. More...
 
bool check_vartype (const int32_t &var, const Vartype &vartype)
 Check that the variable has appropriate value. More...
 

Variables

 __path__ = extend_path(__path__, __name__)
 
list __all__
 

Typedef Documentation

◆ Adjacency

template<typename IndexType , typename FloatType >
using cimod::Adjacency = typedef std::unordered_map<IndexType, std::unordered_map<IndexType, FloatType> >

Type alias for adjacency list.

Template Parameters
IndexType

◆ Linear

template<typename IndexType , typename FloatType >
using cimod::Linear = typedef std::unordered_map<IndexType, FloatType>

Type alias for linear bias.

Template Parameters
IndexType

◆ Polynomial

template<typename IndexType , typename FloatType >
using cimod::Polynomial = typedef std::unordered_map<std::vector<IndexType>, FloatType, vector_hash>

Type alias for the polynomial interactions as std::unordered_map.

Template Parameters
IndexType
FloatType

◆ PolynomialKeyList

template<typename IndexType >
using cimod::PolynomialKeyList = typedef std::vector<std::vector<IndexType> >

Type alias for the indices of the polynomial interactions (namely, the list of keys of the polynomial interactions as std::unordered_map) as std::vector<std::vector>>.

Template Parameters
IndexType

◆ PolynomialValueList

template<typename FloatType >
using cimod::PolynomialValueList = typedef std::vector<FloatType>

Type alias for the values of the polynomial interactions (namely, the list of values of the polynomial interactions as std::unordered_map) as std::vector.

Template Parameters
FloatType

◆ Quadratic

template<typename IndexType , typename FloatType >
using cimod::Quadratic = typedef std::unordered_map<std::pair<IndexType, IndexType>, FloatType, pair_hash>

Type alias for quadratic bias.

Template Parameters
IndexType

◆ Sample

template<typename IndexType >
using cimod::Sample = typedef std::unordered_map<IndexType, int32_t>

Type alias for sample, which represents the spin or binary configurations.

Type alias for sample.

Template Parameters
IndexType

Enumeration Type Documentation

◆ Vartype

enum cimod::Vartype
strong

Enum class for representing problem type.

Enumerator
SPIN 
BINARY 
NONE 

Function Documentation

◆ check_vartype()

bool cimod::check_vartype ( const int32_t &  var,
const Vartype vartype 
)
inline

Check that the variable has appropriate value.

Parameters
var
vartype
Returns
true or false

References BINARY, SPIN, and cimod.model.legacy.binary_quadratic_model::vartype.

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::energy().

Here is the caller graph for this function:

◆ CheckVariables()

template<typename IntegerType >
void cimod::CheckVariables ( const std::vector< IntegerType > &  configurations,
const Vartype vartype 
)

Convert vartype from string to cimod::Vartype.

Template Parameters
IntegerTypeThe type of spin/binary configuration
Parameters
configurationsThe spin/binary configuration
vartypeThe model's type. cimod::Vartype::SPIN or cimod::Vartype::BINARY.

References BINARY, SPIN, and cimod.model.legacy.binary_quadratic_model::vartype.

◆ CheckVartypeNotNONE()

void cimod::CheckVartypeNotNONE ( const Vartype vartype)

Check if the input vartype is not Vartype::NONE.

Parameters
vartypeThe model's type. cimod::Vartype::SPIN or cimod::Vartype::BINARY.

References NONE, and cimod.model.legacy.binary_quadratic_model::vartype.

◆ FormatPolynomialKey()

template<typename IndexType >
void cimod::FormatPolynomialKey ( std::vector< IndexType > *  key,
const Vartype vartype 
)

Format the input key: for example, {2,1,1}-->{1,2} for BINARY variable and {2,1,1}-->{2} for SPIN variable.

Template Parameters
IndexTypeUsed to represent the indices of variables
Parameters
keyThis may be formatted.
vartypeThe model's type. cimod::Vartype::SPIN or cimod::Vartype::BINARY.

References BINARY, SPIN, and cimod.model.legacy.binary_quadratic_model::vartype.

Referenced by cimod::BinaryPolynomialModel< IndexType, FloatType >::AddInteraction(), cimod::BinaryPolynomialModel< IndexType, FloatType >::GetPolynomial(), and cimod::BinaryPolynomialModel< IndexType, FloatType >::RemoveInteraction().

Here is the caller graph for this function:

◆ insert_or_assign()

template<class C_key , class C_value , class Hash >
void cimod::insert_or_assign ( std::unordered_map< C_key, C_value, Hash > &  um,
const C_key &  key,
const C_value &  val 
)

◆ ToCimodVartype()

cimod::Vartype cimod::ToCimodVartype ( const std::string &  vartype_str)

Convert vartype from string to cimod::Vartype.

Parameters
vartype_str"SPIN" or "BINARY"
Returns
cimod::Vartype::SPIN or cimod::Vartype::BINARY

References BINARY, and SPIN.

Variable Documentation

◆ __all__

list cimod.__all__
private
Initial value:
1 = [
2  "cxxcimod",
3  "SPIN",
4  "BINARY",
5  "Vartype",
6  "make_BinaryQuadraticModel",
7  "make_BinaryQuadraticModel_from_JSON",
8  "BinaryQuadraticModel",
9  "make_BinaryPolynomialModel",
10  "make_BinaryPolynomialModel_from_JSON",
11  "BinaryPolynomialModel",
12 ]

◆ __path__

cimod.__path__ = extend_path(__path__, __name__)
private