Skip to content

Allow SWIFT snapshots to be reused as ICs explicitly#73

Draft
Francyrad wants to merge 1 commit into
SWIFTSIM:masterfrom
Francyrad:codex/reuse-swift-snapshots
Draft

Allow SWIFT snapshots to be reused as ICs explicitly#73
Francyrad wants to merge 1 commit into
SWIFTSIM:masterfrom
Francyrad:codex/reuse-swift-snapshots

Conversation

@Francyrad

@Francyrad Francyrad commented Apr 27, 2026

Copy link
Copy Markdown

Summary

  • Accept SWIFT snapshot field names as aliases for singular IC field names only when InitialConditions:accept_snapshot is enabled.
  • Keep the default behaviour unchanged so IC/snapshot naming conventions remain separate unless the user opts in explicitly.
  • Emit an explicit error if a snapshot field alias is detected while accept_snapshot is disabled.

Validation

  • make -j20 with the local Intel oneAPI/OpenMPI build.
  • Verified that reading a SWIFT planetary snapshot as ICs fails by default with a message pointing to InitialConditions:accept_snapshot.
  • Verified that the same snapshot is accepted and runs when InitialConditions:accept_snapshot: 1 is set.
@WillJRoper

Copy link
Copy Markdown
Contributor

The reason for keeping IC and snapshot naming conventions separate was intentional to prevent mistakes when using them interchangeably.

While this aliasing is a nice feature, if implemented, it should almost certainly be hidden behind a accept_snapshot argument in the parameter file, which is by default False. That way, you intentionally have to acknowledge what you are doing.

Additionally, for what it is worth, I do not like the duplication of the restart flag. That will only ever lead to confusion in my opinion.

@Francyrad

Copy link
Copy Markdown
Author

The reason for keeping IC and snapshot naming conventions separate was intentional to prevent mistakes when using them interchangeably.

While this aliasing is a nice feature, if implemented, it should almost certainly be hidden behind a accept_snapshot argument in the parameter file, which is by default False. That way, you intentionally have to acknowledge what you are doing.

Additionally, for what it is worth, I do not like the duplication of the restart flag. That will only ever lead to confusion in my opinion.

I can make further changes to implement your very fair requests

@Francyrad Francyrad force-pushed the codex/reuse-swift-snapshots branch from 8a16f51 to 433e744 Compare April 27, 2026 15:21
@Francyrad Francyrad changed the title Allow snapshots and restarts to be reused directly Apr 27, 2026
@Francyrad

Copy link
Copy Markdown
Author

Thanks, that makes sense. I have updated the PR to keep snapshot/IC naming separate by default. Snapshot field aliases are now only accepted when InitialConditions:accept_snapshot is set, and the code emits an explicit error pointing to that option when a snapshot alias is found without the opt-in.

I also removed the parameter-file restart flag from the PR; restart remains controlled by the existing command-line option.

@MatthieuSchaller

Copy link
Copy Markdown
Member

Thanks for contributing to the project and suggesting this.

My concern with this is that it's a dangerous option. And that's also the reason we have not implemented it in the first place. Restarting from a snapshot always leads to time integration mistake. But, in most applications for cosmology and galaxy formation it's much worse than that as many of the fields will not be re-read and initialised properly. There is a lot of scheme-dependent re-initialisation of internal fields that would have to happen and we'd need to give them sensible values.

I think that providing the option as coded here then gives a false sense of security and that the code will run as expected. Which it will not, except in some limited cases.

@mladenivkovic

Copy link
Copy Markdown
Contributor

It's as Matthieu says, restarting from a snapshot can lead to a plethora of problems if not done extremely carefully. For example, running a simulation without restarting from a snapshot will almost invariably lead to (somewhat) different results than running a simulation without restarting using snapshots as ICs due to the time integration errors Matthieu mentioned.

If, however, you're absolutely certain you know what you're doing, then there is a python script in the repository which will convert a snapshot into an IC file: https://github.com/SWIFTSIM/SWIFT/blame/master/tools/convert_snapshot_to_ICs.py

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

Labels

None yet

4 participants