Skip to content

Commit

Permalink
Add test isolating SOAP catalogue ordering issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleaoman committed Oct 10, 2024
1 parent cf87644 commit 8b22391
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def toysnap_withfof():
remove_toysnap()


@pytest.fixture(scope="function")
def toysoap_with_virtual_snapshot():
create_toysoap(create_virtual_snapshot=True)

yield

remove_toysoap()


@pytest.fixture(scope="function")
def sg(request):
create_toysnap()
Expand Down
33 changes: 33 additions & 0 deletions tests/test_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ToyHF,
present_particle_types,
toysoap_virtual_snapshot_filename,
toysoap_filename,
)
from swiftsimio.objects import cosmo_array, cosmo_factor, a
from swiftgalaxy.reader import SWIFTGalaxy
Expand Down Expand Up @@ -424,3 +425,35 @@ def f(sg, extra_arg, extra_kwarg=None):

result = sgs.map(f, (extra_arg,), dict(extra_kwarg=extra_kwarg))
assert result == [(extra_arg, extra_kwarg)] * sgs.halo_catalogue.count

def test_soap_target_order_consistency(
self, toysnap_withfof, toysoap_with_virtual_snapshot
):
"""
SOAP implicitly sorts the target mask (when getting things from the catalogue
we get them masked in the order that they appear in the catalogue, rather
than the order that they appear in the mask - say we ask for items [1, 0]
as a mask, we get back those two items in order [0, 1]). This test checks
that we get a SWIFTGalaxy from a SWIFTGalaxies that matches the one
constructed directly when the targets given to the SWIFTGalaxies are not
in the order that they appear in the catalogue.
"""
soaps = [
SOAP(soap_file=toysoap_filename, soap_index=0),
SOAP(soap_file=toysoap_filename, soap_index=1),
]
soap_both = SOAP(soap_file=toysoap_filename, soap_index=[1, 0])
sgs_individual = [
SWIFTGalaxy(toysoap_virtual_snapshot_filename, soap) for soap in soaps
]
sgs = SWIFTGalaxies(
toysoap_virtual_snapshot_filename,
soap_both,
preload={"black_holes.masses"}, # just keep warnings quiet
)
for i, sg in enumerate(sgs):
sg_individual = sgs_individual[sgs.iteration_order[i]]
assert_allclose_units(
sg_individual.halo_catalogue._region_centre,
sg.halo_catalogue._region_centre,
)

0 comments on commit 8b22391

Please sign in to comment.