Skip to content

Commit

Permalink
Updates docstring and simplifies Williamson (#380)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Quesada <[email protected]>
  • Loading branch information
nquesada and Nicolas Quesada authored Jan 24, 2024
1 parent 0b1af63 commit 6247fc8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Improvements

* Further simplifies the implementation of `decompositions.williamson` and corrects its docstring [(#380)](https://github.com/XanaduAI/thewalrus/pull/380).

### Bug fixes

### Documentation
Expand All @@ -14,6 +16,8 @@

This release contains contributions from (in alphabetical order):

Nicolas Quesada

---

# Release 0.21.0
Expand Down
11 changes: 6 additions & 5 deletions thewalrus/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def williamson(V, rtol=1e-05, atol=1e-08):
Returns:
tuple[array,array]: ``(Db, S)`` where ``Db`` is a diagonal matrix
and ``S`` is a symplectic matrix such that :math:`V = S^T Db S`
and ``S`` is a symplectic matrix such that :math:`V = S Db S^T`
"""
(n, m) = V.shape

Expand All @@ -73,7 +73,8 @@ def williamson(V, rtol=1e-05, atol=1e-08):
if not np.all(vals > 0):
raise ValueError("Input matrix is not positive definite")

Mm12 = sqrtm(np.linalg.inv(V)).real
M12 = np.real_if_close(sqrtm(V))
Mm12 = np.linalg.inv(M12)
r1 = Mm12 @ omega @ Mm12
s1, K = schur(r1)
# In what follows a permutation matrix perm1 is constructed so that the Schur matrix has
Expand All @@ -92,9 +93,9 @@ def williamson(V, rtol=1e-05, atol=1e-08):

dd = np.array([1 / s1t[2 * i, 2 * i + 1] for i in range(n)])
dd = np.concatenate([dd, dd])
ddsqrt = np.sqrt(dd)
S = Mm12 @ Ktt * ddsqrt
return np.diag(dd), np.linalg.inv(S).T
ddsqrt = 1 / np.sqrt(dd)
S = M12 @ Ktt * ddsqrt
return np.diag(dd), S


def symplectic_eigenvals(cov):
Expand Down

0 comments on commit 6247fc8

Please sign in to comment.