Base Sampler¶
JijZeptBaseSampler ¶
Parent class for each sampler in JijZept.
This class only provide the constructor. The actual sampling method are implemented by each sampler.
__init__(token=None, url=None, proxy=None, config=None, config_env='default') ¶
Sets token and url.
If you do not set any arguments, JijZept configuration file is used. If you set the url or token here, that will be used as the priority setting for connecting to the API. See JijZeptClient for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token | str | None | Token string. Defaults to None. | None |
url | str | None | API URL. Defaults to None. | None |
proxy | str | None | Proxy URL. Defaults to None. | None |
config | str | None | Config file path. Defaults to None. | None |
config_env | str | configure environment name. Defaults to 'default'. | 'default' |
Raises:
| Type | Description |
|---|---|
TypeError |
|
upload_instance(problem, feed_dict, system_time=jm.SystemTime()) ¶
Upload instance.
An instance is a pair of problem and feed_dict. This method stores the instance into the cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem | 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 |
system_time | SystemTime | Object to store upload time. | SystemTime() |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | The ID of the uploaded instance. |
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)
ParameterSearchParameters dataclass ¶
Data class for parameter_search_parameters.
check_kwargs_against_dataclass(kwargs, param_cls) ¶
Check if the keyword arguments have a key other than the field names of specified dataclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs | dict[str, Any] | A dictionary of keyword arguments to be checked. | required |
param_cls | Type | A type representing the class to be used for | required |
Raises:
| Type | Description |
|---|---|
JijZeptClientValidationError | If **kwargs contain extra keyword argument. |
merge_params_and_kwargs(parameters, kwargs, param_cls) ¶
Merge the set of parameters defined by parameters and the set of parameters defined by kwargs, giving precedence to the values defined in kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters | _DataclassT | None | A instance of the dataclass defining the set of parameters. | required |
kwargs | dict[str, Any] | A dictionary containing the values of the parameters to be used in a computation. | required |
param_cls | Type[_DataclassT] | the dataclass to be used for | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | A dictionary containing the merged set of parameters and keyword arguments. |
sample_instance(client, solver, queue_name, instance_id, fixed_variables, parameter_search_parameters, max_wait_time, sync, system_time=jm.SystemTime(), **kwargs) ¶
Solver using the given parameters, returns a JijModelingResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client | JijZeptClient | JijZept client object. | required |
solver | str | Solver type. | required |
queue_name | str | Queue name to use. | required |
instance_id | str | The ID of the uploaded instance. | required |
fixed_variables | dict[str, dict[tuple[int, ...], int]] | Fixed variables. | required |
parameter_search_parameters | ParameterSearchParameters | Parameters for parameter search. | required |
max_wait_time | int | float | None | Maximum time to wait for the response, in seconds. | required |
sync | bool | Whether to wait for the response. | required |
system_time | SystemTime | Object to store system times other than upload time. | SystemTime() |
Returns:
| Name | Type | Description |
|---|---|---|
JijModelingResponse | JijModelingResponse | Stores minimum energy samples and statistics of the computation. |
Raises:
| Type | Description |
|---|---|
JijZeptSolvingFailedError | If the computation failed to solve the problem. |
JijZeptSolvingUnknownError | If the computation ended in an unknown error. |
JijZeptSolvingValidationError | If the computation failed to validate the input parameters. |
sample_model(client, solver, queue_name, problem, instance_data, fixed_variables, parameter_search_parameters, max_wait_time, sync, **kwargs) ¶
Solver using the given parameters, returns a JijModelingResponse object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client | JijZeptClient | JijZept client object. | required |
solver | str | Solver type. | required |
queue_name | str | Queue name to use. | required |
problem | Problem | The problem to be solved. | required |
instance_data | dict[str, int | float | integer | floating | ndarray | list] | Instance data. | required |
fixed_variables | dict[str, dict[tuple[int, ...], int]] | Fixed variables. | required |
parameter_search_parameters | ParameterSearchParameters | Parameters for parameter search. | required |
max_wait_time | int | float | None | Maximum time to wait for the response, in seconds. | required |
sync | bool | Whether to wait for the response. | required |
Returns:
| Name | Type | Description |
|---|---|---|
JijModelingResponse | JijModelingResponse | Stores minimum energy samples and statistics of the computation. |
Raises:
| Type | Description |
|---|---|
JijZeptSolvingFailedError | If the computation failed to solve the problem. |
JijZeptSolvingUnknownError | If the computation ended in an unknown error. |
JijZeptSolvingValidationError | If the computation failed to validate the input parameters. |
upload_instance(client, problem, instance_data, system_time=jm.SystemTime()) ¶
This function makes problem and instance_data into sendable instance, then store it into the cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client | JijZeptClient | JijZept client object. | required |
problem | Problem | Mathematical expression of JijModeling. | required |
instance_data | dict[str, int | float | integer | floating | ndarray | list] | The actual values to be assigned to the placeholders. | required |
system_time | SystemTime | Object to store upload time. | SystemTime() |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | The ID of the uploaded instance. |