Repository navigation
Give a duplicated virus its own dna list - #498
Merged
Merged
Conversation
VirusAgent.generate_dna() writes into the list it is handed and returns that
same object, and duplicate() calls it with the parent's own genome:
dna=self.generate_dna(self.dna)
So the first time a virus reproduces it rewrites its own dna in place and
hands the child the identical list. Parent and child alias from then on, and
any later mutation by either one changes both.
Copying before mutating makes the behaviour match what duplicate() reads
like it intends: the child is a mutated copy of the parent, not another name
for it.
This is the follow-up to mesa#496, which fixes the matching problem at creation
time, where one shared dna list was passed for every initial virus. Scope
agreed with @RudraDudhat2509 there. The two halves are independent: this one
is reproducible on main today without mesa#496, because it goes through
VirusAgent directly rather than VirusAntibodyModel.
Adds two tests, both failing on main:
- generate_dna() leaves the genome it is given alone
- duplicate() gives the child its own list, and mutating the child does not
change the parent
This was referenced Oct 19, 2026
quaquel
approved these changes
Oct 28, 2026
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.
Follow-up to #496, with scope agreed with @RudraDudhat2509 there.
Summary
VirusAgent.generate_dna()writes into the list it is handed and returns that same object, andduplicate()calls it with the parent's own genome:So the first time a virus reproduces, it rewrites its own dna in place and hands the child the identical list. Parent and child alias from then on, and any later mutation by either one changes both.
Relationship to #496
Same defect, two places. #496 fixes creation, where one shared dna list was passed for every initial virus. This fixes duplication. They are independent: with only #496 applied to a clean checkout,
This PR does not depend on #496 and does not touch
model.py, so there is no overlap in the diff. The tests go throughVirusAgentdirectly rather thanVirusAntibodyModel, which means they run onmaintoday without #496 merged.Implementation
One line. It makes the behaviour match what
duplicate()reads like it intends: the child is a mutated copy of the parent, not another name for it.AntibodyAgentmemory already deep-copies what it stores, so it is unaffected.Testing
Two tests, both failing on
mainand passing with the fix:generate_dna()leaves the genome it is given alone, and returns a different objectduplicate()gives the child its own list, the parent's genome survives, and mutating the child does not change the parentruff checkandruff format --checkclean onexamples/virus_antibody/.