How to use the thewalrus.quantum.find_scaling_adjacency_matrix function in thewalrus

To help you get started, we’ve selected a few thewalrus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github XanaduAI / pennylane-sf / pennylane_sf / vgbs.py View on Github external
def apply(self, operation, wires, par):
        """TODO
        """
        self.weights, A, n_mean = par
        A = A * rescale(A, n_mean)
        W = np.diag(np.sqrt(self.weights))
        self.WAW = W @ A @ W

        singular_values = np.linalg.svd(self.WAW, compute_uv=False)
        n_mean_WAW = np.sum(singular_values ** 2 / (1 - singular_values ** 2))

        op = self._operation_map[operation](self.WAW, mean_photon_per_mode=n_mean_WAW / len(A))
        op | [self.q[i] for i in wires] #pylint: disable=pointless-statement

        if not self.analytic:
            MeasureFock() | [self.q[i] for i in wires]
github XanaduAI / strawberryfields / strawberryfields / decompositions.py View on Github external
mean_photon_per_mode (float): guarantees that the mean photon number in the pure Gaussian state
            representing the graph satisfies  :math:`\frac{1}{N}\sum_{i=1}^N sinh(r_{i})^2 ==` :code:``mean_photon``
        rtol (float): relative tolerance used when checking if the input matrix is symmetric
        atol (float): absolute tolerance used when checking if the input matrix is symmetric

    Returns:
        tuple[array, array, array]: squeezing parameters of the input
        state to the interferometer, and the unitaries matrix representing the interferometer
    """
    (m, n) = A.shape

    if m != n:
        raise ValueError("The matrix is not square.")

    B = np.block([[0 * A, A], [A.T, 0 * A]])
    scale = find_scaling_adjacency_matrix(B, 2 * n * mean_photon_per_mode)
    A = scale * A

    if np.allclose(A, A.T, rtol=rtol, atol=atol):
        s, u = takagi(A, tol=atol)
        v = u
    else:
        u, s, v = np.linalg.svd(A)
        v = v.T

    vals = -np.arctanh(s)
    return vals, u, v
github XanaduAI / strawberryfields / strawberryfields / decompositions.py View on Github external
Returns:
        tuple[array, array]: squeezing parameters of the input
        state to the interferometer, and the unitary matrix representing the interferometer
    """
    (m, n) = A.shape

    if m != n:
        raise ValueError("The matrix is not square.")

    if not np.allclose(A, np.transpose(A), rtol=rtol, atol=atol):
        raise ValueError("The matrix is not symmetric.")

    if make_traceless:
        A = A - np.trace(A) * np.identity(n) / n

    scale = find_scaling_adjacency_matrix(A, n * mean_photon_per_mode)
    A = scale * A
    s, U = takagi(A, tol=atol)
    vals = -np.arctanh(s)
    return vals, U