Skip to content

Commit

Permalink
Revert "new passive circuit compiler (#600)"
Browse files Browse the repository at this point in the history
This reverts commit b4d9153.
  • Loading branch information
jakeffbulmer authored Jun 28, 2021
1 parent b4d9153 commit 3244f30
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 563 deletions.
20 changes: 11 additions & 9 deletions strawberryfields/backends/gaussianbackend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@
"""Gaussian backend"""
import warnings

from numpy import empty, concatenate, array, identity, sqrt, vstack, zeros_like, allclose, ix_
from numpy import (
empty,
concatenate,
array,
identity,
sqrt,
vstack,
zeros_like,
allclose,
ix_,
)
from thewalrus.samples import hafnian_sample_state, torontonian_sample_state
from thewalrus.symplectic import xxpp_to_xpxp

Expand Down Expand Up @@ -198,14 +208,6 @@ def is_vacuum(self, tol=0.0, **kwargs):
def loss(self, T, mode):
self.circuit.loss(T, mode)

def passive(self, T, *modes):
"""
linear optical passive transformations
"""
T_expand = identity(self.circuit.nlen, dtype=T.dtype)
T_expand[ix_(modes, modes)] = T
self.circuit.passive(T_expand)

def thermal_loss(self, T, nbar, mode):
self.circuit.thermal_loss(T, nbar, mode)

Expand Down
10 changes: 3 additions & 7 deletions strawberryfields/backends/gaussianbackend/gaussiancircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,6 @@ def post_select_heterodyne(self, n, alpha_val):

def apply_u(self, U):
"""Transforms the state according to the linear optical unitary that maps a[i] \to U[i, j]^*a[j]"""
self.mean = U @ self.mean
self.nmat = U.conj() @ self.nmat @ U.T
self.mmat = U @ self.mmat @ U.T

def passive(self, T):
"""Transforms the state according to the arbitrary linear transformation that maps a[i] \to T[i, j]^*a[j]"""
self.apply_u(T)
self.mean = np.dot(np.conj(U), self.mean)
self.nmat = np.dot(np.dot(U, self.nmat), np.conj(np.transpose(U)))
self.mmat = np.dot(np.dot(np.conj(U), self.mmat), np.conj(np.transpose(U)))
14 changes: 1 addition & 13 deletions strawberryfields/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,8 @@
from .gbs import GBS
from .gaussian_unitary import GaussianUnitary
from .gaussian_merge import GaussianMerge
from .passive import Passive

compilers = (
Fock,
Gaussian,
Bosonic,
GBS,
GaussianUnitary,
Xcov,
Xstrict,
Xunitary,
GaussianMerge,
Passive,
)
compilers = (Fock, Gaussian, Bosonic, GBS, GaussianUnitary, Xcov, Xstrict, Xunitary, GaussianMerge)

compiler_db = {c.short_name: c for c in compilers}
"""dict[str, ~strawberryfields.compilers.Compiler]: Map from compiler name to the corresponding
Expand Down
1 change: 0 additions & 1 deletion strawberryfields/compilers/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Gaussian(Compiler):
# channels
"LossChannel",
"ThermalLossChannel",
"PassiveChannel",
# single mode gates
"Dgate",
"Sgate",
Expand Down
209 changes: 0 additions & 209 deletions strawberryfields/compilers/passive.py

This file was deleted.

29 changes: 2 additions & 27 deletions strawberryfields/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,9 @@ def merge(self, other):
# channels can be merged if they are the same class and share all the other parameters
if self.p[1:] == other.p[1:]:
# determine the combined first parameter

T = np.dot(other.p[0], self.p[0])
T = self.p[0] * other.p[0]
# if one, replace with the identity
T_arr = np.atleast_2d(T)
if np.allclose(T_arr, np.eye(T_arr.shape[0])):
if T == 1:
return None

# return a copy
Expand Down Expand Up @@ -1413,29 +1411,6 @@ def _apply(self, reg, backend, **kwargs):
return ancilla_val / s


class PassiveChannel(Channel):
r"""Perform an arbitrary multimode passive operation
Args:
T (array): an NxN matrix acting on a N mode state
.. details::
Acts the following transformation on the state:
.. math::
a^{\dagger}_i \to \sum_j T_{ij} a^{\dagger}j
"""

def __init__(self, T):
super().__init__([T])
self.ns = T.shape[0]

def _apply(self, reg, backend, **kwargs):
p = par_evaluate(self.p)
backend.passive(p[0], *reg)


# ====================================================================
# Unitary gates
# ====================================================================
Expand Down
Loading

0 comments on commit 3244f30

Please sign in to comment.