Skip to content

Commit

Permalink
Refuse to normalize in place a zero MPS
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjosegarciaripoll committed Mar 29, 2024
1 parent fe00716 commit 4e7dc9a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/seemps/state/canonical_mps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations
import warnings
import numpy as np
from typing import Optional, Sequence, Iterable
from ..typing import Vector, Tensor3, Tensor4, VectorLike, Environment
Expand Down Expand Up @@ -394,7 +395,11 @@ def normalize_inplace(self) -> CanonicalMPS:
"""Normalize the state by updating the central tensor."""
n = self.center
A = self._data[n]
self._data[n] = A / np.linalg.norm(A)
N = np.linalg.norm(A)
if N == 0:
warnings.warn("Refusing to normalize zero vector")
else:
self._data[n] = A / N
return self

def __copy__(self):
Expand Down

0 comments on commit 4e7dc9a

Please sign in to comment.