Skip to content

Commit

Permalink
Record stint root id changeovers
Browse files Browse the repository at this point in the history
  • Loading branch information
mmore500 committed May 30, 2021
1 parent 712dcce commit 66d623e
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 7 deletions.
24 changes: 20 additions & 4 deletions include/dish2/algorithm/seed_genomes_into.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <algorithm>

#include "../../../third-party/conduit/include/uitsl/algorithm/for_each.hpp"
#include "../../../third-party/Empirical/include/emp/base/optional.hpp"
#include "../../../third-party/Empirical/include/emp/base/vector.hpp"
#include "../../../third-party/Empirical/include/emp/math/random_utils.hpp"
#include "../../../third-party/signalgp-lite/include/sgpl/introspection/count_modules.hpp"
Expand All @@ -13,12 +14,13 @@
#include "../cell/Cell.hpp"
#include "../config/cfg.hpp"
#include "../enum/CauseOfDeath.hpp"
#include "../record/StintRootIDChangeoverRecorder.hpp"
#include "../world/iterators/LiveCellIterator.hpp"
#include "../world/ThreadWorld.hpp"

namespace dish2 {

template< typename Spec >
template< typename Spec, bool record_stint_root_id_changeover=false >
void seed_genomes_into(
emp::vector< emp::vector<dish2::Genome<Spec>> > seed_buckets,
dish2::ThreadWorld<Spec>& world
Expand Down Expand Up @@ -61,22 +63,34 @@ void seed_genomes_into(
// shuffle incoming_population...
emp::Shuffle( sgpl::tlrand.Get(), incoming_population );

emp::optional<dish2::StintRootIDChangeoverRecorder> recorder;
if constexpr ( record_stint_root_id_changeover ) recorder.emplace();

// ... then inject into ThreadWorld's population
uitsl::for_each(
std::begin( incoming_population ), std::end( incoming_population ),
std::begin( population ),
[]( const auto& seed, auto& cell ){
[&recorder]( const auto& seed, auto& cell ){
cell.genome = seed;
cell.genome->SetupSeededGenotype();
cell.MakeAliveRoutine();

if constexpr (
record_stint_root_id_changeover
) recorder->record_changeover(
seed.root_id.GetID(),
seed.stint_root_id.GetID(),
cell.genome->stint_root_id.GetID()
);

}
);

}

}

template< typename Spec >
template< typename Spec, bool record_stint_root_id_changeover=false >
void seed_genomes_into(
const emp::vector< dish2::Genome<Spec> >& seeds,
dish2::ThreadWorld<Spec>& world
Expand All @@ -90,7 +104,9 @@ void seed_genomes_into(
[]( const auto& seed ){ return emp::vector<dish2::Genome<Spec>>{ seed }; }
);

dish2::seed_genomes_into<Spec>( seed_buckets, world );
dish2::seed_genomes_into<Spec, record_stint_root_id_changeover>(
seed_buckets, world
);

}

Expand Down
2 changes: 1 addition & 1 deletion include/dish2/load/innoculate_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void innoculate_population( dish2::ThreadWorld<Spec>& world ) {
}(), emp::to_string( innoculum_paths ));


dish2::seed_genomes_into<Spec>( innoculum_buckets, world );
dish2::seed_genomes_into<Spec, true>( innoculum_buckets, world );

dish2::log_msg( "loaded ", innoculum_buckets.size(), " innoculum buckets" );

Expand Down
2 changes: 1 addition & 1 deletion include/dish2/load/monoculture_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void monoculture_population( dish2::ThreadWorld<Spec>& world ) {

dish2::log_msg( " loaded monoculture from ", monoculture_paths.front() );

dish2::seed_genomes_into<Spec>( {monoculture}, world );
dish2::seed_genomes_into<Spec, true>( {monoculture}, world );

dish2::log_msg( "applied monoculture" );

Expand Down
2 changes: 1 addition & 1 deletion include/dish2/load/reconstitute_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void reconstitute_population( dish2::ThreadWorld<Spec>& world ) {

dish2::log_msg("reconstituted ", reconstituted.size(), " cells from ", src);

dish2::seed_genomes_into<Spec>( reconstituted, world );
dish2::seed_genomes_into<Spec, true>( reconstituted, world );

}

Expand Down
94 changes: 94 additions & 0 deletions include/dish2/record/StintRootIDChangeoverRecorder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once
#ifndef DISH2_RECORD_STINTROOTIDCHANGEOVERRECORDER_HPP_INCLUDE
#define DISH2_RECORD_STINTROOTIDCHANGEOVERRECORDER_HPP_INCLUDE

#include <string>

#include "../../../third-party/bxzstr/include/bxzstr.hpp"
#include "../../../third-party/conduit/include/uitsl/mpi/comm_utils.hpp"
#include "../../../third-party/Empirical/include/emp/data/DataFile.hpp"
#include "../../../third-party/Empirical/include/emp/tools/keyname_utils.hpp"
#include "../../../third-party/Empirical/include/emp/tools/string_utils.hpp"
#include "../../../third-party/signalgp-lite/include/sgpl/utility/CountingIterator.hpp"

#include "../config/has_replicate.hpp"
#include "../config/has_series.hpp"
#include "../config/has_stint.hpp"
#include "../config/thread_idx.hpp"
#include "../debug/log_msg.hpp"
#include "../utility/pare_keyname_filename.hpp"

#include "make_filename/make_data_path.hpp"
#include "make_filename/make_stint_root_id_changeover_filename.hpp"


namespace dish2 {

class StintRootIDChangeoverRecorder {

std::string outpath;
bxz::ofstream ofstream;
emp::DataFile file;

// thread_local so that copying/moving doesn't break DataFile refs
inline static thread_local uint64_t root_id_;
inline static thread_local uint64_t incoming_stint_root_id_;
inline static thread_local uint64_t outgoing_stint_root_id_;

public:

StintRootIDChangeoverRecorder()
: outpath(
dish2::make_data_path(
dish2::pare_keyname_filename(
dish2::make_stint_root_id_changeover_filename(),
dish2::make_data_path()
)
)
)
, ofstream(
outpath, bxz::lzma, 6
)
, file( ofstream ) {

if ( dish2::has_stint() ) file.AddVal(cfg.STINT(), "Stint");
if ( dish2::has_series() ) file.AddVal(cfg.SERIES(), "Series");
if ( dish2::has_replicate() ) file.AddVal(cfg.REPLICATE(), "Replicate");
file.AddVal(cfg.TREATMENT(), "Treatment");
if ( cfg.TREATMENT().find('=') != std::string::npos ) {
for ( const auto& [k, v] : emp::keyname::unpack( cfg.TREATMENT() ) ) {
file.AddVal( v, emp::to_string("Treatment ", k) );
}
}
file.AddVal( uitsl::get_proc_id(), "proc" );
file.AddVal( dish2::thread_idx, "thread" );

file.AddVar(root_id_, "Root ID");
file.AddVar(incoming_stint_root_id_, "Incoming Stint Root ID");
file.AddVar(outgoing_stint_root_id_, "Outgoing Stint Root ID");

file.PrintHeaderKeys();

dish2::log_msg( "initialized stint_root_id record at ", outpath );

}

void record_changeover(
const uint64_t root_id,
const uint64_t incoming_stint_root_id,
const uint64_t outgoing_stint_root_id
) {

root_id_ = root_id;
incoming_stint_root_id_ = incoming_stint_root_id;
outgoing_stint_root_id_ = outgoing_stint_root_id;

file.Update();

}

};

} // namespace dish2

#endif // #ifndef DISH2_RECORD_STINTROOTIDCHANGEOVERRECORDER_HPP_INCLUDE
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#pragma once
#ifndef DISH2_RECORD_MAKE_FILENAME_MAKE_STINT_ROOT_ID_CHANGEOVER_FILENAME_HPP_INCLUDE
#define DISH2_RECORD_MAKE_FILENAME_MAKE_STINT_ROOT_ID_CHANGEOVER_FILENAME_HPP_INCLUDE

#include <cstdlib>
#include <string>

#include "../../../../third-party/conduit/include/uitsl/mpi/comm_utils.hpp"
#include "../../../../third-party/Empirical/include/emp/base/macros.hpp"
#include "../../../../third-party/Empirical/include/emp/tools/keyname_utils.hpp"
#include "../../../../third-party/Empirical/include/emp/tools/string_utils.hpp"

#include "../../config/cfg.hpp"
#include "../../config/get_endeavor.hpp"
#include "../../config/get_repro.hpp"
#include "../../config/get_slurm_job_id.hpp"
#include "../../config/has_replicate.hpp"
#include "../../config/has_series.hpp"
#include "../../config/has_stint.hpp"
#include "../../config/thread_idx.hpp"

namespace dish2 {

std::string make_stint_root_id_changeover_filename() {
auto keyname_attributes = emp::keyname::unpack_t{
{"a", "stint_root_id_changeover"},
{"proc", emp::to_string( uitsl::get_proc_id() )},
{"_source", EMP_STRINGIFY(DISHTINY_HASH_)},
{"thread", emp::to_string( dish2::thread_idx )},
{"_treatment", emp::keyname::demote( dish2::cfg.TREATMENT() )},
{"ext", ".csv.xz"}
};

if ( dish2::get_repro() ) {
keyname_attributes[ "_repro" ] = *dish2::get_repro();
}

if ( dish2::has_series() ) {
keyname_attributes[ "series" ] = emp::to_string( cfg.SERIES() );
}

if ( dish2::has_stint() ) {
keyname_attributes[ "stint" ] = emp::to_string( cfg.STINT() );
}

if ( dish2::has_replicate() ) {
keyname_attributes[ "replicate" ] = cfg.REPLICATE();
}

if ( dish2::get_endeavor() ) {
keyname_attributes[ "_endeavor" ] = emp::to_string(*dish2::get_endeavor());
}

if ( dish2::get_slurm_job_id() ) {
keyname_attributes[ "_slurm_job_id" ] = emp::to_string(
*dish2::get_slurm_job_id()
);
}

return emp::keyname::pack( keyname_attributes );
}

} // namespace dish2

#endif // #ifndef DISH2_RECORD_MAKE_FILENAME_MAKE_STINT_ROOT_ID_CHANGEOVER_FILENAME_HPP_INCLUDE
18 changes: 18 additions & 0 deletions slurm/evolve/evolvejob.slurm.sh.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ for p in outdata/*a={demographic_phenotypic_phylogenetic_metrics,kin_conflict_st
done
echo "uploading any changeover files..."
for p in outdata/*a=stint_root_id_changeover*; do
f="$(basename "${p}")"
echo "uploading ${p} -> ${f}"
for retry in {1..20}; do
aws s3 cp --quiet \
"${p}" \
"s3://{{ bucket }}/endeavor=${ENDEAVOR}/evolve/stint-root-id-changeover/stage=0+what=generated/stint={{ stint }}/series={{ series }}/${f}" \
&& echo " ${f} upload success" && break \
|| (echo "retrying ${f} upload (${retry})" && sleep $((RANDOM % 10)))
if ((${retry}==20)); then echo "$f upload fail" && exit 123123; fi
done & pids+=($!)
# limit to twenty concurrent upload jobs
while (( $(jobs -p | wc -l) > 20 )); do sleep 1; done
done
echo "uploading any asconfigured files..."
for p in outmeta/*a=asconfigured*.csv*; do
f="$(basename "${p}")"
Expand Down
18 changes: 18 additions & 0 deletions slurm/polycultures/polyculturejob.slurm.sh.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ for p in outdata/*a={demographic_phenotypic_phylogenetic_metrics,kin_conflict_st
done
echo "uploading any changeover files..."
for p in outdata/*a=stint_root_id_changeover*; do
f="$(basename "${p}")"
echo "uploading ${p} -> ${f}"
for retry in {1..20}; do
aws s3 cp --quiet \
"${p}" \
"s3://{{ bucket }}/endeavor=${ENDEAVOR}/polycultures/stint-root-id-changeover/stage=0+what=generated/stint={{ stint }}/series={{ series }}/${f}" \
&& echo " ${f} upload success" && break \
|| (echo "retrying ${f} upload (${retry})" && sleep $((RANDOM % 10)))
if ((${retry}==20)); then echo "$f upload fail" && exit 123123; fi
done & pids+=($!)
# limit to twenty concurrent upload jobs
while (( $(jobs -p | wc -l) > 20 )); do sleep 1; done
done
echo "uploading any running log files..."
for p in outdata/*a={birth_log,death_log,spawn_log}*; do
f="$(basename "${p}")"
Expand Down

0 comments on commit 66d623e

Please sign in to comment.