def norm(mpa):
"""Computes the norm (Hilbert space norm for MPS, Frobenius norm for MPO)
of the matrix product operator. In contrast to ``mparray.inner``, this can
take advantage of the canonicalization
WARNING This also changes the MPA inplace by normalizing.
:param mpa: MPArray
:returns: l2-norm of that array
"""
mpa.canonicalize()
current_lcanon, current_rcanon = mpa.canonical_form
if current_rcanon == 1:
return np.linalg.norm(mpa.lt[0])
elif current_lcanon == len(mpa) - 1:
return np.linalg.norm(mpa.lt[-1])
else:
raise ValueError("Normalization error in MPArray.norm")
评论列表
文章目录