Skip to content

Conversation

@boryanah
Copy link
Collaborator

Attempting a memory improvement of the compute environment script in prepare_sim.py.
Addressing issue #143

allpos[index_bounds], r=rad_outer, workers=nthread
)
# this is the true number of randoms
for ind in np.arange(len(index_bounds)):
Copy link
Member

Choose a reason for hiding this comment

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

This should be for ind in range(len(index_bounds)), right? No need to construct the full array with np.arange.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, thanks for catching! Also changed it in one more place

# repeat until condition satisfied
while count < len(index_bounds) * rand_final:
# generate randoms in L shape
randpos, randdist = gen_rand(
Copy link
Member

Choose a reason for hiding this comment

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

The test failure is due to this function calling np.random functions a different number of times than before, causing subsequent np.random calls to return different results. Maybe we should decouple this RNG with later RNG?

In other words, can this function be modified to accept an RNG object (created by np.random.default_rng(seed)) instead of using np.random directly? And then we reuse the RNG object for all calls to this function, and a different RNG object for other parts of the code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense! Included rng object set at newseed that is passed to that function -- hopefully it passes the tests now (though I worry that we also had a check for Menv so it might still fail because the values are different?)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it will fix the tests, because previously the RNG for the randoms and Menv was coupled, and now we're decoupling it. But at least it will prevent the tests from breaking in the future.

lgarrison and others added 3 commits March 24, 2025 13:29
This lets us give informative error messages that include the field name,
and reduces repetition.
@lgarrison lgarrison changed the title Mem prepare sim halo light cones: reduce memory usage in prepare_sim Mar 25, 2025
@boryanah boryanah merged commit da8ce13 into main Mar 25, 2025
9 checks passed
@boryanah boryanah deleted the mem_prepare_sim branch March 25, 2025 19:58
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.

3 participants