sampler
class JijDA4Sampler
Sampler using Digital Annealer v4.
__init__ (self, token, url, proxy, config, config_env, da4_token, da4_url) -> -
Sets Jijzept token and url and fourth generation Digital Annealer token and url.
If da4_token
and 'da4_urlare not specified in the arguments,
JijZept configuration file is used.
If
da4_tokenand
da4_url` are specified in the arguments,
that will be used as priority setting.
Parameters
- token(Optional[str]) : Token string.
- url(Optional[Union[str, dict]]) : API URL.
- proxy(Optional[str]) : Proxy URL.
- config(Optional[str]) : Config file path for JijZept.
- config_env(str) : config env.
- da4_token(Optional[str]) : Token string for Degital Annealer 4.
- da4_url(Optional[str]) : API Url string for Degital Annealer 4.
sample_instance (self, instance_id, fixed_variables, inequalities_lambda, parameters, normalize_qubo, max_wait_time, sync, queue_name, system_time, api_version, kwargs) -> JijModelingResponse
Sample using the uploaded instance by means of fourth generation Digital Annealer.
Note that this sampler solve problems with using Azure Blob Storage, which is a feature of Digital Annealer v4, and there is no option not to use Azure Blob Storage.
To configure the solver, instantiate the JijDA4SolverParameters
class and pass the instance to the parameters
argument.
Parameters
- instance_id(str) : The ID of the uploaded instance.
- fixed_variables(dict[str, dict[tuple[int, ...], int]]) : Dictionary of variables to fix.
- inequalities_lambda(dict[str, int]) : Coefficient of inequality. If omitted, set to 1. The coefficients of the equality constraints can be set from JijDA4SolverParameters.
- parameters(Optional[JijDA4SolverParameters]) : Parameters used in Digital Annealer 4. If
None
, the default value of the JijDA4SolverParameters will be set. - normalize_qubo(bool) : Option to normalize the QUBO coefficient and inequality constraint conditions. Defaults to
False
. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- system_time(jm.SystemTime) : Object to store system times other than upload time.
- api_version(Literal["v4", "v3c"]) : The API version of Digital Annealer. JijZept suppoorts "v4" and "v3c". Defaults to "v4".
- **kwargs : Digital Annealer 4 parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- JijModelingResponse : Stores minimum energy samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijDA4Sampler, JijDA4SolverParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint(
"knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j
)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
inequalities_lambda = {"knapsack_constraint": 22}
sampler = JijDA4Sampler(config="xx", da4_token="oo")
parameters = JijDA4SolverParameters(penalty_coef=2)
# upload instance
instance_id = sampler.upload_instance(problem, feed_dict)
# sample instance
sampleset = sampler.sample_instance(
instance_id, inequalities_lambda=inequalities_lambda, parameters=parameters
)
sample_model (self, model, feed_dict, fixed_variables, inequalities_lambda, parameters, normalize_qubo, max_wait_time, sync, queue_name, api_version, kwargs) -> JijModelingResponse
Sample using JijModeling by means of fourth generation Digital Annealer.
Note that this sampler solve problems with using Azure Blob Storage, which is a feature of Digital Annealer v4, and there is no option not to use Azure Blob Storage.
To configure the solver, instantiate the JijDA4SolverParameters
class and pass the instance to the parameters
argument.
Parameters
- model(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- fixed_variables(dict[str, dict[tuple[int, ...], int]]) : Dictionary of variables to fix.
- inequalities_lambda(dict[str, int]) : Coefficient of inequality. If omitted, set to 1. The coefficients of the equality constraints can be set from JijDA4SolverParameters.
- parameters(Optional[JijDA4SolverParameters]) : Parameters used in Digital Annealer 4. If
None
, the default value of the JijDA4SolverParameters will be set. - normalize_qubo(bool) : Option to normalize the QUBO coefficient and inequality constraint conditions. Defaults to
False
. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- api_version(Literal["v4", "v3c"]) : The API version of Digital Annealer. JijZept suppoorts "v4" and "v3c". Defaults to "v4".
- **kwargs : Digital Annealer 4 parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- JijModelingResponse : Stores minimum energy samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijDA4Sampler, JijDA4SolverParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint(
"knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j
)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
inequalities_lambda = {"knapsack_constraint": 22}
sampler = JijDA4Sampler(config="xx", da4_token="oo")
parameters = JijDA4SolverParameters(penalty_coef=2)
sampleset = sampler.sample_model(
problem, feed_dict, inequalities_lambda=inequalities_lambda, parameters=parameters
)
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijDA4SolverParameters
Manage Parameters for using fourth generation Digital Annealer.
Attributes
- time_limit_sec(int) : Set the timeout in seconds in the range 1 ~ 1800.
- target_energy(Optional[float]) : Set the target energy value. The calculation is terminated when the minimum energy savings reaches the target energy.
- num_run(int) : Set the number of parallel trial iterations in the range 1 ~ 16.
- num_group(int) : Set the number of groups of parallel trials in the range 1 ~ 16.
- num_output_solution(int) : Set the number of output solutions for each parallel trial group in the range 1 ~ 1024.
- gs_level(int) : Set the level of global search. The higher this value, the longer the constraint utilization search will search in the range 0 ~ 100. If set the 1way 1hot or 2way 1hot, it is recommended that 0 be set for gs_level.
- gs_cutoff(int) : Set the convergence decision level in the constraint utilization search of the solver in the range 0 ~ 1000000. If
0
, convergence judgement is off. - one_hot_level(int) : Levels of 1hot constraints search.
- one_hot_cutoff(int) : Convergence decision level for 1hot constraints search. If 0 is set, this function is turned off.
- internal_penalty(int) : 1hot constraint internal generation mode. Note that if 1way- or 2way 1hot constraints are specified to
jijmodeling.Constraint
, internal_penalty is set to 1 internally, regardless of user input. - penalty_auto_mode(int) : Set the coefficient adjustment mode for the constaint term. If
0
, fixed to the value setinpenlaty_coef
. If1
, the value set inpenalty_coef
is used as the initial value and adjusted automatically. - penalty_coef(int) : Set the coefficients of the constraint term.
- penalty_inc_rate(int) : Set parameters for automatic adjustment of constriant term.
- max_penalty_coef(int) : Set the maximum value of the constraint term coefficient in the global search. If no maximum value is specified, set to 0.
class JijFixstarsAmplifyParameters
Manage Parameters for using Fixstars Amplify.
Attributes
- amplify_timeout(int) : Set the timeout in milliseconds. Defaults to 1000.
- num_gpus(int) : Set the number of GPUs to be used. The maximum number of GPUs available depends on the subscription plan, and 0 means the maximum number available. Defaults to 1.
- penalty_calibration(bool) : Set whether to enable the automatic adjustment of the penalty function's multipliers. If multiplier is not set, it will be set true. Defaults to False.
- duplicate(bool) : If True, all solutions with the same energy and the same feasibility are output. Otherwise, only one solution with the same energy and feasibility is output.
- num_outputs(int) : The number of solutions to be output which have different energies and feasibility. Assumed 1 if no value is set. If set to 0, all the solutions are output. Defaults to 1.
class JijFixstarsAmplifySampler
Sampler using Fixstars Amplify.
__init__ (self, token, url, proxy, config, config_env, fixstars_token, fixstars_url) -> -
Sets Jijzept token and url and fixstars amplify token and url.
If fixstars_token
and 'fixstars_urlare not specified in the arguments,
JijZept configuration file is used.
If
fixstars_tokenand
fixstars_url` are specified in the arguments,
that will be used as priority setting.
Parameters
- token(Optional[str]) : Token string.
- url(Union[str, dict]) : API URL.
- proxy(Optional[str]) : Proxy URL.
- config(Optional[str]) : Config file path for JijZept.
- config_env(str) : config env.
- fixstars_token(Optional[str]) : Token string for Fixstars Amplify.
- fixstars_url(Optional[str]) : Url string for Fixstars Ampplify.
sample_instance (self, instance_id, multipliers, fixed_variables, parameters, normalize_qubo, max_wait_time, sync, queue_name, needs_square_constraints, relax_as_penalties, system_time, kwargs) -> Union[DimodResponse, JijModelingResponse]
Converts the uploaded instance to amplify.BinaryQuadraticModel and run.
Fixstars Amplify Solver. Note here that the supported type of decision variables is only Binary when using Fixstars Ampplify Solver from Jijzept.
To configure the solver, instantiate the JijFixstarsAmplifyParameters
class and pass the instance to the parameters
argument.
Parameters
- instance_id(str) : The ID of the uploaded instance.
- 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.
- parameters(Optional[JijFixstarsAmplifyParameters]) : Parameters used in Fixstars Amplify. If
None
, the default value of the JijFixstarsAmplifyParameters will be set. - normalize_qubo(bool) : Option to normalize the QUBO coefficient. Defaults to
False
. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- 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.
- system_time(jm.SystemTime) : Object to store system times other than upload time.
- **kwargs : Fixstars Amplify parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- Union[DimodResponse, JijModelingResponse] : Stores samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijFixstarsAmplifySampler, JijFixstarsAmplifyParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint("knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
multipliers = {"onehot_constraint": 11, "knapsack_constraint": 22}
sampler = JijFixstarsAmplifySampler(config="xx", fixstars_token="oo")
parameters = JijFixstarsAmplifyParameters(
amplify_timeout=1000,
num_outputs=1,
filter_solution=False,
penalty_calibration=False
)
# upload instance
instance_id = sampler.upload_instance(problem, feed_dict)
# sample instance
sampleset = sampler.sample_model(
instance_id, multipliers, parameters=parameters
)
sample_model (self, model, feed_dict, multipliers, fixed_variables, parameters, normalize_qubo, max_wait_time, sync, queue_name, needs_square_constraints, relax_as_penalties, kwargs) -> Union[DimodResponse, JijModelingResponse]
Converts the given problem to amplify.BinaryQuadraticModel and run.
Fixstars Amplify Solver. Note here that the supported type of decision variables is only Binary when using Fixstars Ampplify Solver from Jijzept.
To configure the solver, instantiate the JijFixstarsAmplifyParameters
class and pass the instance to the parameters
argument.
Parameters
- model(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- 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.
- parameters(Optional[JijFixstarsAmplifyParameters]) : Parameters used in Fixstars Amplify. If
None
, the default value of the JijFixstarsAmplifyParameters will be set. - normalize_qubo(bool) : Option to normalize the QUBO coefficient. Defaults to
False
. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- 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.
- **kwargs : Fixstars Amplify parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- Union[DimodResponse, JijModelingResponse] : Stores samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijFixstarsAmplifySampler, JijFixstarsAmplifyParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint("knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
multipliers = {"onehot_constraint": 11, "knapsack_constraint": 22}
sampler = JijFixstarsAmplifySampler(config="xx", fixstars_token="oo")
parameters = JijFixstarsAmplifyParameters(amplify_timeout=1000, num_outputs=1, filter_solution=False,
penalty_calibration=False)
sampleset = sampler.sample_model(
problem, feed_dict, multipliers, parameters=parameters
)
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijLeapHybridBQMParameters
Manage Parameters for using Leap Hybrid Samplers.
Attributes
- time_limit(Optional[Union[int, float]]) : the maximum run time, in seconds, the solver is allowed to work on the given problem. Must be at least the minimum required for the problem, which is calculated and set by default. It is deprecated to set this up due to high credit consumption.
- label(str) : The problem label given to the SampelSet instance returned by the JijLeapHybridSamplers. Defaults to None.
class JijLeapHybridBQMSampler
Sampler using Leap Hybrid BQM Sampler, which is D-Wave's Binary Quadratic Model (BQM).
__init__ (self, token, url, proxy, config, config_env, leap_token, leap_url) -> -
Sets token and url.
If leap_token
and 'leap_urlare not specified in the arguments,
JijZept configuration file is used.
If
leap_tokenand
leap_url` are specified in the arguments,
that will be used as priority setting.
Parameters
- token(Optional[str]) : Token string for JijZept.
- url(Optional[str]) : API URL for JijZept.
- proxy(Optional[str]) : Proxy URL. Defaults to None.
- config(Optional[str]) : Config file path for JijZept.
- leap_token(Optional[str]) : Token string for Dwave Leap.
- leap_url(Optional[str]) : API URL for Dwave Leap.
sample_instance (self, instance_id, fixed_variables, parameters, normalize_qubo, multipliers, needs_square_constraints, max_wait_time, sync, queue_name, system_time, kwargs) -> JijModelingResponse
Converts the uploaded instance to dimod.BinaryQuadraticModel and runs.
Dwave's LeapHybridBQMSampler. Note here that the supported type of decision variables is only Binary when using LeapHybridSampler from Jijzept.
To configure the solver, instantiate the JijLeapHybridBQMParameters
class and pass the instance to the parameters
argument.
Parameters
- instance_id(str) : The ID of the uploaded instance.
- fixed_variables(Optional[dict[str, dict[tuple[int, ...], int]]]) : variables to fix.
- relax_list(Optional[List[str]]) : variable labels for continuous relaxation.
- parameters(Optional[JijLeapHybridCQMParameters]) : Parameters used in Dwave LeapHybridSampler. If
None
, the default value of the JijLeapHybridBQMParameters will be set. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- system_time(jm.SystemTime) : Object to store system times other than upload time.
- **kwargs : Dwave Leap parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- JijModelingResponse : Stores samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijLeapHybridBQMSampler, JijLeapHybridBQMParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint("knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
sampler = JijLeapHybridBQMSampler(config="XX", token_leap="XX")
parameters = JijLeapHybridBQMParameters(label="bin_packing")
# upload instance
instance_id = sampler.upload_instance(problem, feed_dict)
# sample instance
sampleset = sampler.sample_instance(instance_id, parameters=parameters)
sample_model (self, model, feed_dict, fixed_variables, parameters, normalize_qubo, multipliers, needs_square_constraints, max_wait_time, sync, queue_name, kwargs) -> JijModelingResponse
Converts the given problem to dimod.BinaryQuadraticModel and runs.
Dwave's LeapHybridSampler. Note here that the supported type of decision variables is only Binary when using LeapHybridSampler from Jijzept.
To configure the solver, instantiate the JijLeapHybridBQMParameters
class and pass the instance to the parameters
argument.
Parameters
- model(jm.Problem) : Optimization problem of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- fixed_variables(Optional[dict[str, dict[tuple[int, ...], int]]]) : variables to fix.
- relax_list(Optional[List[str]]) : variable labels for continuous relaxation.
- parameters(Optional[JijLeapHybridCQMParameters]) : Parameters used in Dwave LeapHybridSampler. If
None
, the default value of the JijLeapHybridBQMParameters will be set. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- **kwargs : Dwave Leap parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- JijModelingResponse : Stores samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijLeapHybridBQMSampler, JijLeapHybridBQMParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint("knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
sampler = JijLeapHybridBQMSampler(config="XX", token_leap="XX")
parameters = JijLeapHybridBQMParameters(label="bin_packing")
sampleset = sampler.sample_model(
problem, feed_dict, parameters=parameters
)
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijLeapHybridCQMParameters
Manage Parameters for using Leap Hybrid Samplers.
Attributes
- time_limit(Optional[Union[int, float]]) : the maximum run time, in seconds, the solver is allowed to work on the given problem. Must be at least the minimum required for the problem, which is calculated and set by default. It is deprecated to set this up due to high credit consumption.
- label(str) : The problem label given to the SampelSet instance returned by the JijLeapHybridSamplers. Defaults to None.
class JijLeapHybridCQMSampler
Sampler using Leap Hybrid CQM Sampler, which is D-Wave's Constrained Quandratic Model (CQM).
__init__ (self, token, url, proxy, config, config_env, leap_token, leap_url) -> -
Sets token and url.
If leap_token
and 'leap_urlare not specified in the arguments,
JijZept configuration file is used.
If
leap_tokenand
leap_url` are specified in the arguments,
that will be used as priority setting.
Parameters
- token(Optional[str]) : Token string for JijZept.
- url(Optional[str]) : API URL for JijZept.
- proxy(Optional[str]) : Proxy URL. Defaults to None.
- config(Optional[str]) : Config file path for JijZept.
- leap_token(Optional[str]) : Token string for Dwave Leap.
- leap_url(Optional[str]) : API URL for Dwave Leap.
sample_instance (self, instance_id, fixed_variables, relax_list, parameters, max_wait_time, sync, queue_name, system_time, kwargs) -> JijModelingSampleset
Converts the uploaded instance to dimod.ConstrainedQuadraticModel and runs.
Dwave's LeapHybridCQMSampler. Note here that the supported type of decision variables is only Binary when using LeapHybridCQMSolver from Jijzept.
To configure the solver, instantiate the JijLeapHybridCQMParameters
class and pass the instance to the parameters
argument.
Parameters
- instance_id(str) : The ID of the uploaded instance.
- fixed_variables(Optional[dict[str, dict[tuple[int, ...], int]]]) : variables to fix.
- relax_list(Optional[List[str]]) : variable labels for continuous relaxation.
- parameters(Optional[JijLeapHybridCQMParameters]) : Parameters used in Dwave Leap Hybrid CQMSampler. If
None
, the default value of the JijLeapHybridCQMParameters will be set. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- system_time(jm.SystemTime) : Object to store system times other than upload time.
- **kwargs : Dwave Leap parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- JijModelingSampleset : Stores samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijLeapHybridCQMSampler, JijLeapHybridCQMParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint("knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
sampler = JijLeapHybridCQMSampler(config="XX", token_leap="XX")
parameters = JijLeapHybridCQMParameters(label="bin_packing")
# upload instance
instance_id = sampler.upload_instance(problem, feed_dict)
# sample instance
sampleset = sampler.sample_instance(instance_id, parameters=parameters)
sample_model (self, model, feed_dict, fixed_variables, relax_list, parameters, max_wait_time, sync, queue_name, kwargs) -> JijModelingSampleset
Converts the given problem to dimod.ConstrainedQuadraticModel and runs.
Dwave's LeapHybridCQMSampler. Note here that the supported type of decision variables is only Binary when using LeapHybridCQMSolver from Jijzept.
To configure the solver, instantiate the JijLeapHybridCQMParameters
class and pass the instance to the parameters
argument.
Parameters
- model(jm.Problem) : Optimization problem of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- fixed_variables(Optional[dict[str, dict[tuple[int, ...], int]]]) : variables to fix.
- relax_list(Optional[List[str]]) : variable labels for continuous relaxation.
- parameters(Optional[JijLeapHybridCQMParameters]) : Parameters used in Dwave Leap Hybrid CQMSampler. If
None
, the default value of the JijLeapHybridCQMParameters will be set. - max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- **kwargs : Dwave Leap parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- JijModelingSampleset : Stores samples and other information.
Examples
import jijmodeling as jm
from jijzept import JijLeapHybridCQMSampler, JijLeapHybridCQMParameters
w = jm.Placeholder("w", ndim=1)
num_items = jm.Placeholder("num_items")
c = jm.Placeholder("c")
y = jm.BinaryVar("y", shape=(num_items,))
x = jm.BinaryVar("x", shape=(num_items, num_items))
i = jm.Element("i", belong_to=num_items)
j = jm.Element("j", belong_to=num_items)
problem = jm.Problem("bin_packing")
problem += y[:].sum()
problem += jm.Constraint("onehot_constraint", jm.sum(j, x[i, j]) - 1 == 0, forall=i)
problem += jm.Constraint("knapsack_constraint", jm.sum(i, w[i] * x[i, j]) - y[j] * c <= 0, forall=j)
feed_dict = {"num_items": 2, "w": [9, 1], "c": 10}
sampler = JijLeapHybridCQMSampler(config="XX", token_leap="XX")
parameters = JijLeapHybridCQMParameters(label="bin_packing")
sampleset = sampler.sample_model(
problem, feed_dict, parameters=parameters
)
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijMINLPParameters
Manage the parameters for JijMINLPSolver.
Attributes
- gap_limit(float) : If the relative gap is less than the specified value, the solver stops.
- time_limit(float) : The maximum time in seconds to run the solver.
- solutions_limit(int) : When the given number of solutions has been found, the solver stops.
class JijMINLPSolver
The client for solving MINLP problems using JijModeling.
__init__ (self, token, url, proxy, config, config_env) -> -
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
- token(str | None) : Token string. Defaults to None.
- url(str | None) : API URL. Defaults to None.
- proxy(str | None) : Proxy URL. Defaults to None.
- config(str | None) : Config file path. Defaults to None.
- config_env(str) : configure environment name. Defaults to 'default'.
Raises
- TypeError:
token
,url
, orconfig
is not str.
sample_instance (self, instance_id, fixed_variables, relaxed_variables, ignored_constraints, parameters, max_wait_time, sync, queue_name, system_time, kwargs) -> JijModelingResponse
Solve the MINLP problem using JijModeling.
Parameters
- instance_id(str) : The ID of the uploaded instance.
- fixed_variables(FixedVariables) : The dictionary of variables to be fixed.
- relaxed_variables(List[str]) : The labels of the variables to be relaxed to continuous.
- max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode. If
True
, the method waits until the solution is returned. - queue_name(Optional[str]) : Queue name.
Returns
- JijModelingResponse : Stores solution and other information.
Examples
import jijmodeling as jm
import jijzept as jz
problem = jm.Problem("One-dimensional Bin Packing Problem")
L = jm.Placeholder("L")
b = jm.Placeholder("b", ndim=1)
w = jm.Placeholder("w", ndim=1)
m = b.len_at(0, latex="m")
n = w.len_at(0, latex="n")
x = jm.IntegerVar("x", shape=(m, n), lower_bound=0, upper_bound=10)
y = jm.BinaryVar("y", shape=(n,))
i = jm.Element("i", belong_to=(0, m))
j = jm.Element("j", belong_to=(0, n))
problem += jm.sum(j, y[j])
problem += jm.Constraint("const1", jm.sum(j, x[i, j]) >= b[i], forall=i)
problem += jm.Constraint("const2", jm.sum(i, w[i] * x[i, j]) <= L * y[j], forall=j)
instance_data = {
"L": 250,
"w": [187, 119, 74, 90],
"b": [1, 2, 2, 1]
}
solver = jz.JijMINLPSolver(config="config.toml")
# upload instance
instance_id = sampler.upload_instance(problem, instance_data)
# solve
response = solver.sample_instance(instance_id)
sampleset = response.get_sampleset()
sample_model (self, model, instance_data, fixed_variables, relaxed_variables, ignored_constraints, parameters, max_wait_time, sync, queue_name, kwargs) -> JijModelingResponse
Solve the MINLP problem using JijModeling.
Parameters
- model(jm.Problem) : The mathematical model of JijModeling.
- instance_data(InstanceData) : The actual values to be assined to the placeholders.
- fixed_variables(FixedVariables) : The dictionary of variables to be fixed.
- relaxed_variables(List[str]) : The labels of the variables to be relaxed to continuous.
- ignored_constraints(list[str]) : The list of constraint names to be ignored.
- max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode. If
True
, the method waits until the solution is returned. - queue_name(Optional[str]) : Queue name.
Returns
- JijModelingResponse : Stores solution and other information.
Examples
import jijmodeling as jm
import jijzept as jz
problem = jm.Problem("One-dimensional Bin Packing Problem")
L = jm.Placeholder("L")
b = jm.Placeholder("b", ndim=1)
w = jm.Placeholder("w", ndim=1)
m = b.len_at(0, latex="m")
n = w.len_at(0, latex="n")
x = jm.IntegerVar("x", shape=(m, n), lower_bound=0, upper_bound=10)
y = jm.BinaryVar("y", shape=(n,))
i = jm.Element("i", belong_to=(0, m))
j = jm.Element("j", belong_to=(0, n))
problem += jm.sum(j, y[j])
problem += jm.Constraint("const1", jm.sum(j, x[i, j]) >= b[i], forall=i)
problem += jm.Constraint("const2", jm.sum(i, w[i] * x[i, j]) <= L * y[j], forall=j)
instance_data = {
"L": 250,
"w": [187, 119, 74, 90],
"b": [1, 2, 2, 1]
}
solver = jz.JijMINLPSolver(config="config.toml")
response = solver.sample_model(problem, instance_data)
sampleset = response.get_sampleset()
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijSAParameters
Manage Parameters for using JijSASampler.
Attributes
- beta_min(Optional[float]) : Minimum (initial) inverse temperature. If
None
, this will be set automatically. - beta_max(Optional[float]) : Maximum (final) inverse temperature. If
None
, this will be set automatically. - num_sweeps(Optional[int]) : The number of Monte-Carlo steps. If
None
, 1000 will be set. - num_reads(Optional[int]) : The number of samples. If
None
, 1 will be set. - initial_state(Optional[dict]) : Initial state. If
None
, this will be set automatically. - updater(Optional[str]) : Updater algorithm. "single spin flip" or "swendsen wang". If
None
, "single spin flip" will be set. - sparse(Optional[bool]) : If
True
, only non-zero matrix elements are stored, which will save memory. IfNone
,False
will be set. - reinitialize_state(Optional[bool]) : If
True
, reinitialize state for each run. IfNone
,True
will be set. - seed(Optional[int]) : Seed for Monte Carlo algorithm. If
None
, this will be set automatically. - 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.
- ignored_constraints(list[str]) : The list of constraint names to be ignored.
class JijSASampler
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.
__init__ (self, token, url, proxy, config, config_env) -> -
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
- token(str | None) : Token string. Defaults to None.
- url(str | None) : API URL. Defaults to None.
- proxy(str | None) : Proxy URL. Defaults to None.
- config(str | None) : Config file path. Defaults to None.
- config_env(str) : configure environment name. Defaults to 'default'.
Raises
- TypeError:
token
,url
, orconfig
is not str.
sample_instance (self, instance_id, multipliers, fixed_variables, search, num_search, algorithm, parameters, max_wait_time, sync, queue_name, system_time, kwargs) -> JijModelingResponse
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
- instance_id(str) : The ID of the uploaded instance.
- 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
True
, the parameter search will be carried out, which tries to find better values of multipliers for penalty terms. - num_search(int) : The number of parameter search iteration. Defaults to set 15. This option works if
search
isTrue
. - algorithm(Optional[str]) : Algorithm for parameter search. Defaults to None.
- parameters(JijSAParameters | None) : defaults None.
- max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- system_time(jm.SystemTime) : Object to store system times other than upload time.
- **kwargs : SA parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- 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 (self, model, feed_dict, multipliers, fixed_variables, needs_square_dict, search, num_search, algorithm, parameters, max_wait_time, sync, queue_name, kwargs) -> JijModelingResponse
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
- model(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- 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
True
, the parameter search will be carried out, which tries to find better values of multipliers for penalty terms. - num_search(int) : The number of parameter search iteration. Defaults to set 15. This option works if
search
isTrue
. - algorithm(Optional[str]) : Algorithm for parameter search. Defaults to None.
- parameters(JijSAParameters | None) : defaults None.
- max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- **kwargs : SA parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- 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]})
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijSQAParameters
Manage Parameters for using JijSQASampler.
Attributes
- 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
None
, 1000 will be set. - num_reads(Optional[int]) : The number of samples. If
None
, 1 will be set. - sparse(Optional[bool]) : If
True
, only non-zero matrix elements are stored, which will save memory. IfNone
,False
will be set. - reinitialize_state(Optional[bool]) : If
True
, reinitialize state for each run. IfNone
,True
will be set. - seed(Optional[int]) : Seed for Monte Carlo algorithm. If
None
, this will be set automatically. - 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.
- ignored_constraints(list[str]) : The list of constraint names to be ignored.
class JijSQASampler
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.
__init__ (self, token, url, proxy, config, config_env) -> -
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
- token(str | None) : Token string. Defaults to None.
- url(str | None) : API URL. Defaults to None.
- proxy(str | None) : Proxy URL. Defaults to None.
- config(str | None) : Config file path. Defaults to None.
- config_env(str) : configure environment name. Defaults to 'default'.
Raises
- TypeError:
token
,url
, orconfig
is not str.
sample_instance (self, instance_id, multipliers, fixed_variables, search, num_search, algorithm, parameters, max_wait_time, sync, queue_name, system_time, kwargs) -> JijModelingResponse
Sample using the uploaded instance by means of the simulated quantum annealing.
To configure the solver, instantiate the JijSQAParameters
class and pass the instance to the parameters
argument.
Parameters
- instance_id(str) : The ID of the uploaded instance.
- 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
True
, the parameter search will be carried out, which tries to find better values of multipliers for penalty terms. - num_search(int) : The number of parameter search iteration. Defaults to set 15. This option works if
search
isTrue
. - algorithm(Optional[str]) : Algorithm for parameter search. Defaults to None.
- parameters(JijSQAParameters | None) : defaults None.
- max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- system_time(jm.SystemTime) : Object to store system times other than upload time.
- **kwargs : SQA parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- 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.JijSQASampler(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 (self, problem, feed_dict, multipliers, fixed_variables, needs_square_dict, search, num_search, algorithm, parameters, max_wait_time, sync, queue_name, kwargs) -> JijModelingResponse
Sample using JijModeling by means of the simulated quantum annealing.
To configure the solver, instantiate the JijSQAParameters
class and pass the instance to the parameters
argument.
Parameters
- model(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- 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
True
, the parameter search will be carried out, which tries to find better values of multipliers for penalty terms. - num_search(int) : The number of parameter search iteration. Defaults to set 15. This option works if
search
isTrue
. - algorithm(Optional[str]) : Algorithm for parameter search. Defaults to None.
- parameters(JijSQAParameters | None) : defaults None.
- max_wait_time(int | float | None) : The number of timeout [sec] for post request. If
None
, 600 will be set. Please note that this argument is for thejijzept
timeout and not for configuring solver settings, such as solving time. - sync(bool) : Synchronous mode.
- queue_name(Optional[str]) : Queue name.
- **kwargs : SQA parameters using kwargs. If both `kwargs
and
parametersare exist, the value of
**kwargs` takes precedence.
Returns
- 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]})
upload_instance (self, problem, feed_dict, system_time) -> str
Upload instance.
An instance is a pair of problem
and feed_dict
.
This method stores the instance into the cloud.
Parameters
- problem(jm.Problem) : Mathematical expression of JijModeling.
- feed_dict(dict[str, int | float | numpy.integer | numpy.floating | numpy.ndarray | list]) : The actual values to be assigned to the placeholders.
- system_time(jm.SystemTime) : Object to store upload time.
Returns
- 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)
class JijSolverParameters
Manage Parameters for using JijSolver's WeightedLS.
Attributes
- num_iters(int) : The number of iterations (each iteration consists of SFSA, SFLS, MFLS, and update of the weights).
- time_limit_msec(int) : How long does the solver take for each SA (LS) part (in units of millisecond).
- count(int) : The number of iterations during each SA (LS) part.
- ignored_constraints(list[str]) : The list of constraint names to be ignored.