openjij.model.model#

This module defines the BinaryQuadraticModel with the Hamiltonian,
H=ijJijσiσj+ihiσi,H = \sum_{i\neq j} J_{ij}\sigma_i \sigma_j + \sum_{i} h_{i}\sigma_i,
in an Ising form and
H=ijQijxixj+iHixi,H = \sum_{ij} Q_{ij}x_i x_j + \sum_{i} H_{i}x_i,
in a QUBO form.
The methods and usage are basically the same as dimod.

Module Contents#

Functions#

BinaryPolynomialModel(*args, **kwargs)

BinaryQuadraticModel(linear, quadratic, *args, **kwargs)

Generate BinaryQuadraticModel object.

bqm_from_ising(linear, quadratic[, offset])

bqm_from_numpy_matrix(mat[, variables, offset, vartype])

bqm_from_qubo(Q[, offset])

make_BinaryPolynomialModel(polynomial[, index_type, ...])

make_BinaryPolynomialModel_from_JSON(obj)

make_BinaryPolynomialModel_from_hising(*args, **kwargs)

make_BinaryPolynomialModel_from_hubo(*args, **kwargs)

make_BinaryQuadraticModel(linear, quadratic, sparse)

BinaryQuadraticModel factory.

make_BinaryQuadraticModel_from_JSON(obj)

Make BinaryQuadraticModel from JSON.

Attributes#

from_hising

from_hubo

from_ising

from_numpy_matrix

from_qubo

from_serializable

from_serializable

openjij.model.model.BinaryPolynomialModel(*args, **kwargs)[source]#
openjij.model.model.BinaryQuadraticModel(linear, quadratic, *args, **kwargs)[source]#

Generate BinaryQuadraticModel object.

openjij.model.model.vartype#

variable type SPIN or BINARY

Type

dimod.Vartype

openjij.model.model.linear#

represents linear term

Type

dict

openjij.model.model.quadratic#

represents quadratic term

Type

dict

openjij.model.model.offset#

represents constant energy term when convert to SPIN from BINARY

Type

float

openjij.model.model.num_variables#

represents number of variables in the model

Type

int

openjij.model.model.variables#

represents variables of the binary quadratic model

Type

list

Parameters
  • linear (dict) – linear biases

  • quadratic (dict) – quadratic biases

  • offset (float) – offset

  • vartype (openjij.variable_type.Vartype) – vartype (‘SPIN’ or ‘BINARY’)

  • gpu (bool) – if true, this can be used for gpu samplers.

  • kwargs

Returns

generated BinaryQuadraticModel

Examples

BinaryQuadraticModel can be initialized by specifing h and J:

>>> h = {0: 1, 1: -2}
>>> J = {(0, 1): -1, (1, 2): -3, (2, 3): 0.5}
>>> bqm = oj.BinaryQuadraticModel(self.h, self.J)

You can also use strings and tuples of integers (up to 4 elements) as indices:

>>> h = {'a': 1, 'b': -2}
>>> J = {('a', 'b'): -1, ('b', 'c'): -3, ('c', 'd'): 0.5}
>>> bqm = oj.BinaryQuadraticModel(self.h, self.J)
openjij.model.model.bqm_from_ising(linear, quadratic, offset=0.0, **kwargs)[source]#
openjij.model.model.bqm_from_numpy_matrix(mat, variables: list = None, offset=0.0, vartype='BINARY', **kwargs)[source]#
Parameters

variables (list) –

openjij.model.model.bqm_from_qubo(Q, offset=0.0, **kwargs)[source]#
openjij.model.model.make_BinaryPolynomialModel(polynomial, index_type=None, tuple_size=0)[source]#
openjij.model.model.make_BinaryPolynomialModel_from_JSON(obj)[source]#
openjij.model.model.make_BinaryPolynomialModel_from_hising(*args, **kwargs)[source]#
openjij.model.model.make_BinaryPolynomialModel_from_hubo(*args, **kwargs)[source]#
openjij.model.model.make_BinaryQuadraticModel(linear: dict, quadratic: dict, sparse)[source]#

BinaryQuadraticModel factory.

Returns

generated BinaryQuadraticModel class

Parameters
  • linear (dict) –

  • quadratic (dict) –

openjij.model.model.make_BinaryQuadraticModel_from_JSON(obj: dict)[source]#

Make BinaryQuadraticModel from JSON.

Returns

corresponding BinaryQuadraticModel type

Parameters

obj (dict) –

openjij.model.model.from_hising#
openjij.model.model.from_hubo#
openjij.model.model.from_ising#
openjij.model.model.from_numpy_matrix#
openjij.model.model.from_qubo#
openjij.model.model.from_serializable#
openjij.model.model.from_serializable#