|
openjij
Framework for the Ising model and QUBO.
|


Public Member Functions | |
| parameters (self) | |
| __init__ (self) | |
| "openjij.sampler.response.Response" | sample (self, Union["openjij.model.model.BinaryQuadraticModel", dimod.BinaryQuadraticModel] bqm, Optional[float] beta=None, Optional[float] gamma=None, Optional[int] num_sweeps=None, Optional[list] schedule=None, Optional[int] trotter=None, Optional[int] num_reads=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, *, Optional[float] beta_min=None, Optional[float] beta_max=None, Optional[float] coupling_min=None, Optional[float] coupling_max=None, Optional[int] num_threads=None) |
| Public Member Functions inherited from openjij.sampler.sampler.BaseSampler | |
| sample_ising (self, h, J, **parameters) | |
| sample_qubo (self, Q, **parameters) | |
Public Attributes | |
| dict | schedule_info = {"schedule": "custom schedule"} |
| Public Attributes inherited from openjij.sampler.sampler.BaseSampler | |
| sample_ising | |
| sample_qubo | |
Protected Member Functions | |
| _convert_validation_schedule (self, schedule, beta) | |
| _get_result (self, system, model) | |
| _parallel_sampling (self, model, ising_graph, init_generator, make_system, algorithm, gamma, reinitialize_state, read_seeds, num_threads) | |
| _annealing_schedule_setting (self, model, beta=None, gamma=None, num_sweeps=None, schedule=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, *, read_seeds=None) | |
Protected Attributes | |
| _params = dict(self._default_params) | |
| dict | _make_system |
| dict | _algorithm |
| Protected Attributes inherited from openjij.sampler.sampler.BaseSampler | |
| _default_params | |
Additional Inherited Members | |
| Static Public Attributes inherited from openjij.sampler.sampler.BaseSampler | |
| properties = dict() | |
Sampler with Simulated Quantum Annealing (SQA).
Inherits from :class:`openjij.sampler.sampler.BaseSampler`.
Hamiltonian
.. math::
H(s) = s H_p + \\Gamma (1-s)\\sum_i \\sigma_i^x
where :math:`H_p` is the problem Hamiltonian we want to solve.
The quantum Monte Carlo simulation uses the Suzuki-Trotter
decomposition with ``trotter`` slices. Every slice feels the problem
Hamiltonian at inverse temperature :math:`s\\beta/M` and neighbouring
slices are coupled ferromagnetically with
:math:`J_\\perp = -\\frac12\\ln\\tanh(\\beta\\Gamma(1-s)/M)`.
Unless ``schedule``, ``beta`` or ``gamma`` is given, the annealing
schedule is generated by :func:`geometric_sqa_schedule`: the classical
inverse temperature of every slice follows the automatic schedule of
:class:`openjij.SASampler` (estimated from the coefficients of the
problem), and the transverse field decreases such that
:math:`J_\\perp` grows geometrically. Both ends of :math:`J_\\perp` are
chosen from the energy landscape (:func:`trotter_coupling_range`): weak
for frustrated spin glasses, where nearly independent replicas work
best, and stronger for problems with rigid local structure or tall and
narrow barriers such as global constraints. The transverse field stays
finite at the end of the annealing.
Reads run in parallel on ``num_threads`` threads.
Args:
beta (float): Inverse temperature (legacy schedule).
gamma (float): Amplitude of quantum fluctuation (legacy schedule).
trotter (int): Trotter number.
num_sweeps (int): number of sweeps
schedule (list): schedule list
num_reads (int): Number of iterations.
schedule_info (dict): Information about a annealing schedule.
Raises:
ValueError: If the schedule violates as below.
- not list or numpy.array.
- schedule range is '0 <= s <= 1'.
| openjij.sampler.sqa_sampler.SQASampler.__init__ | ( | self | ) |
|
protected |
Set the legacy schedule (used by :class:`CSQASampler`).
References openjij.sampler.sa_sampler.SASampler._convert_validation_schedule(), _convert_validation_schedule(), openjij.sampler.csqa_sampler.CSQASampler._params, openjij.sampler.sa_sampler.SASampler._params, _params, openjij.sampler.sqa_sampler.quartic_ising_schedule(), openjij.sampler.sa_sampler.SASampler.schedule_info, and schedule_info.
Referenced by openjij.sampler.csqa_sampler.CSQASampler.sample_ising().


|
protected |
Referenced by _annealing_schedule_setting(), and sample().

|
protected |
Reimplemented from openjij.sampler.sampler.BaseSampler.
Reimplemented in openjij.sampler.csqa_sampler.CSQASampler.
References _get_result().
Referenced by _get_result().


|
protected |
Run the reads on concurrent systems and collect the results. Each read owns a random seed, so the samples do not depend on ``num_threads``. With ``reinitialize_state=False`` every read continues from the final state of the previous one, so the reads run one by one.
References openjij.sampler.sqa_sampler._concurrent_systems(), openjij.sampler.csqa_sampler.CSQASampler._get_result(), openjij.sampler.sampler.BaseSampler._get_result(), openjij.sampler.csqa_sampler.CSQASampler._params, openjij.sampler.sa_sampler.SASampler._params, and _params.

| openjij.sampler.sqa_sampler.SQASampler.parameters | ( | self | ) |
Reimplemented from openjij.sampler.sampler.BaseSampler.
| "openjij.sampler.response.Response" openjij.sampler.sqa_sampler.SQASampler.sample | ( | self, | |
| Union[ "openjij.model.model.BinaryQuadraticModel", dimod.BinaryQuadraticModel ] | bqm, | ||
| Optional[float] | beta = None, | ||
| Optional[float] | gamma = None, | ||
| Optional[int] | num_sweeps = None, | ||
| Optional[list] | schedule = None, | ||
| Optional[int] | trotter = None, | ||
| Optional[int] | num_reads = 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, | ||
| * | , | ||
| Optional[float] | beta_min = None, | ||
| Optional[float] | beta_max = None, | ||
| Optional[float] | coupling_min = None, | ||
| Optional[float] | coupling_max = None, | ||
| Optional[int] | num_threads = None ) |
Sampling from the Ising model.
The annealing schedule is chosen as follows.
- ``schedule`` is given: the custom schedule.
- ``beta`` or ``gamma`` is given: the legacy schedule, i.e. fixed
``beta`` (default 5) and ``s`` following
:func:`quartic_ising_schedule` from 0 to 1.
- otherwise: :func:`geometric_sqa_schedule`. ``beta_min`` and
``beta_max`` override the estimated range of the classical inverse
temperature of each Trotter slice, and ``coupling_min`` and
``coupling_max`` the range of the Trotter coupling chosen from the
energy landscape (:func:`trotter_coupling_range`).
Args:
bqm (openjij.BinaryQuadraticModel) binary quadratic model
beta (float, optional): inverse temperature of the legacy schedule.
gamma (float, optional): strength of transverse field. Defaults to 1 for custom and legacy schedules.
num_sweeps (int, optional): number of sweeps. Defaults to 1000.
schedule (list[list[float, int]], optional): List of annealing parameter. Defaults to None.
trotter (int): Trotter number. Defaults to 8.
num_reads (int, optional): number of sampling. Defaults to 1.
initial_state (list[int], optional): Initial state. Defaults to None.
updater (str, optional): update method, "single spin flip" (default)
or "trotter cluster flip". The latter flips segments of Trotter
copies at once and keeps the replicas moving when the Trotter
coupling is strong (e.g. near s = 1 in reverse annealing).
sparse (bool): use sparse matrix or not.
reinitialize_state (bool, optional): Re-initilization at each sampling. Defaults to True.
If False, reads run sequentially, each starting from the previous final state.
seed (int, optional): seed for reproducible batches with a distinct random seed per read.
beta_min (float, optional): initial classical inverse temperature per Trotter slice
of the automatic schedule.
beta_max (float, optional): final classical inverse temperature per Trotter slice
of the automatic schedule.
coupling_min (float, optional): initial Trotter coupling of the automatic schedule.
coupling_max (float, optional): final Trotter coupling of the automatic schedule.
num_threads (int, optional): number of threads that run reads in parallel.
Defaults to ``OMP_NUM_THREADS`` if set, otherwise the number of CPUs.
Results do not depend on the number of threads.
Raises:
ValueError:
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 = openjij.SQASampler()
>>> 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 = openjij.SQASampler()
>>> res = sampler.sample_qubo(Q)
Reimplemented from openjij.sampler.sampler.BaseSampler.
References openjij.sampler.sa_sampler.SASampler._algorithm, _algorithm, openjij.sampler.sa_sampler.SASampler._convert_validation_schedule(), _convert_validation_schedule(), openjij.sampler.sa_sampler.SASampler._make_system, _make_system, openjij.sampler.csqa_sampler.CSQASampler._params, openjij.sampler.sa_sampler.SASampler._params, _params, openjij.sampler.sqa_sampler._resolve_num_threads(), and openjij.sampler.sampler.BaseSampler._set_params().

|
protected |
Referenced by sample().
|
protected |
Referenced by sample().
|
protected |
Referenced by _annealing_schedule_setting(), _parallel_sampling(), and sample().
| dict openjij.sampler.sqa_sampler.SQASampler.schedule_info = {"schedule": "custom schedule"} |
Referenced by _annealing_schedule_setting(), and openjij.sampler.csqa_sampler.CSQASampler.sample_ising().