Skip to content

Commit

Permalink
Fix bug introduced into server (non-shared-mem) mode. Add unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
apontzen committed Dec 12, 2023
1 parent e110bad commit 74c5ad4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tangos/input_handlers/pynbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,12 @@ def load_timestep_without_caching(self, ts_extension, mode=None):
raise NotImplementedError("Load mode %r is not implemented"%mode)

def load_region(self, ts_extension, region_specification, mode=None):
if mode is None or mode=='server':
if mode is None:
timestep = self.load_timestep(ts_extension, mode)
return timestep[region_specification]
elif mode=='server':
timestep = self.load_timestep(ts_extension, mode)
return timestep.get_view(region_specification)
elif mode=='server-shared-mem':
from ..parallel_tasks import pynbody_server as ps
timestep = self.load_timestep(ts_extension, mode)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_pynbody_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ def test_correct_object_loading():
pt.launch(_test_correct_object_loading)


def _test_region_loading():
"""This test ensures that a region can be loaded correctly under server mode"""
f_remote = handler.load_region("tiny.000640", pynbody.filt.Sphere("3 Mpc"), mode='server')
f_local = handler.load_region("tiny.000640", pynbody.filt.Sphere("3 Mpc"), mode=None)
assert (f_remote.dm['pos'] == f_local.dm['pos']).all()
assert (f_remote.st['pos'] == f_local.st['pos']).all()
def test_region_loading():
"""This test ensures that a region can be loaded correctly under server mode"""
pt.use("multiprocessing-3")
pt.launch(_test_region_loading)


def _test_oserror_on_nonexistent_file():
with npt.assert_raises(OSError):
Expand Down

0 comments on commit 74c5ad4

Please sign in to comment.