cimod
C++ library for a binary (and polynomial) quadratic model.
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType > Class Template Reference

Class for dense binary quadratic model. More...

#include <binary_quadratic_model.hpp>

Public Types

using DenseMatrix = Eigen::Matrix< FloatType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor >
 Eigen Matrix if DataType is Dense , Matrix is equal to Eigen::Matrix if DataType is Sparse, Matrix is equal to Eigen::SparseMatrix. More...
 
using SparseMatrix = Eigen::SparseMatrix< FloatType, Eigen::RowMajor >
 
using SpIter = typename SparseMatrix::InnerIterator
 
using Matrix = std::conditional_t< std::is_same_v< DataType, Dense >, DenseMatrix, SparseMatrix >
 
using Vector = Eigen::Matrix< FloatType, Eigen::Dynamic, 1 >
 
using json = nlohmann::json
 

Public Member Functions

 BinaryQuadraticModel (const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, const FloatType &offset, const Vartype vartype)
 BinaryQuadraticModel constructor. More...
 
 BinaryQuadraticModel (const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, const Vartype vartype)
 BinaryQuadraticModel constructor. More...
 
 BinaryQuadraticModel (const Eigen::Ref< const DenseMatrix > &mat, const std::vector< IndexType > &labels_vec, const FloatType &offset, const Vartype vartype, bool fix_format=true)
 BinaryQuadraticModel constructor (with matrix);. More...
 
 BinaryQuadraticModel (const Eigen::Ref< const DenseMatrix > &mat, const std::vector< IndexType > &labels_vec, const Vartype vartype, bool fix_format=true)
 BinaryQuadraticModel constructor (with matrix);. More...
 
 BinaryQuadraticModel (const SparseMatrix &mat, const std::vector< IndexType > &labels_vec, const FloatType &offset, const Vartype vartype)
 BinaryQuadraticModel constructor (with sparse matrix); this constructor is for developers. More...
 
 BinaryQuadraticModel (const SparseMatrix &mat, const std::vector< IndexType > &labels_vec, const Vartype vartype)
 BinaryQuadraticModel constructor (with sparse matrix); this constructor is for developers. More...
 
 BinaryQuadraticModel (const BinaryQuadraticModel &)=default
 
size_t get_num_variables () const
 get the number of variables More...
 
size_t length () const
 Return the number of variables. More...
 
bool contains (const IndexType &v) const
 Return true if the variable contains v. More...
 
FloatType get_linear (IndexType label_i) const
 Get the element of linear object. More...
 
Linear< IndexType, FloatType > get_linear () const
 Get linear object. More...
 
FloatType get_quadratic (IndexType label_i, IndexType label_j) const
 Get the element of quadratic object. More...
 
Quadratic< IndexType, FloatType > get_quadratic () const
 Get uadratic object. More...
 
FloatType get_offset () const
 Get the offset. More...
 
Vartype get_vartype () const
 Get the vartype object. More...
 
const std::vector< IndexType > & get_variables () const
 Get variables. More...
 
BinaryQuadraticModel< IndexType, FloatType, DataType > empty (Vartype vartype)
 Create an empty BinaryQuadraticModel. More...
 
void add_variable (const IndexType &v, const FloatType &bias)
 Add variable v and/or its bias to a binary quadratic model. More...
 
void add_variables_from (const Linear< IndexType, FloatType > &linear)
 Add variables and/or linear biases to a binary quadratic model. More...
 
void add_interaction (const IndexType &u, const IndexType &v, const FloatType &bias)
 Add an interaction and/or quadratic bias to a binary quadratic model. More...
 
void add_interactions_from (const Quadratic< IndexType, FloatType > &quadratic)
 Add interactions and/or quadratic biases to a binary quadratic model. More...
 
void remove_variable (const IndexType &v)
 Remove variable v and all its interactions from a binary quadratic model. More...
 
void remove_variables_from (const std::vector< IndexType > &variables)
 Remove specified variables and all of their interactions from a binary quadratic model. More...
 
void remove_interaction (const IndexType &u, const IndexType &v)
 Remove interaction of variables u, v from a binary quadratic model. More...
 
void remove_interactions_from (const std::vector< std::pair< IndexType, IndexType >> &interactions)
 Remove all specified interactions from the binary quadratic model. More...
 
void add_offset (const FloatType &offset)
 Add specified value to the offset of a binary quadratic model. More...
 
void remove_offset ()
 Set the binary quadratic model's offset to zero. More...
 
void scale (const FloatType &scalar, const std::vector< IndexType > &ignored_variables={}, const std::vector< std::pair< IndexType, IndexType >> &ignored_interactions={}, const bool ignored_offset=false)
 Multiply by the specified scalar all the biases and offset of a binary quadratic model. More...
 
void normalize (const std::pair< FloatType, FloatType > &bias_range={ 1.0, 1.0 }, const bool use_quadratic_range=false, const std::pair< FloatType, FloatType > &quadratic_range={ 1.0, 1.0 }, const std::vector< IndexType > &ignored_variables={}, const std::vector< std::pair< IndexType, IndexType >> &ignored_interactions={}, const bool ignored_offset=false)
 Normalizes the biases of the binary quadratic model such that they fall in the provided range(s), and adjusts the offset appropriately. More...
 
void fix_variable (const IndexType &v, const int32_t &value)
 Fix the value of a variable and remove it from a binary quadratic model. More...
 
void fix_variables (const std::vector< std::pair< IndexType, int32_t >> &fixed)
 Fix the value of the variables and remove it from a binary quadratic model. More...
 
void flip_variable (const IndexType &v)
 Flip variable v in a binary quadratic model. More...
 
void change_vartype (const Vartype &vartype)
 ‍** More...
 
BinaryQuadraticModel< IndexType, FloatType, DataType > change_vartype (const Vartype &vartype, bool inplace)
 Create a binary quadratic model with the specified vartype. More...
 
FloatType energy (const Sample< IndexType > &sample) const
 Determine the energy of the specified sample of a binary quadratic model. More...
 
std::vector< FloatType > energies (const std::vector< Sample< IndexType >> &samples_like) const
 Determine the energies of the given samples. More...
 
std::tuple< Quadratic< IndexType, FloatType >, FloatType > to_qubo ()
 Convert a binary quadratic model to QUBO format. More...
 
std::tuple< Linear< IndexType, FloatType >, Quadratic< IndexType, FloatType >, FloatType > to_ising ()
 Convert a binary quadratic model to Ising format. More...
 
Matrix interaction_matrix () const
 generate (Dense or Sparse) interaction matrix with given list of indices The generated matrix will be the following triangular matrix: More...
 
template<typename T = DataType>
json to_serializable (dispatch_t< T, Dense >=nullptr) const
 Convert the binary quadratic model to a dense-version serializable object. More...
 
template<typename T = DataType>
json to_serializable (dispatch_t< T, Sparse >=nullptr) const
 Convert the binary quadratic model to a serializable object. More...
 

Static Public Member Functions

static BinaryQuadraticModel< IndexType, FloatType, DataType > from_qubo (const Quadratic< IndexType, FloatType > &Q, FloatType offset=0.0)
 Create a binary quadratic model from a QUBO model. More...
 
static BinaryQuadraticModel< IndexType, FloatType, DataType > from_ising (const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, FloatType offset=0.0)
 Create a binary quadratic model from an Ising problem. More...
 
template<typename IndexType_serial = IndexType, typename FloatType_serial = FloatType, typename T = DataType>
static BinaryQuadraticModel< IndexType_serial, FloatType_serial, DataType > from_serializable (const json &input, dispatch_t< T, Dense >=nullptr)
 Create a BinaryQuadraticModel instance from a serializable object. More...
 
template<typename IndexType_serial = IndexType, typename FloatType_serial = FloatType, typename T = DataType>
static BinaryQuadraticModel< IndexType_serial, FloatType_serial, DataType > from_serializable (const json &input, dispatch_t< T, Sparse >=nullptr)
 Create a BinaryQuadraticModel instance from a serializable object. More...
 

Protected Member Functions

void _set_label_to_idx ()
 set _label_to_idx from _idx_to_label More...
 
template<typename T = DataType>
FloatType & _quadmat_get (size_t i, size_t j, dispatch_t< T, Dense >=nullptr)
 access elements for dense matrix More...
 
template<typename T = DataType>
FloatType _quadmat_get (size_t i, size_t j, dispatch_t< T, Dense >=nullptr) const
 access elements for dense matrix More...
 
template<typename T = DataType>
FloatType & _quadmat_get (size_t i, size_t j, dispatch_t< T, Sparse >=nullptr)
 access elements for sparse matrix More...
 
template<typename T = DataType>
FloatType _quadmat_get (size_t i, size_t j, dispatch_t< T, Sparse >=nullptr) const
 access elements for sparse matrix More...
 
FloatType & _mat (IndexType label_i, IndexType label_j)
 get reference of _quadmat(i,j) More...
 
FloatType & _mat (IndexType label_i)
 get reference of _quadmat(i,i) More...
 
FloatType _mat (IndexType label_i, IndexType label_j) const
 get reference of _quadmat(i,j) More...
 
FloatType _mat (IndexType label_i) const
 get reference of _quadmat(i,i) More...
 
template<typename T = DataType>
FloatType _max_linear (dispatch_t< T, Dense >=nullptr) const
 calculate maximum element in linear term for dense graph More...
 
template<typename T = DataType>
FloatType _max_quadratic (dispatch_t< T, Dense >=nullptr) const
 calculate maximum element in quadratic term for dense graph More...
 
template<typename T = DataType>
FloatType _min_linear (dispatch_t< T, Dense >=nullptr) const
 calculate minimum element in linear term for dense graph More...
 
template<typename T = DataType>
FloatType _min_quadratic (dispatch_t< T, Dense >=nullptr) const
 calculate minimum element in quadratic term for dense graph More...
 
template<typename T = DataType>
FloatType _max_linear (dispatch_t< T, Sparse >=nullptr) const
 calculate maximum element in linear term for dense graph More...
 
template<typename T = DataType>
FloatType _max_quadratic (dispatch_t< T, Sparse >=nullptr) const
 calculate maximum element in quadratic term for dense graph More...
 
template<typename T = DataType>
FloatType _min_linear (dispatch_t< T, Sparse >=nullptr) const
 calculate minimum element in linear term for dense graph More...
 
template<typename T = DataType>
FloatType _min_quadratic (dispatch_t< T, Sparse >=nullptr) const
 calculate minimum element in quadratic term for dense graph More...
 
template<typename T = DataType>
void _insert_label_into_mat (IndexType label_i, dispatch_t< T, Dense >=nullptr)
 insert row and column that corresponds to added label into _quadmat for dense matrix More...
 
template<typename T = DataType>
void _insert_label_into_mat (IndexType label_i, dispatch_t< T, Sparse >=nullptr)
 insert row and column that corresponds to added label into _quadmat for sparse matrix More...
 
template<typename T = DataType>
void _delete_label_from_mat (IndexType label_i, dispatch_t< T, Dense >=nullptr)
 delete row and column that corresponds to existing label from _quadmat for dense matrix More...
 
template<typename T = DataType>
void _delete_label_from_mat (IndexType label_i, dispatch_t< T, Sparse >=nullptr)
 delete row and column that corresponds to existing label from _quadmat for sparse matrix More...
 
void _add_new_label (IndexType label_i)
 add new label if label_i already exists, this process is skipped. More...
 
void _delete_label (IndexType label_i, bool force_delete=true)
 delete label if label_i does not exist, this process is skipped. More...
 
template<typename T = DataType>
void _initialize_quadmat (const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, dispatch_t< T, Dense >=nullptr)
 initialize matrix with linear and quadratic dicts (for dense matrix) More...
 
template<typename T = DataType>
void _initialize_quadmat (const Linear< IndexType, FloatType > &linear, const Quadratic< IndexType, FloatType > &quadratic, dispatch_t< T, Sparse >=nullptr)
 initialize matrix with linear and quadratic dicts (for sparse matrix) More...
 
template<typename T = DataType>
void _add_triangular_elements (const DenseMatrix &mat, bool fix_format, dispatch_t< T, Dense >=nullptr)
 add non-diagonal elements to upper triangular components for dense matrix More...
 
template<typename T = DataType>
void _add_triangular_elements (const DenseMatrix &mat, bool fix_format, dispatch_t< T, Sparse >=nullptr)
 add non-diagonal elements to upper triangular components for sparse matrix More...
 
void _initialize_quadmat (const DenseMatrix &mat, const std::vector< IndexType > &labels_vec, bool fix_format)
 initialize matrix with matrix and labels the form of matrix is assumed to be the following two forms: More...
 
Linear< IndexType, FloatType > _generate_linear () const
 
template<typename T = DataType>
Quadratic< IndexType, FloatType > _generate_quadratic (dispatch_t< T, Dense >=nullptr) const
 
template<typename T = DataType>
Quadratic< IndexType, FloatType > _generate_quadratic (dispatch_t< T, Sparse >=nullptr) const
 
void _initialize_quadmat (const SparseMatrix &mat, const std::vector< IndexType > &labels_vec)
 initialize matrix with matrix and labels the form of matrix is assumed to be the following form: More...
 
template<typename T = DataType>
void _spin_to_binary (dispatch_t< T, Dense >=nullptr)
 change internal variable from Ising to QUBO ones for dense matrix The following conversion is applied: More...
 
template<typename T = DataType>
void _spin_to_binary (dispatch_t< T, Sparse >=nullptr)
 change internal variable from Ising to QUBO ones for sparse matrix The following conversion is applied: More...
 
template<typename T = DataType>
void _binary_to_spin (dispatch_t< T, Dense >=nullptr)
 change internal variable from QUBO to Ising ones for dense matrix The following conversion is applied: More...
 
template<typename T = DataType>
void _binary_to_spin (dispatch_t< T, Sparse >=nullptr)
 change internal variable from QUBO to Ising ones for sparse matrix The following conversion is applied: More...
 

Protected Attributes

Matrix _quadmat
 quadratic dense-type matrix The stored matrix has the following triangular form: More...
 
std::vector< IndexType > _idx_to_label
 vector for converting index to label the list is asssumed to be sorted More...
 
std::unordered_map< IndexType, size_t > _label_to_idx
 dict for converting label to index More...
 
FloatType m_offset
 The energy offset associated with the model. More...
 
Vartype m_vartype = Vartype::NONE
 The model's type. More...
 

Private Types

template<typename T , typename U >
using dispatch_t = std::enable_if_t< std::is_same_v< T, U >, std::nullptr_t >
 template type for dispatch used for SFINAE More...
 

Detailed Description

template<typename IndexType, typename FloatType, typename DataType>
class cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >

Class for dense binary quadratic model.

Template Parameters
IndexTypeindex type. type must be hashable and comparable.
FloatType
IndexType

Member Typedef Documentation

◆ DenseMatrix

template<typename IndexType , typename FloatType , typename DataType >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::DenseMatrix = Eigen::Matrix<FloatType, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>

Eigen Matrix if DataType is Dense , Matrix is equal to Eigen::Matrix if DataType is Sparse, Matrix is equal to Eigen::SparseMatrix.

◆ dispatch_t

template<typename IndexType , typename FloatType , typename DataType >
template<typename T , typename U >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::dispatch_t = std::enable_if_t<std::is_same_v<T, U>, std::nullptr_t>
private

template type for dispatch used for SFINAE

Template Parameters
T
U

◆ json

template<typename IndexType , typename FloatType , typename DataType >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::json = nlohmann::json

◆ Matrix

template<typename IndexType , typename FloatType , typename DataType >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::Matrix = std::conditional_t<std::is_same_v<DataType, Dense>, DenseMatrix, SparseMatrix>

◆ SparseMatrix

template<typename IndexType , typename FloatType , typename DataType >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::SparseMatrix = Eigen::SparseMatrix<FloatType, Eigen::RowMajor>

◆ SpIter

template<typename IndexType , typename FloatType , typename DataType >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::SpIter = typename SparseMatrix::InnerIterator

◆ Vector

template<typename IndexType , typename FloatType , typename DataType >
using cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::Vector = Eigen::Matrix<FloatType, Eigen::Dynamic, 1>

Constructor & Destructor Documentation

◆ BinaryQuadraticModel() [1/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const Linear< IndexType, FloatType > &  linear,
const Quadratic< IndexType, FloatType > &  quadratic,
const FloatType &  offset,
const Vartype  vartype 
)
inline

BinaryQuadraticModel constructor.

Parameters
linear
quadratic
offset
vartype

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat().

Here is the call graph for this function:

◆ BinaryQuadraticModel() [2/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const Linear< IndexType, FloatType > &  linear,
const Quadratic< IndexType, FloatType > &  quadratic,
const Vartype  vartype 
)
inline

BinaryQuadraticModel constructor.

Parameters
linear
quadratic
vartype

◆ BinaryQuadraticModel() [3/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const Eigen::Ref< const DenseMatrix > &  mat,
const std::vector< IndexType > &  labels_vec,
const FloatType &  offset,
const Vartype  vartype,
bool  fix_format = true 
)
inline

BinaryQuadraticModel constructor (with matrix);.

Parameters
mat
labels_vec
offset
vartype

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat().

Here is the call graph for this function:

◆ BinaryQuadraticModel() [4/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const Eigen::Ref< const DenseMatrix > &  mat,
const std::vector< IndexType > &  labels_vec,
const Vartype  vartype,
bool  fix_format = true 
)
inline

BinaryQuadraticModel constructor (with matrix);.

Parameters
mat
labels_vec
vartype

◆ BinaryQuadraticModel() [5/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const SparseMatrix mat,
const std::vector< IndexType > &  labels_vec,
const FloatType &  offset,
const Vartype  vartype 
)
inline

BinaryQuadraticModel constructor (with sparse matrix); this constructor is for developers.

Parameters
mat
labels_vec
offset
vartype

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat().

Here is the call graph for this function:

◆ BinaryQuadraticModel() [6/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const SparseMatrix mat,
const std::vector< IndexType > &  labels_vec,
const Vartype  vartype 
)
inline

BinaryQuadraticModel constructor (with sparse matrix); this constructor is for developers.

Parameters
mat
labels_vec
vartype

◆ BinaryQuadraticModel() [7/7]

template<typename IndexType , typename FloatType , typename DataType >
cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::BinaryQuadraticModel ( const BinaryQuadraticModel< IndexType, FloatType, DataType > &  )
default

Member Function Documentation

◆ _add_new_label()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_add_new_label ( IndexType  label_i)
inlineprotected

◆ _add_triangular_elements() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_add_triangular_elements ( const DenseMatrix mat,
bool  fix_format,
dispatch_t< T, Dense = nullptr 
)
inlineprotected

add non-diagonal elements to upper triangular components for dense matrix

Template Parameters
T
Parameters
mat
fix_format

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat().

Here is the caller graph for this function:

◆ _add_triangular_elements() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_add_triangular_elements ( const DenseMatrix mat,
bool  fix_format,
dispatch_t< T, Sparse = nullptr 
)
inlineprotected

add non-diagonal elements to upper triangular components for sparse matrix

Template Parameters
T
Parameters
mat
fix_format

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _binary_to_spin() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_binary_to_spin ( dispatch_t< T, Dense = nullptr)
inlineprotected

change internal variable from QUBO to Ising ones for dense matrix The following conversion is applied:

\[ \mathrm{offset} += \frac{1}{4}\sum_{i<j} Q_{ij} + \frac{1}{2}\sum_{i}Q_{ii} \]

\[ h_i += \frac{1}{4}\left(\sum_{j}Q_{ji}+\sum_{j}Q_{ij}\right) + \frac{1}{2}Q_{ii} \]

\[ J_{ij} = \frac{1}{4}Q_{ij} \]

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_offset, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_vartype, and cimod::SPIN.

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::change_vartype().

Here is the caller graph for this function:

◆ _binary_to_spin() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_binary_to_spin ( dispatch_t< T, Sparse = nullptr)
inlineprotected

change internal variable from QUBO to Ising ones for sparse matrix The following conversion is applied:

\[ \mathrm{offset} += \frac{1}{4}\sum_{i<j} Q_{ij} + \frac{1}{2}\sum_{i}Q_{ii} \]

\[ h_i += \frac{1}{4}\left(\sum_{j}Q_{ji}+\sum_{j}Q_{ij}\right) + \frac{1}{2}Q_{ii} \]

\[ J_{ij} = \frac{1}{4}Q_{ij} \]

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_offset, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_vartype, and cimod::SPIN.

◆ _delete_label()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label ( IndexType  label_i,
bool  force_delete = true 
)
inlineprotected

delete label if label_i does not exist, this process is skipped.

Parameters
label_i
force_deleteif true, delete label whenever there exists corresponding nonzero elements in the matrix. otherwise, delete label only if there are no corresponding nonzero elements in the matrix.

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label_from_mat(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_set_label_to_idx().

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_interaction(), and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_variable().

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

◆ _delete_label_from_mat() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label_from_mat ( IndexType  label_i,
dispatch_t< T, Dense = nullptr 
)
inlineprotected

delete row and column that corresponds to existing label from _quadmat for dense matrix

Parameters
label_i

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_label_to_idx, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label().

Here is the caller graph for this function:

◆ _delete_label_from_mat() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label_from_mat ( IndexType  label_i,
dispatch_t< T, Sparse = nullptr 
)
inlineprotected

delete row and column that corresponds to existing label from _quadmat for sparse matrix

Parameters
label_i

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_label_to_idx, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _generate_linear()

template<typename IndexType , typename FloatType , typename DataType >
Linear<IndexType, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_generate_linear ( ) const
inlineprotected

◆ _generate_quadratic() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
Quadratic<IndexType, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_generate_quadratic ( dispatch_t< T, Dense = nullptr) const
inlineprotected

◆ _generate_quadratic() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
Quadratic<IndexType, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_generate_quadratic ( dispatch_t< T, Sparse = nullptr) const
inlineprotected

◆ _initialize_quadmat() [1/4]

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat ( const DenseMatrix mat,
const std::vector< IndexType > &  labels_vec,
bool  fix_format 
)
inlineprotected

initialize matrix with matrix and labels the form of matrix is assumed to be the following two forms:

\[ \begin{pmatrix} J_{0,0} & J_{0,1} & \cdots & J_{0,N-1} & h_{0}\\ J_{1,0} & J_{1,1} & \cdots & J_{1,N-1} & h_{1}\\ \vdots & \vdots & \vdots & \vdots & \vdots \\ J_{N-1,0} & J_{N-1,1} & \cdots & J_{N-1,N-1} & h_{N-1}\\ h_{0} & h_{1} & \cdots & h_{N-1} & 1 \\ \end{pmatrix} \]

or

\[ \begin{pmatrix} h_{0} & J_{0,1} & \cdots & J_{0,N-1}\\ J_{1,0} & h_{1} & \cdots & J_{1,N-1}\\ \vdots & \vdots & \vdots & \vdots\\ J_{N-1,0} & J_{N-1,1} & \cdots & h_{N-1}\\ \end{pmatrix} \]

if fix_format is set to false, the following shape is assumed:

\[ \begin{pmatrix} J_{0,0} & J_{0,1} & \cdots & J_{0,N-1} & h_{0}\\ 0 & J_{1,1} & \cdots & J_{1,N-1} & h_{1}\\ \vdots & \vdots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & J_{N-1,N-1} & h_{N-1}\\ 0 & 0 & \cdots & 0 & 1 \\ \end{pmatrix} \]

Parameters
mat
labels
fix_format

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_add_triangular_elements(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get(), and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_set_label_to_idx().

Here is the call graph for this function:

◆ _initialize_quadmat() [2/4]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat ( const Linear< IndexType, FloatType > &  linear,
const Quadratic< IndexType, FloatType > &  quadratic,
dispatch_t< T, Dense = nullptr 
)
inlineprotected

◆ _initialize_quadmat() [3/4]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat ( const Linear< IndexType, FloatType > &  linear,
const Quadratic< IndexType, FloatType > &  quadratic,
dispatch_t< T, Sparse = nullptr 
)
inlineprotected

◆ _initialize_quadmat() [4/4]

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat ( const SparseMatrix mat,
const std::vector< IndexType > &  labels_vec 
)
inlineprotected

initialize matrix with matrix and labels the form of matrix is assumed to be the following form:

\[ \begin{pmatrix} J_{0,0} & J_{0,1} & \cdots & J_{0,N-1} & h_{0}\\ 0 & J_{1,1} & \cdots & J_{1,N-1} & h_{1}\\ \vdots & \vdots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & J_{N-1,N-1} & h_{N-1}\\ 0 & 0 & \cdots & 0 & 1 \\ \end{pmatrix} \]

Parameters
mat
labels_vec

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_set_label_to_idx().

Here is the call graph for this function:

◆ _insert_label_into_mat() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_insert_label_into_mat ( IndexType  label_i,
dispatch_t< T, Dense = nullptr 
)
inlineprotected

insert row and column that corresponds to added label into _quadmat for dense matrix

Parameters
label_i

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_label_to_idx, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_add_new_label().

Here is the caller graph for this function:

◆ _insert_label_into_mat() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_insert_label_into_mat ( IndexType  label_i,
dispatch_t< T, Sparse = nullptr 
)
inlineprotected

insert row and column that corresponds to added label into _quadmat for sparse matrix

Parameters
label_i

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_label_to_idx, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _mat() [1/4]

template<typename IndexType , typename FloatType , typename DataType >
FloatType& cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_mat ( IndexType  label_i)
inlineprotected

◆ _mat() [2/4]

template<typename IndexType , typename FloatType , typename DataType >
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_mat ( IndexType  label_i) const
inlineprotected

◆ _mat() [3/4]

◆ _mat() [4/4]

template<typename IndexType , typename FloatType , typename DataType >
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_mat ( IndexType  label_i,
IndexType  label_j 
) const
inlineprotected

get reference of _quadmat(i,j)

Parameters
label_i
label_j
Returns
reference of _quadmat(i,j)

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_label_to_idx, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get().

Here is the call graph for this function:

◆ _max_linear() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_max_linear ( dispatch_t< T, Dense = nullptr) const
inlineprotected

calculate maximum element in linear term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _max_linear() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_max_linear ( dispatch_t< T, Sparse = nullptr) const
inlineprotected

calculate maximum element in linear term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _max_quadratic() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_max_quadratic ( dispatch_t< T, Dense = nullptr) const
inlineprotected

calculate maximum element in quadratic term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _max_quadratic() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_max_quadratic ( dispatch_t< T, Sparse = nullptr) const
inlineprotected

calculate maximum element in quadratic term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _min_linear() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_min_linear ( dispatch_t< T, Dense = nullptr) const
inlineprotected

calculate minimum element in linear term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _min_linear() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_min_linear ( dispatch_t< T, Sparse = nullptr) const
inlineprotected

calculate minimum element in linear term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _min_quadratic() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_min_quadratic ( dispatch_t< T, Dense = nullptr) const
inlineprotected

calculate minimum element in quadratic term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _min_quadratic() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_min_quadratic ( dispatch_t< T, Sparse = nullptr) const
inlineprotected

calculate minimum element in quadratic term for dense graph

Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _quadmat_get() [1/4]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType& cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get ( size_t  i,
size_t  j,
dispatch_t< T, Dense = nullptr 
)
inlineprotected

◆ _quadmat_get() [2/4]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get ( size_t  i,
size_t  j,
dispatch_t< T, Dense = nullptr 
) const
inlineprotected

access elements for dense matrix

Template Parameters
T
Parameters
i
j
dispatch_t
Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _quadmat_get() [3/4]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType& cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get ( size_t  i,
size_t  j,
dispatch_t< T, Sparse = nullptr 
)
inlineprotected

access elements for sparse matrix

Template Parameters
T
Parameters
i
j
dispatch_t
Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _quadmat_get() [4/4]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get ( size_t  i,
size_t  j,
dispatch_t< T, Sparse = nullptr 
) const
inlineprotected

access elements for sparse matrix

Template Parameters
T
Parameters
i
j
dispatch_t
Returns

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ _set_label_to_idx()

◆ _spin_to_binary() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_spin_to_binary ( dispatch_t< T, Dense = nullptr)
inlineprotected

change internal variable from Ising to QUBO ones for dense matrix The following conversion is applied:

\[ \mathrm{offset} += \sum_{i<j} J_{ij} - \sum_{i}h_{i} \]

\[ Q_ii += -2\left(\sum_{j}J_{ji}+\sum_{j}J_{ij}\right) + 2h_{i} \]

\[ Q_{ij} = 4J_{ij} \]

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat, cimod::BINARY, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_offset, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_vartype.

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::change_vartype().

Here is the caller graph for this function:

◆ _spin_to_binary() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_spin_to_binary ( dispatch_t< T, Sparse = nullptr)
inlineprotected

change internal variable from Ising to QUBO ones for sparse matrix The following conversion is applied:

\[ \mathrm{offset} += \sum_{i<j} J_{ij} - \sum_{i}h_{i} \]

\[ Q_ii += -2\left(\sum_{j}J_{ji}+\sum_{j}J_{ij}\right) + 2h_{i} \]

\[ Q_{ij} = 4J_{ij} \]

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_idx_to_label, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat, cimod::BINARY, cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_offset, and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_vartype.

◆ add_interaction()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::add_interaction ( const IndexType &  u,
const IndexType &  v,
const FloatType &  bias 
)
inline

◆ add_interactions_from()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::add_interactions_from ( const Quadratic< IndexType, FloatType > &  quadratic)
inline

Add interactions and/or quadratic biases to a binary quadratic model.

Parameters
quadratic

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::add_interaction().

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

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

◆ add_offset()

◆ add_variable()

◆ add_variables_from()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::add_variables_from ( const Linear< IndexType, FloatType > &  linear)
inline

Add variables and/or linear biases to a binary quadratic model.

Parameters
linear

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::add_variable().

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

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

◆ change_vartype() [1/2]

◆ change_vartype() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
BinaryQuadraticModel<IndexType, FloatType, DataType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::change_vartype ( const Vartype vartype,
bool  inplace 
)
inline

Create a binary quadratic model with the specified vartype.

This function generates and returns a new object.

Parameters
vartype
inplaceif set true, the current object is converted.
Returns
created object

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::change_vartype(), and cimod.model.legacy.binary_quadratic_model::vartype.

Here is the call graph for this function:

◆ contains()

template<typename IndexType , typename FloatType , typename DataType >
bool cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::contains ( const IndexType &  v) const
inline

Return true if the variable contains v.

Returns
Return true if the variable contains v.
Parameters
v

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_label_to_idx.

◆ empty()

template<typename IndexType , typename FloatType , typename DataType >
BinaryQuadraticModel<IndexType, FloatType, DataType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::empty ( Vartype  vartype)
inline

Create an empty BinaryQuadraticModel.

Returns
empty object

References cimod.model.legacy.binary_quadratic_model::vartype.

◆ energies()

template<typename IndexType , typename FloatType , typename DataType >
std::vector<FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::energies ( const std::vector< Sample< IndexType >> &  samples_like) const
inline

Determine the energies of the given samples.

Parameters
samples_like
Returns
A vector including energies with respect to the samples.

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::energy().

Here is the call graph for this function:

◆ energy()

template<typename IndexType , typename FloatType , typename DataType >
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::energy ( const Sample< IndexType > &  sample) const
inline

◆ fix_variable()

◆ fix_variables()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::fix_variables ( const std::vector< std::pair< IndexType, int32_t >> &  fixed)
inline

Fix the value of the variables and remove it from a binary quadratic model.

Parameters
fixed

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::fix_variable().

Here is the call graph for this function:

◆ flip_variable()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::flip_variable ( const IndexType &  v)
inline

◆ from_ising()

template<typename IndexType , typename FloatType , typename DataType >
static BinaryQuadraticModel<IndexType, FloatType, DataType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::from_ising ( const Linear< IndexType, FloatType > &  linear,
const Quadratic< IndexType, FloatType > &  quadratic,
FloatType  offset = 0.0 
)
inlinestatic

Create a binary quadratic model from an Ising problem.

Parameters
linear
quadratic
offset
Returns
Binary quadratic model with vartype set to .Vartype.SPIN.

References cimod::SPIN.

◆ from_qubo()

template<typename IndexType , typename FloatType , typename DataType >
static BinaryQuadraticModel<IndexType, FloatType, DataType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::from_qubo ( const Quadratic< IndexType, FloatType > &  Q,
FloatType  offset = 0.0 
)
inlinestatic

Create a binary quadratic model from a QUBO model.

Parameters
Q
offset
Returns
Binary quadratic model with vartype set to .Vartype.BINARY.

References cimod::BINARY.

◆ from_serializable() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename IndexType_serial = IndexType, typename FloatType_serial = FloatType, typename T = DataType>
static BinaryQuadraticModel<IndexType_serial, FloatType_serial, DataType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::from_serializable ( const json input,
dispatch_t< T, Dense = nullptr 
)
inlinestatic

Create a BinaryQuadraticModel instance from a serializable object.

Template Parameters
IndexType_serial
FloatType_serial
Parameters
input
Returns
BinaryQuadraticModel<IndexType_serial, FloatType_serial>

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

◆ from_serializable() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename IndexType_serial = IndexType, typename FloatType_serial = FloatType, typename T = DataType>
static BinaryQuadraticModel<IndexType_serial, FloatType_serial, DataType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::from_serializable ( const json input,
dispatch_t< T, Sparse = nullptr 
)
inlinestatic

Create a BinaryQuadraticModel instance from a serializable object.

Template Parameters
IndexType_serial
FloatType_serial
Parameters
input
Returns
BinaryQuadraticModel<IndexType_serial, FloatType_serial>

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

◆ get_linear() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
Linear<IndexType, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_linear ( ) const
inline

Get linear object.

Returns
A linear object

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_generate_linear().

Here is the call graph for this function:

◆ get_linear() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_linear ( IndexType  label_i) const
inline

◆ get_num_variables()

◆ get_offset()

◆ get_quadratic() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
Quadratic<IndexType, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_quadratic ( ) const
inline

Get uadratic object.

Returns
A quadratic object.

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_generate_quadratic().

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::fix_variable().

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

◆ get_quadratic() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
FloatType cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_quadratic ( IndexType  label_i,
IndexType  label_j 
) const
inline

◆ get_variables()

template<typename IndexType , typename FloatType , typename DataType >
const std::vector<IndexType>& cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_variables ( ) const
inline

◆ get_vartype()

template<typename IndexType , typename FloatType , typename DataType >
Vartype cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_vartype ( ) const
inline

◆ interaction_matrix()

template<typename IndexType , typename FloatType , typename DataType >
Matrix cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::interaction_matrix ( ) const
inline

generate (Dense or Sparse) interaction matrix with given list of indices The generated matrix will be the following triangular matrix:

\[ \begin{pmatrix} J_{0,0} & J_{0,1} & \cdots & J_{0,N-1} & h_{0}\\ 0 & J_{1,1} & \cdots & J_{1,N-1} & h_{1}\\ \vdots & \vdots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & J_{N-1,N-1} & h_{N-1}\\ 0 & 0 & \cdots & 0 & 1 \\ \end{pmatrix} \]

Parameters
indices
Returns
corresponding interaction matrix (Eigen)

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat.

◆ length()

template<typename IndexType , typename FloatType , typename DataType >
size_t cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::length ( ) const
inline

Return the number of variables.

Deprecated:
use get_num_variables instead.
Returns
The number of variables.

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::get_num_variables().

Here is the call graph for this function:

◆ normalize()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::normalize ( const std::pair< FloatType, FloatType > &  bias_range = { 1.0, 1.0 },
const bool  use_quadratic_range = false,
const std::pair< FloatType, FloatType > &  quadratic_range = { 1.0, 1.0 },
const std::vector< IndexType > &  ignored_variables = {},
const std::vector< std::pair< IndexType, IndexType >> &  ignored_interactions = {},
const bool  ignored_offset = false 
)
inline

Normalizes the biases of the binary quadratic model such that they fall in the provided range(s), and adjusts the offset appropriately.

Parameters
bias_range
use_quadratic_range
quadratic_range
ignored_variables
ignored_interactions
ignored_offset

◆ remove_interaction()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_interaction ( const IndexType &  u,
const IndexType &  v 
)
inline

◆ remove_interactions_from()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_interactions_from ( const std::vector< std::pair< IndexType, IndexType >> &  interactions)
inline

◆ remove_offset()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_offset ( )
inline

Set the binary quadratic model's offset to zero.

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::add_offset(), and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::m_offset.

Here is the call graph for this function:

◆ remove_variable()

◆ remove_variables_from()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_variables_from ( const std::vector< IndexType > &  variables)
inline

Remove specified variables and all of their interactions from a binary quadratic model.

Parameters
variables

References cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::remove_variable().

Here is the call graph for this function:

◆ scale()

template<typename IndexType , typename FloatType , typename DataType >
void cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::scale ( const FloatType &  scalar,
const std::vector< IndexType > &  ignored_variables = {},
const std::vector< std::pair< IndexType, IndexType >> &  ignored_interactions = {},
const bool  ignored_offset = false 
)
inline

Multiply by the specified scalar all the biases and offset of a binary quadratic model.

Parameters
scalar
ignored_variables
ignored_interactions
ignored_offset

◆ to_ising()

template<typename IndexType , typename FloatType , typename DataType >
std::tuple<Linear<IndexType, FloatType>, Quadratic<IndexType, FloatType>, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::to_ising ( )
inline

◆ to_qubo()

template<typename IndexType , typename FloatType , typename DataType >
std::tuple<Quadratic<IndexType, FloatType>, FloatType> cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::to_qubo ( )
inline

◆ to_serializable() [1/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
json cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::to_serializable ( dispatch_t< T, Dense = nullptr) const
inline

◆ to_serializable() [2/2]

template<typename IndexType , typename FloatType , typename DataType >
template<typename T = DataType>
json cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::to_serializable ( dispatch_t< T, Sparse = nullptr) const
inline

Member Data Documentation

◆ _idx_to_label

◆ _label_to_idx

◆ _quadmat

template<typename IndexType , typename FloatType , typename DataType >
Matrix cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat
protected

quadratic dense-type matrix The stored matrix has the following triangular form:

\[ \begin{pmatrix} J_{0,0} & J_{0,1} & \cdots & J_{0,N-1} & h_{0}\\ 0 & J_{1,1} & \cdots & J_{1,N-1} & h_{1}\\ \vdots & \vdots & \vdots & \vdots & \vdots \\ 0 & 0 & \cdots & J_{N-1,N-1} & h_{N-1}\\ 0 & 0 & \cdots & 0 & 1 \\ \end{pmatrix} \]

Referenced by cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_add_triangular_elements(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_binary_to_spin(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_delete_label_from_mat(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_generate_quadratic(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_initialize_quadmat(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_insert_label_into_mat(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_mat(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_max_linear(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_max_quadratic(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_min_linear(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_min_quadratic(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_quadmat_get(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::_spin_to_binary(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::energy(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::flip_variable(), cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::interaction_matrix(), and cimod::BinaryQuadraticModel< IndexType, FloatType, DataType >::to_serializable().

◆ m_offset

◆ m_vartype


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