openjij.model package¶
Submodules¶
openjij.model.chimera_model module¶
- openjij.model.chimera_model.ChimeraModel(linear: Optional[dict] = None, quadratic: Optional[dict] = None, offset: float = 0.0, vartype=<Vartype.SPIN: frozenset({1, -1})>, unit_num_L: Optional[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
vartype – 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.king_graph module¶
- openjij.model.king_graph.KingGraph(linear=None, quadratic=None, offset=0.0, king_graph=None, vartype=<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]
vartype – ‘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.model module¶
- 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 constant energy term when convert to SPIN from BINARY
- Type
int
- openjij.model.model.variables¶
represents constant energy term when convert to SPIN from BINARY
- 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_numpy_matrix(mat, variables: Optional[list] = None, offset=0.0, vartype='BINARY', **kwargs)[source]¶