Skip to content

Bugfix/2568 output fenceposting#2575

Merged
fluidnumericsJoe merged 15 commits intomainfrom
bugfix/2568-output-fenceposting
Apr 15, 2026
Merged

Bugfix/2568 output fenceposting#2575
fluidnumericsJoe merged 15 commits intomainfrom
bugfix/2568-output-fenceposting

Conversation

@fluidnumericsJoe
Copy link
Copy Markdown
Contributor

AI Disclosure

  • [ X ] This PR contains AI-generated content.
    • [ X ] I have tested any AI-generated content in my PR.
    • [ X ] I take responsibility for any AI-generated content in my PR.
    • Describe how you used it (e.g., by pasting your prompt): After making changes to dump output after each positionupdate and add initial condition IO, I've used Claude Code to review Issue Particle positions in output are lagged by one dt relative to time labels #2568 with failing tests for context to suggest potential test failure resolution options.

In the previous version of parcels, particleset.execute() overshoots the
particle trajectories by exactly one time step while leading to repeated
initial condition output lagged by exactly one time step. This leads to
an inconsistency in the actual particle positions and those written to
files

In this updated approach, when an outputfile is provided, we write the
initial condition to file before the time loop. Then, inside the time
loop, the kernels are executed with particle position updated
immediately after all other kernels and just before file IO. This
corrects the inconsistency in the actual and reported time levels for
each particle state in the output.

Unfortunately this breaks a number of tests. The unit tests are checking
for incorrect values (lagged by exactly one time loop iteration..)
…ate after user kernels

This removes the `PositionUpdate` kernel from the list of kernels. This
change was made to fix `funcname` polution if the `test_kernel_merging`,
`test_kernel_from_list`, and `test_metadata`.
With the correction in place, the particle positions are now obtained by
1 less call to positionupdate (correctly); the values in the test output
for validation were based off the wrong number of iterations due to the
fenceposting bug we're trying to address.
…ion time

With the fence posting bugfix in place, the particleset execute call
updates the position once; previously, this happened twice (this was the
bug). This test failed because the particle didn't go out of bounds with
a single position update. Semantically, setting the runtime to 2 days,
achieved what was intended here (to get the particle out of bounds)
Copy link
Copy Markdown
Member

@erikvansebille erikvansebille left a comment

Choose a reason for hiding this comment

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

Nice improvement! But it seems that this doesn't (yet) fix the ParticleFile? That now raises some unit test errors. Do you want me to help?

Comment thread src/parcels/_core/kernel.py
Comment thread src/parcels/_core/kernel.py Outdated
Comment thread tests/test_advection.py
Comment thread tests/test_uxadvection.py Outdated
@fluidnumericsJoe
Copy link
Copy Markdown
Contributor Author

Nice improvement! But it seems that this doesn't (yet) fix the ParticleFile? That now raises some unit test errors. Do you want me to help?

It'd be great to get your input on those. It looks like I need to have some awareness for particles being injected at different points in time into the simulation for the explicit initial condition write in particleset.execute()

Copy link
Copy Markdown
Contributor

@VeckoTheGecko VeckoTheGecko left a comment

Choose a reason for hiding this comment

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

Should we have an additional test that isolates #2568 and tests it? I'm worried that at the moment this only surfaces in position assert statements within other tests

Comment thread tests/test_particlesetview.py
@fluidnumericsJoe
Copy link
Copy Markdown
Contributor Author

Should we have an additional test that isolates #2568 and tests it? I'm worried that at the moment this only surfaces in position assert statements within other tests

This is now covered in tests/test_uxadvection.py with commit 0e08123

@fluidnumericsJoe
Copy link
Copy Markdown
Contributor Author

Failed test looks like a 404 error unrelated to my changes....

@fluidnumericsJoe fluidnumericsJoe merged commit 22dbf10 into main Apr 15, 2026
27 of 29 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Parcels development Apr 15, 2026
@fluidnumericsJoe fluidnumericsJoe deleted the bugfix/2568-output-fenceposting branch April 15, 2026 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Particle positions in output are lagged by one dt relative to time labels

3 participants