openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
openjij::sampler::SASampler< ModelType > Class Template Reference

Class for executing simulated annealing. More...

#include <sa_sampler.hpp>

Public Member Functions

 SASampler (const ModelType &model)
 Constructor for SASampler class.
 
void SetNumSweeps (const std::int32_t num_sweeps)
 Set the number of sweeps.
 
void SetNumReads (const std::int32_t num_reads)
 Set the number of samples.
 
void SetNumThreads (const std::int32_t num_threads)
 Set the number of threads in the calculation.
 
void SetBetaMin (const ValueType beta_min)
 Set the minimum inverse temperature.
 
void SetBetaMax (const ValueType beta_max)
 Set the minimum inverse temperature.
 
void SetBetaMinAuto ()
 Set the minimum inverse temperature automatically.
 
void SetBetaMaxAuto ()
 Set the maximum inverse temperature automatically.
 
void SetUpdateMethod (const algorithm::UpdateMethod update_method)
 Set update method used in the state update.
 
void SetRandomNumberEngine (const algorithm::RandomNumberEngine random_number_engine)
 Set random number engine for updating initializing state.
 
void SetTemperatureSchedule (const utility::TemperatureSchedule schedule)
 Set the cooling schedule.
 
const ModelType & GetModel () const
 Get the model.
 
std::int32_t GetNumSweeps () const
 Get the number of sweeps.
 
std::int32_t GetNumReads () const
 Get the number of reads.
 
std::int32_t GetNumThreads () const
 Get the number of threads.
 
ValueType GetBetaMin () const
 Get the minimum inverse temperature.
 
ValueType GetBetaMax () const
 Get the maximum inverse temperature.
 
algorithm::UpdateMethod GetUpdateMethod () const
 Get the update method used in the state update.
 
algorithm::RandomNumberEngine GetRandomNumberEngine () const
 Get the random number engine for updating and initializing state.
 
utility::TemperatureSchedule GetTemperatureSchedule () const
 Get the temperature schedule.
 
std::uint64_t GetSeed () const
 Get the seed to be used in the calculation.
 
const std::vector< typename ModelType::IndexType > & GetIndexList () const
 
const std::vector< std::vector< VariableType > > & GetSamples () const
 Get the samples.
 
std::vector< ValueTypeCalculateEnergies () const
 
void Sample ()
 Execute sampling.
 
void Sample (const std::uint64_t seed)
 Execute sampling.
 

Private Types

using ValueType = typename ModelType::ValueType
 The value type.
 
using VariableType = typename ModelType::VariableType
 The variable type.
 

Private Member Functions

template<typename RandType >
std::vector< std::pair< typename RandType::result_type, typename RandType::result_type > > GenerateSeedPairList (const typename RandType::result_type seed, const std::int32_t num_reads) const
 
template<class SystemType , class RandType >
void TemplateSampler ()
 

Private Attributes

const ModelType model_
 The model.
 
std::int32_t num_sweeps_ = 1000
 The number of sweeps.
 
std::int32_t num_reads_ = 1
 The number of reads (samples).
 
std::int32_t num_threads_ = 1
 The number of threads in the calculation.
 
ValueType beta_min_ = 1
 The start inverse temperature.
 
ValueType beta_max_ = 1
 The end inverse temperature.
 
algorithm::UpdateMethod update_method_ = algorithm::UpdateMethod::METROPOLIS
 The update method used in the state update.
 
algorithm::RandomNumberEngine random_number_engine_ = algorithm::RandomNumberEngine::XORSHIFT
 Random number engine for updating and initializing state.
 
utility::TemperatureSchedule schedule_ = utility::TemperatureSchedule::GEOMETRIC
 Cooling schedule.
 
std::uint64_t seed_ = std::random_device()()
 The seed to be used in the calculation.
 
std::vector< std::vector< VariableType > > samples_
 The samples.
 

Detailed Description

template<class ModelType>
class openjij::sampler::SASampler< ModelType >

Class for executing simulated annealing.

Template Parameters
ModelTypeThe type of models.

Member Typedef Documentation

◆ ValueType

template<class ModelType >
using openjij::sampler::SASampler< ModelType >::ValueType = typename ModelType::ValueType
private

The value type.

◆ VariableType

template<class ModelType >
using openjij::sampler::SASampler< ModelType >::VariableType = typename ModelType::VariableType
private

The variable type.

Constructor & Destructor Documentation

◆ SASampler()

template<class ModelType >
openjij::sampler::SASampler< ModelType >::SASampler ( const ModelType &  model)
inline

Constructor for SASampler class.

Parameters
modelThe model.

Member Function Documentation

◆ CalculateEnergies()

◆ GenerateSeedPairList()

template<class ModelType >
template<typename RandType >
std::vector< std::pair< typename RandType::result_type, typename RandType::result_type > > openjij::sampler::SASampler< ModelType >::GenerateSeedPairList ( const typename RandType::result_type  seed,
const std::int32_t  num_reads 
) const
inlineprivate

◆ GetBetaMax()

template<class ModelType >
ValueType openjij::sampler::SASampler< ModelType >::GetBetaMax ( ) const
inline

Get the maximum inverse temperature.

Returns
The maximum inverse temperature.

References openjij::sampler::SASampler< ModelType >::beta_max_.

◆ GetBetaMin()

template<class ModelType >
ValueType openjij::sampler::SASampler< ModelType >::GetBetaMin ( ) const
inline

Get the minimum inverse temperature.

Returns
The minimum inverse temperature.

References openjij::sampler::SASampler< ModelType >::beta_min_.

◆ GetIndexList()

template<class ModelType >
const std::vector< typename ModelType::IndexType > & openjij::sampler::SASampler< ModelType >::GetIndexList ( ) const
inline

◆ GetModel()

template<class ModelType >
const ModelType & openjij::sampler::SASampler< ModelType >::GetModel ( ) const
inline

Get the model.

Returns
The model.

References openjij::sampler::SASampler< ModelType >::model_.

◆ GetNumReads()

template<class ModelType >
std::int32_t openjij::sampler::SASampler< ModelType >::GetNumReads ( ) const
inline

Get the number of reads.

Returns
The number of reads.

References openjij::sampler::SASampler< ModelType >::num_reads_.

◆ GetNumSweeps()

template<class ModelType >
std::int32_t openjij::sampler::SASampler< ModelType >::GetNumSweeps ( ) const
inline

Get the number of sweeps.

Returns
The number of sweeps.

References openjij::sampler::SASampler< ModelType >::num_sweeps_.

◆ GetNumThreads()

template<class ModelType >
std::int32_t openjij::sampler::SASampler< ModelType >::GetNumThreads ( ) const
inline

Get the number of threads.

Returns
The number of threads.

References openjij::sampler::SASampler< ModelType >::num_threads_.

◆ GetRandomNumberEngine()

template<class ModelType >
algorithm::RandomNumberEngine openjij::sampler::SASampler< ModelType >::GetRandomNumberEngine ( ) const
inline

Get the random number engine for updating and initializing state.

Returns
The random number engine for updating and initializing state.

References openjij::sampler::SASampler< ModelType >::random_number_engine_.

◆ GetSamples()

template<class ModelType >
const std::vector< std::vector< VariableType > > & openjij::sampler::SASampler< ModelType >::GetSamples ( ) const
inline

Get the samples.

Returns
The samples.

References openjij::sampler::SASampler< ModelType >::samples_.

◆ GetSeed()

template<class ModelType >
std::uint64_t openjij::sampler::SASampler< ModelType >::GetSeed ( ) const
inline

Get the seed to be used in the calculation.

Returns
The seed.

References openjij::sampler::SASampler< ModelType >::seed_.

◆ GetTemperatureSchedule()

template<class ModelType >
utility::TemperatureSchedule openjij::sampler::SASampler< ModelType >::GetTemperatureSchedule ( ) const
inline

Get the temperature schedule.

Returns
The temperature schedule.

References openjij::sampler::SASampler< ModelType >::schedule_.

◆ GetUpdateMethod()

template<class ModelType >
algorithm::UpdateMethod openjij::sampler::SASampler< ModelType >::GetUpdateMethod ( ) const
inline

Get the update method used in the state update.

Returns
The update method used in the state update.

References openjij::sampler::SASampler< ModelType >::update_method_.

◆ Sample() [1/2]

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::Sample ( )
inline

Execute sampling.

Seed to be used in the calculation will be set automatically.

References openjij::sampler::SASampler< ModelType >::Sample().

Referenced by openjij::sampler::SASampler< ModelType >::Sample().

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

◆ Sample() [2/2]

◆ SetBetaMax()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetBetaMax ( const ValueType  beta_max)
inline

Set the minimum inverse temperature.

Parameters
beta_maxThe minimum inverse temperature, which must be larger than zero.

References openjij::sampler::SASampler< ModelType >::beta_max_.

◆ SetBetaMaxAuto()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetBetaMaxAuto ( )
inline

Set the maximum inverse temperature automatically.

References openjij::sampler::SASampler< ModelType >::beta_max_, and openjij::sampler::SASampler< ModelType >::model_.

◆ SetBetaMin()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetBetaMin ( const ValueType  beta_min)
inline

Set the minimum inverse temperature.

Parameters
beta_minThe minimum inverse temperature, which must be larger than zero.

References openjij::sampler::SASampler< ModelType >::beta_min_.

◆ SetBetaMinAuto()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetBetaMinAuto ( )
inline

Set the minimum inverse temperature automatically.

References openjij::sampler::SASampler< ModelType >::beta_min_, and openjij::sampler::SASampler< ModelType >::model_.

◆ SetNumReads()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetNumReads ( const std::int32_t  num_reads)
inline

Set the number of samples.

Parameters
num_readsThe number of samples, which must be larger than zero.

References openjij::sampler::SASampler< ModelType >::num_reads_.

◆ SetNumSweeps()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetNumSweeps ( const std::int32_t  num_sweeps)
inline

Set the number of sweeps.

Parameters
num_sweepsThe number of sweeps, which must be larger than zero.

References openjij::sampler::SASampler< ModelType >::num_sweeps_.

◆ SetNumThreads()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetNumThreads ( const std::int32_t  num_threads)
inline

Set the number of threads in the calculation.

Parameters
num_threadsThe number of threads in the calculation, which must be larger than zero.

References openjij::sampler::SASampler< ModelType >::num_threads_.

◆ SetRandomNumberEngine()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetRandomNumberEngine ( const algorithm::RandomNumberEngine  random_number_engine)
inline

Set random number engine for updating initializing state.

Parameters
random_number_engineThe random number engine.

References openjij::sampler::SASampler< ModelType >::random_number_engine_.

◆ SetTemperatureSchedule()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetTemperatureSchedule ( const utility::TemperatureSchedule  schedule)
inline

Set the cooling schedule.

Parameters
scheduleThe cooling schedule.

References openjij::sampler::SASampler< ModelType >::schedule_.

◆ SetUpdateMethod()

template<class ModelType >
void openjij::sampler::SASampler< ModelType >::SetUpdateMethod ( const algorithm::UpdateMethod  update_method)
inline

Set update method used in the state update.

Parameters
update_methodThe update method.

References openjij::sampler::SASampler< ModelType >::update_method_.

◆ TemplateSampler()

Member Data Documentation

◆ beta_max_

◆ beta_min_

◆ model_

◆ num_reads_

◆ num_sweeps_

◆ num_threads_

template<class ModelType >
std::int32_t openjij::sampler::SASampler< ModelType >::num_threads_ = 1
private

◆ random_number_engine_

◆ samples_

◆ schedule_

◆ seed_

template<class ModelType >
std::uint64_t openjij::sampler::SASampler< ModelType >::seed_ = std::random_device()()
private

◆ update_method_


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