openjij.sampler.csqa_sampler#

Classes#

CSQASampler

Sampler with continuous-time simulated quantum annealing (CSQA) using

Module Contents#

class openjij.sampler.csqa_sampler.CSQASampler(beta=5.0, gamma=1.0, num_sweeps=1000, schedule=None, num_reads=1)[source]#

Bases: openjij.sampler.sqa_sampler.SQASampler

Inheritance diagram of openjij.sampler.csqa_sampler.CSQASampler

Sampler with continuous-time simulated quantum annealing (CSQA) using

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.

  • schedule (list) – schedule list

  • step_num (int) – Number of Monte Carlo step.

  • schedule_info (dict) – Information about a annealing schedule.

  • num_reads (int) – Number of iterations.

  • num_sweeps (int) – number of sweeps

  • schedule_info – Information about a annealing schedule.

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#

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, beta: float = 5.0, gamma: float = 1.0, num_sweeps: int = 1000, schedule=None, num_reads: int = 1, initial_state=None, updater=None, reinitialize_state=True, seed=None)[source]#

Sampling from the Ising model.

Parameters:
  • h (dict) – linear biases

  • J (dict) – quadratic biases

  • beta (float, optional) – inverse temperature

  • gamma (float, optional) – strength of transverse field

  • num_sweeps (int, optional) – number of sampling.

  • schedule (list, optional) – schedule list

  • num_reads (int, optional) – number of iterations

  • initial_state (optional) – initial state of spins

  • updater (str, optional) – updater algorithm

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

  • seed (int, optional) – Sampling seed.

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.CSQASampler()
>>> 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 = openjijj.CSQASampler()
>>> res = sampler.sample_qubo(Q)
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

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#