Skip to content

Commit e56c28a

Browse files
authored
Merge pull request #237 from pynbody/remote-derived-array
Fix error when mixing derived and loaded arrays (pynbody server mode)
2 parents e085e37 + 26753e3 commit e56c28a

File tree

5 files changed

+29
-160
lines changed

5 files changed

+29
-160
lines changed

.github/workflows/integration-test.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ jobs:
5656
working-directory: test_tutorial_build
5757
run: |
5858
wget https://zenodo.org/record/10051592/files/reference_database.db?download=1 -O reference_database.db -nv
59-
tangos diff data.db reference_database.db --property-tolerance dm_density_profile 1e-2 0
59+
tangos diff data.db reference_database.db --property-tolerance dm_density_profile 1e-2 0 --property-tolerance gas_map 1e-2 0 --property-tolerance gas_map_sideon 1e-2 0 --property-tolerance gas_map_faceon 1e-2 0
6060
# --property-tolerance dm_density_profile here is because if a single particle crosses between bins
6161
# (which seems to happen due to differing library versions), the profile can change by this much
6262
#
63-
# previously had:
63+
# Images also occasionally differ by one or two particles. To deal with this previously had:
6464
# --ignore-value-of gas_map gas_map_faceon gas_map_sideon uvi_image uvi_image_sideon uvi_image_faceon
65-
# ignore-value-of above is a clunky fix for the use of 'approximate fast' images -- is it needed any longer?

tangos/blocking.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tangos/parallel_tasks/pynbody_server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,11 @@ def _load_array(self, array_name, fam=None):
317317
log.logger.debug("Array received; waited %.2fs",time.time()-start_time)
318318
except KeyError:
319319
raise OSError("No such array %r available from the remote"%array_name)
320-
if fam is None:
321-
self[array_name] = data
322-
else:
323-
self[fam][array_name] = data
320+
with self.auto_propagate_off:
321+
if fam is None:
322+
self[array_name] = data
323+
else:
324+
self[fam][array_name] = data
324325

325326

326327
_connection_active = False

tests/test_blocking_session.py

Lines changed: 0 additions & 125 deletions
This file was deleted.

tests/test_pynbody_server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33

4+
import numpy as np
45
import numpy.testing as npt
56
import pynbody
67

@@ -188,3 +189,24 @@ def _test_oserror_on_nonexistent_file():
188189
def test_oserror_on_nonexistent_file():
189190
pt.use("multiprocessing-2")
190191
pt.launch(_test_oserror_on_nonexistent_file)
192+
193+
194+
195+
@pynbody.snapshot.tipsy.TipsySnap.derived_quantity
196+
def metals(sim):
197+
"""Derived array that will only be invoked for dm, since metals is present on disk for gas/stars"""
198+
return pynbody.array.SimArray(np.ones(len(sim)))
199+
200+
def _test_mixed_derived_loaded_arrays():
201+
f_remote = handler.load_object('tiny.000640', 1, 1, mode='server')
202+
f_local = handler.load_object('tiny.000640', 1, 1, mode=None)
203+
assert (f_remote.dm['metals'] == f_local.dm['metals']).all()
204+
assert (f_remote.st['metals'] == f_local.st['metals']).all()
205+
206+
207+
def test_mixed_derived_loaded_arrays():
208+
"""Sometimes an array is present on disk for some families but is derived for others. A notable real-world example
209+
is the mass array for gas in ramses snapshots. Previously accessing this array in a remotesnap could cause errors,
210+
specifically a "derived array is not writable" error on the server. This test ensures that the correct behaviour"""
211+
pt.use("multiprocessing-2")
212+
pt.launch(_test_mixed_derived_loaded_arrays)

0 commit comments

Comments
 (0)