Skip to main content

to_dimod

class CompiledInstance

CompiledInstance: object return compile_model method.

Attributes

  • sense(jijmodeling.ProblemSense) : problem sense minimize or maximize.
  • objective(SubstitutedExpression) : objective expression.
  • constraint(dict[str, dict[tuple[int, ...], SubstitutedExpression]]) : constraints. str key represents name of constraint. tuple[int,...] is values of forall index.
  • penalty : dict[str, dict[tuple[int, ...], SubstitutedExpression]]
  • var_map : VariableMap
  • data : InstanceData
  • problem : jijmodeling.InstanceData

Examples

import jijmodeling as jm
import jijmodeling_transpiler as jmt
n = jm.Placeholder("n")
x = jm.Binary("x", (n, n))
i = jm.Element("i", n)
problem = jm.Problem("sample")
problem += x[:, :]
problem += jm.Constraint("onehot", x[:, i], forall=i)
compiled_instance = jmt.core.compile_model(problem, {"n": 2}, {})
compiled_instance
CompiledInstance(
objective=SubstitutedExpression(
linear=LinearSubstitutedExpr(coeff={0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0}, constant=0.0),
nonlinear=None),
constraint={
'onehot': {
(0,): SubstitutedExpression(
linear=LinearSubstitutedExpr(coeff={0: 1.0, 1: 1.0}, constant=0.0),
nonlinear=None),
(1,): SubstitutedExpression(
linear=LinearSubstitutedExpr(coeff={2: 1.0, 3: 1.0}, constant=0.0),
nonlinear=None)}
},
penalty={},
var_map=VariableMap(var_map={'x': {(0, 0): 0, (0, 1): 2, (1, 0): 1, (1, 1): 3}},
var_num=4,
integer_bound={}),
...
)

add (self, source) -> -


class DimodBuilder

Dimod model builder.

Attributes

  • compiled_model(CompiledInstance) : Compiled model.
  • _model(dimod.ConstrainedQuadraticModel) : Dimod model.
  • _objective(dimod.QuadraticModel) : Objective of dimod model.
  • custome_penalties(dict[str, dimod.BinaryQuadraticModel]) : Custom penalties.

decode_from_cqm_result (self, sampleset) -> jm.SampleSet

Decode sampleset from dimod model.

Parameters

  • sampleset(dimod.SampleSet) : Dimod sampleset.

Returns

  • jm.SampleSet : Decoded sampleset.

get_model (self, penalty_weight) -> dimod.BinaryQuadraticModel

Get dimod model.

Parameters

  • penalty_weight(dict[str, float]) : Penalty weight. Defaults to None.

Returns

  • dimod.BinaryQuadraticModel : Dimod model.

class ProblemSense

An enumeration.


class SubstitutedExpression

SubstitutedExpression(coeff: 'dict[tuple[int, ...], float]', constant: 'float', order: 'int')

add (self, other) -> -

from_serializable (data) -> -

is_constant (self) -> -

mul (self, other) -> -

power (self, exponent) -> -

to_serializable (self) -> -


eval_constraint (sample, compield_model) -> -


transpile_to_dimod_cqm (compiled_model) -> DimodBuilder

Transpile compiled model to dimod CQM.

Parameters

  • compiled_model(CompiledInstance) : Compiled model.

Returns

  • DimodBuilder : Dimod CQM builder.