コード例 #1
0
    def test_merge(self, hbar, tol):
        """Test that two covariances matrices overwrite each other on merge"""
        n = 3
        V1 = random_covariance(n, pure=False, hbar=hbar)
        V2 = random_covariance(n, pure=True, hbar=hbar)

        cov1 = ops.Gaussian(V1, hbar=hbar)
        cov2 = ops.Gaussian(V2, hbar=hbar)

        # applying a second covariance matrix replaces the first
        assert cov1.merge(cov2) == cov2

        # the same is true of state preparations
        assert ops.Squeezed(2).merge(cov2) == cov2
コード例 #2
0
    def test_interferometer(self, setup_eng, tol):
        """Test applying an interferometer"""
        eng, q = setup_eng(3)

        with eng:
            ops.All(ops.Squeezed(0.5)) | q
            init = eng.run()
            ops.Interferometer(u1) | q

        state = eng.run()
        O = np.vstack(
            [np.hstack([u1.real, -u1.imag]),
             np.hstack([u1.imag, u1.real])])
        assert np.allclose(state.cov(), O @ init.cov() @ O.T, atol=tol)
コード例 #3
0
    def test_interferometer(self, setup_eng, tol):
        """Test applying an interferometer"""
        eng, p1 = setup_eng(3)

        with p1.context as q:
            ops.All(ops.Squeezed(0.5)) | q
        init = eng.run(p1).state

        p2 = sf.Program(p1)
        with p2.context as q:
            ops.Interferometer(u1) | q

        state = eng.run(p2).state
        O = np.vstack([np.hstack([u1.real, -u1.imag]), np.hstack([u1.imag, u1.real])])
        assert np.allclose(state.cov(), O @ init.cov() @ O.T, atol=tol)
コード例 #4
0
    def test_passive_gaussian_transform(self, setup_eng, tol):
        """Test applying a passive Gaussian symplectic transform,
        which is simply an interferometer"""
        eng, q = setup_eng(3)
        O = np.vstack(
            [np.hstack([u1.real, -u1.imag]),
             np.hstack([u1.imag, u1.real])])

        with eng:
            ops.All(ops.Squeezed(0.5)) | q
            init = eng.run()
            ops.GaussianTransform(O) | q

        state = eng.run()
        assert np.allclose(state.cov(), O @ init.cov() @ O.T, atol=tol)
コード例 #5
0
    def test_merge(self, hbar, tol):
        """Test that merging two Preparations only keeps the latter one."""
        n = 3
        V1 = random_covariance(n, pure=False, hbar=hbar)
        V2 = random_covariance(n, pure=True, hbar=hbar)
        r1 = np.random.randn(2 * n)
        r2 = np.random.randn(2 * n)

        G1 = ops.Gaussian(V1, r1)
        G2 = ops.Gaussian(V2, r2)

        # applying a second state preparation replaces the first
        assert G1.merge(G2) is G2

        # the same is true of all state preparations
        S = ops.Squeezed(2)
        assert S.merge(G2) is G2
        assert G2.merge(S) is S
コード例 #6
0
def prog():
    prog = Program(4, name="test_program")

    with prog.context as q:
        # state preparation
        ops.Vac | q[1]
        ops.Squeezed(0.12) | q[2]

        # one mode gates
        ops.Sgate(1) | q[0]
        ops.Dgate(np.abs(0.54 + 0.5j), np.angle(0.54 + 0.5j)) | q[1]

        # two mode gates
        ops.S2gate(0.543, -0.12) | (q[0], q[3])

        # decomposition
        ops.Interferometer(U) | q

        # measurement
        ops.MeasureX | q[0]
        ops.MeasureHomodyne(0.43, select=0.32) | q[2]
        ops.MeasureHomodyne(phi=0.43, select=0.32) | q[2]

    return prog