Exemple #1
0
 def test_invalid_n_mean(self):
     """Test if function raises a ``ValueError`` when the mean photon number is specified to
     be negative."""
     g = nx.complete_graph(5)
     with pytest.raises(ValueError,
                        match="Mean photon number must be non-negative"):
         similarity.prob_orbit_exact(g, [1, 1, 1, 1], n_mean=-1)
Exemple #2
0
 def test_invalid_loss(self):
     """Test if function raises a ``ValueError`` when the loss parameter is specified outside
     of range."""
     g = nx.complete_graph(5)
     with pytest.raises(
             ValueError,
             match="Loss parameter must take a value between zero and one"):
         similarity.prob_orbit_exact(g, [1, 1, 1, 1], loss=2)
Exemple #3
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)
Exemple #4
0
 def test_known_result(self):
     """Tests if the probability for known cases is correctly
     reproduced."""
     graph = nx.complete_graph(4)
     p1 = similarity.prob_event_exact(graph, 2, 2, 1)
     p2 = similarity.prob_event_exact(graph, 2, 1, 1)
     p3 = similarity.prob_orbit_exact(graph, [1, 1], 1)
     p4 = similarity.prob_event_exact(graph, 2, 2, 4)
     assert np.allclose(p1 - p2, 0)
     assert np.allclose(p2, p3)
     assert np.allclose(p4, 0.21087781178526066)
Exemple #5
0
 def test_correct_result_returned(self, monkeypatch):
     """Tests if the call to _get_state function is performed correctly and probabilities over all
     permutations of the given orbit are summed correctly. The test monkeypatches the fock_prob
     function so that the probability is the same for each sample permutation and
     is equal to 1/8. For a 4-mode graph, [1, 1] has 6 possible permutations."""
     graph = nx.complete_graph(4)
     with monkeypatch.context() as m:
         m.setattr(
             "strawberryfields.backends.BaseGaussianState.fock_prob",
             lambda *args, **kwargs: 1 / 8,
         )
         assert similarity.prob_orbit_exact(graph, [1, 1]) == 6 / 8
Exemple #6
0
 def test_calls_exact_for_zero_samples(self):
     """Test if function calls the exact function for zero samples"""
     g = nx.complete_graph(5)
     assert similarity.feature_vector_orbits(
         g, [[1, 1]], samples=0) == similarity.prob_orbit_exact(g, [1, 1])
Exemple #7
0
 def test_odd_photon_numbers(self, k):
     """Test if function returns zero probability for odd number of total photons."""
     graph = nx.complete_graph(10)
     assert similarity.prob_orbit_exact(graph, [k]) == 0.0
Exemple #8
0
 def test_prob_vacuum_orbit(self):
     """Tests if the function gives the right probability for the empty orbit when the GBS
     device has been configured to have zero mean photon number."""
     graph = nx.complete_graph(5)
     assert similarity.prob_orbit_exact(graph, [], 0) == 1.0