openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
openjij.sampler.sa_sampler.SASampler Class Reference
Inheritance diagram for openjij.sampler.sa_sampler.SASampler:
Collaboration diagram for openjij.sampler.sa_sampler.SASampler:

Public Member Functions

 parameters (self)
 
 __init__ (self)
 
"oj.sampler.response.Response" sample (self, Union["openj.model.model.BinaryQuadraticModel", dimod.BinaryQuadraticModel] bqm, Optional[float] beta_min=None, Optional[float] beta_max=None, Optional[int] num_sweeps=None, Optional[int] num_reads=None, Optional[list] schedule=None, Optional[Union[list, dict]] initial_state=None, Optional[str] updater=None, Optional[bool] sparse=None, Optional[bool] reinitialize_state=None, Optional[int] seed=None)
 
 sample_hubo (self, dict[tuple, float] J, Optional[str] vartype=None, int num_sweeps=1000, int num_reads=1, int num_threads=1, Optional[float] beta_min=None, Optional[float] beta_max=None, str updater="METROPOLIS", str random_number_engine="XORSHIFT", Optional[int] seed=None, str temperature_schedule="GEOMETRIC")
 
- Public Member Functions inherited from openjij.sampler.sampler.BaseSampler
 sample_ising (self, h, J, **parameters)
 
 sample_qubo (self, Q, **parameters)
 

Public Attributes

 schedule_info
 
- Public Attributes inherited from openjij.sampler.sampler.BaseSampler
 sample_ising
 
 sample_qubo
 

Protected Member Functions

 _convert_validation_schedule (self, schedule)
 
"openjij.sampler.response.Response" _sample_hubo_old (self, Union[dict, "openj.model.model.BinaryPolynomialModel", cimod.BinaryPolynomialModel] J, Optional[str] vartype=None, Optional[float] beta_min=None, Optional[float] beta_max=None, Optional[int] num_sweeps=None, Optional[int] num_reads=None, Optional[list] schedule=None, Optional[Union[list, dict]] initial_state=None, Optional[str] updater=None, Optional[bool] reinitialize_state=None, Optional[int] seed=None)
 
- Protected Member Functions inherited from openjij.sampler.sampler.BaseSampler
 _set_params (self, **kwargs)
 
 _sampling (self, **kwargs)
 
 _cxxjij_sampling (self, model, init_generator, algorithm, system, reinitialize_state=None, seed=None, offset=None)
 
 _get_result (self, system, model)
 

Protected Attributes

 _default_params
 
 _params
 
 _make_system
 
 _algorithm
 

Additional Inherited Members

- Static Public Attributes inherited from openjij.sampler.sampler.BaseSampler
 properties = dict()
 

Detailed Description

Sampler with Simulated Annealing (SA).

Args:
    beta_min (float):
        Minmum beta (inverse temperature).
        You can overwrite in methods .sample_*.

    beta_max (float):
        Maximum beta (inverse temperature).
        You can overwrite in methods .sample_*.

    num_reads (int):
        number of sampling (algorithm) runs. defaults None.
        You can overwrite in methods .sample_*.

    num_sweeps (int):
        number of MonteCarlo steps during SA. defaults None.
        You can overwrite in methods .sample_*.

    schedule_info (dict):
        Information about an annealing schedule.

Raises:
    ValueError: If schedules or variables violate as below.
    - not list or numpy.array.
    - not list of tuple (beta : float, step_length : int).
    - beta is less than zero.

Constructor & Destructor Documentation

◆ __init__()

openjij.sampler.sa_sampler.SASampler.__init__ (   self)

Member Function Documentation

◆ _convert_validation_schedule()

openjij.sampler.sa_sampler.SASampler._convert_validation_schedule (   self,
  schedule 
)
protected
Checks if the schedule is valid and returns cxxjij schedule.

Referenced by openjij.sampler.sqa_sampler.SQASampler._annealing_schedule_setting().

Here is the caller graph for this function:

◆ _sample_hubo_old()

"openjij.sampler.response.Response" openjij.sampler.sa_sampler.SASampler._sample_hubo_old (   self,
Union[ dict, "openj.model.model.BinaryPolynomialModel", cimod.BinaryPolynomialModel ]  J,
Optional[str]   vartype = None,
Optional[float]   beta_min = None,
Optional[float]   beta_max = None,
Optional[int]   num_sweeps = None,
Optional[int]   num_reads = None,
Optional[list]   schedule = None,
Optional[Union[list, dict]]   initial_state = None,
Optional[str]   updater = None,
Optional[bool]   reinitialize_state = None,
Optional[int]   seed = None 
)
protected
Sampling from higher order unconstrainted binary optimization.

Args:
    J (dict): Interactions.
    vartype (str, openjij.VarType): "SPIN" or "BINARY".
    beta_min (float, optional): Minimum beta (initial inverse temperature). Defaults to None.
    beta_max (float, optional): Maximum beta (final inverse temperature). Defaults to None.
    schedule (list, optional): schedule list. Defaults to None.
    num_sweeps (int, optional): number of sweeps. Defaults to None.
    num_reads (int, optional): number of reads. Defaults to 1.
    init_state (list, optional): initial state. Defaults to None.
    reinitialize_state (bool): if true reinitialize state for each run
    seed (int, optional): seed for Monte Carlo algorithm. Defaults to None.

Returns:
    :class:`openjij.sampler.response.Response`: results

Examples::
    for Ising case::
        >>> sampler = openjij.SASampler()
        >>> J = {(0,): -1, (0, 1): -1, (0, 1, 2): 1}
        >>> response = sampler.sample_hubo(J, "SPIN")

    for Binary case::
        >>> sampler = ooenjij.SASampler()
        >>> J = {(0,): -1, (0, 1): -1, (0, 1, 2): 1}
        >>> response = sampler.sample_hubo(J, "BINARY")

References openjij.sampler.sampler.BaseSampler._cxxjij_sampling(), openjij.sampler.csqa_sampler.CSQASampler._params, openjij.sampler.sa_sampler.SASampler._params, openjij.sampler.sqa_sampler.SQASampler._params, openjij.sampler.sampler.BaseSampler._set_params(), openjij.sampler.sa_sampler.geometric_hubo_beta_schedule(), openjij.sampler.sa_sampler.SASampler.schedule_info, and openjij.sampler.sqa_sampler.SQASampler.schedule_info.

Referenced by openjij.sampler.sa_sampler.SASampler.sample_hubo().

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

◆ parameters()

openjij.sampler.sa_sampler.SASampler.parameters (   self)

◆ sample()

"oj.sampler.response.Response" openjij.sampler.sa_sampler.SASampler.sample (   self,
Union[ "openj.model.model.BinaryQuadraticModel", dimod.BinaryQuadraticModel ]  bqm,
Optional[float]   beta_min = None,
Optional[float]   beta_max = None,
Optional[int]   num_sweeps = None,
Optional[int]   num_reads = None,
Optional[list]   schedule = None,
Optional[Union[list, dict]]   initial_state = None,
Optional[str]   updater = None,
Optional[bool]   sparse = None,
Optional[bool]   reinitialize_state = None,
Optional[int]   seed = None 
)
Sample Ising model.

Args:
    bqm (openjij.model.model.BinaryQuadraticModel) binary quadratic model
    beta_min (float): minimal value of inverse temperature
    beta_max (float): maximum value of inverse temperature
    num_sweeps (int): number of sweeps
    num_reads (int): number of reads
    schedule (list): list of inverse temperature
    initial_state (dict): initial state
    updater(str): updater algorithm
    sparse (bool): use sparse matrix or not.
    reinitialize_state (bool): if true reinitialize state for each run
    seed (int): seed for Monte Carlo algorithm
Returns:
    :class:`openjij.sampler.response.Response`: results

Examples:

    for Ising case::

        >>> h = {0: -1, 1: -1, 2: 1, 3: 1}
        >>> J = {(0, 1): -1, (3, 4): -1}
        >>> sampler = openj.SASampler()
        >>> res = sampler.sample_ising(h, J)

    for QUBO case::

        >>> Q = {(0, 0): -1, (1, 1): -1, (2, 2): 1, (3, 3): 1, (4, 4): 1, (0, 1): -1, (3, 4): 1}
        >>> sampler = openj.SASampler()
        >>> res = sampler.sample_qubo(Q)

Reimplemented from openjij.sampler.sampler.BaseSampler.

References openjij.sampler.csqa_sampler.CSQASampler._params, openjij.sampler.sa_sampler.SASampler._params, openjij.sampler.sqa_sampler.SQASampler._params, openjij.sampler.sampler.BaseSampler._set_params(), and openjij.sampler.sa_sampler.geometric_ising_beta_schedule().

Referenced by openjij.sampler.sampler.BaseSampler.sample_ising(), and openjij.sampler.sampler.BaseSampler.sample_qubo().

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

◆ sample_hubo()

openjij.sampler.sa_sampler.SASampler.sample_hubo (   self,
dict[tuple, float]  J,
Optional[str]   vartype = None,
int   num_sweeps = 1000,
int   num_reads = 1,
int   num_threads = 1,
Optional[float]   beta_min = None,
Optional[float]   beta_max = None,
str   updater = "METROPOLIS",
str   random_number_engine = "XORSHIFT",
Optional[int]   seed = None,
str   temperature_schedule = "GEOMETRIC" 
)
Sampling from higher order unconstrainted binary optimization.

Args:
    J (dict): Interactions.
    vartype (str): "SPIN" or "BINARY".
    num_sweeps (int, optional): The number of sweeps. Defaults to 1000.
    num_reads (int, optional): The number of reads. Defaults to 1.
    num_threads (int, optional): The number of threads. Parallelized for each sampling with num_reads > 1. Defaults to 1.
    beta_min (float, optional): Minimum beta (initial inverse temperature). Defaults to None.
    beta_max (float, optional): Maximum beta (final inverse temperature). Defaults to None.
    updater (str, optional): Updater. One can choose "METROPOLIS", "HEAT_BATH", or "k-local". Defaults to "METROPOLIS".
    random_number_engine (str, optional): Random number engine. One can choose "XORSHIFT", "MT", or "MT_64". Defaults to "XORSHIFT".            
    seed (int, optional): seed for Monte Carlo algorithm. Defaults to None.
    temperature_schedule (str, optional): Temperature schedule. One can choose "LINEAR", "GEOMETRIC". Defaults to "GEOMETRIC".

Returns:
    :class:`openjij.sampler.response.Response`: results

Examples::
    for Ising case::
        >>> sampler = openjij.SASampler()
        >>> J = {(0,): -1, (0, 1): -1, (0, 1, 2): 1}
        >>> response = sampler.sample_hubo(J, "SPIN")

    for Binary case::
        >>> sampler = ooenjij.SASampler()
        >>> J = {(0,): -1, (0, 1): -1, (0, 1, 2): 1}
        >>> response = sampler.sample_hubo(J, "BINARY")

References openjij.sampler.sa_sampler.SASampler._sample_hubo_old().

Here is the call graph for this function:

Member Data Documentation

◆ _algorithm

openjij.sampler.sa_sampler.SASampler._algorithm
protected

◆ _default_params

openjij.sampler.sa_sampler.SASampler._default_params
protected

◆ _make_system

openjij.sampler.sa_sampler.SASampler._make_system
protected

◆ _params

◆ schedule_info


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