amplify.IsingIntMatrix

class IsingIntMatrix

Upper triangular matrix representation of the Ising model with integer coefficients.

The Ising model will be the form of \(H = s^{\mathrm{T}} J s - \mathrm{Tr}J + s^{\mathrm{T}} \cdot \operatorname{diag} J\), where \(s\) is a vector of variables and \(J\) is a square matrix.

This class denotes the upper triangular matrix representation of \(J\).

注釈

In the descriptions of class methods, \(J\) and \(s\) are the matrix and the vector this class represents, respectively.

注釈

The following operators are defined for the class.
  • Indexing: a[slices] (__getitem__(), __setitem__())

  • Equality: a == b (__eq__())

  • Inequality: a != b (__ne__())

  • Addition: a + b (__add__(), __radd__(), __iadd__())

  • Subtraction: a - b (__sub__(), __rsub__(), __isub__())

  • Multiplication: a * b (__mul__(), __rmul__(), __imul__())

  • Division: a / b (__truediv__(), __rtruediv__(), __itruediv__())

  • Floor Division: a // b (__floordiv__(), __rfloordiv__(), __ifloordiv__())

__init__(size)

Returns a zero-matirx with specified size.

パラメータ:

size (int) -- Size of the matrix.

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(3)
>>> m[0, 1] = 1
>>> m[0, 2] = 2
>>> m[1, 2] = 3
>>> m
[[0, 1, 2],
 [0, 0, 3],
 [0, 0, 0]]

Methods

__init__(size)

Returns a zero-matirx with specified size.

evaluate(self, object)

Evaluates the matrix with array s.

resize(self, size)

Resizes the matrix.

size(self)

Returns the matrix size.

to_BinaryMatrix(self[, ascending])

Converts the matrix to BinaryIntMatrix.

to_IsingMatrix(self[, ascending])

Converts the matrix to IsingIntMatrix.

to_Poly(self)

Converts the matrix to IsingIntPoly.

to_numpy(self)

no docstring

evaluate(self, object)

Evaluates the matrix with array s.

パラメータ:

object -- array-like. The size of arary object should be equal to the matrix size.

戻り値:

\(s^{\mathrm{T}} J s - \mathrm{Tr}J + s^{\mathrm{T}} \cdot \operatorname{diag} J\)

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(3)
>>> m[0, 1] = 1
>>> m[0, 2] = 2
>>> m[1, 2] = 3
>>> m
[[0, 1, 2],
 [0, 0, 3],
 [0, 0, 0]]
>>> m.evaluate([0, 1, 1])
3
resize(self: amplify.IsingIntMatrix, size: int) None

Resizes the matrix.

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(2)
>>> m[0, 1] = 1
>>> m
[[0, 1],
 [0, 0]]
>>> m.resize(3)
>>> m
[[0, 1, 0],
 [0, 0, 0],
 [0, 0, 0]]
size(self: amplify.IsingIntMatrix) int

Returns the matrix size.

戻り値:

size of the matrix

戻り値の型:

int

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(3)
>>> m.size()
3
to_BinaryMatrix(self: amplify.IsingIntMatrix, ascending: bool = True) Tuple[amplify.BinaryIntMatrix, int]

Converts the matrix to BinaryIntMatrix.

By this function, the Ising model formulation \(s^{\mathrm{T}} J s - \mathrm{Tr}J + s^{\mathrm{T}} \cdot \operatorname{diag} J\) would be transformed to the QUBO formulation \(q^T Q q\), where \(q\) is a vector of variables and \(Q\) is an upper triangular square matrix. The conversion is along \(s = 2q - \left\{1 \right\}\).

This function returns the pair of the converted BinaryIntMatrix \(Q\) and the constant term \(c\) in the converted QUBO formulation.

戻り値:

\((Q, c)\)

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(3)
>>> m[0, 1] = 1
>>> m[0, 2] = 2
>>> m[1, 2] = 3
>>> m
[[0, 1, 2],
 [0, 0, 3],
 [0, 0, 0]]
>>> m.to_BinaryMatrix()
([[-6, 4, 8],
 [0, -8, 12],
 [0, 0, -10]], 6)
to_IsingMatrix(self: amplify.IsingIntMatrix, ascending: bool = True) Tuple[amplify.IsingIntMatrix, int]

Converts the matrix to IsingIntMatrix.

This function returns the pair of the converted IsingIntMatrix \(J\) and the constant term \(c\) in the converted Ising model formulation.

戻り値:

\((J, c)\)

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(3)
>>> m[0, 1] = 1
>>> m[0, 2] = 2
>>> m[1, 2] = 3
>>> m
[[0, 1, 2],
 [0, 0, 3],
 [0, 0, 0]]
>>> m.to_IsingMatrix()
([[0, 1, 2],
 [0, 0, 3],
 [0, 0, 0]], 0)
to_Poly(self: amplify.IsingIntMatrix) amplify.IsingIntPoly

Converts the matrix to IsingIntPoly.

戻り値:

polynomial expression of the matrix

戻り値の型:

IsingIntPoly

Example

>>> from amplify import IsingIntMatrix
>>> m = IsingIntMatrix(3)
>>> m[0, 1] = 1
>>> m[0, 2] = 2
>>> m[1, 2] = 3
>>> m
[[0, 1, 2],
 [0, 0, 3],
 [0, 0, 0]]
>>> m.to_Poly()
s_0 s_1 + 2 s_0 s_2 + 3 s_1 s_2
to_numpy(self: amplify.IsingIntMatrix) numpy.ndarray[numpy.float64]

no docstring