Jij CPU SA Sampler¶
JijSAParameters
dataclass
¶
Parameters for JijSASampler.
Attributes:
Name | Type | Description |
---|---|---|
beta_min | Optional[float] | Minimum (initial) inverse temperature. If |
beta_max | Optional[float] | Maximum (final) inverse temperature. If |
num_sweeps | Optional[int] | The number of Monte-Carlo steps. If |
num_reads | Optional[int] | The number of samples. If |
initial_state | Optional[dict] | Initial state. If |
updater | Optional[str] | Updater algorithm. "single spin flip" or "swendsen wang". If |
sparse | Optional[bool] | If |
reinitialize_state | Optional[bool] | If |
seed | Optional[int] | Seed for Monte Carlo algorithm. If |
JijSASampler
¶
Bases: JijZeptBaseSampler
Simulated annealing sampler on CPU.
This class is a sampler using SA that allows you to check if the mathematical model is correct in small problems.
See JijZeptBaseSampler for the constructor of the class.
sample_hubo(J, parameters=None, timeout=None, sync=True, queue_name=None, **kwargs)
¶
Sampling from higher unconstrained binary optimization model (HUBO).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
J | dict | Polynomial interactions. | required |
parameters | JijSAParameters | None | (JijSAParameters | None, optional): defaults None. | None |
timeout | Optional[int] | The number of timeout [sec] for post request. If | None |
sync | bool | Synchronous mode. | True |
queue_name | str | queue_name. | None |
Returns:
Type | Description |
---|---|
JijModelingResponse | An extended type of |
Examples:
import jijzept as jz
sampler = jz.JijSASampler(config='config.toml')
J = {(0,): -1, (0, 1): -1, (0, 1, 2): 1}
response = sampler.sample_hubo(J)
sample_model(model, feed_dict, multipliers={}, fixed_variables={}, search=False, num_search=15, algorithm=None, parameters=None, timeout=None, sync=True, queue_name=None, **kwargs)
¶
Sample using JijModeling by means of the simulated annealing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Expression | Mathematical expression of JijModeling. | required |
feed_dict | Dict[str, Union[Number, list, np.ndarray]] | The actual values to be assigned to the placeholders. | required |
multipliers | Dict[str, Number] | The actual multipliers for penalty terms, derived from constraint conditions. | {} |
fixed_variables | Dict[str, Dict[Tuple[int, ...], Union[int, float]]] | dictionary of variables to fix. | {} |
search | bool | If | False |
num_search | int | The number of parameter search iteration. Defaults to set 15. This option works if | 15 |
algorithm | Optional[str] | Algorithm for parameter search. Defaults to None. | None |
timeout | Optional[int] | The number of timeout [sec] for post request. If | None |
sync | bool | Synchronous mode. | True |
queue_name | str | queue_name. | None |
Returns:
Name | Type | Description |
---|---|---|
JijModelingResponse | JijModelingResponse | Stores minimum energy samples and other information. |
Examples:
import jijzept as jz
import jijmodeling as jm
n = jm.Placeholder('n')
x = jm.Binary('x', shape=n)
d = jm.Placeholder('d', shape=n)
i = jm.Element("i", n)
problem = jm.Problem('problem')
problem += jm.Sum(i, d[i] * x[i])
sampler = jz.JijSASampler(config='config.toml')
response = sampler.sample_model(problem, feed_dict={'n': 5, 'd': [1,2,3,4,5]})
sample_qubo(qubo, constant=0, parameters=None, timeout=None, sync=True, queue_name=None, **kwargs)
¶
Sampling from QUBO.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qubo | dict[tuple[int, int], float] | QUBO dictionary. | required |
parameters | JijSAParameters | None | SA parameters, defaults None. | None |
timeout | int | None | The number of timeout [sec] for post request. If | None |
sync | bool | Synchronous mode. | True |
queue_name | str | queue_name. | None |
**kwargs | You can pass SA parameters as keyword arguments instead of specifying them in | {} |
Returns:
Type | Description |
---|---|
JijModelingResponse | An extended type of |
Examples:
import jijzept as jz
Q = {(0, 0): -1, (1, 1): -1, (2, 2): 1, (0, 1): -1, (1, 2): 1}
sampler = jz.JijSASampler(config='config.toml')
response = sampler.sample_qubo(Q)