Skip to content

[BUG] Make Gizmo's creation_time field robust against empty chunks#5440

Open
chummels wants to merge 3 commits into
yt-project:mainfrom
chummels:gizmo_time
Open

[BUG] Make Gizmo's creation_time field robust against empty chunks#5440
chummels wants to merge 3 commits into
yt-project:mainfrom
chummels:gizmo_time

Conversation

@chummels
Copy link
Copy Markdown
Member

PR Summary

The gizmo frontend's creation_time derived field assumes that each data chunk contains at least one star particle. When evaluating particle filters over chunked data, some chunks may contain zero particles of the filtered parent type. In this case, the creation_time field is evaluated on an empty array, which propagates into a call to:

data.ds.cosmology.t_from_z(z_form)

and ultimately raises the erorr:

ValueError: zero-size array to reduction operation minimum which has no identity

This issue arises in workflows that combine: particle filters, derived quantities, and chunked data access.

This PR modifies the GIZMO creation_time field to explicitly handle empty inputs:

If StellarFormationTime has zero size, return an empty yt array with appropriate time units.
Otherwise, proceed with the existing cosmological or non-cosmological calculation.

This ensures that downstream derived fields and particle filters behave correctly when applied to chunks with zero particles.

This PR resolves Issue #5439 .

PR Checklist

  • New features are documented, with docstrings and narrative docs
  • [X ] Adds a test for any bugs fixed. Adds tests for new features.

@chummels chummels added the bug label Apr 27, 2026
@chummels
Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@matthewturk
Copy link
Copy Markdown
Member

This looks reasonable to me, but I want to just verify that I understand -- does the same error happen if you use a field that doesn't explicitly call the cosmology routine? I just want to know if, for instance, a particle filter will fail if the chunk is empty even if the cosmology routines aren't used. From my reading it's explicitly from calling .min() on an empty array -- is that right?

@jzuhone
Copy link
Copy Markdown
Contributor

jzuhone commented Apr 27, 2026

I'll bet that at least for the GIZMO frontend this bug was never encountered for a non-cosmo sim, but if the array is zero-shaped so long as some internal function is called you should pass the field fine. But yes, some downstream things will cause errors.

In any case, @chummels's fix works for either case.

@chrishavlin chrishavlin added this to the 4.4.3 milestone Apr 28, 2026
@chummels
Copy link
Copy Markdown
Member Author

@matthewturk I think your reading of this is correct. Normally, a particle field is just applying some sort of boolean mask based on a condition (e.g., age < 10 Myr). For most fields, this is a straightforward task and when you have an empty chunk, you'd just get an empty mask, so particle filters should still work. But in this case, the failure was because the age field has to go through this t_from_z() function, and that fails because it calls min() on an empty array. So I think it should be unique to this particular field. But maybe this is a problem for other frontends that also require the t_from_z() functional call or something similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants