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

Rebased splice potential #127

Open
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

AnatoleStorck
Copy link

Here is my code to spliced the potential, rebased onto the current master branch.

cphyc and others added 30 commits September 30, 2024 13:51
This is particularly useful as the potential splicing takes ages to converge.
Restart functionality commented out, needs work.
the default criteria for splicing.
fourier parallel seeding by default. Fixed bug in minres file causing
splicing to always be 24 hrs.
I will now always check if the code compiles before pushing, sorry.
Copy link
Member

@apontzen apontzen left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great. I've added some very cosmetic comments, but if you could run over these that'd be much appreciated.

Also, could you add a test potential splicing scenario, so that we catch any later regression? e.g. you could make a copy of and adapt this test: https://github.com/pynbody/genetIC/tree/master/genetIC/tests/test_24_splicing

genetIC/src/ic.hpp Outdated Show resolved Hide resolved
genetIC/src/ic.hpp Outdated Show resolved Hide resolved
genetIC/src/main.cpp Outdated Show resolved Hide resolved
genetIC/src/main.cpp Outdated Show resolved Hide resolved
genetIC/src/ic.hpp Outdated Show resolved Hide resolved
genetIC/src/ic.hpp Outdated Show resolved Hide resolved
genetIC/src/ic.hpp Show resolved Hide resolved
genetIC/src/simulation/field/field.hpp Outdated Show resolved Hide resolved
genetIC/src/tools/numerics/cg.hpp Outdated Show resolved Hide resolved
genetIC/src/tools/numerics/minres.hpp Show resolved Hide resolved
@apontzen
Copy link
Member

Thanks, changes look good - are you OK to add a test as described above?

@AnatoleStorck
Copy link
Author

AnatoleStorck commented Sep 30, 2024 via email

@apontzen
Copy link
Member

apontzen commented Oct 3, 2024

Shouldn't the result be deterministic to within a certain numerical tolerance? If so, I think we should adjust the tolerance rather than force it to run on a single thread (which is perhaps not a realistic test).

@AnatoleStorck
Copy link
Author

AnatoleStorck commented Oct 3, 2024

I tried this up to a relative tolerance of 1e-7, with 93% elements matching at that point. The problem is it needs to do 1e4 iterations so when the tester outputs the log, its all there is in the console. I will test and set it to 1e-8 which should match all elements, but outputting the log will have to be done differently.

@apontzen
Copy link
Member

apontzen commented Oct 3, 2024

I'm not sure I entirely follow - for this test, can't we just ignore what's in the log and examine the final result?

@AnatoleStorck
Copy link
Author

So instead of trying to set arbitrarily lower tolerances (which were never reached as the minimizer reached 10*res**3 iterations anyways), I've reduced the splicing region to 5 Mpc/h on a 50 Mpc/h box. This makes the number of iterations needed to reach a standard tolerance of 1e-5 around 15, which is not enough for nondeterministic deviations to accumulate. Not only that, but a smaller splicing regions is more in line with the current science case of potential splicing, dark matter halo Lagrangian patches.

@apontzen
Copy link
Member

apontzen commented Oct 6, 2024

Perfect, thanks.

Sorry for asking one more thing but I just realised that all the existing method names in the ICGenerator class (with one mistaken exception) are camelCased whereas you have used some_underscores -- would you mind renaming your methods to be consistently camel-cased?

I promise this is the last thing then we can merge.

@apontzen
Copy link
Member

apontzen commented Oct 6, 2024

This seems ready to go. To understand for the documentation -- why do you recommend ZELDOVICH_GRADIENT_FOURIER_SPACE is disabled when splicing potential?

@apontzen apontzen mentioned this pull request Oct 6, 2024
@AnatoleStorck
Copy link
Author

The decision to disable ZELDOVICH_GRADIENT_FOURIER_SPACE was made pretty early on in the development of potential splicing by @cphyc . I think it came down to it being more advantageous to calculate the displacement field in real space using finite differences than in Fourier space. Corentin can probably motivate the decision better than I can.

@AnatoleStorck
Copy link
Author

Perhaps adding a warning in the splicePotential function like in line 325 of linearmodification.hpp for compiling with ZELDOVICH_GRADIENT_FOURIER_SPACE could be helpful.

@cphyc
Copy link
Collaborator

cphyc commented Oct 7, 2024

The motivation to disable ZELDOVICH_GRADIENT_FOURIER_SPACE is to force the velocities (and hence the density) to be obtained using a local finite-difference approach. That way, once the potential is set up to machine precision in the spliced region, so are the velocities and densities (minus a few pixels on the edge).
If gradients are computed in Fourier space, the differencing isn't local anymore and some information from the outside can leak into the spliced region when going from potential to velocities.

@apontzen
Copy link
Member

apontzen commented Oct 7, 2024

That makes sense, but I don't think it will be a huge issue for most potential users (unless you have tests that show otherwise)?

I'd suggest we update the warning message to be something more like

You are splicing potential with ZELDOVICH_GRADIENT_FOURIER_SPACE. Due to non-locality, the density field may not exactly match within the spliced region. Consider recompiling with ZELDOVICH_GRADIENT_FOURIER_SPACE disabled if precise density field matching is important to you.

appropriately split across lines...

Does that sounds reasonable?

Copy link
Author

@AnatoleStorck AnatoleStorck left a comment

Choose a reason for hiding this comment

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

Well if you are interested in keeping all local linear information about the evolution of your patch the same, then it would be important. Otherwise you wouldn't know if the effect on your evolved patch is from the environment or on the changes made in the initial velocity and density fields while taking the gradient in fourier space. Its not something Corentin and I have quantified but maybe doing a quick check in my free time might be possible. In any case, I'm pretty happy with the changes and suggestions made, thank you Andrew!

@cphyc
Copy link
Collaborator

cphyc commented Oct 9, 2024

This looks good to me! Thanks @AnatoleStorck for the work! Once https://arxiv.org/abs/2409.13010 is accepted and this PR merged, it'd be great to add this to the manual. @apontzen what is the procedure for this?

@apontzen
Copy link
Member

@cphyc Agree we need to document it.

At the moment the manual is very 'manual'; it's just a latex document.

Ideally we should turn it into markdown or something like that and host it in a repository that uses Jekyll or something, hosted in this repository. Do you feel like doing that? Or would you prefer just to edit a latex file and send back to me?

@apontzen
Copy link
Member

apontzen commented Dec 2, 2024

@cphyc @AnatoleStorck quick ping re the documentation discussion above - we can add something very basic if you like, but we should definitely describe the basics at a minimum. Let me know! It will be good to get this merged and released shortly.

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