openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
openjij.sampler.sqa_sampler Namespace Reference

Classes

class  SQASampler

Functions

 _resolve_num_threads (num_threads)
 _read_seeds (seed, num_reads)
 _concurrent_systems (ising_graph, trotter, num_reads, num_threads)
 _log_interp (x, xs, ys)
 _dominance (cxxgraph, *, from_qubo)
 _low_energy_moves (cxxgraph, *, from_qubo, num_reads=4, num_sweeps=100)
 trotter_coupling_range (cxxgraph, *, from_qubo=False)
 geometric_sqa_schedule (Union[openjij.cxxjij.graph.Dense, openjij.cxxjij.graph.CSRSparse] cxxgraph, int trotter, int num_sweeps=1000, Optional[float] beta_min=None, Optional[float] beta_max=None, *, Optional[float] coupling_min=None, Optional[float] coupling_max=None, Optional[float] gamma=None, bool from_qubo=False)
 _well_conditioned_gamma (beta_cl, quantum_field)
 linear_ising_schedule (model, beta, gamma, num_sweeps)
 quartic_ising_schedule (model, beta, gamma, num_sweeps)

Variables

tuple _DOMINANCE_RANGE = (0.4, 0.9)
tuple _COUPLING_MIN_RANGE = (0.01, 0.2)
tuple _PAIR_MOVE_RANGE = (0.3, 0.8)
tuple _COUPLING_MAX_RANGE = (0.5, 2.0)
tuple _ZERO_MODE_RANGE = (0.003, 0.03)
float _ZERO_MODE_SCALE = 0.1
int _MAX_SYSTEMS_MEMORY = 1 << 30

Function Documentation

◆ _concurrent_systems()

openjij.sampler.sqa_sampler._concurrent_systems ( ising_graph,
trotter,
num_reads,
num_threads )
protected
Number of systems that run concurrently.

A few systems per thread let fast cores pick up more reads (dynamic
scheduling). Every system holds a copy of the interactions, so the
total memory is bounded.

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

Here is the caller graph for this function:

◆ _dominance()

openjij.sampler.sqa_sampler._dominance ( cxxgraph,
* ,
from_qubo )
protected
Median over spins of the largest coefficient over the RMS of all of them.

It uses the statistics of the automatic SA schedule. Spins whose
coefficients are all zero are skipped; returns 1 if all are.

Referenced by trotter_coupling_range().

Here is the caller graph for this function:

◆ _log_interp()

openjij.sampler.sqa_sampler._log_interp ( x,
xs,
ys )
protected
Interpolate log(y) linearly in x, constant outside ``xs``.

Referenced by trotter_coupling_range().

Here is the caller graph for this function:

◆ _low_energy_moves()

openjij.sampler.sqa_sampler._low_energy_moves ( cxxgraph,
* ,
from_qubo,
num_reads = 4,
num_sweeps = 100 )
protected
Pair-move and zero-mode fractions of low-energy states.

Short SA runs (fixed seeds, so the result depends only on the problem)
give low-energy states. For each spin ``i`` with a positive flip cost
``dE_i`` the cheapest flip together with a neighbour ``j`` costs
``dE_i + dE_j + 4 J_ij s_i s_j``. The spin counts as a pair move if that
is below ``dE_i / 2``: the barrier of the single flip is much taller
than the cost of the two-spin move. Spins with ``dE_i = 0`` are zero
modes. Returns both fractions averaged over the runs.

Referenced by trotter_coupling_range().

Here is the caller graph for this function:

◆ _read_seeds()

openjij.sampler.sqa_sampler._read_seeds ( seed,
num_reads )
protected
Distinct per-read seeds; reproducible for a given ``seed``.

◆ _resolve_num_threads()

openjij.sampler.sqa_sampler._resolve_num_threads ( num_threads)
protected

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

Here is the caller graph for this function:

◆ _well_conditioned_gamma()

openjij.sampler.sqa_sampler._well_conditioned_gamma ( beta_cl,
quantum_field )
protected
Transverse field that centres s = beta_cl / (beta_cl + quantum_field / gamma).

The ratio beta_cl * gamma / quantum_field is s / (1 - s). Choosing gamma so
that its smallest and largest values over the schedule are reciprocal keeps
both s and 1 - s representable: a ratio range R gives 1 - s >= 1 / (1 + sqrt(R)).

Referenced by geometric_sqa_schedule().

Here is the caller graph for this function:

◆ geometric_sqa_schedule()

openjij.sampler.sqa_sampler.geometric_sqa_schedule ( Union[openjij.cxxjij.graph.Dense, openjij.cxxjij.graph.CSRSparse] cxxgraph,
int trotter,
int num_sweeps = 1000,
Optional[float] beta_min = None,
Optional[float] beta_max = None,
* ,
Optional[float] coupling_min = None,
Optional[float] coupling_max = None,
Optional[float] gamma = None,
bool from_qubo = False )
Default SQA schedule: classical and quantum terms annealed together.

Write the Trotterized weight of the replicas
:math:`\\sigma_1, \\dots, \\sigma_M` as

.. math::

    \\exp\\Big(-\\beta_{\\mathrm{cl}} \\sum_t H_p(\\sigma_t)
    + J_\\perp \\sum_{t,i} \\sigma_{i,t}\\sigma_{i,t+1}\\Big),

with :math:`\\beta_{\\mathrm{cl}} = s\\beta/M` and
:math:`J_\\perp = -\\frac12\\ln\\tanh(\\beta\\Gamma(1-s)/M)`.
The schedule controls both energy scales directly.

- :math:`\\beta_{\\mathrm{cl}}` follows the automatic SA schedule
  (:func:`openjij.sampler.sa_sampler.geometric_ising_beta_schedule`),
  which is estimated from the coefficients of the problem, so each slice
  is cooled like an SA run.
- :math:`J_\\perp` grows geometrically from ``coupling_min`` to
  ``coupling_max``; the transverse field in units of the slice
  temperature is :math:`\\beta_{\\mathrm{cl}}\\Gamma_{\\mathrm{eff}} =
  \\operatorname{artanh} e^{-2J_\\perp}`, so it decreases together with
  the temperature and stays finite at the end. Weak couplings keep the
  replicas diverse (close to independent SA runs); strong couplings make
  them move together. Unless given, both ends are chosen from the
  energy landscape by :func:`trotter_coupling_range`.

The pair is converted to :math:`(\\beta, s)` for a system created with
the transverse field ``gamma``. Only :math:`s\\beta` and
:math:`\\beta\\Gamma(1-s)` matter, so ``gamma`` is a choice of units.
Leave it ``None`` to pick the value that keeps :math:`s` away from 0 and 1
over the whole schedule; with a fixed ``gamma``, a classical inverse
temperature far above :math:`\\operatorname{artanh} e^{-2J_\\perp}/\\Gamma`
rounds :math:`s` to 1 and loses the coupling. The value used is reported
as ``info["gamma"]`` and must be the transverse field of the system.

Args:
    cxxgraph: Ising graph, ``Dense`` or ``CSRSparse``.
    trotter (int): Trotter number M.
    num_sweeps (int): number of sweeps.
    beta_min (float, optional): initial classical inverse temperature per slice.
    beta_max (float, optional): final classical inverse temperature per slice.
    coupling_min (float, optional): initial Trotter coupling :math:`J_\\perp`.
    coupling_max (float, optional): final Trotter coupling :math:`J_\\perp`.
    gamma (float, optional): transverse field of the system that runs the
        schedule. Chosen automatically when None.
    from_qubo (bool): the graph was converted from a BINARY model.

Returns:
    list of cxxjij.utility.TransverseFieldSchedule, and schedule information.

References _well_conditioned_gamma(), and trotter_coupling_range().

Here is the call graph for this function:

◆ linear_ising_schedule()

openjij.sampler.sqa_sampler.linear_ising_schedule ( model,
beta,
gamma,
num_sweeps )
Generate linear ising schedule.

Args:
    model (:class:`openjij.model.model.BinaryQuadraticModel`): BinaryQuadraticModel
    beta (float): inverse temperature
    gamma (float): transverse field
    num_sweeps (int): number of steps
Returns:
    generated schedule

◆ quartic_ising_schedule()

openjij.sampler.sqa_sampler.quartic_ising_schedule ( model,
beta,
gamma,
num_sweeps )
Generate quartic ising schedule based on S

Morita and H. Nishimori,
Journal of Mathematical Physics 49, 125210 (2008).

Args:
    model (:class:`openjij.model.model.BinaryQuadraticModel`): BinaryQuadraticModel
    beta (float): inverse temperature
    gamma (float): transverse field
    num_sweeps (int): number of steps
Returns:
    generated schedule

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

Here is the caller graph for this function:

◆ trotter_coupling_range()

openjij.sampler.sqa_sampler.trotter_coupling_range ( cxxgraph,
* ,
from_qubo = False )
Initial and final Trotter coupling of the default schedule.

Both are chosen from the energy landscape of the problem.

- ``coupling_min`` grows with the dominance, the median over spins of
  ``max_j |c_ij| / sqrt(sum_j c_ij^2)`` over the coefficients ``c_ij``
  (couplings and field) of spin ``i``; the automatic SA schedule uses
  the same statistics. In frustrated spin glasses many comparable
  terms act on every spin and the replicas must stay nearly
  independent early on. When one term rules each spin, rigid local
  structures form early and coupled replicas move them together.
- ``coupling_max`` grows with the pair-move fraction
  (``_low_energy_moves``): the share of spins of low-energy states
  whose single flip is much more expensive than a flip together with a
  neighbour, as with global constraints. Such tall and narrow barriers
  need strongly coupled replicas at the end. Otherwise strong coupling
  at the end locks the replicas onto one configuration.
- Both shrink as the zero-mode fraction grows: the share of spins of
  low-energy states that flip at no cost. Degenerate landscapes, such as
  lattice spin glasses with +-1 couplings, are searched through
  zero-energy flips, and the Trotter coupling would suppress them.

Args:
    cxxgraph: Ising graph, ``Dense`` or ``CSRSparse``.
    from_qubo (bool): the graph was converted from a BINARY model.

Returns:
    ``(coupling_min, coupling_max)`` and a dict with the dominance, the
    pair-move fraction and the zero-mode fraction.

References _dominance(), _log_interp(), and _low_energy_moves().

Referenced by geometric_sqa_schedule().

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

Variable Documentation

◆ _COUPLING_MAX_RANGE

tuple openjij.sampler.sqa_sampler._COUPLING_MAX_RANGE = (0.5, 2.0)
protected

◆ _COUPLING_MIN_RANGE

tuple openjij.sampler.sqa_sampler._COUPLING_MIN_RANGE = (0.01, 0.2)
protected

◆ _DOMINANCE_RANGE

tuple openjij.sampler.sqa_sampler._DOMINANCE_RANGE = (0.4, 0.9)
protected

◆ _MAX_SYSTEMS_MEMORY

int openjij.sampler.sqa_sampler._MAX_SYSTEMS_MEMORY = 1 << 30
protected

◆ _PAIR_MOVE_RANGE

tuple openjij.sampler.sqa_sampler._PAIR_MOVE_RANGE = (0.3, 0.8)
protected

◆ _ZERO_MODE_RANGE

tuple openjij.sampler.sqa_sampler._ZERO_MODE_RANGE = (0.003, 0.03)
protected

◆ _ZERO_MODE_SCALE

float openjij.sampler.sqa_sampler._ZERO_MODE_SCALE = 0.1
protected