Jij CPU SA Sampler¶
JijSAParameters dataclass ¶
Manage Parameters for using 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 |
needs_square_constraints | Optional[dict[str, bool]] | This dictionary object is utilized to determine whether to square the constraint condition while incorporating it into the QUBO/HUBO penalty term. Here, the constraint's name is used as the key. If the value is set to True, the corresponding constraint is squared upon its addition to the QUBO/HUBO penalty term. By default, the value is set to True for linear constraints, and to False for non-linear ones. |
relax_as_penalties | Optional[dict[str, bool]] | This dictionary object is designed to regulate the incorporation of constraint conditions into the QUBO/HUBO penalty term, with the constraint's name functioning as the key. If the key's value is True, the respective constraint is added to the QUBO/HUBO penalty term. If the value is False, the constraint is excluded from the penalty term, though it remains subject to evaluation to verify if it meets the constraint conditions. By default, all constraint conditions have this value set to True. |
JijSASampler ¶
Bases: JijZeptBaseSampler
Simulated Annealing (SA) sampler.
SA for QUBO and the Ising Model. This sampler is designed for verifying and testing models with small instances and is best suited for initial testing and exploration of your models.
sample_instance(instance_id, multipliers={}, fixed_variables={}, search=False, num_search=15, algorithm=None, parameters=None, max_wait_time=None, sync=True, queue_name=None, system_time=jm.SystemTime(), **kwargs) ¶
Sample using the uploaded instance by means of the simulated annealing.
To configure the solver, instantiate the JijSAParameters class and pass the instance to the parameters argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance_id | str | The ID of the uploaded instance. | required |
multipliers | Dict[str, Number] | The actual multipliers for penalty terms, derived from constraint conditions. | {} |
fixed_variables | dict[str, dict[tuple[int, ...], int]] | 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 |
parameters | JijSAParameters | None | defaults None. | None |
max_wait_time | int | float | None | The number of timeout [sec] for post request. If | None |
sync | bool | Synchronous mode. | True |
queue_name | Optional[str] | Queue name. | None |
system_time | SystemTime | Object to store system times other than upload time. | SystemTime() |
**kwargs | SA parameters using **kwargs. If both | {} |
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.BinaryVar('x', shape=(n,))
d = jm.Placeholder('d', ndim=1)
i = jm.Element("i", belong_to=n)
problem = jm.Problem('problem')
problem += jm.sum(i, d[i] * x[i])
# initialize sampler
sampler = jz.JijSASampler(config='config.toml')
# upload instance
instance_id = sampler.upload_instance(problem, {'n': 5, 'd': [1,2,3,4,5]})
# sample uploaded instance
sample_set = sampler.sample_instance(instance_id)
sample_model(model, feed_dict, multipliers={}, fixed_variables={}, needs_square_dict=None, search=False, num_search=15, algorithm=None, parameters=None, max_wait_time=None, sync=True, queue_name=None, **kwargs) ¶
Sample using JijModeling by means of the simulated annealing.
To configure the solver, instantiate the JijSAParameters class and pass the instance to the parameters argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model | Problem | Mathematical expression of JijModeling. | required |
feed_dict | dict[str, int | float | integer | floating | ndarray | list] | 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, ...], int]] | 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 |
parameters | JijSAParameters | None | defaults None. | None |
max_wait_time | int | float | None | The number of timeout [sec] for post request. If | None |
sync | bool | Synchronous mode. | True |
queue_name | Optional[str] | Queue name. | None |
**kwargs | SA parameters using **kwargs. If both | {} |
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.BinaryVar('x', shape=(n,))
d = jm.Placeholder('d', ndim=1)
i = jm.Element("i", belong_to=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]})