amplify.IsingMatrix

class IsingMatrix

Upper triangular matrix representation of the Ising model with real 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 IsingMatrix
>>> m = IsingMatrix(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 BinaryMatrix.

to_IsingMatrix(self[, ascending])

Converts the matrix to IsingMatrix.

to_Poly(self)

Converts the matrix to IsingPoly.

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 IsingMatrix
>>> m = IsingMatrix(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.0
resize(self: amplify.IsingMatrix, size: int) None

Resizes the matrix.

Example

>>> from amplify import IsingMatrix
>>> m = IsingMatrix(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.IsingMatrix) int

Returns the matrix size.

戻り値:

size of the matrix

戻り値の型:

int

Example

>>> from amplify import IsingMatrix
>>> m = IsingMatrix(3)
>>> m.size()
3
to_BinaryMatrix(self: amplify.IsingMatrix, ascending: bool = True) Tuple[amplify.BinaryMatrix, float]

Converts the matrix to BinaryMatrix.

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 BinaryMatrix \(Q\) and the constant term \(c\) in the converted QUBO formulation.

戻り値:

\((Q, c)\)

Example

>>> from amplify import IsingMatrix
>>> m = IsingMatrix(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.0)
to_IsingMatrix(self: amplify.IsingMatrix, ascending: bool = True) Tuple[amplify.IsingMatrix, float]

Converts the matrix to IsingMatrix.

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

戻り値:

\((J, c)\)

Example

>>> from amplify import IsingMatrix
>>> m = IsingMatrix(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.0)
to_Poly(self: amplify.IsingMatrix) amplify.IsingPoly

Converts the matrix to IsingPoly.

戻り値:

polynomial expression of the matrix

戻り値の型:

IsingPoly

Example

>>> from amplify import IsingMatrix
>>> m = IsingMatrix(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.000000 s_0 s_2 + 3.000000 s_1 s_2
to_numpy(self: amplify.IsingMatrix) numpy.ndarray[numpy.float64]

no docstring