Пример #1
0
    def test_loss(self, monkeypatch):
        """Test if function correctly creates the SF program for lossy GBS."""
        graph = nx.complete_graph(5)
        mock_eng_run = mock.MagicMock()

        with monkeypatch.context() as m:
            m.setattr(sf.LocalEngine, "run", mock_eng_run)
            similarity._get_state(graph, loss=0.5)
            p_func = mock_eng_run.call_args[0][0]

        assert isinstance(p_func.circuit[1].op, sf.ops.LossChannel)
Пример #2
0
    def test_no_loss(self, monkeypatch):
        """Test if function correctly creates the SF program for GBS without loss."""
        graph = nx.complete_graph(5)
        mock_eng_run = mock.MagicMock()

        with monkeypatch.context() as m:
            m.setattr(sf.LocalEngine, "run", mock_eng_run)
            similarity._get_state(graph)
            p_func = mock_eng_run.call_args[0][0]

        assert not all(
            [isinstance(op, sf.ops.LossChannel) for op in p_func.circuit])
Пример #3
0
    def test_max_loss(self):
        """Test if function samples from the vacuum when maximum loss is applied."""
        dim = 5
        graph = nx.complete_graph(dim)
        state = similarity._get_state(graph, 0, 1)
        cov = state.cov()
        disp = state.displacement()

        assert np.allclose(cov, 0.5 * state.hbar * np.eye(2 * dim))
        assert np.allclose(disp, np.zeros(dim))
Пример #4
0
    def test_known_result(self):
        """Tests if the probability for known cases is correctly
        reproduced."""
        g = nx.complete_graph(3)

        p = similarity.prob_orbit_exact(g, [1, 1], 2)
        assert np.allclose(p, 0.24221526825385403)

        s = similarity._get_state(g, 2)
        temp = s.fock_prob([1, 1, 0]) + s.fock_prob([1, 0, 1]) + s.fock_prob(
            [0, 1, 1])
        assert np.allclose(p, temp)

        assert np.allclose(similarity.prob_orbit_exact(g, [4], 1), 0)