コード例 #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_event_exact(g, 2, 2, n_mean=-1)
コード例 #2
0
 def test_low_count(self):
     """Test if function raises a ``ValueError`` if ``max_count_per_mode`` is negative."""
     g = nx.complete_graph(5)
     with pytest.raises(
             ValueError,
             match="Maximum number of photons per mode must be non-negative"
     ):
         similarity.prob_event_exact(g, 2, max_count_per_mode=-1)
コード例 #3
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_event_exact(g, 2, 2, loss=2)
コード例 #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)
コード例 #5
0
 def test_correct_result_returned(self, monkeypatch):
     """Tests if the call to _get_state function is performed correctly and probabilities over all
     constituent orbits of the given event are summed correctly. The test monkeypatches the fock_prob
     function so that the probability is the same for each sample permutation of all constituent orbits
     and is equal to 1/8. For a 4-mode graph, an event with ``photon_number = 2``, and
     ``max_count_per_mode = 1`` contains orbit [1, 1] which has 6 possible sample 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_event_exact(graph, 2, 1) == 6 / 8
コード例 #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_events(
         g, [2], 1, samples=0) == similarity.prob_event_exact(g, 2, 1)
コード例 #7
0
 def test_odd_photon_numbers(self, k, nmax):
     """Test if function returns zero probability for odd number of total photons."""
     graph = nx.complete_graph(10)
     assert similarity.prob_event_exact(graph, k, nmax) == 0.0
コード例 #8
0
 def test_prob_vacuum_event(self):
     """Tests if the function gives the right probability for an event with zero photons when
     the GBS device has been configured to have zero mean photon number."""
     graph = nx.complete_graph(5)
     assert similarity.prob_event_exact(graph, 0, 0, 0) == 1.0
コード例 #9
0
 def test_invalid_photon_number(self):
     """Test if function raises a ``ValueError`` when a photon number below zero is specified"""
     g = nx.complete_graph(5)
     with pytest.raises(ValueError,
                        match="Photon number must not be below zero"):
         similarity.prob_event_exact(g, -1, 2)