Wiki

Clone wiki

pygad / FAQ

home - up - previous next

Frequently Asked Questions

  1. What's the difference to pynbody?
  2. Why does my script take so much memory?
  3. Why does the derived block "xy" not appear in snap.derivable_blocks() though defined in derived.cfg?
  4. Why does the block "xy" not appear in snap.always_cached_derived though listed for always_cache in derived.cfg?
  5. I get a UnitError that two units such as 'ckpc/h_0' and 'kpc' are not convertible. Is this a bug?

Answers

1. What's the difference to pynbody?

Indeed, pygad and pynbody are very similar. pygad is more light-weight and especially designed for Gadget, though.

2. Why does my script take so much memory?

Well, pygad is Python and that is not a very efficient language -- but nice to use one! A pure C(++) would most likely be more efficient, however, there are some things you can do:

  • Call pygad.gc_full_collect(), specially when looping over snapshots (in this case at the end/beginning of each loop): this will more regularly free "unreachable memory" (see garbage collector).
  • Stop pygad from caching derived blocks: for a single snapshot by setting snap.cache_derived = False, or globally by setting cache_derived = False in derived.cfg or pygad.snapshot.derived.general['cache_derived'] = False.

Both will make your script a little slower though. However, that's mostly insignificant.

For some fine-tuning, you can adjust the list of always cached derived blocks (always_cache in derived.cfg) and/or explicitly free blocks that are no longer needed by calling del snap[<block_name>] in you script.

3. Why does the derived block "xy" not appear in snap.derivable_blocks() though defined in derived.cfg?

This can be due to different reasons:

  • Not derivable due to missing required blocks. If "xy" depends on some other block "ab" that is neither loadable or derivable, "xy" will not be listed in derivable_blocks() even if properly defined.
  • This block is actually loadable, which is why the derived block is simply ignored. Loadable blocks have priority over derived blocks.
  • There is an actual bug...

4. Why does the block "xy" not appear in snap.always_cached_derived though listed for always_cache in derived.cfg?

The block is most likely either not defined or not derivable (see also question 3). Otherwise its probably a bug. Please, report!

5. I get a UnitError that two units such as 'ckpc/h_0' and 'kpc' are not convertible. Is this a bug?

No, that is (most likely) no bug! To convert the units given here the scale parameter 'a' and the Hubble parameter 'h_0' are needed. They can be specified by the subs argument for convert_to/in_units_of by either a Python dictionary or a snapshot (see the documentation!). The latter has values for those and pygad is using them.

In case of SimArrs there is a associated snapshot from which these cosmological parameters are automatically taken from. This is why in some cases (namely those where SimArrs are used) you don't need to specify them.

Updated