MatrixProductState
- class mpsprep.mpsstatepreparation.MatrixProductState(tensor_list)[source]
Bases:
objectA class for representing a matrix product state.
- __init__(tensor_list)[source]
Initializes a Matrix Product State. Given a list of
LocalMPSTensorrepresenting \([G[j_0], G[j_1], ..., G[j_N-1]]\), this initializes the matrix product state \(|MPS> = \sum_{j_0 ... j_N-1} G[j_0] G[j_1] ... G[j_N-1] x |j_N-1, ...,j_0 >\).Note that \(G[j_0] G[j_1] ... G[j_N-1]\) are matrix products, and the order is therefore important.
- Parameters
- tensor_listlist of
LocalMPSTensor List of tensors that describes the desired MPS state.
- tensor_listlist of
Methods
__init__(tensor_list)Initializes a Matrix Product State.
contract_matrices(matrix_list)Contract a list of matrices.
Return the amplitudes of all states in the MPS.
get_amplitude(state)Return the amplitude of the state in the MPS.
plot_singular_values(s_vals[, ...])Plot the singular values of an MPS.
right_normalize([order])Right normalize the MPS.
svd_decompose(A[, truncate_ranks])Decomposes the tensor A into a list of
LocalMPSTensorusing the TT-SVD algorithm.Attributes
The computational basis states of the MPS.
The number of qubits in the MPS.
- property computational_states
The computational basis states of the MPS.
- Type
numpy.ndarray
- static contract_matrices(matrix_list)[source]
Contract a list of matrices.
- Parameters
- matrix_listlist of np.ndarray
List of matrices to be contracted.
- Returns
- matrixnp.ndarray
The contracted matrix.
- get_all_amplitudes()[source]
Return the amplitudes of all states in the MPS.
- Returns
- all_amplitudesnumpy.ndarray
The amplitudes of all states in the MPS.
- get_amplitude(state)[source]
Return the amplitude of the state in the MPS.
- Parameters
- stateint
The computational basis state of the MPS.
- Returns
- state_amplitudefloat
The amplitude of the state in the MPS.
- property num_qubits
The number of qubits in the MPS.
- Type
int
- static plot_singular_values(s_vals, subplot_kwargs=None, yscale='log', ylabel='Singular values', bar_kwargs=None)[source]
Plot the singular values of an MPS. Does not explicitly return a Matplotlib figure or plot object.
- Parameters
- s_valslist of np.ndarray
The singular values of the MPS SVD.
- subplot_kwargsdict, optional
Keyword arguments for the subplot. Default is None.
- yscalestr, optional
The scale of the y-axis. Either “log” or “linear”. Default is “log”.
- ylabelstr, optional
The label of the y-axis. Default is “Singular values”.
- bar_kwargsdict, optional
Keyword arguments for the bar plot. Default is None.
- Returns
- None
- right_normalize(order='F')[source]
Right normalize the MPS.
- Parameters
- order{“F”, “C”}, optional
The layout of the matrix in memory. Default is “F”.
- Returns
- None
- static svd_decompose(A, truncate_ranks=None)[source]
Decomposes the tensor A into a list of
LocalMPSTensorusing the TT-SVD algorithm. Typically, A gives the expansion coefficients of an MPS state as follows: \(|MPS> = \sum_{j_0 ... j_N-1} A(j_0, ..., j_N-1) |j_N-1, ... ,j_0>\).Note that \(j_0\) is assumed to be in the first dimension/axis of A.
- Parameters
- Anp.ndarray of shape (2**N) for integer N
The tensor to decompose.
- truncate_rankslist of int, optional
The number of singular values to preserve at each SVD step. This defines the aggressiveness of the approximation scheme. If None, all singular values are preserved. Default is None.
- Returns
- MPS_tensorsList of
LocalMPSTensor Desired MPS tensors.
- singular_valuesList of np.ndarray
Returns the singular values obtained at each stage of the decomposition.
- MPS_tensorsList of