def test_sample_composition(self): """Test if function returns a sample that corresponds to the input orbit. Input orbits are orbits from ``all_orbits_cumulative``, i.e., all orbits from 3-5 photons. This test checks if a sample corresponds to an orbit by counting the occurrence of elements in the sample and comparing to a count of elements in the orbit.""" modes = 5 all_orbits_zeros = [ [1, 1, 1, 0, 0], [2, 1, 0, 0, 0], [3, 0, 0, 0, 0], [1, 1, 1, 1, 0], [2, 1, 1, 0, 0], [3, 1, 0, 0, 0], [2, 2, 0, 0, 0], [4, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 1, 1, 1, 0], [3, 1, 1, 0, 0], [2, 2, 1, 0, 0], [4, 1, 0, 0, 0], [3, 2, 0, 0, 0], [5, 0, 0, 0, 0], ] # padding orbits with zeros at the end for comparison to samples counts = [Counter(similarity.orbit_to_sample(o, modes)) for o in all_orbits_cumulative] ideal_counts = [Counter(o) for o in all_orbits_zeros] assert counts == ideal_counts
# The feature vector of a graph can be composed in a variety of ways. One approach is to # associate features with the relative frequencies of certain types of measurements being # recorded from a GBS device configured to sample from the graph, as we now discuss. # # We begin by defining the concept of an *orbit*, which is the set of all GBS samples that are # equivalent under permutation of the modes. A sample can be converted to its corresponding orbit # using the :func:`~.sample_to_orbit` function. For example, the first sample of ``m0`` is ``[0, # 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]`` and has orbit: print(similarity.sample_to_orbit(m0[0])) ############################################################################## # Here, ``[1, 1]`` means that two photons were detected, each in a separate mode. Other samples # can be randomly generated from the ``[1, 1]`` orbit using: print(similarity.orbit_to_sample([1, 1], modes=m0.modes)) ############################################################################## # Orbits provide a useful way to coarse-grain the samples from GBS into outcomes that are # statistically more likely to be observed. However, we are interested in coarse-graining further # into *events*, which correspond to a combination of orbits with the same photon number such # that the number of photons counted in each mode does not exceed a fixed value # ``max_count_per_mode``. To understand this, let's look at all of the orbits with a photon # number of 5: print(list(similarity.orbits(5))) ############################################################################## # All 5-photon samples belong to one of the orbits above. A 5-photon event with # ``max_count_per_mode = 3`` means that we include the orbits: ``[[1, 1, 1, 1, 1], [2, 1, 1, 1], # [3, 1, 1], [2, 2, 1], [3, 2]]`` and ignore the orbits ``[[4, 1], [5]]``. For example,
def test_sample_length(self, orb_dim, modes_dim): """Test if function returns a sample that is of correct length ``modes_dim`` when fed a collision-free event of ``orb_dim`` photons.""" samp = similarity.orbit_to_sample(all_orbits[orb_dim][0], modes_dim) assert len(samp) == modes_dim
def test_low_modes(self): """Test if function raises a ``ValueError`` if fed an argument for ``modes`` that does not exceed the length of the input orbit.""" with pytest.raises(ValueError, match="Number of modes cannot"): similarity.orbit_to_sample([1, 2, 3], 2)