Repository navigation
Conversation
new_particle numbered a new particle n_real_glb+1. After a removal n_real_glb drops, so that id can still belong to a live particle: two AMUSE indices then address one PeTar particle, and the other particle can no longer be reached. Number new particles from a counter that never decreases (reset in initialize_code). Fixes amusecode#1288 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 #1288.
new_particleinsrc/amuse_petar/interface.ccnumbered a new particlen_real_glb + 1. Removing a particle lowersn_real_glb, so the next id handed out can belong to a particle that is still live. Two AMUSE indices then point at the same PeTar particle (it is looked up throughid_adr_map), and the other particle can't be reached anymore.New ids now come from a counter that only ever goes up:
last_particle_id, kept next to the other interface flags and reset ininitialize_code. That meansreset()still starts at 1. The existingid_offsetcheck is unchanged.id_adr_mapis astd::map, so ids with gaps are fine.Test.
TestPetar.test_removed_particle_id_not_reusedadds 10 particles, evolves, removes the third, evolves, adds one more, and evolves again. It checks that the indices are unique, that there are 10 particles, and that the masses match.[1, 2, 4, 5, 6, 7, 8, 9, 10, 10], the old particle 10 reports the new mass, and the test fails.I built with
./setup install amuse-framework amuse-petarin a conda env using OpenMPI 4.1, the same as the PeTar CI job.pytest tests/test_petar.py -k "not noci"gives 10 passed and 1 skipped. flake8 is clean on the test file. I could not check the multi-workernocitest locally: it did not finish within 400 s. CI skips it as well.AI use: the fix, the test and this description were written with Claude Code (Claude Opus 5.5), which also reproduced the duplicate ids and checked that the test fails before and passes after.
🤖 Generated with Claude Code