Skip to content

Dwave Leap Hybrid CQM

JijLeapHybridCQMParameters dataclass

Manage Parameters for using Leap Hybrid CQM Sampler.

Attributes:

Name Type Description
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 dimod.SampelSet instance returned by the JijLeapHybridCQMSampler. Defaults to None.

JijLeapHybridCQMSampler

Bases: JijZeptBaseSampler

Sampler using Leap Hybrid CQM Sampler, which is D-Wave's Constrained Quandratic Model (CQM).

__init__(token=None, url=None, proxy=None, config=None, config_env='default', leap_token=None, leap_url=None)

Sets token and url.

If leap_token and 'leap_urlare not specified in the arguments, JijZept configuration file is used. Ifleap_tokenandleap_url` are specified in the arguments, that will be used as priority setting.

Parameters:

Name Type Description Default
token Optional[str]

Token string for JijZept.

None
url Optional[str]

API URL for JijZept.

None
proxy Optional[str]

Proxy URL. Defaults to None.

None
config Optional[str]

Config file path for JijZept.

None
leap_token Optional[str]

Token string for Dwave Leap.

None
leap_url Optional[str]

API URL for Dwave Leap.

None

Raises:

Type Description
ConfigError

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

sample_instance(instance_id, fixed_variables=None, relax_list=None, parameters=None, max_wait_time=None, sync=True, queue_name=None, system_time=jm.SystemTime(), **kwargs)

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:

Name Type Description Default
instance_id str

The ID of the uploaded instance.

required
fixed_variables Optional[dict[str, dict[tuple[int, ...], int]]]

variables to fix.

None
relax_list Optional[List[str]]

variable labels for continuous relaxation.

None
parameters Optional[JijLeapHybridCQMParameters]

Parameters used in Dwave Leap Hybrid CQMSampler. If None, the default value of the JijLeapHybridCQMParameters will be set.

None
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
system_time SystemTime

Object to store system times other than upload time.

SystemTime()
**kwargs

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

{}

Returns:

Name Type Description
JijModelingSampleset JijModelingResponse

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(model, feed_dict, fixed_variables=None, relax_list=None, parameters=None, max_wait_time=None, sync=True, queue_name=None, **kwargs)

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:

Name Type Description Default
model Problem

Optimization problem of JijModeling.

required
feed_dict dict[str, int | float | integer | floating | ndarray | list]

The actual values to be assigned to the placeholders.

required
fixed_variables Optional[dict[str, dict[tuple[int, ...], int]]]

variables to fix.

None
relax_list Optional[List[str]]

variable labels for continuous relaxation.

None
parameters Optional[JijLeapHybridCQMParameters]

Parameters used in Dwave Leap Hybrid CQMSampler. If None, the default value of the JijLeapHybridCQMParameters will be set.

None
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
**kwargs

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

{}

Returns:

Name Type Description
JijModelingSampleset JijModelingResponse

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
)