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

WIP Prepare next version #86

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ CFLAGS_nat_profile := -pg -DNDEBUG $(OMP_FLAG) $(CFLAGS_all)

# Emscripten compiler information
CXX_web := emcc
OFLAGS_web_all := $(CXXFLAGS) -Wno-mismatched-tags -Wno-empty-body -s USE_ZLIB=1 -s USE_LIBLZMA=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s TOTAL_MEMORY=671088640 --js-library $(EMP_DIR)/web/library_emp.js -s EXPORTED_FUNCTIONS="['_main', '_empCppCallback', '_empDoCppCallback']" -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=1 -s ABORTING_MALLOC=0 -I/usr/lib/x86_64-linux-gnu/openmpi/include/
OFLAGS_web_all := $(CXXFLAGS) -Wno-mismatched-tags -Wno-empty-body -s USE_ZLIB=1 -s USE_LIBLZMA=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s TOTAL_MEMORY=671088640 --js-library $(EMP_DIR)/web/library_emp.js -s EXPORTED_FUNCTIONS="['_main', '_empCppCallback', '_empDoCppCallback']" -s NO_EXIT_RUNTIME=1 -s ABORTING_MALLOC=0 -I/usr/lib/x86_64-linux-gnu/openmpi/include/
OFLAGS_web_pthread := -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1
OFLAGS_web := -O3 -DNDEBUG
OFLAGS_web_debug := -g4 -Wno-dollar-in-identifier-extension -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2 -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG
OFLAGS_web := -O3 -DNDEBUG -s DISABLE_EXCEPTION_CATCHING=1
OFLAGS_web_debug := -g4 -Oz -Wno-dollar-in-identifier-extension -s DEMANGLE_SUPPORT=1 -s ASSERTIONS=2 -s SAFE_HEAP=1 -s STACK_OVERFLOW_CHECK=2 -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG -fexceptions

CFLAGS_web := $(CFLAGS_all) $(OFLAGS_web) $(OFLAGS_web_all)
CFLAGS_web_pthread := $(CFLAGS_all) $(OFLAGS_web) $(OFLAGS_web_pthread) $(OFLAGS_web_all)
Expand Down
4 changes: 1 addition & 3 deletions include/dish2/config/dump_config_csv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ void dump_config_csv() {
auto keyname_attributes = emp::keyname::unpack_t{
{"a", "asconfigured"},
{"proc", emp::to_string( uitsl::get_proc_id() ) },
{"source", EMP_STRINGIFY(DISHTINY_HASH_)},
{"ext", ".csv"}
};

if ( dish2::get_repro() ) keyname_attributes[ "repro" ] = *dish2::get_repro();

dish2::mkdir_exists_ok( "./outmeta" );

const std::string outname = dish2::pare_keyname_filename(
Expand All @@ -39,6 +36,7 @@ void dump_config_csv() {
const std::string outpath = emp::to_string("outmeta/", outname);

emp::DataFile df( outpath );
df.AddVal( EMP_STRINGIFY(DISHTINY_HASH_), "source" );
if ( dish2::get_repro() ) df.AddVal( *dish2::get_repro(), "Repro" );
if ( dish2::get_endeavor() ) df.AddVal( *dish2::get_endeavor(), "Endeavor" );
if ( dish2::get_slurm_job_id() ) df.AddVal(
Expand Down
145 changes: 145 additions & 0 deletions include/dish2/genome/PhyloFingerprints.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#pragma once
#ifndef DISH2_GENOME_PHYLOFINGERPRINTS_HPP_INCLUDE
#define DISH2_GENOME_PHYLOFINGERPRINTS_HPP_INCLUDE

#include <algorithm>
#include <cmath>

#include "../polyfill/bit_floor.hpp"
#include "../polyfill/bit_width.hpp"
#include "../polyfill/countr_zero.hpp"

// #include "../../../third-party/Empirical/include/emp/base/vector.hpp"
#include "../../../third-party/signalgp-lite/include/sgpl/utility/ThreadLocalRandom.hpp"

namespace dish2 {

class PhyloFingerprints {

uint64_t generation_counter{};

// ordered from most ancient (index 0 / fingerprints.front())
// to most recent (index n - 1 / fingerprints.back())
std::vector<uint64_t> fingerprints;
// absolute generation corresponding to each fingerprint
std::vector<uint64_t> generations;

// todo remove
public:

// msb == most significant bit
static uint64_t clear_msb(const uint64_t v) {
return v - std::bit_floor(v);
}

// lsb == lowest set bit
// aka (x & -x).set_width()
// not defined for x == 0
// == https://oeis.org/A001511 - 1
static uint64_t get_lsb_index(const uint64_t v) {
emp_assert(v);
return std::countr_zero(v);
}

// 0 == no drop
// should generate sequence
// 0, 0, 1, 0, 1, 2, 1, 0, 1, 2, 1, 3, 1, 2, 1, 0, ...
// non-zero interludes are from https://oeis.org/A001511
// zeros occur when index is an even power of two
static uint64_t calc_drop_idx(const uint64_t gen) {
const uint64_t leftover = clear_msb(gen);
if ( leftover ) return get_lsb_index(leftover) + 1;
else return 0;
}

void append_fingerprint() {
fingerprints.push_back(
sgpl::tlrand.Get().GetUInt64()
);
generations.push_back(
generation_counter
);
}

void maybe_drop_fingerprint(const size_t drop_idx) {
if ( drop_idx ) {
fingerprints.erase(
std::next( std::rbegin(fingerprints), drop_idx ).base()
);
generations.erase(
std::next( std::rbegin(generations), drop_idx ).base()
);
}
}

void print() {
for ( auto& g : generations ) std::cout << generation_counter - g << " ";
std::cout << '\n';
}

public:

PhyloFingerprints() { append_fingerprint(); ++generation_counter; }

void ElapseGeneration() {
++generation_counter;

maybe_drop_fingerprint( calc_drop_idx(generation_counter) );

append_fingerprint();
}

size_t DivergedAtLeast( const PhyloFingerprints& other ) const {
const auto [our_mismatch, others_mismatch] = std::mismatch(
std::begin( fingerprints ), std::end( fingerprints ),
std::begin( other.fingerprints )
);

const size_t num_divergent_fingerprints = std::distance(
our_mismatch, std::end( fingerprints )
);

if ( num_divergent_fingerprints ) {
const size_t first_divergent_generation = generations[
generations.size() - num_divergent_fingerprints
];
return generation_counter - first_divergent_generation;
} else return 0;

}

size_t DivergedLessThan( const PhyloFingerprints& other ) const {
const auto [our_mismatch, others_mismatch] = std::mismatch(
std::begin( fingerprints ), std::end( fingerprints ),
std::begin( other.fingerprints )
);

const size_t num_common_fingerprints = std::distance(
std::begin( fingerprints ), our_mismatch
);

if ( num_common_fingerprints ) {
const size_t last_common_generation = generations[
num_common_fingerprints - 1
];
return generation_counter - last_common_generation;
} else return -1;

}

[[deprecated("Temporary interface for Phylogenetic Fingerprints Demo.")]]
const std::vector<uint64_t>& GetGenerations() const { return generations; }

[[deprecated("Temporary interface for Phylogenetic Fingerprints Demo.")]]
const size_t GetGenerationCount() const { return generation_counter; }

[[deprecated("Temporary interface for Phylogenetic Fingerprints Demo.")]]
const size_t GetFingerprint(const size_t idx) const {
return fingerprints[idx];
}

};

} // namespace dish2

#endif // #ifndef DISH2_GENOME_PHYLOFINGERPRINTS_HPP_INCLUDE
1 change: 0 additions & 1 deletion include/dish2/load/reconstitute_population_load.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "../../../third-party/Empirical/include/emp/tools/keyname_utils.hpp"
#include "../../../third-party/Empirical/include/emp/tools/string_utils.hpp"

#include "../algorithm/seed_genomes_into.hpp"
#include "../genome/Genome.hpp"
#include "../utility/autoload.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace dish2 {

struct Epoch : public uitsl::PodLeafNode<size_t> {
struct Epoch : public uitsl::PodLeafNode<uint64_t> {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t>;
using parent_t = uitsl::PodLeafNode<uint64_t>;
using parent_t::parent_t;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace dish2 {

struct IncomingInterMessageCounter : public uitsl::PodLeafNode<size_t> {
struct IncomingInterMessageCounter : public uitsl::PodLeafNode<uint64_t> {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t>;
using parent_t = uitsl::PodLeafNode<uint64_t>;
using parent_t::parent_t;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace dish2 {

struct IncomingIntraMessageCounter : public uitsl::PodLeafNode<size_t> {
struct IncomingIntraMessageCounter : public uitsl::PodLeafNode<uint64_t> {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t>;
using parent_t = uitsl::PodLeafNode<uint64_t>;
using parent_t::parent_t;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
namespace dish2 {

template< typename Spec >
struct KinGroupAge : public uitsl::PodLeafNode< size_t, Spec::NLEV > {
struct KinGroupAge : public uitsl::PodLeafNode< uint64_t, Spec::NLEV > {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t, Spec::NLEV>;
using parent_t = uitsl::PodLeafNode<uint64_t, Spec::NLEV>;
using parent_t::parent_t;

void Refresh(
const size_t epoch, const dish2::KinGroupEpochStamps< Spec > stamps
const uint64_t epoch, const dish2::KinGroupEpochStamps< Spec > stamps
) {
std::transform(
std::begin( stamps.GetBuffer() ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
namespace dish2 {

template< typename Spec >
struct KinGroupIDAncestorView : public uitsl::PodLeafNode< size_t, Spec::NLEV > {
struct KinGroupIDAncestorView : public uitsl::PodLeafNode< uint64_t, Spec::NLEV > {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t, Spec::NLEV>;
using parent_t = uitsl::PodLeafNode<uint64_t, Spec::NLEV>;
using parent_t::parent_t;

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
namespace dish2 {

template< typename Spec >
struct NumKnownQuorumBits : public uitsl::PodLeafNode< size_t, Spec::NLEV > {
struct NumKnownQuorumBits : public uitsl::PodLeafNode< uint64_t, Spec::NLEV > {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t, Spec::NLEV>;
using parent_t = uitsl::PodLeafNode<uint64_t, Spec::NLEV>;
using parent_t::parent_t;

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace dish2 {

struct PhylogeneticRootView : public uitsl::PodLeafNode< size_t > {
struct PhylogeneticRootView : public uitsl::PodLeafNode< uint64_t > {
// inherit constructors
using parent_t = uitsl::PodLeafNode<size_t>;
using parent_t = uitsl::PodLeafNode<uint64_t>;
using parent_t::parent_t;

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace dish2 {

struct SpawnCount : public uitsl::PodLeafNode<char> {
using parent_t = uitsl::PodLeafNode<char>;
struct SpawnCount : public uitsl::PodLeafNode<uint64_t> {
using parent_t = uitsl::PodLeafNode<uint64_t>;
using parent_t::parent_t;
};

Expand Down
17 changes: 17 additions & 0 deletions include/dish2/polyfill/bit_floor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#ifndef DISH2_POLYFILL_BIT_FLOOR_HPP_INCLUDE
#define DISH2_POLYFILL_BIT_FLOOR_HPP_INCLUDE

#include "bit_width.hpp"

namespace std {

template< typename T >
T bit_floor(T x) {
if (x != 0) return T{1} << (std::bit_width(x) - 1);
else return 0;
}

} // namespace std

#endif // #ifndef DISH2_POLYFILL_BIT_FLOOR_HPP_INCLUDE
19 changes: 19 additions & 0 deletions include/dish2/polyfill/bit_width.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#ifndef DISH2_POLYFILL_BIT_WIDTH_HPP_INCLUDE
#define DISH2_POLYFILL_BIT_WIDTH_HPP_INCLUDE

namespace std {

template< typename T >
size_t bit_width(T x) {
size_t res{};
while (x) {
x >>= 1;
++res;
}
return res;
}

} // namespace std

#endif // #ifndef DISH2_POLYFILL_BIT_WIDTH_HPP_INCLUDE
18 changes: 18 additions & 0 deletions include/dish2/polyfill/countr_zero.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#ifndef DISH2_POLYFILL_COUNTR_ZERO_HPP_INCLUDE
#define DISH2_POLYFILL_COUNTR_ZERO_HPP_INCLUDE

namespace std {

// adapted from https://johnmcfarlane.github.io/cnl/bit_8h_source.html
template< typename T >
size_t countr_zero(T x) {
return (x & 1)
? 0
: countr_zero<T>(static_cast<T>(x >> 1)) + 1
;
}

} // namespace std

#endif // #ifndef DISH2_POLYFILL_COUNTR_ZERO_HPP_INCLUDE
3 changes: 2 additions & 1 deletion include/dish2/record/dump_genome_statistics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void dump_genome_statistics(
file.AddVal( v, emp::to_string("Treatment ", k) );
}
}
file.AddVal( "proc", emp::to_string( uitsl::get_proc_id() ) );
file.AddVal( uitsl::get_proc_id(), "proc" );
file.AddVal( dish2::thread_idx, "thread" );

const std::string slug = dish2::make_genome_slug( genome_filename );
file.AddVar(slug, "Genome Slug");
Expand Down
6 changes: 3 additions & 3 deletions include/dish2/record/dump_spawn_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <algorithm>
#include <string>

#include "../../../third-party/bxzstr/include/bxzstr.hpp"
#include "../../../third-party/conduit/include/uitsl/algorithm/for_each.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/header-only-gzstream/include/hogzstr/gzstream.hpp"
#include "../../../third-party/signalgp-lite/include/sgpl/utility/CountingIterator.hpp"

#include "../config/has_replicate.hpp"
Expand All @@ -30,12 +30,12 @@ void dump_spawn_log( const dish2::ThreadWorld< Spec >& world ) {

const auto& population = world.population;

const thread_local std::string out_filename = dish2::pare_keyname_filename(
const std::string out_filename = dish2::pare_keyname_filename(
dish2::make_spawn_log_filename(),
dish2::make_data_path()
);

thread_local bxz::ofstream out_stream(
bxz::ofstream out_stream(
dish2::make_data_path( out_filename ), bxz::lzma, 6
);
emp::DataFile file( out_stream );
Expand Down
3 changes: 2 additions & 1 deletion include/dish2/services/BirthSetupService.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ struct BirthSetupService {
fresh_input_idxs.clear();

for (size_t idx{}; idx < cell.cardinals.size(); ++idx) {
if ( cell.cardinals[idx].genome_node_input.Jump() ) {
const size_t num_entries = cell.cardinals[idx].genome_node_input.Jump();
for ( size_t ticket{}; ticket < num_entries; ++ticket ) {
fresh_input_idxs.push_back( idx );
}
}
Expand Down
Loading