Skip to content

Fixstars Amplify

JijFixstarsAmplifyParameters dataclass

Manage Parameters for using Fixstars Amplify.

Attributes:

Name Type Description
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.

JijFixstarsAmplifySampler

Bases: JijZeptBaseSampler

Sampler using Fixstars Amplify.

__init__(token=None, url=None, proxy=None, config=None, config_env='default', fixstars_token=None, fixstars_url=None)

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. Iffixstars_tokenandfixstars_url` are specified in the arguments, that will be used as priority setting.

Parameters:

Name Type Description Default
token Optional[str]

Token string.

None
url Union[str, dict]

API URL.

None
proxy Optional[str]

Proxy URL.

None
config Optional[str]

Config file path for JijZept.

None
config_env str

config env.

'default'
fixstars_token Optional[str]

Token string for Fixstars Amplify.

None
fixstars_url Optional[str]

Url string for Fixstars Ampplify.

None

Raises:

Type Description
ConfigError

if fixstars_token is not defined in the argument or config.toml.

sample_instance(instance_id, multipliers={}, fixed_variables={}, parameters=None, normalize_qubo=False, max_wait_time=None, sync=True, queue_name=None, needs_square_constraints=None, relax_as_penalties=None, system_time=jm.SystemTime(), **kwargs)

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:

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.

{}
parameters Optional[JijFixstarsAmplifyParameters]

Parameters used in Fixstars Amplify. If None, the default value of the JijFixstarsAmplifyParameters will be set.

None
normalize_qubo bool

Option to normalize the QUBO coefficient. Defaults to False.

False
max_wait_time int | float | None

The number of timeout [sec] for post request. If None, 60 (one minute) will be set. Please note that this argument is for the jijzept timeout and not for configuring solver settings, such as solving time.

None
sync bool

Synchronous mode.

True
queue_name Optional[str]

Queue name.

None
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.

None
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.

None
system_time SystemTime

Object to store system times other than upload time.

SystemTime()
**kwargs

Fixstars Amplify parameters using **kwargs. If both **kwargs and parameters are exist, the value of **kwargs takes precedence.

{}

Returns:

Type Description
JijModelingResponse

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(model, feed_dict, multipliers={}, fixed_variables={}, parameters=None, normalize_qubo=False, max_wait_time=None, sync=True, queue_name=None, needs_square_constraints=None, relax_as_penalties=None, **kwargs)

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:

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.

{}
parameters Optional[JijFixstarsAmplifyParameters]

Parameters used in Fixstars Amplify. If None, the default value of the JijFixstarsAmplifyParameters will be set.

None
normalize_qubo bool

Option to normalize the QUBO coefficient. Defaults to False.

False
max_wait_time int | float | None

The number of timeout [sec] for post request. If None, 60 (one minute) will be set. Please note that this argument is for the jijzept timeout and not for configuring solver settings, such as solving time.

None
sync bool

Synchronous mode.

True
queue_name Optional[str]

Queue name.

None
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.

None
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.

None
**kwargs

Fixstars Amplify parameters using **kwargs. If both **kwargs and parameters are exist, the value of **kwargs takes precedence.

{}

Returns:

Type Description
JijModelingResponse

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
)