Repository navigation
Conversation
A second Simulation.run() on the same object (e.g. the restart in the model tests) re-allocates spline vectors, mass operators and particles, but the scalars had cached the objects of the first run on their first update and saved stale values. - Scalar.allocate() hook, called by update() once after each allocation; BilinearEnergyFEEC, VolumeFormEnergyFEEC and PICScalar fetch their objects there instead of caching them in _local_update. - Scalars.reset_allocation(), called at the end of Simulation.allocate(). - Model-side caches (_divUv of the variational models, _f0/_f0_values of LinearVlasovAmpereOneSpecies) move to post_allocate. - Unit test for scalars following a new allocation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #852.
Problem
A second
Simulation.run()on the same object (the restart in the model tests,utils_testing.call_test, or a notebook that runs twice) saved stale scalar quantities: every value equal to the last value of the first run.run()callsallocate()again, which creates new spline vectors, mass operators and particles, but the scalars had cached the objects of the first run on their first update (hasattrchecks in_local_update).Fix
Scalar.allocate(): new hook that fetches the objects created by the allocation;update()calls it once after each allocation.BilinearEnergyFEEC,VolumeFormEnergyFEECandPICScalar(clone config) fetch their objects there instead of caching them in_local_update. TheScalardocstring states the rule.Scalars.reset_allocation(): marks every scalar, including the summands of sums such asen_tot, for a new fetch; called at the end ofSimulation.allocate().post_allocate:_divUvofVariationalMHDandVariationalCompressibleFluid(only fordivdiv_alpha > 0),_f0/_f0_valuesofLinearVlasovAmpereOneSpecies.test_scalars_follow_a_new_allocation.No baseline changes: the regression data is taken before the restart, and the first run is unchanged.
Verification
Maxwell, default parameters (
Tend = 0.03), electric energyen_E:[0, 2.159e-5, 8.467e-5, 1.8439e-4][1.8439e-4, 1.8439e-4, 1.8439e-4, 1.8439e-4][0, 2.159e-5, 8.467e-5, 1.8439e-4]3.131146e-43.131146e-4Tests run locally:
src/struphy/models/tests/test_scalars.py(6 passed),test_variational_divdiv.py(5 passed)🤖 Generated with Claude Code