Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Recursion #415

Draft
wants to merge 19 commits into
base: v4-prep
Choose a base branch
from
Draft

Remove Recursion #415

wants to merge 19 commits into from

Conversation

steven-murray
Copy link
Member

This PR removes recursion from all the component calculations. It changes a whole bunch of stuff to achieve this well, including:

  1. Modified InputStruct objects that get subclassed to UserParams etc. These are now attrs-based classes, which makes them a little more transparent.
  2. New InputParameter class that handles collections of the InputStruct objects and their validation.
  3. Some new sub-packages to break up the wrapper a bit.

src/py21cmfast/_cfg.py Outdated Show resolved Hide resolved
brightness_temp,
ts_box,
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be saved to the struct itself instead of taking the brightness_temp struct's parameters?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We certainly could do that -- at the moment we always require having a brightness_temp struct in this instance, and the various input structs must be the same for all boxes, so merely referencing them from the brightness_temp struct makes sense to me

and self.flag_options == other.flag_options
and self.astro_params == other.astro_params
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much older issue but we don't have random seed in __eq__?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. We should probably ensure that as well -- problematically sometimes you also want to compare without the random seed. But I think you're right that the default equality method should include the random seed.

Copy link
Contributor

@daviesje daviesje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks 95% done to me, I've left some notes for things to look into which I should be able to get to relatively quickly.

"flag_options": inputs.flag_options,
"init_boxes": initial_conditions,
},
**iokw,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we put the init boxes instead of user/cosmo params in the kwargs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- because every other low-level function other than initial_conditions requires passing initial_conditions instead of the user and cosmo params (because they now require the initial conditions to be passed, which already has those params defined in it, so it's easier to take them from there, rather than having two ways to get the params and having to make sure they match.

spin_temp=st2 if inputs.flag_options.USE_TS_FLUCT else None,
z_heat_max=global_params.Z_HEAT_MAX,
# cleanup if its the last time through
cleanup=cleanup and z == redshifts[-1],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't have a cleanup kwarg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the kwarg has been removed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah, because I don't think you need it once recursion is removed

redshift = redshift.tolist()

# Get the list of redshift we need to scroll through.
redshifts = _get_required_redshifts_coeval(flag_options, redshift)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider renaming redshifts and redshift to node_redshifts and out_redshifts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea -- that would be a lot more clear.

return redshifts.tolist()


def _get_coeval_callbacks(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find where these are used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we've moved away from using these callbacks -- instead we just do a yield from the main wrapper so the user can do anything they like with the result. Perhaps we'd still want something like this to exist for a CLI interface or something where the user has less control over what happens at each step.


return kwargs

def __eq__(self, other):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missing something but should the random seed be included in __eq__?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, same reply as above.

If you know what you are doing, please modify the global parameter:
NU_X_MAX
"""
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I think would be nice here is to have different running "modes" which are sets of default parameters we can switch between e.g a default parameter set for the halo model, grid model, and constant zeta model

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, see #10. But I think not in this PR

src/py21cmfast/drivers/single_field.py Outdated Show resolved Hide resolved
src/py21cmfast/wrapper/outputs.py Outdated Show resolved Hide resolved
src/py21cmfast/wrapper/outputs.py Outdated Show resolved Hide resolved
Conflicts:
	src/py21cmfast/__init__.py
	src/py21cmfast/inputs.py
	src/py21cmfast/src/21cmFAST.h
	src/py21cmfast/src/Stochasticity.c
	src/py21cmfast/wrapper.py
	src/py21cmfast/wrapper/outputs.py
	src/py21cmfast/wrapper/structs.py
@daviesje daviesje linked an issue Oct 17, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove/Improve Recursive Generation
2 participants