-
Notifications
You must be signed in to change notification settings - Fork 33
kelleyde sgp-copy: Event System, TaskValue Event Tests, CreateNANDProgram #312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kelleyde
wants to merge
52
commits into
anyaevostinar:main
Choose a base branch
from
kelleyde:sgp-copy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
ea9ebcc
adding event handling files
kelleyde 77083bb
ChangingEventsHandler functions
kelleyde 804ccd9
stash old files
kelleyde 2dd517d
stash old files
kelleyde cb91625
update old files
kelleyde 37d651b
new changes up to date
kelleyde a11f577
LoadEvents, DeleteEvents
kelleyde 0bf3438
ProcessEvents, DeleteEvents, SortEvents
kelleyde 2f95355
Resolve merge conflicts with main
amlalejini 6aaff06
Remove accidentally duplicated function in Host.h
amlalejini 197faa1
Move event system into its own directory. Separate event type definit…
amlalejini 48da76e
Start separating out different event types
amlalejini 1e6d4e0
Continue updating event parsing from json
amlalejini 26fd923
Fix many compilation errors in current draft of event system
amlalejini ca6104e
Implement one-time event processing function
amlalejini 596c718
Refactor event processing functions in event manager
amlalejini 7c3f88b
Implement process function for TaskValueEvent, make it easier to add …
amlalejini 62c80b4
Integrate events system into world, remove temporary solution to conf…
amlalejini 64128d7
Remove debugging print statements
amlalejini 13ce5f2
Move temp changing environment and sense instruction tests into need …
amlalejini 11b9d83
Ignore Data/ directory
amlalejini 8ed6304
Clean up event system code, implement manual AddEvent functions in Ev…
amlalejini 6ad9b16
Updates during code review
amlalejini fee13f7
Merge pull request #1 from amlalejini/event-system-lalejini
kelleyde 91a2276
commiting changes to SGPWorldSetup.cc to pull events files
kelleyde 19c8e46
Merge branch 'sgp-copy' of github.com:kelleyde/SymbulationEmp into sg…
kelleyde 3151e52
add changes to Makefile
kelleyde 1db449a
TaskValue events tests
kelleyde 7864ddc
update task-value events tests, ProgramBuilder.h, add event json files
kelleyde ff4400a
fix typo in comment ProgramBuilder CreateNANDProgram
kelleyde d9dc96b
fixing merge conflicts with all the other updates to main
anyaevostinar b766f82
fixing last merge conflict remnants
anyaevostinar 6ee9e79
Merge pull request #2 from anyaevostinar/kelleyde-sgp-copy
kelleyde 319b50e
Merge main into event system pr branch
amlalejini f1bafd1
Fix unresolved merge conflict from prev merge
amlalejini 470cea2
Add function docstrings to json utils
amlalejini 136fb65
Add doc strings for Event.h
amlalejini 8280e06
Add doc strings in ExampleEvent.h
amlalejini 2af3c7f
Add docstrings for TaskValueEvent
amlalejini 8bf8757
Add doc strings to EventManager
amlalejini f1733cc
Add doc strings to EventTiming
amlalejini a048db0
Add doc strings to EventTypeDefinition
amlalejini 4b93164
Add doc strings for EventTypeLibrary
amlalejini 4a3425a
Update variable names for readability in Event.h as per PR review
amlalejini 5e34461
Update events tests
amlalejini de892e5
Update spacing for consistency
amlalejini 4cd9759
Merge branch 'main' into sgp-copy
amlalejini 537df74
Add events file cfg to sgpmode tests, fix pointer that wasn't being d…
amlalejini 37ed4ee
Add no-events.json events file
amlalejini 9a8a494
Fix issues with config files not being found, add emp_assert to make …
amlalejini 3b3887f
Merge pull request #3 from amlalejini/sgp-copy
kelleyde 27aa395
Merge branch 'main' into sgp-copy
anyaevostinar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,5 +25,6 @@ log.txt | |
| *.json | ||
| *_test_output/ | ||
| *_output/ | ||
| Data/* | ||
|
|
||
|
|
||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #pragma once | ||
|
|
||
| #include "json.hpp" | ||
|
|
||
| #include "emp/base/vector.hpp" | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace sym_json { | ||
|
|
||
| /** | ||
| * Purpose: Convenience function for more easily getting a value from a json field | ||
| * with a default return value if the field doesn't exist. | ||
| * | ||
| * Input: json object to access, field to access in json object, and a default | ||
| * value to return if the field doesn't exist in the json object. | ||
| * | ||
| * Output: Either the accessed field value or the provided default value. | ||
| * | ||
| */ | ||
| template<typename RET_TYPE> | ||
| RET_TYPE GetVal( | ||
| nlohmann::json& json, | ||
| const std::string& field, | ||
| RET_TYPE default_val | ||
| ) { | ||
| return (json.contains(field)) ? | ||
| static_cast<RET_TYPE>(json[field]) : | ||
| default_val; | ||
| } | ||
|
|
||
| /** | ||
| * Purpose: Convenience function for more easily getting a value from a json field. | ||
| * This version of the GetVal function assumes that the field exists. | ||
| * | ||
| * Input: json object to access, field to access in json object | ||
| * | ||
| * Output: The accessed field value | ||
| * | ||
| */ | ||
| template<typename RET_TYPE> | ||
| RET_TYPE GetVal( | ||
| nlohmann::json& json, | ||
| const std::string& field | ||
| ) { | ||
| emp_assert(json.contains(field)); | ||
| return static_cast<RET_TYPE>(json[field]); | ||
| } | ||
|
|
||
| /** | ||
| * Purpose: Validate that specified strings exist as fields inside of a json object. | ||
| * This function is useful for asserting that required/expected fields | ||
| * exist. | ||
| * | ||
| * Input: json object to check, fields to check in json object | ||
| * | ||
| * Output: Boolean indicating whether all given fields are contained in the json | ||
| * object. | ||
| * | ||
| */ | ||
| bool ValidateFieldsJSON( | ||
| const nlohmann::json& json_line, | ||
| const emp::vector<std::string>& fields | ||
| ) { | ||
| for (const std::string& name : fields) { | ||
| if (!json_line.contains(name)) { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| #include "hardware/SGPHardwareSpec.h" | ||
| #include "hardware/GenomeLibrary.h" | ||
| #include "hardware/SGPHardware.h" | ||
| #include "events/EventManager.h" | ||
|
|
||
| #include "emp/Evolve/World_structure.hpp" | ||
| #include "emp/data/DataNode.hpp" | ||
|
|
@@ -49,6 +50,7 @@ class SGPWorld : public SymWorld { | |
| using task_io_t = typename task_io_bank_t::TaskIO; | ||
| using mutator_t = SGPMutator<sgp_prog_t, Library>; | ||
| using sgp_prog_rectifier_t = sgpl::OpCodeRectifier<Library>; | ||
| using event_manager_t = EventManager<SGPWorld>; | ||
|
|
||
| using fun_sym_do_birth_t = std::function<emp::WorldPosition( | ||
| emp::Ptr<sgp_sym_t>, /* symbiont baby ptr */ | ||
|
|
@@ -381,6 +383,7 @@ class SGPWorld : public SymWorld { | |
| size_t max_world_size; // Maximum number of locations in the world | ||
| ReproductionQueue repro_queue; // Stores which organisms are queued for reproduction | ||
| tasks::LogicTaskEnvironment task_env; // Manages task set, task requirements, and task rewards | ||
| event_manager_t event_manager; | ||
| // TODO - Consider having symbiont rectifier and host rectifier | ||
| // -> Symbiont-specific instructions wouldn't be in host's instruction set | ||
| sgp_prog_rectifier_t opcode_rectifier; // Used to "disable" instructions at runtime based on run configuration | ||
|
|
@@ -549,6 +552,7 @@ class SGPWorld : public SymWorld { | |
| void SetupFindHostForHorizontalTransmission(); | ||
| void SetupHostSymInteractions(); | ||
| void SetupTaskEnvironment(); | ||
| void SetupEvents(); | ||
| void SetupMutator(); | ||
| void SetupStressInteractions(); | ||
| void SetupHealthInteractions(); | ||
|
|
@@ -576,7 +580,6 @@ class SGPWorld : public SymWorld { | |
| } | ||
|
|
||
|
|
||
|
|
||
| // Utility function to get cpu state from an org pointer | ||
| sgp_cpu_peripheral_t& GetCPUState(emp::Ptr<Organism> org_ptr) { | ||
| return (org_ptr->IsHost()) ? | ||
|
|
@@ -660,12 +663,22 @@ class SGPWorld : public SymWorld { | |
| size_t GetTaskCount() const { return task_env.GetTaskCount(); } | ||
|
|
||
| /* Accessor for host task profiles */ | ||
| const emp::BitVector& GetHostTaskProfile(const sgp_host_t& host){return fun_get_host_task_profile(host);} | ||
| const emp::BitVector& GetHostTaskProfile(const sgp_host_t& host) { return fun_get_host_task_profile(host); } | ||
|
|
||
| /* Accessor for symbiont task profiles */ | ||
| const emp::BitVector& GetSymbiontTaskProfile(const sgp_sym_t& symbiont){return fun_get_sym_task_profile(symbiont);} | ||
| const emp::BitVector& GetSymbiontTaskProfile(const sgp_sym_t& symbiont) { return fun_get_sym_task_profile(symbiont); } | ||
|
|
||
| /** | ||
| * Purpose: Accessor for event manager (const) | ||
| */ | ||
| const event_manager_t& GetEventManager() const { return event_manager; } | ||
|
|
||
| /** | ||
| /** | ||
| * Purpose: Accessor for event manager | ||
| */ | ||
| event_manager_t& GetEventManager() { return event_manager; } | ||
|
|
||
| /** | ||
| * Input: A host, a symbiont, the value of a task before applying nutrient interaction, and the task id. | ||
| * Output: The change in the points the host will gain from the task after the nutrient interaction. | ||
| * Purpose: To calculate the configured nutrient interaction for the given symbiont and task | ||
|
|
@@ -824,6 +837,10 @@ class SGPWorld : public SymWorld { | |
| */ | ||
| void Update() override { | ||
| emp_assert(setup); | ||
| // NOTE - When do we want events to occur? Typically, I think we want them | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, I think they have to just be the first thing that happens in an update. So let's remove the comment |
||
| // as the *very* first thing that happens on an update. E.g., changing | ||
| // a task value, etc. | ||
| event_manager.ProcessEvents(*this); | ||
| begin_update_sig.Trigger(); | ||
| // Handle resource inflow | ||
| // TODO - implement inflow configuration | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably clearly call it 'SenseTask' so that it's obvious what the name of the instruction is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, totally agree. Just in case there are future enable/disable config options, what about
INCLUDE_INSTRUCTION_SenseTask? to make it super clear what we're toggling