Jij CPU SQA Sampler¶
JijSQAParameters
dataclass
¶
Manage Parameters for using JijSQASampler.
Attributes:
Name | Type | Description |
---|---|---|
beta | Optional[float] | Inverse tempareture. this will be set automatically. |
gamma | Optional[float] | Strangth of transverse field. this will be set automatically. |
trotter | Optional[int] | The number of Trotter. this will be set automatically. |
num_sweeps | Optional[int] | The number of Monte-Carlo steps. If |
num_reads | Optional[int] | The number of samples. If |
sparse | Optional[bool] | If |
reinitialize_state | Optional[bool] | If |
seed | Optional[int] | Seed for Monte Carlo algorithm. If |
JijSQASampler
¶
Bases: JijZeptBaseSampler
Simulated Quantum Annealing (SQA) sampler.
SQA is one of the quantum-inspired algorithms that simulates quantum annealing. It serves as a good intermediate step for simulating quantum annealing. However, due to the use of resources like replica copies for quantum simulation and the lack of parameter tuning in JijZept, it is not recommended for optimization purposes at now. 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_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 JijSQAParameters
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, 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 | JijSQAParameters | 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 | SQA 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])
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, max_wait_time=None, sync=True, queue_name=None, **kwargs)
¶
Sample using BinaryQuadraticModel by means of the simulated annealing.
To configure the solver, instantiate the JijSQAParameters
class and pass the instance to the parameters
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qubo | Union[cimod.BinaryQuadraticModel, openjij.BinaryQuadraticModel] | Binary quadratic model. | required |
constant | float | A float representing the constant energy offset in the QUBO problem. | 0 |
parameters | JijSQAParameters | 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 | SQA parameters using **kwargs. If both | {} |
Returns:
Type | Description |
---|---|
JijModelingResponse | dimod.SampleSet: Stores minimum energy samples and other information. |
Examples:
For cimod.BinaryQuadraticModel
case:
import jijzept as jz
import cimod
bqm = cimod.BinaryQuadraticModel({0: -1, 1: -1}, {(0, 1): -1, (1, 2): -1}, "SPIN")
sampler = jz.JijSASampler(config='config.toml')
response = sampler.sample(bqm)
sample_ising
and sample_qubo
methods. For Ising case:
import jijzept as jz
h = {0: -1, 1: -1, 2: 1, 3: 1}
J = {(0, 1): -1, (3, 4): -1}
sampler = jz.JijSASampler(config='config.toml')
response = sampler.sample_ising(h, J)
For QUBO case:
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)