Esempio n. 1
0
def beamsplitter(theta, phi, trunc):
    r"""The beamsplitter :math:`B(\theta, \phi)`.

    Uses the `beamsplitter operation from The Walrus`_ to calculate the beamsplitter.

    .. _`beamsplitter operation from The Walrus`: https://the-walrus.readthedocs.io/en/latest/code/api/thewalrus.fock_gradients.beamsplitter.html
    """
    BS_tw = beamsplitter_tw(theta, phi, cutoff=trunc)

    # Transpose needed because of different conventions in SF and The Walrus.
    return BS_tw.transpose((0, 2, 1, 3))
Esempio n. 2
0
def single_beamsplitter_matrix(theta, phi, cutoff, dtype=def_type.as_numpy_dtype):
    """creates a single mode beamsplitter matrix"""
    theta = theta.numpy()
    phi = phi.numpy()

    gate = beamsplitter_tw(theta, phi, cutoff, dtype)
    gate = np.transpose(gate, [0, 2, 1, 3])

    def grad(dy):
        Dtheta, Dphi = grad_beamsplitter_tw(np.transpose(gate, [0, 2, 1, 3]), theta, phi)
        Dtheta = np.transpose(Dtheta, [0, 2, 1, 3])
        Dphi = np.transpose(Dphi, [0, 2, 1, 3])
        grad_theta = tf.math.real(tf.reduce_sum(dy * tf.math.conj(Dtheta)))
        grad_phi = tf.math.real(tf.reduce_sum(dy * tf.math.conj(Dphi)))
        return grad_theta, grad_phi, None

    return gate, grad