Jij Swap Moving Sampler¶
NHOT_CONSTRAINTS = typ.List[typ.Tuple[typ.List[int], int]]
module-attribute
¶
N-hot constraint indices.
x0 + x1 + x2 = 3, x3 + x4 + x5 = 1 -> [([0, 1, 2], 3), ([3, 4, 5], 1)]
JijSwapMovingParameters
dataclass
¶
Manage Parameters for using JijSwapMovingSampler.
Attributes:
Name | Type | Description |
---|---|---|
constraints | Optional[list] | Constraint term. x0+x1=1 and x2+x3=1 is written as [([0,1], 1), ([2,3], 1)]. |
penalties | Optional[list] | Penalty term. 1.3(0.1x1+0.2x2+0.3x3-1)^2 is written as [(1.3, {1:0.1, 2:0.2, 3:0.3}, 1)]. |
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 |
JijSwapMovingSampler
¶
Bases: JijZeptBaseSampler
A sampler class for JijSwapMoving.
parameters
property
¶
Returns a dictionary of parameters for the model.
properties
property
¶
Returns a dictionary of properties for the model.
__init__(token=None, url=None, proxy=None, config=None, config_env='default')
¶
Sets token and url.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token | str | Token string. Defaults to None. | None |
url | Union[str, dict] | API URL. Defaults to None. | None |
proxy | str | Proxy URL. Defaults to None. | None |
config | str | Config file path. Defaults to None. | None |
Raises:
Type | Description |
---|---|
obj: |
sample_hubo(J, parameters=None, max_wait_time=None, sync=True, queue_name=None, **kwargs)
¶
The simulated annealing is performed for higher ordered unconstraind.
binary optimizations (hubo) with the linear constraint conditions. Note here that the linear constraint conditions are strictly satisfied.
To configure the solver, instantiate the JijSwapMovingParameters
class and pass the instance to the parameters
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
J | Dict | Polynomial interactions. | required |
parameters | JijSwapMovingParameters | 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 | SwapMoving parameters using **kwargs. If both | {} |
Returns:
Type | Description |
---|---|
JijModelingResponse | dimod.SampleSet: Stores minimum energy samples and other information. |
Examples:
import jijzept as jz
sampler = jz.JijSwapMovingSampler(config='config.toml')
response = sampler.sample_hubo(J={(0,1,2,3,4): -1}, vartype="SPIN",
constraints=[([0,1], 0), ([2,3,4], 1)])
sample_model(problem, 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 JijSwapMovingParameters
class and pass the instance to the parameters
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
problem | Problem | Mathematical expression of JijModeling. The decision variable type should be Binary. | 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. | {} |
needs_square_dict | Dict[str, bool] | If | None |
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 | JijSwapMovingParameters | 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 | SwapMoving 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.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])
problem += jm.Constraint("one-hot", jm.Sum(i, x[i]) == 1)
sampler = jz.JijSwapMovingSampler(config='config.toml')
response = sampler.sample_model(problem, feed_dict={'n': 5, 'd': [1,2,3,4,5]})
sample_qubo(Q, parameters=None, max_wait_time=None, sync=True, queue_name=None, **kwargs)
¶
The simulated annealing is performed for binary quadratic models with.
the linear constraint conditions. Note here that the linear constraint conditions are strictly satisfied.
To configure the solver, instantiate the JijSwapMovingParameters
class and pass the instance to the parameters
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Q | Dict | The linear or quadratic terms. | required |
parameters | JijSwapMovingParameters | 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 | SwapMoving parameters using **kwargs. If both | {} |
Returns:
Type | Description |
---|---|
JijModelingResponse | dimod.SampleSet: Stores minimum energy samples and other information. |
Examples:
import jijzept as jz
sampler = jz.JijSwapMovingSampler(config='config.toml')
response = sampler.sample_qubo(Q={(0,0): -0.5, (0,1): -1, (0,2): -1, (2,3): -1},
constraints=[([0,1], 1), ([2,3], 1)])
sample_nhot(is_hubo, client, solver, queue_name, qubo, constant, max_wait_time, sync, constraints, **kwargs)
¶
Sample from a QUBO or Ising Hamiltonian with NHOT constraints using D-Wave's quantum annealer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_hubo | bool | Whether the input problem is a HUBO or not. | required |
client | JijZeptClient | A JijZeptClient instance. | required |
solver | str | The name of the D-Wave solver to use. | required |
queue_name | str | The name of the D-Wave queue to use. | required |
qubo | dict[tuple[int, int], float] | The input QUBO or Ising Hamiltonian. | required |
constant | float | The constant offset for the Hamiltonian. | required |
max_wait_time | int | float | None | Maximum time to wait for the solver in seconds. If None, waits indefinitely. | required |
sync | bool | Whether to wait for the results to complete before returning. | required |
constraints | NHOT_CONSTRAINTS | The NHOT constraints to apply to the problem. | required |
**kwargs | Additional keyword arguments to pass to | {} |
Returns:
Name | Type | Description |
---|---|---|
SampleSet | The sample set obtained from the solver. |