cimod
C++ library for a binary (and polynomial) quadratic model.
|
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__ |
using cimod::Adjacency = typedef std::unordered_map<IndexType, std::unordered_map<IndexType, FloatType> > |
Type alias for adjacency list.
IndexType |
using cimod::Linear = typedef std::unordered_map<IndexType, FloatType> |
Type alias for linear bias.
IndexType |
using cimod::Polynomial = typedef std::unordered_map<std::vector<IndexType>, FloatType, vector_hash> |
Type alias for the polynomial interactions as std::unordered_map.
IndexType | |
FloatType |
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>>.
IndexType |
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.
FloatType |
using cimod::Quadratic = typedef std::unordered_map<std::pair<IndexType, IndexType>, FloatType, pair_hash> |
Type alias for quadratic bias.
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.
IndexType |
|
strong |
|
inline |
Check that the variable has appropriate value.
var | |
vartype |
References BINARY, SPIN, and cimod.model.legacy.binary_quadratic_model::vartype.
Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::energy().
void cimod::CheckVariables | ( | const std::vector< IntegerType > & | configurations, |
const Vartype & | vartype | ||
) |
Convert vartype from string to cimod::Vartype.
IntegerType | The type of spin/binary configuration |
configurations | The spin/binary configuration |
vartype | The model's type. cimod::Vartype::SPIN or cimod::Vartype::BINARY. |
References BINARY, SPIN, and cimod.model.legacy.binary_quadratic_model::vartype.
void cimod::CheckVartypeNotNONE | ( | const Vartype & | vartype | ) |
Check if the input vartype is not Vartype::NONE.
vartype | The model's type. cimod::Vartype::SPIN or cimod::Vartype::BINARY. |
References NONE, and cimod.model.legacy.binary_quadratic_model::vartype.
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.
IndexType | Used to represent the indices of variables |
key | This may be formatted. |
vartype | The 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().
void cimod::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)
C_key | |
C_value |
um | |
key | |
val |
Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::add_interaction(), cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::add_variable(), cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::binary_to_spin(), cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::from_serializable(), cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::spin_to_binary(), and cimod::BinaryQuadraticModel< IndexType, FloatType, Dict >::to_qubo().
cimod::Vartype cimod::ToCimodVartype | ( | const std::string & | vartype_str | ) |
Convert vartype from string to cimod::Vartype.
vartype_str | "SPIN" or "BINARY" |
|
private |
|
private |