Skip to content
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

Changes to Systematics manager to support MABE #451

Merged
merged 142 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
7db913f
Merge branch 'master' into mabe-systematics
emilydolson Feb 28, 2023
576a7a0
Add span-lite back in (not sure how it got remove)
emilydolson Feb 28, 2023
f5210eb
remove span-lite again
emilydolson Feb 28, 2023
4636ce4
Fix tidy include
emilydolson Feb 28, 2023
14bff00
Get rid of extraneous bracket
emilydolson Feb 28, 2023
cc05c56
Fix boiler plate
emilydolson Feb 28, 2023
249cba7
Fix trailing whitespace
emilydolson Feb 28, 2023
b647081
Fix license
emilydolson Feb 28, 2023
47e6222
Make bitset_utils compile in clang
emilydolson Feb 28, 2023
96343e4
remove extra bracket
emilydolson Feb 28, 2023
24b4fda
Fix alphabetization
emilydolson Feb 28, 2023
d6ec8e9
Fix bits destructor
emilydolson Feb 28, 2023
b6ecd90
Fix newlines at end of files
emilydolson Feb 28, 2023
939a928
Fix variable name
emilydolson Feb 28, 2023
e69a188
Maybe fix span
emilydolson Feb 28, 2023
5ba7bd4
Temporary workaround because span doesn't have a constructor for emp …
emilydolson Mar 1, 2023
0d268b8
Switch SmallFifoMap to std array
emilydolson Mar 1, 2023
18e2884
Fix trailing whitespace
emilydolson Mar 1, 2023
5fcaab8
Merge branch 'MABE_devel' into mabe-systematics
emilydolson Mar 1, 2023
70ac008
Change test to reflect changes to slice
emilydolson Mar 1, 2023
c029285
Fix bug where 1s outside part of bitstring containing numberare being…
emilydolson Mar 1, 2023
6dbeb87
Temporarily swap in std::array in a couple spots
emilydolson Mar 1, 2023
8a7e5d8
view_slices no longer includes trailing EOF
emilydolson Mar 1, 2023
7b689c1
Update web test tool chain
emilydolson Mar 1, 2023
89d27f4
CountOnes was removed, so remove tests for it
emilydolson Mar 1, 2023
fed868a
Remove make command for EmphaticText because there is no EmphaticText…
emilydolson Mar 1, 2023
930f208
Behavior has changed due to new slice implementation - commented test…
emilydolson Mar 1, 2023
9c58ba2
Update slice tests to match new behavior
emilydolson Mar 1, 2023
533519a
Fix whitespace
emilydolson Mar 1, 2023
c2a6e71
Restore original behavior of slice
emilydolson Mar 1, 2023
55390fb
Fix whitespace
emilydolson Mar 1, 2023
9f0f2da
Possibly working version?
emilydolson Mar 7, 2023
0675839
Add preliminary tests + bug fixes to phylo import
emilydolson Mar 7, 2023
d3b0ec6
Fix trailing whitespace
emilydolson Mar 7, 2023
5bb3f08
Fix tidying
emilydolson Mar 7, 2023
15321f7
Fix clang compilation error
emilydolson Mar 7, 2023
5972800
Fix trailing whitespace
emilydolson Mar 7, 2023
dbf012d
Add test ensuring file save and load are identical
rodsan0 Mar 7, 2023
de128c9
Add some assets for load/save test
rodsan0 Mar 7, 2023
8502ed8
Store tracked phenotype to file
rodsan0 Mar 7, 2023
c46e604
Comment out broken tests
rodsan0 Mar 7, 2023
fda8efe
Org info is type string
rodsan0 Mar 7, 2023
9952d31
Origination and destruction time are optional
emilydolson Mar 7, 2023
f9d6b22
Fix total offspring and depth
emilydolson Mar 7, 2023
8f65891
Merge branch 'mabe-systematics' of github.com:devosoft/Empirical into…
emilydolson Mar 7, 2023
dbd17b4
Fix trailing whitespace
emilydolson Mar 7, 2023
f0f9517
Add comments
emilydolson Mar 7, 2023
5dd3e8c
Read num_orgs and tot_orgs from file, if present
rodsan0 Mar 8, 2023
f439620
Add total_offspring tests
emilydolson Mar 8, 2023
80f2e64
Origin and destruction time are doubles
emilydolson Mar 8, 2023
258767e
Merge branch 'mabe-systematics' of github.com:devosoft/Empirical into…
emilydolson Mar 8, 2023
cbc7e16
Add degree distribution + fix loading total_offspring
emilydolson Mar 8, 2023
c49c548
Add GetAverageOriginTime
emilydolson Mar 9, 2023
e46fa2b
Fix trailing whitespace
emilydolson Mar 9, 2023
d836675
Add docstrings
emilydolson Mar 9, 2023
bb90c6c
Revert range changes that clang cant handle
emilydolson Mar 9, 2023
6ba8421
fix constness
emilydolson Mar 9, 2023
e01b3ec
remove ranges include
emilydolson Mar 9, 2023
40dc072
Temporarily swap in std library log2
emilydolson Mar 9, 2023
fe6c456
Speed up loading
emilydolson Mar 9, 2023
e770848
Remove todo; keeping a set of ancestor pointers is cheap and necessar…
emilydolson Mar 9, 2023
5222ec6
Add ability to configure total offspring; assume extant orgs have pop…
emilydolson Mar 9, 2023
82f5932
Add org_count and total_depth to load
emilydolson Mar 9, 2023
a56c167
Add evolutionary distinctiveness functions
emilydolson Mar 9, 2023
9c25c55
Fix evolutionary distinctiveness functions
emilydolson Mar 9, 2023
0dcfad4
Fix trailing whitespace
emilydolson Mar 9, 2023
77f1eed
Get rid of test for large file
emilydolson Mar 9, 2023
afb7a41
Merge branch 'mabe-systematics' of github.com:devosoft/Empirical into…
emilydolson Mar 9, 2023
8658616
Fix catch version
emilydolson Mar 9, 2023
f11e64a
Fix force-cover version
emilydolson Mar 9, 2023
09466e4
On no parent id, return string that python can eval()
rodsan0 Mar 10, 2023
e9be868
Fix capitalization of NONE
rodsan0 Mar 10, 2023
5ad8697
Do not remove whitespace when parsing file
rodsan0 Mar 10, 2023
b386769
Do not call emp::from_string when ORG_INFO is str
rodsan0 Mar 10, 2023
a72c1f1
Actually run tests
rodsan0 Mar 10, 2023
96717aa
Include algorithm library
emilydolson Apr 11, 2023
9524e33
Add get NK fitness
emilydolson Jun 3, 2023
ae7a26d
Merge branch 'master' into mabe-systematics
emilydolson Jun 11, 2023
1578787
Fix tabs
emilydolson Jun 11, 2023
881fbf5
Add assert throw for use with Python
emilydolson Nov 17, 2023
f02249f
Swap systematics to optional_throw
emilydolson Nov 17, 2023
2173dc5
Change python_throw to optional_throw
emilydolson Nov 18, 2023
1604d6f
Fix redeclaration
emilydolson Nov 18, 2023
aeed4ee
Add test for optional_throw
emilydolson Nov 18, 2023
ed27152
Fix optional throw
emilydolson Nov 18, 2023
205b566
Edit error message
emilydolson Nov 26, 2023
9d8f4c4
Add windows version of optional_throw
emilydolson Nov 26, 2023
2412737
Allow just message for optional throw
emilydolson Nov 26, 2023
f0d9d42
Fix windows optional_throw
emilydolson Nov 26, 2023
2a00356
Avoid windows type confusion
emilydolson Nov 26, 2023
b4e3996
Avoid windows type confusion
emilydolson Nov 26, 2023
87cad79
Avoid windows type confusion
emilydolson Nov 26, 2023
a87e569
Fix windows optional_throw
emilydolson Nov 26, 2023
7448a41
Fix windows optional_throw
emilydolson Nov 26, 2023
5428ebb
Fix windows optional_throw
emilydolson Nov 26, 2023
6626860
Fix windows optional_throw
emilydolson Nov 26, 2023
58c6d81
Fix windows optional_throw
emilydolson Nov 26, 2023
d62b475
Add method to get pairwise distance between one pair of taxa
emilydolson Dec 2, 2023
e750878
Fix segfault in load
emilydolson Dec 5, 2023
9a853af
Implement, test GetSumDistance member for Systematics
mmore500 Feb 27, 2024
8301ddc
Merge in master
emilydolson Feb 28, 2024
8f10adf
Merge branch 'mabe-systematics' into sum-distance-sys
emilydolson Feb 28, 2024
1e542a3
Reintegrate necessary changes to world.hpp
emilydolson Feb 29, 2024
1b323cf
Merge branch 'mabe-systematics' into sum-distance-sys
emilydolson Feb 29, 2024
2d7b807
Clean up optional throw
emilydolson Feb 29, 2024
cad65b0
Fix trailing whitespace
emilydolson Feb 29, 2024
9f73a69
Fix alphabetize includes
emilydolson Feb 29, 2024
99386bd
Fix docstrings
emilydolson Feb 29, 2024
2a90a30
Fix headergaurd
emilydolson Feb 29, 2024
ab563bf
Fix license
emilydolson Feb 29, 2024
f11a154
Merge branch 'mabe-systematics' into sum-distance-sys
emilydolson Feb 29, 2024
136a7f2
Fix tabs
emilydolson Feb 29, 2024
0fc3e62
Fix opt test case
emilydolson Feb 29, 2024
c416384
Merge branch 'mabe-systematics' into sum-distance-sys
emilydolson Feb 29, 2024
dca7b0c
Pull includes out of header
emilydolson Feb 29, 2024
96dc6ed
Merge branch 'mabe-systematics' into sum-distance-sys
emilydolson Feb 29, 2024
279944f
Remove defunct tests
emilydolson Feb 29, 2024
46610db
Merge branch 'mabe-systematics' into sum-distance-sys
emilydolson Feb 29, 2024
915bc4c
Fix tests
emilydolson Feb 29, 2024
d34e95a
Add bounds checking
emilydolson Feb 29, 2024
98a114f
Discard changes to include/emp/datastructs/SmallFifoMap.hpp
emilydolson Feb 29, 2024
a3e835a
Discard changes to include/emp/hardware/AvidaGP.hpp
emilydolson Feb 29, 2024
786e74d
Discard changes to include/emp/hardware/EventDrivenGP.hpp
emilydolson Feb 29, 2024
9bbc8f8
Discard changes to include/emp/bits/Bits.hpp
emilydolson Feb 29, 2024
8e61986
Discard changes to tests/tools/string_utils.cpp
emilydolson Feb 29, 2024
e65d525
Discard changes to tests/text/Makefile
emilydolson Feb 29, 2024
5abbf48
Discard changes to tests/matching/MatchBin_logging.cpp
emilydolson Feb 29, 2024
184ae28
Merge pull request #507 from devosoft/sum-distance-sys
emilydolson Feb 29, 2024
a0b6ecc
Merge branch 'mabe-systematics' of https://github.com/devosoft/Empiri…
emilydolson Feb 29, 2024
746d050
Update include/emp/Evolve/Systematics.hpp
emilydolson Mar 1, 2024
0c79c80
Update include/emp/Evolve/Systematics.hpp
emilydolson Mar 1, 2024
bbff40c
Little cleanups
emilydolson Mar 2, 2024
97c59cf
Merge branch 'mabe-systematics' of github.com:devosoft/Empirical into…
emilydolson Mar 2, 2024
4b422e5
Strip trailing whitespace
emilydolson Mar 2, 2024
b0c9e70
Update include/emp/Evolve/Systematics.hpp
emilydolson Mar 2, 2024
dd09c54
Swap in ternary
emilydolson Mar 2, 2024
c362b78
Merge branch 'mabe-systematics' of github.com:devosoft/Empirical into…
emilydolson Mar 2, 2024
02c7992
Update include/emp/Evolve/Systematics.hpp
emilydolson Mar 2, 2024
6974ac0
Minor fixes
emilydolson Mar 2, 2024
7132965
Merge
emilydolson Mar 2, 2024
b58329a
Merge
emilydolson Mar 2, 2024
9e7165a
Change variable name to defaulted
emilydolson Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/emp/Evolve/NK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,21 @@ namespace emp {
return GetFitness(n, cur_val);
}

/// Get the fitness of a whole bitstring (pass by value so can be modified.)
emp::vector<double> GetFitnesses(emp::BitVector genome) const {
// Use a double-length genome to easily handle wrap-around.
genome.Resize(N*2);
genome |= (genome << N);
emp::vector<double> fits;

size_t mask = emp::MaskLow<size_t>(K+1);
for (size_t i = 0; i < N; i++) {
const size_t cur_val = (genome >> i).GetUInt(0) & mask;
const double cur_fit = GetFitness(i, cur_val);
fits.push_back(cur_fit);
}
return fits;
}

void SetState(size_t n, size_t state, double in_fit) { landscape[n][state] = in_fit; }

Expand Down
2,293 changes: 1,445 additions & 848 deletions include/emp/Evolve/Systematics.hpp

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions include/emp/Evolve/World.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ namespace emp {

};

#ifndef DOXYGEN_SHOULD_SKIP_THIS
// =============================================================
// === ===
// === Out-of-class member function definitions from above ===
Expand Down Expand Up @@ -972,7 +973,7 @@ namespace emp {

// Track the new systematics info
for (Ptr<SystematicsBase<ORG> > s : systematics) {
s->AddOrg(*new_org, pos, (int) update);
s->AddOrg(*new_org, pos);
}

SetupOrg(*new_org, pos, *random_ptr);
Expand All @@ -996,7 +997,7 @@ namespace emp {
}

for (Ptr<SystematicsBase<ORG> > s : systematics) {
s->RemoveOrgAfterRepro(pos, update); // Notify systematics about organism removal
s->RemoveOrgAfterRepro(pos); // Notify systematics about organism removal
}

}
Expand Down Expand Up @@ -1489,6 +1490,13 @@ namespace emp {
pop.resize(0);
std::swap(pops[0], pops[1]); // Move next pop into place.

// Tell systematics manager to swap next population and population
// Needs to happen here so that you can refer to systematics in
// OnPlacement functions
for (Ptr<SystematicsBase<ORG>> s : systematics) {
s->Update();
}

// Update the active population.
num_orgs = 0;
for (size_t i = 0; i < pop.size(); i++) {
Expand All @@ -1498,12 +1506,7 @@ namespace emp {
}
}

// 3. Handle systematics and any data files that need to be printed this update.

// Tell systematics manager to swap next population and population
for (Ptr<SystematicsBase<ORG>> s : systematics) {
s->Update();
}
// 3. Handle any data files that need to be printed this update.

for (auto file : files) file->Update(update);

Expand Down Expand Up @@ -1734,6 +1737,7 @@ namespace emp {
os << std::endl;
}
}
#endif // DOXYGEN_SHOULD_SKIP_THIS
}

#endif // #ifndef EMP_EVOLVE_WORLD_HPP_INCLUDE
1 change: 1 addition & 0 deletions include/emp/base/_assert_macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define emp_assert_STRINGIFY_IMPL(...) #__VA_ARGS__
#define emp_assert_TO_PAIR(X) emp_assert_STRINGIFY(X) , X
#define emp_assert_GET_ARG_1(a, ...) a
#define emp_assert_GET_ARG_2(a,b, ...) b
#define emp_assert_GET_ARG_21(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t, u, ...) u
#define emp_assert_MERGE(A, B) A ## B
#define emp_assert_ASSEMBLE(BASE, ARG_COUNT, ...) emp_assert_MERGE(BASE, ARG_COUNT) (__VA_ARGS__)
Expand Down
60 changes: 60 additions & 0 deletions include/emp/base/_optional_throw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @file
* @brief Implementation of emp_optional_throw.
*/

#ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE
#define EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE

#include <sstream>
#include <string>

#include "_is_streamable.hpp"

namespace emp {

/// Base case for assert_print...
inline void assert_print_opt(std::stringstream &) { ; }

/// Print out information about the next variable and recurse...
template <typename T, typename... EXTRA>
void assert_print_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T, typename... EXTRA>
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T>
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val) {;}

template <typename T, typename... EXTRA>
void assert_print_first_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_second_opt(ss, std::forward<EXTRA>(extra)...);
}

void assert_print_first_opt(std::stringstream & ss, int placeholder) {;}

template <typename... EXTRA>
void assert_throw_opt(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) {
std::stringstream ss;
ss << "Internal Error (in " << filename << " line " << line << "): " << expr << ".\n\n Message: " << message << "\n\n";
assert_print_first_opt(ss, std::forward<EXTRA>(extra)...);
throw(std::runtime_error(ss.str()));
}
}

#endif // #ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE
14 changes: 14 additions & 0 deletions include/emp/base/always_assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "_assert_macros.hpp"
#include "_assert_trigger.hpp"
#include "_optional_throw.hpp"

#if defined( __EMSCRIPTEN__ )

Expand All @@ -58,6 +59,19 @@

#define emp_always_assert_impl(TEST) emp_always_assert_msvc_impl(TEST)

#elif defined(EMP_OPTIONAL_THROW_ON)

#define emp_always_assert_impl(...) \
do { \
if (!(emp_assert_GET_ARG_1(__VA_ARGS__, ~))) { \
emp::assert_throw( \
__FILE__, __LINE__, \
emp_assert_STRINGIFY( emp_assert_GET_ARG_1(__VA_ARGS__, ~), ), \
emp_assert_TO_PAIRS(__VA_ARGS__)); \
} \
} while(0)


#else

#define emp_always_assert_impl(...) \
Expand Down
70 changes: 70 additions & 0 deletions include/emp/base/optional_throw.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of Empirical, https://github.com/devosoft/Empirical
* Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* date: 2024
*/
/**
* @file
* @brief A version of emp_assert that throws a runtime error if compiled with -DEMP_OPTIONAL_THROW_ON.
*
* This is useful if you want the option to throw a runtime error outside of debug mode. A common use
* case is wrapping C++ code in Python, since segfaults kill the entire Python interpreter.
*/

#ifndef EMP_BASE_OPTIONAL_THROW_HPP_INCLUDE
#define EMP_BASE_OPTIONAL_THROW_HPP_INCLUDE

#include "assert.hpp"

/// NDEBUG should trigger its EMP equivalent.
#ifdef NDEBUG
#define EMP_NDEBUG
#endif


#if defined( EMP_OPTIONAL_THROW_ON )

// #if defined (_MSC_VER )

#define emp_optional_throw(TEST, MESSAGE) \
do { \
if (!(TEST)) { \
emp::assert_throw_opt(__FILE__, __LINE__, #TEST, MESSAGE, 0); \
} \
} while(0)

/* #define emp_optional_throw_impl(TEST, MESSAGE) emp_optional_throw_mscv_impl(TEST, MESSAGE)

/ #else

/ #define emp_optional_throw_impl(...) \
/ do { \
/ if (!(emp_assert_GET_ARG_1(__VA_ARGS__, ~))) { \
/ emp::assert_throw( \
/ __FILE__, __LINE__, \
/ emp_assert_STRINGIFY( emp_assert_GET_ARG_1(__VA_ARGS__, ~), ), \
/ emp_assert_STRINGIFY( emp_assert_GET_ARG_2(__VA_ARGS__, ~), ), \
/ emp_assert_TO_PAIRS(__VA_ARGS__)); \
/ } \
/ } while(0)

/ #endif

/ #define emp_optional_throw(...) emp_optional_throw_impl(__VA_ARGS__)
*/
#elif defined( EMP_NDEBUG )

#define emp_optional_throw(...)

#else
/// Require a specified condition to be true. If it is false, immediately
/// halt execution. Print also extra information on any variables or
/// expressions provided as variadic args. Note: If NDEBUG is defined,
/// emp_assert() will not do anything. Due to macro parsing limitations, extra
/// information will not be printed when compiling with MSVC.
#define emp_optional_throw(...) emp_assert(__VA_ARGS__)

#endif


#endif // #ifndef EMP_BASE_OPTIONAL_THROW_HPP_INCLUDE
4 changes: 4 additions & 0 deletions include/emp/data/DataManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ namespace emp {
return Has(node_map, name);
}

bool HasNoNode(const std::string & name) {
return !Has(node_map, name);
}

/// Creates and adds a new DataNode
/// @param name the name of the DataNode
node_t & New(const std::string & name) {
Expand Down
13 changes: 13 additions & 0 deletions include/emp/datastructs/map_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ namespace emp {
return in_map.find(key) != in_map.end();
}

/// Take a map where the value is an integer and a key.
/// Increment value associated with that key if its present
/// or if its not add it and set it to 1
template <class MAP_T, class KEY_T>
inline void IncrementCounter( MAP_T & in_map, const KEY_T & key ) {
mmore500 marked this conversation as resolved.
Show resolved Hide resolved
static_assert( std::is_same< typename MAP_T::key_type, int >::value);
if (emp::Has(in_map, key)) {
mmore500 marked this conversation as resolved.
Show resolved Hide resolved
in_map[key]++;
} else {
in_map[key] = 1;
}
}

// Check to see if any of the elements in a map satisfy a function.
template <typename KEY_T, typename ELEMENT_T, typename FUN_T>
bool AnyOf(const std::map<KEY_T, ELEMENT_T> & c, FUN_T fun) {
Expand Down
2 changes: 1 addition & 1 deletion include/emp/math/info_theory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace emp {
double entropy = 0.0;
for (auto & o : objs) {
double p = ((double) fun(o)) / total;
entropy -= p * Log2(p);
entropy -= p * log2(p);
}
return entropy;
}
Expand Down
Loading
Loading