openjij.sampler.sqa_sampler#
Classes#
Sampler with Simulated Quantum Annealing (SQA). |
Functions#
|
Generate linear ising schedule. |
|
Generate quartic ising schedule based on S |
Module Contents#
- class openjij.sampler.sqa_sampler.SQASampler[source]#
Bases:
openjij.sampler.sampler.BaseSampler
Sampler with Simulated Quantum Annealing (SQA).
Inherits from
openjij.sampler.sampler.BaseSampler
. Hamiltonianwhere is the problem Hamiltonian we want to solve.
- Parameters:
- Raises:
ValueError – If the schedule violates as below.
- not list or numpy.array. –
- schedule range is '0 <= s <= 1'. –
- 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:
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:
- Returns:
results
- Return type:
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:
- Returns:
results
- Return type:
- 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:
- 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#
- openjij.sampler.sqa_sampler.linear_ising_schedule(model, beta, gamma, num_sweeps)[source]#
Generate linear ising schedule.