openjij.sampler.sqa_sampler#

Module Contents#

Classes#

SQASampler

Sampler with Simulated Quantum Annealing (SQA).

Functions#

linear_ising_schedule(model, beta, gamma, num_sweeps)

Generate linear ising schedule.

quartic_ising_schedule(model, beta, gamma, num_sweeps)

Generate quartic ising schedule based on S

class openjij.sampler.sqa_sampler.SQASampler[source]#

Bases: openjij.sampler.sampler.BaseSampler

Inheritance diagram of openjij.sampler.sqa_sampler.SQASampler

Sampler with Simulated Quantum Annealing (SQA).

Inherits from openjij.sampler.sampler.BaseSampler. Hamiltonian

H(s)=sHp+Γ(1s)iσixH(s) = s H_p + \Gamma (1-s)\sum_i \sigma_i^x

where HpH_p is the problem Hamiltonian we want to solve.

Parameters:
  • beta (float) – Inverse temperature.

  • gamma (float) – Amplitude of quantum fluctuation.

  • 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'.

property parameters#

Parameters as a dict, where keys are keyword parameters accepted by the sampler methods and values are lists of the properties relevent to each parameter.

properties#
remove_unknown_kwargs(**kwargs) Dict[str, Any]#

Remove with warnings any keyword arguments not accepted by the sampler.

Parameters:

**kwargs – Keyword arguments to be validated.

Return type:

Dict[str, Any]

Returns: Updated kwargs dict.

Examples

>>> import warnings
>>> sampler = dimod.RandomSampler()
>>> with warnings.catch_warnings():
...     warnings.filterwarnings('ignore')
...     try:
...         sampler.remove_unknown_kwargs(num_reads=10, non_param=3)
...     except dimod.exceptions.SamplerUnknownArgWarning:
...        pass
{'num_reads': 10}
sample(bqm: openjij.model.model.BinaryQuadraticModel | dimod.BinaryQuadraticModel, beta: float | None = None, gamma: float | None = None, num_sweeps: int | None = None, schedule: list | None = None, trotter: int | None = None, num_reads: int | None = None, initial_state: list | dict | None = None, updater: str | None = None, sparse: bool | None = None, reinitialize_state: bool | None = None, seed: int | None = None) Response[source]#

Sampling from the Ising model.

Parameters:
  • bqm (openjij.BinaryQuadraticModel) –

  • beta (float, optional) – inverse tempareture.

  • gamma (float, optional) – strangth of transverse field. Defaults to None.

  • num_sweeps (int, optional) – number of sweeps. Defaults to None.

  • schedule (list[list[float, int]], optional) – List of annealing parameter. Defaults to None.

  • trotter (int) – Trotter number.

  • 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. Defaults to ‘single spin flip’.

  • sparse (bool) – use sparse matrix or not.

  • reinitialize_state (bool, optional) – Re-initilization at each sampling. Defaults to True.

  • seed (int, optional) – Sampling seed. Defaults to None.

Raises:

ValueError

Returns:

results

Return type:

openjij.sampler.response.Response

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)
sample_ising(h, J, **parameters)#

Sample from an Ising model using the implemented sample method.

Parameters:
  • h (dict) – Linear biases

  • J (dict) – Quadratic biases

Returns:

results

Return type:

openjij.sampler.response.Response

sample_qubo(Q, **parameters)#

Sample from a QUBO model using the implemented sample method.

Parameters:

Q (dict or numpy.ndarray) – Coefficients of a quadratic unconstrained binary optimization

Returns:

results

Return type:

openjij.sampler.response.Response

openjij.sampler.sqa_sampler.linear_ising_schedule(model, beta, gamma, num_sweeps)[source]#

Generate linear ising schedule.

Parameters:
  • model (:class:`openjij.model.model.BinaryQuadraticModel`) – BinaryQuadraticModel

  • beta (float) – inverse temperature

  • gamma (float) – transverse field

  • num_sweeps (int) – number of steps

Returns:

generated schedule

openjij.sampler.sqa_sampler.quartic_ising_schedule(model, beta, gamma, num_sweeps)[source]#

Generate quartic ising schedule based on S

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

Parameters:
  • model (:class:`openjij.model.model.BinaryQuadraticModel`) – BinaryQuadraticModel

  • beta (float) – inverse temperature

  • gamma (float) – transverse field

  • num_sweeps (int) – number of steps

Returns:

generated schedule