Manual MPS implementation¶
-
manual.
apply_one_qubit_gate
(gate, pos, state)[source]¶ Applies a one qubit gate gate to the site pos of the MPS state.
- Parameters
gate_matrix (numpy array shape (2, 2)) -- Matrix representation of the quantum gate
pos (int) -- Position of the qubit where to apply gate_matrix.
state (list of N ndarrays) -- Matrix product state to which we want to apply the gate
- Returns
state -- Matrix product state where we have applied the gate
- Return type
list of N ndarrays
-
manual.
apply_two_qubit_gate
(gate_matrix, pos, state, chi=2)[source]¶ Apply a 2-qubit gate specified by the unitary matrix gate_matrix to qubits at sites (pos, pos*+1) for a MPS *state and contract the resulting tensor back with maximum bond dimension chi. chi cannot be less than the maximum bond dimension of the initial mps state.
- Parameters
gate_matrix (numpy array shape (4, 4)) -- Matrix representation of the quantum gate
pos (int) -- Position of the first qubit where to apply gate_matrix. It will be applied to (pos, *pos*+1).
state (list of N ndarrays) -- Matrix product state to which we want to apply the gate
chi (int, optional) -- Bond dimension of the state after the qubit application. Default to 2
- Returns
state -- Matrix product state where we have applied the gate
- Return type
MPS
-
manual.
apply_two_qubit_gate_full
(gate_matrix, pos, state)[source]¶ Apply a 2-qubit gate specified by the unitary matrix gate_matrix to qubits at sites (pos, pos*+1) for a MPS *state.
- Parameters
gate_matrix (numpy array shape (4, 4)) -- Matrix representation of the quantum gate
pos (int) -- Position of the first qubit where to apply gate_matrix. It will be applied to (pos, *pos*+1).
state (list of N ndarrays) -- Matrix product state to which we want to apply the gate
- Returns
state -- Matrix product state where we have applied the gate
- Return type
list of N ndarrays
-
manual.
left_canonize
(sites)[source]¶ Apply a gauge transformation to all bonds between sites, so that all sites beside the last (rightmost one) are set to (semi)-unitary tensors.
- Parameters
sites (list of N ndarrays) -- Tensor to which we want to apply the right-canonization
- Returns
sites -- Left-canonized tensor
- Return type
list of N ndarrays
-
manual.
left_compress
(left, right)[source]¶ Perform a change of gauge in the bond between the tensors left and right, making left a (semi)-unitary tensor.
- Parameters
left (list of N ndarrays) -- left tensor
right (list of N ndarrays) -- right tensor
- Returns
(left, right) -- left is now a semi-unitary tensor
- Return type
tuple of tensors
-
manual.
max_bond_dimension
(mps)[source]¶ Return the maximum bond dimension of a mps state.
- Parameters
mps (list of N ndarrays) -- Matrix product state
- Returns
max_bond -- Maximum bond dimension of the MPS
- Return type
int
Examples
>>> from MPS_QFT.helper import to_full_MPS >>> GHZ = np.zeros(2**N) >>> GHZ[0] = 1 >>> GHZ[-1] = 1 # We created a GHZ, which max bond dim is 2. We now translate it in MPS >>> GHZ_MPS = to_full_MPS(GHZ, N) >>> max_bond_dimension(GHZ_MPS) 2
-
manual.
right_canonize
(sites)[source]¶ Apply a gauge transformation to all bonds between sites, so that all sites beside the first (leftmost one) are set to (semi)-unitary tensors.
- Parameters
sites (list of N ndarrays) -- Tensor to which we want to apply the right-canonization
- Returns
sites -- Right-canonized tensor
- Return type
list of N ndarrays
-
manual.
right_compress
(left, right)[source]¶ Perform a change of gauge in the bond between the tensors left and right, making right a (semi)-unitary tensor.
- Parameters
left (list of N ndarrays) -- left tensor
right (list of N ndarrays) -- right tensor
- Returns
(left, right) -- right is now a semi-unitary tensor
- Return type
tuple of tensors