openjij.model package

Submodules

openjij.model.chimera_model module

openjij.model.chimera_model.ChimeraModel(linear: dict = None, quadratic: dict = None, offset: float = 0.0, var_type=<Vartype.SPIN: frozenset({1, -1})>, unit_num_L: int = None, model=None, gpu: bool = False)[source]

generate ChimeraModel object. This model deal with chimera graph. ChimeraModel provide methods to verify whether a given interaction graph matches a Chimera graph and to convert it to cxxjij.graph.Chimera.

Parameters
  • linear (dict) – linear biases

  • quadratic (dict) – quadratic biases

  • offset (float) – offset

  • var_type – vartype (‘SPIN’ or ‘BINARY’)

  • unit_num_L (int) – unit_num_L

  • model (BinaryQuadraticModel) – if model is not None, the object is initialized by model.

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

Returns

generated ChimeraModel

Examples

Example shows how to initialize ChimeraModel.:

# This interactions satisfy chimera topology.
>>> Q={(0, 4): -1, (4, 12): -1}
>>> chimera_model = ChimeraModel(Q, unit_num_L=2)  # make
>>> chimera_self.validate_chimera()
openjij.model.chimera_model.make_ChimeraModel(linear, quadratic)[source]

ChimeraModel factory.

Returns

generated ChimeraModel class

openjij.model.chimera_model.make_ChimeraModel_from_JSON(obj)[source]

make ChimeraModel from JSON.

Returns

corresponding ChimeraModel type

openjij.model.higher_order_model module

class openjij.model.higher_order_model.BinaryHigherOrderModel(interactions: list)[source]

Bases: object

Higher order model.

adj_dict()[source]

adjacency list of each variables

Returns

key (variables key), value (list of tuple represents connected indices)

Return type

dict

calc_energy(state)[source]

alias of energy

Parameters

state (list of int) – list of SPIN or BINARY

Returns

energy of state

Return type

float

energy(state)[source]

calculate energy of state

Parameters

state (list of int) – list of SPIN or BINARY

Returns

energy of state

Return type

float

openjij.model.king_graph module

openjij.model.king_graph.KingGraph(linear=None, quadratic=None, offset=0.0, king_graph=None, var_type=<Vartype.SPIN: frozenset({1, -1})>, machine_type='')[source]

generate KingGraph model.

Parameters
  • linear (dict) – linear biases

  • quadratic (dict) – quadratic biases

  • offset (float) – offset

  • king_graph

    represents ising or QUBO interaction. Each spins are decided by 2-d corrdinate x, y.

    • Quadratic term: [x1, y1, x2, y2, value]

    • Linear term: [x1, y1, x1, y1, value]

  • var_type – ‘SPIN’ or ‘BINARY’

  • machine_type (str) – choose ‘ASIC’ or ‘FPGA’

Returns

generated KingGraphModel

Examples

The following code shows intialization of KingGraph:

>>> h = {}
>>> J = {(0, 1): -1.0, (1, 2): -3.0}
>>> king_graph = oj.KingGraph(machine_type="ASIC", linear=h, quadratic=J)

You can initialize it from king_interaction:

>>> king_interaction = [[0, 0, 1, 0, -1.0], [1, 0, 2, 0, -3.0]]
>>> king_graph = oj.KingGraph(machine_type="ASIC", king_graph=king_interaction)
openjij.model.king_graph.make_KingGraph(linear=None, quadratic=None, king_graph=None)[source]

KingGraph factory :returns: generated KingGraph class

openjij.model.king_graph.make_KingGraph_from_JSON(obj)[source]

KingGraph factory for JSON :param obj: JSON object :type obj: dict

Returns

generated KingGraph class

openjij.model.model module

This module defines the BinaryQuadraticModel with the Hamiltonian,
\[H = \sum_{i\neq j} J_{ij}\sigma_i \sigma_j + \sum_{i} h_{i}\sigma_i,\]
in an Ising form and
\[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.
openjij.model.model.BinaryQuadraticModel(linear: dict, quadratic: dict, offset: float = 0.0, var_type=<Vartype.SPIN: frozenset({1, -1})>, gpu: bool = False, **kwargs)[source]

generate BinaryQuadraticModel object.

openjij.model.model.var_type

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

represents adjacency

Type

dict

openjij.model.model.indices

labels of each variables sorted by results variables.

Type

list

openjij.model.model.offset

represents constant energy term when convert to SPIN from BINARY

Type

float

Parameters
  • linear (dict) – linear biases

  • quadratic (dict) – quadratic biases

  • offset (float) – offset

  • var_type (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.make_BinaryQuadraticModel(linear: dict, quadratic: dict)[source]

BinaryQuadraticModel factory.

Returns

generated BinaryQuadraticModel class

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

make BinaryQuadraticModel from JSON.

Returns

corresponding BinaryQuadraticModel type

Module contents