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< ValueType > CalculateEnergies () const
void Sample ()
 Execute sampling. Seed to be used in the calculation will be set automatically.
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.

References model_.

Member Function Documentation

◆ CalculateEnergies()

template<class ModelType>
std::vector< ValueType > openjij::sampler::SASampler< ModelType >::CalculateEnergies ( ) const
inline

References model_, num_reads_, and samples_.

◆ 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

Referenced by TemplateSampler().

Here is the caller graph for this function:

◆ GetBetaMax()

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

Get the maximum inverse temperature.

Returns
The maximum inverse temperature.

References 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 beta_min_.

◆ GetIndexList()

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

References model_.

◆ GetModel()

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

Get the model.

Returns
The model.

References 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 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 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 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 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 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 seed_.

◆ GetTemperatureSchedule()

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

Get the temperature schedule.

Returns
The temperature schedule.

References 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 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 Sample().

Referenced by Sample().

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

◆ Sample() [2/2]

template<class ModelType>
void openjij::sampler::SASampler< ModelType >::Sample ( const std::uint64_t seed)
inline

Execute sampling.

Parameters
seedThe seed to be used in the calculation.

References openjij::algorithm::MT, openjij::algorithm::MT_64, num_reads_, random_number_engine_, samples_, seed_, TemplateSampler(), and openjij::algorithm::XORSHIFT.

Here is the call graph for this function:

◆ 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 beta_max_.

◆ SetBetaMaxAuto()

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

Set the maximum inverse temperature automatically.

References beta_max_, and 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 beta_min_.

◆ SetBetaMinAuto()

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

Set the minimum inverse temperature automatically.

References beta_min_, and 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 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 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 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 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 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 update_method_.

◆ TemplateSampler()

template<class ModelType>
template<class SystemType, class RandType>
void openjij::sampler::SASampler< ModelType >::TemplateSampler ( )
inlineprivate

References beta_max_, beta_min_, openjij::utility::GenerateBetaList(), GenerateSeedPairList(), model_, num_reads_, num_sweeps_, samples_, schedule_, seed_, openjij::updater::SingleFlipUpdater(), and update_method_.

Referenced by Sample().

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

Member Data Documentation

◆ beta_max_

template<class ModelType>
ValueType openjij::sampler::SASampler< ModelType >::beta_max_ = 1
private

The end inverse temperature.

Referenced by GetBetaMax(), SetBetaMax(), SetBetaMaxAuto(), and TemplateSampler().

◆ beta_min_

template<class ModelType>
ValueType openjij::sampler::SASampler< ModelType >::beta_min_ = 1
private

The start inverse temperature.

Referenced by GetBetaMin(), SetBetaMin(), SetBetaMinAuto(), and TemplateSampler().

◆ model_

template<class ModelType>
const ModelType openjij::sampler::SASampler< ModelType >::model_
private

◆ num_reads_

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

The number of reads (samples).

Referenced by CalculateEnergies(), GetNumReads(), Sample(), SetNumReads(), and TemplateSampler().

◆ num_sweeps_

template<class ModelType>
std::int32_t openjij::sampler::SASampler< ModelType >::num_sweeps_ = 1000
private

The number of sweeps.

Referenced by GetNumSweeps(), SetNumSweeps(), and TemplateSampler().

◆ num_threads_

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

The number of threads in the calculation.

Referenced by GetNumThreads(), and SetNumThreads().

◆ random_number_engine_

template<class ModelType>
algorithm::RandomNumberEngine openjij::sampler::SASampler< ModelType >::random_number_engine_ = algorithm::RandomNumberEngine::XORSHIFT
private

Random number engine for updating and initializing state.

Referenced by GetRandomNumberEngine(), Sample(), and SetRandomNumberEngine().

◆ samples_

template<class ModelType>
std::vector<std::vector<VariableType> > openjij::sampler::SASampler< ModelType >::samples_
private

The samples.

Referenced by CalculateEnergies(), GetSamples(), Sample(), and TemplateSampler().

◆ schedule_

template<class ModelType>
utility::TemperatureSchedule openjij::sampler::SASampler< ModelType >::schedule_ = utility::TemperatureSchedule::GEOMETRIC
private

◆ seed_

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

The seed to be used in the calculation.

Referenced by GetSeed(), Sample(), and TemplateSampler().

◆ update_method_

template<class ModelType>
algorithm::UpdateMethod openjij::sampler::SASampler< ModelType >::update_method_ = algorithm::UpdateMethod::METROPOLIS
private

The update method used in the state update.

Referenced by GetUpdateMethod(), SetUpdateMethod(), and TemplateSampler().


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