Skip to content

Commit

Permalink
More cleaning shared ops (#560)
Browse files Browse the repository at this point in the history
* removes unused variables in test_tdmprogram

* First version
  • Loading branch information
nquesada committed Mar 19, 2021
1 parent 1cced3f commit de44467
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 56 deletions.
30 changes: 0 additions & 30 deletions strawberryfields/backends/shared_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,6 @@
# ================================+


@functools.lru_cache()
def rotation_matrix(phi):
r"""Rotation matrix.
Args:
phi (float): rotation angle
Returns:
array: :math:`2\times 2` rotation matrix
"""
return np.array([[np.cos(phi), -np.sin(phi)], [np.sin(phi), np.cos(phi)]])


@functools.lru_cache()
def sympmat(n):
r"""Returns the symplectic matrix of order n
Args:
n (int): order
Returns:
array: symplectic matrix
"""
idm = np.identity(n)
omega = np.concatenate(
(np.concatenate((0 * idm, idm), axis=1), np.concatenate((-idm, 0 * idm), axis=1)), axis=0
)
return omega


@functools.lru_cache()
def changebasis(n):
r"""Change of basis matrix between the two Gaussian representation orderings.
Expand Down
3 changes: 2 additions & 1 deletion strawberryfields/backends/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
from scipy.special import factorial
from scipy.integrate import simps

from thewalrus.symplectic import rotation as _R

import thewalrus.quantum as twq

import strawberryfields as sf

from .shared_ops import rotation_matrix as _R
from .shared_ops import changebasis

indices = string.ascii_lowercase
Expand Down
3 changes: 2 additions & 1 deletion strawberryfields/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
import numpy as np
from scipy.linalg import block_diag, sqrtm, polar, schur
from thewalrus.quantum import adj_scaling
from thewalrus.symplectic import sympmat

from .backends.shared_ops import sympmat, changebasis
from .backends.shared_ops import changebasis


def takagi(N, tol=1e-13, rounding=13):
Expand Down
4 changes: 3 additions & 1 deletion tests/backend/test_states_polyquad.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
from scipy.integrate import simps
from scipy.linalg import block_diag

from thewalrus.symplectic import rotation as R

from strawberryfields import backends
from strawberryfields import utils
from strawberryfields.backends.shared_ops import rotation_matrix as R, changebasis
from strawberryfields.backends.shared_ops import changebasis

# some tests require a higher cutoff for accuracy
CUTOFF = 12
Expand Down
3 changes: 2 additions & 1 deletion tests/backend/test_states_wigner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import numpy as np
from scipy.stats import multivariate_normal

from thewalrus.symplectic import rotation as rotm

from strawberryfields import backends
from strawberryfields import utils
from strawberryfields.backends.shared_ops import rotation_matrix as rotm


A = 0.3 + 0.1j
Expand Down
18 changes: 0 additions & 18 deletions tests/frontend/test_shared_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@
class TestPhaseSpaceFunctions:
"""Tests for the shared phase space operations"""

@pytest.mark.parametrize("phi", np.linspace(0, np.pi, 4))
def test_rotation_matrix(self, phi):
"""Test the function rotation_matrix"""
res = so.rotation_matrix(phi)
expected = np.array([[np.cos(phi), -np.sin(phi)], [np.sin(phi), np.cos(phi)]])

assert np.all(res == expected)

@pytest.mark.parametrize("n", [1, 2, 4])
def test_sympmat(self, n):
"""Test the symplectic matrix function"""
res = so.sympmat(n)
O = np.zeros([n, n])
I = np.identity(n)
expected = np.block([[O, I], [-I, O]])

assert np.all(res == expected)

def test_means_changebasis(self):
"""Test the change of basis function applied to vectors. This function
converts from xp to symmetric ordering, and vice versa."""
Expand Down
7 changes: 3 additions & 4 deletions tests/integration/test_decompositions_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import numpy as np
from scipy.linalg import qr, block_diag

from thewalrus.symplectic import rotation as rot

import strawberryfields as sf
from strawberryfields import decompositions as dec
from strawberryfields.utils import (
Expand All @@ -26,10 +28,7 @@
squeezed_state,
)
from strawberryfields import ops
from strawberryfields.backends.shared_ops import (
changebasis,
rotation_matrix as rot,
)
from strawberryfields.backends.shared_ops import changebasis

from strawberryfields.utils import random_interferometer as haar_measure
# make the test file deterministic
Expand Down

0 comments on commit de44467

Please sign in to comment.