Esempio n. 1
0
    def test_correct_vector_returned(self, monkeypatch):
        """Test if function correctly constructs the feature vector. The ``prob_orbit_exact``
        and ``prob_orbit_mc`` function called within ``feature_vector_orbits`` are
        monkeypatched to return hard-coded outputs that depend only on the orbit."""

        with monkeypatch.context() as m:
            m.setattr(
                similarity,
                "prob_orbit_mc",
                lambda _graph, orbit, n_mean, samples, loss: 1.0 / sum(orbit),
            )
            graph = nx.complete_graph(8)
            assert similarity.feature_vector_orbits(graph, [[1, 1], [2, 1, 1]],
                                                    samples=1) == [
                                                        0.5,
                                                        0.25,
                                                    ]

        with monkeypatch.context() as m:
            m.setattr(
                similarity,
                "prob_orbit_exact",
                lambda _graph, orbit, n_mean, loss: 0.5 * (1.0 / sum(orbit)),
            )
            graph = nx.complete_graph(8)
            assert similarity.feature_vector_orbits(
                graph, [[1, 1], [2, 1, 1]]) == [0.25, 0.125]
Esempio n. 2
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.feature_vector_orbits(g, [[1, 1], [2]], n_mean=-1)
Esempio n. 3
0
 def test_invalid_orbits_list(self):
     """Test if function raises a ``ValueError`` when the list of orbits is empty."""
     g = nx.complete_graph(5)
     with pytest.raises(
             ValueError,
             match="List of orbits must have at least one orbit"):
         similarity.feature_vector_orbits(g, list_of_orbits=[])
Esempio n. 4
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.feature_vector_orbits(g, [[1, 1], [2]], loss=2)
Esempio n. 5
0
 def test_bad_orbit_photon_numbers(self):
     """Test if function raises a ``ValueError`` when input is an orbit with numbers
     below zero."""
     graph = nx.complete_graph(5)
     with pytest.raises(
             ValueError,
             match="Cannot request orbits with photon number below zero"):
         similarity.feature_vector_orbits(graph, [[-1, 1]])
Esempio n. 6
0
 def test_known_result(self):
     """Tests if the probability for known cases is correctly
     reproduced."""
     graph = nx.complete_graph(4)
     p = similarity.feature_vector_orbits(graph, [[1, 1], [2, 1, 1]], 2)
     assert np.allclose(p, [0.22918531118334962, 0.06509669127495163])
     assert np.allclose(
         similarity.feature_vector_orbits(graph, [[2], [4]], 1, samples=10),
         [0, 0])
Esempio n. 7
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])