@@ -256,6 +256,39 @@ def check_canonical_form(self):
256256 # form.append('B')
257257 # print("The MPS has the form: ", form)
258258
259+ def convert_to_vector (self ) -> np .ndarray :
260+ """
261+ Converts the MPS to a full state vector representation.
262+
263+ Returns:
264+ A one-dimensional NumPy array of length \(\prod_{\ell=1}^L d_\ell\)
265+ representing the state vector.
266+ """
267+ # Start with the first tensor.
268+ # Assume each tensor has shape (d, chi_left, chi_right) with chi_left=1 for the first tensor.
269+ vec = self .tensors [0 ] # shape: (d_1, 1, chi_1)
270+
271+ # Contract sequentially with the remaining tensors.
272+ for i in range (1 , self .length ):
273+ # Contract the last bond of vec with the middle index (left bond) of the next tensor.
274+ vec = np .tensordot (vec , self .tensors [i ], axes = ([- 1 ], [1 ]))
275+ # After tensordot, if vec had shape (..., chi_i) and the new tensor has shape (d_{i+1}, chi_i, chi_{i+1}),
276+ # then vec now has shape (..., d_{i+1}, chi_{i+1}).
277+ # Reshape to merge all physical indices into one index.
278+ new_shape = (- 1 , vec .shape [- 1 ])
279+ vec = np .reshape (vec , new_shape )
280+
281+ # At the end, the final bond dimension should be 1.
282+ vec = np .squeeze (vec , axis = - 1 )
283+ # Flatten the resulting multi-index into a one-dimensional state vector.
284+ vec = vec .flatten ()
285+ return vec
286+
287+
288+
289+
290+
291+
259292
260293# Convention (sigma, sigma', chi_l, chi_l+1)
261294class MPO :
0 commit comments