Skip to content

Stress escapees refactor - #328

Open
Gabe-Rose wants to merge 16 commits into
anyaevostinar:mainfrom
Gabe-Rose:Stress_Escapees_Refactor
Open

Stress escapees refactor#328
Gabe-Rose wants to merge 16 commits into
anyaevostinar:mainfrom
Gabe-Rose:Stress_Escapees_Refactor

Conversation

@Gabe-Rose

@Gabe-Rose Gabe-Rose commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Overview:

Stress References removed from SGPWorld* and into SGPW_InteractionMechanismSetup.cc

  • after_reproduction_sig used to trigger processing of escapees
  • emp::vector symbiont_stress_escapees and StressEscapee moved to SGPW_InteractionMechanismSettup.cc
  • Now uses SymDoBirth

SymDoBirth modified to take offspring, parent, and world position

  • default mode changed to maintain override
  • Relevant functors/lower level functions changed to align with SymDoBirth

SetupHorizontalTransmissionCompatibilityMode() changed to set one functor

  • stress-specific functor removed
  • now takes pointers to the (prospective) host and (offspring) symbiont

Other:

  • Various useless comments removed
  • Variables named "baby" renamed to "offspring" where convenient

Next steps:

  • change all .Delete() calls to SendToGraveyard()
  • move all sym_offspring SendToGraveyard() calls to SymDoBirth
  • ^^^ same with HostDoBirth()?
  • Why are we doing the compatibility check with the sym_parent, not the sym_offspring?

Comment thread source/sgp_mode/SGPWorld.cc Outdated
// TODO - add any signals?
const size_t parent_pop_idx = parent_pos.GetPopID();
emp::Ptr<Organism> parent = this->GetOrgPtr(parent_pop_idx)->GetSymbionts()[parent_pos.GetIndex() - 1];
emp_assert(!parent->IsHost());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm confused where "parent" is being defined now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

your right! that is pretty confusing. I wonder why that passed compile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed to sym_parent_ptr

Comment thread source/sgp_mode/SGPWorld.h Outdated
Comment thread source/sgp_mode/SGPWorld.h Outdated
std::function<std::optional<emp::WorldPosition>(
size_t, /* Parent's host location id in world (pops[0][id])*/
emp::Ptr<sgp_sym_t> /* Pointer to symbiont parent (producing the sym offspring) */
emp::Ptr<sgp_sym_t> sym_offspring_ptr,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't think that you can include parameter names, hence the previous syntanx

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Also, why are we now passing the offspring as well as the parent? We should only need whatever symbiont is being used to check for compatibility

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed parameter names. Good question with the offspring; They are not used currently and could easily be removed. we are checking the task profile of the parent with the prospective host, but that doesent quite sit right with me. We are determining the "fate" of the offspring based on the parent, not the symbiont itself. In other words fun_horizontal_transmission_compatibility_check determines the compatibility of the parent and prospective host, but that value is used to determine the compatabilty of the sym and prospective host.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See SGPWorld.test.cc comment as well

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Let's focus on just refactoring to capture existing functionality and not changing functionality in this PR, since otherwise too many things are changing and it is likely that a bug gets introduced.

The parent is injecting its offspring into a new host and the offspring hasn't done anything yet, so it can't do its own infecting. The fate of offspring is very often dependent on the parent's behavior ;)


emp::Ptr<sgp_host_t> host = emp::NewPtr<sgp_host_t>(&random, &world, &config);
emp::Ptr<sgp_sym_t> symbiont = emp::NewPtr<sgp_sym_t>(&random, &world, &config);
symbiont->GetHardware().GetCPUState().MarkTaskPerformed(8);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why was this necessary to add?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved it out of the WHEN block below. Initially in my refactor I had:

void SGPWorld::SetupFindHostForHorizontalTransmission() {
...
    const bool compatible = fun_horizontal_transmission_compatibility_check(
      *prospective_host_ptr,
      *sym_offspring_ptr
      );
...
}

Now:

void SGPWorld::SetupFindHostForHorizontalTransmission() {
...
    const bool compatible = fun_horizontal_transmission_compatibility_check(
      *prospective_host_ptr,
      *sym_parent_ptr     //This Line Changed
      );
...
}

As mentioned earlier in your comment in SGPWorld.h, initially I thought it would make sense to compare the offspring to the host. Plus, I saw this in Reproduce():

offspring_cpu_state.SetParentTasksPerformed(
  hardware.GetCPUState().GetTasksPerformed()
);
offspring_cpu_state.SetParentFirstTaskPerformed(
  hardware.GetCPUState().GetFirstTaskPerformed()
);

By putting MarkTaskPerformed() before Reproduce() in the test, I thought it would properly get copied to the offspring, and then the offspring would be able to pass the compatibility check. When I was wrong, I forgot to move this line back and remove the reproduction.

Comment thread source/test/sgp_mode_test/unit_tests/SGPWorld.test.cc Outdated
symbiont->GetHardware().GetCPUState().MarkTaskPerformed(8);
WHEN("Task matching is not required for horizontal transmission") {
auto pos_found = world.FindHostForHorizontalTrans(source_id, symbiont);
auto pos_found = world.FindHostForHorizontalTrans(offspring, symbiont, symbiont->GetLocation());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Pretty sure it should be just "symbiont" being passed since offspring has no useful information

world.AddOrgAt(host, 0);
size_t source_id = symbiont->GetLocation().GetPopID();
emp::Ptr<Organism> offspring_org = symbiont->Reproduce();
emp::Ptr<sgp_sym_t> offspring = static_cast<sgp_sym_t*>(offspring_org.Raw());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You'll be able to remove these lines once you make the change to not pass offspring, so please don't forget to do so

@anyaevostinar anyaevostinar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Some things to change back. Make sure to be careful not to change functionality other than the specific thing that is the target. Also, it's good to clean up small things, but try to resist moving small lines around when they really don't change much since it adds to the complication of reviews and merge conflicts

@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.78238% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.09%. Comparing base (80c2445) to head (0e4e09b).

Files with missing lines Patch % Lines
source/sgp_mode/SGPW_InteractionMechanismSetup.cc 75.00% 7 Missing ⚠️
source/sgp_mode/SGPW_TaskProfileSetup.cc 75.00% 3 Missing ⚠️
source/default_mode/SymWorld.h 87.50% 1 Missing ⚠️
source/sgp_mode/SGPWorldSetup.cc 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #328      +/-   ##
==========================================
- Coverage   77.09%   77.09%   -0.01%     
==========================================
  Files         108      108              
  Lines       23155    23131      -24     
  Branches     1615     1613       -2     
==========================================
- Hits        17852    17832      -20     
+ Misses       5232     5229       -3     
+ Partials       71       70       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants