Skip to content

Commit

Permalink
fix profile metrics for multichrom
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Nov 25, 2024
1 parent 7ef3008 commit 90ee0d0
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 233 deletions.
153 changes: 83 additions & 70 deletions QtSLiM/QtSLiMWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3974,78 +3974,92 @@ void QtSLiMWindow::displayProfileResults(void)
continue;
}

int64_t power_tallies[20]; // we only go up to 1024 mutruns right now, but this gives us some headroom
int64_t power_tallies_total = static_cast<int>(focal_species->profile_mutcount_history_.size());

for (int power = 0; power < 20; ++power)
power_tallies[power] = 0;

for (int32_t count : focal_species->profile_mutcount_history_)
{
int power = static_cast<int>(round(log2(count)));

power_tallies[power]++;
}

for (int power = 0; power < 20; ++power)
{
if (power_tallies[power] > 0)
{
tc.insertText(QString("%1%").arg((power_tallies[power] / static_cast<double>(power_tallies_total)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(QString(" of ticks : %1 mutation runs per haplosome\n").arg(static_cast<int>(round(pow(2.0, power)))), optima13_d);
}
}


int64_t regime_tallies[3];
int64_t regime_tallies_total = static_cast<int>(focal_species->profile_nonneutral_regime_history_.size());

for (int regime = 0; regime < 3; ++regime)
regime_tallies[regime] = 0;

for (int32_t regime : focal_species->profile_nonneutral_regime_history_)
if ((regime >= 1) && (regime <= 3))
regime_tallies[regime - 1]++;
else
regime_tallies_total--;

tc.insertText(" \n", optima13_d);

for (int regime = 0; regime < 3; ++regime)
{
tc.insertText(QString("%1%").arg((regime_tallies[regime] / static_cast<double>(regime_tallies_total)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(QString(" of ticks : regime %1 (%2)\n").arg(regime + 1).arg(regime == 0 ? "no mutationEffect() callbacks" : (regime == 1 ? "constant neutral mutationEffect() callbacks only" : "unpredictable mutationEffect() callbacks present")), optima13_d);
}


tc.insertText(" \n", optima13_d);

tc.insertText(QString("%1").arg(focal_species->profile_mutation_total_usage_), menlo11_d);
tc.insertText(" mutations referenced, summed across all ticks\n", optima13_d);

tc.insertText(QString("%1").arg(focal_species->profile_nonneutral_mutation_total_), menlo11_d);
tc.insertText(" mutations considered potentially nonneutral\n", optima13_d);

tc.insertText(QString("%1%").arg(((focal_species->profile_mutation_total_usage_ - focal_species->profile_nonneutral_mutation_total_) / static_cast<double>(focal_species->profile_mutation_total_usage_)) * 100.0, 0, 'f', 2), menlo11_d);
tc.insertText(" of mutations excluded from fitness calculations\n", optima13_d);
{
int64_t regime_tallies[3];
int64_t regime_tallies_total = static_cast<int>(focal_species->profile_nonneutral_regime_history_.size());

for (int regime = 0; regime < 3; ++regime)
regime_tallies[regime] = 0;

for (int32_t regime : focal_species->profile_nonneutral_regime_history_)
if ((regime >= 1) && (regime <= 3))
regime_tallies[regime - 1]++;
else
regime_tallies_total--;

for (int regime = 0; regime < 3; ++regime)
{
tc.insertText(QString("%1%").arg((regime_tallies[regime] / static_cast<double>(regime_tallies_total)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(QString(" of ticks : regime %1 (%2)\n").arg(regime + 1).arg(regime == 0 ? "no mutationEffect() callbacks" : (regime == 1 ? "constant neutral mutationEffect() callbacks only" : "unpredictable mutationEffect() callbacks present")), optima13_d);
}

tc.insertText(" \n", optima8_d);
}

tc.insertText(QString("%1").arg(focal_species->profile_max_mutation_index_), menlo11_d);
tc.insertText(QString("%1").arg(focal_species->profile_max_mutation_index_), menlo11_d);
tc.insertText(" maximum simultaneous mutations\n", optima13_d);


const std::vector<Chromosome *> &chromosomes = focal_species->Chromosomes();


tc.insertText(" \n", optima13_d);

tc.insertText(QString("%1").arg(focal_species->profile_mutrun_total_usage_), menlo11_d);
tc.insertText(" mutation runs referenced, summed across all ticks\n", optima13_d);

tc.insertText(QString("%1").arg(focal_species->profile_unique_mutrun_total_), menlo11_d);
tc.insertText(" unique mutation runs maintained among those\n", optima13_d);

tc.insertText(QString("%1%").arg((focal_species->profile_mutrun_nonneutral_recache_total_ / static_cast<double>(focal_species->profile_unique_mutrun_total_)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(" of mutation run nonneutral caches rebuilt per tick\n", optima13_d);

tc.insertText(QString("%1%").arg(((focal_species->profile_mutrun_total_usage_ - focal_species->profile_unique_mutrun_total_) / static_cast<double>(focal_species->profile_mutrun_total_usage_)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(" of mutation runs shared among haplosomes", optima13_d);
for (Chromosome *focal_chromosome : chromosomes)
{
tc.insertText(" \n", optima13_d);
tc.insertText("Chromosome ", optima13i_d);
tc.insertText(QString::fromStdString(focal_chromosome->Symbol()), optima13i_d);
tc.insertText(":\n", optima13i_d);
tc.insertText(" \n", optima3_d);

{
int64_t power_tallies[20]; // we only go up to 1024 mutruns right now, but this gives us some headroom
int64_t power_tallies_total = static_cast<int>(focal_chromosome->profile_mutcount_history_.size());

for (int power = 0; power < 20; ++power)
power_tallies[power] = 0;

for (int32_t count : focal_chromosome->profile_mutcount_history_)
{
int power = static_cast<int>(round(log2(count)));

power_tallies[power]++;
}

for (int power = 0; power < 20; ++power)
{
if (power_tallies[power] > 0)
{
tc.insertText(QString("%1%").arg((power_tallies[power] / static_cast<double>(power_tallies_total)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(QString(" of ticks : %1 mutation runs per haplosome\n").arg(static_cast<int>(round(pow(2.0, power)))), optima13_d);
}
}
}

tc.insertText(" \n", optima8_d);

tc.insertText(QString("%1").arg(focal_chromosome->profile_mutation_total_usage_), menlo11_d);
tc.insertText(" mutations referenced, summed across all ticks\n", optima13_d);

tc.insertText(QString("%1").arg(focal_chromosome->profile_nonneutral_mutation_total_), menlo11_d);
tc.insertText(" mutations considered potentially nonneutral\n", optima13_d);

tc.insertText(QString("%1%").arg(((focal_chromosome->profile_mutation_total_usage_ - focal_chromosome->profile_nonneutral_mutation_total_) / static_cast<double>(focal_chromosome->profile_mutation_total_usage_)) * 100.0, 0, 'f', 2), menlo11_d);
tc.insertText(" of mutations excluded from fitness calculations\n", optima13_d);


tc.insertText(" \n", optima8_d);

tc.insertText(QString("%1").arg(focal_chromosome->profile_mutrun_total_usage_), menlo11_d);
tc.insertText(" mutation runs referenced, summed across all ticks\n", optima13_d);

tc.insertText(QString("%1").arg(focal_chromosome->profile_unique_mutrun_total_), menlo11_d);
tc.insertText(" unique mutation runs maintained among those\n", optima13_d);

tc.insertText(QString("%1%").arg((focal_chromosome->profile_mutrun_nonneutral_recache_total_ / static_cast<double>(focal_chromosome->profile_unique_mutrun_total_)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(" of mutation run nonneutral caches rebuilt per tick\n", optima13_d);

tc.insertText(QString("%1%").arg(((focal_chromosome->profile_mutrun_total_usage_ - focal_chromosome->profile_unique_mutrun_total_) / static_cast<double>(focal_chromosome->profile_mutrun_total_usage_)) * 100.0, 6, 'f', 2), menlo11_d);
tc.insertText(" of mutation runs shared among haplosomes\n", optima13_d);
}
}
#endif

Expand All @@ -4062,7 +4076,6 @@ void QtSLiMWindow::displayProfileResults(void)
double average_total = (mem_tot_C.totalMemoryUsage + mem_tot_S.totalMemoryUsage) / ddiv;
double final_total = mem_last_C.totalMemoryUsage + mem_last_S.totalMemoryUsage;

tc.insertText(" \n", menlo11_d);
tc.insertText(" \n", optima13_d);
tc.insertText("SLiM memory usage (average / final tick)\n", optima14b_d);
tc.insertText(" \n", optima3_d);
Expand Down
137 changes: 75 additions & 62 deletions SLiMgui/SLiMWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2059,78 +2059,92 @@ - (void)displayProfileResults
continue;
}

int64_t power_tallies[20]; // we only go up to 1024 mutruns right now, but this gives us some headroom
int64_t power_tallies_total = (int)focal_species->profile_mutcount_history_.size();

for (int power = 0; power < 20; ++power)
power_tallies[power] = 0;

for (int32_t count : focal_species->profile_mutcount_history_)
{
int power = (int)round(log2(count));
int64_t regime_tallies[3];
int64_t regime_tallies_total = (int)focal_species->profile_nonneutral_regime_history_.size();

power_tallies[power]++;
}

for (int power = 0; power < 20; ++power)
{
if (power_tallies[power] > 0)
for (int regime = 0; regime < 3; ++regime)
regime_tallies[regime] = 0;

for (int32_t regime : focal_species->profile_nonneutral_regime_history_)
if ((regime >= 1) && (regime <= 3))
regime_tallies[regime - 1]++;
else
regime_tallies_total--;

for (int regime = 0; regime < 3; ++regime)
{
[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", (power_tallies[power] / (double)power_tallies_total) * 100.0] attributes:menlo11_d];
[content eidosAppendString:[NSString stringWithFormat:@" of ticks : %d mutation runs per haplosome\n", (int)(round(pow(2.0, power)))] attributes:optima13_d];
[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", (regime_tallies[regime] / (double)regime_tallies_total) * 100.0] attributes:menlo11_d];
[content eidosAppendString:[NSString stringWithFormat:@" of ticks : regime %d (%@)\n", regime + 1, (regime == 0 ? @"no mutationEffect() callbacks" : (regime == 1 ? @"constant neutral mutationEffect() callbacks only" : @"unpredictable mutationEffect() callbacks present"))] attributes:optima13_d];
}

[content eidosAppendString:@"\n" attributes:optima8_d];
}


int64_t regime_tallies[3];
int64_t regime_tallies_total = (int)focal_species->profile_nonneutral_regime_history_.size();

for (int regime = 0; regime < 3; ++regime)
regime_tallies[regime] = 0;

for (int32_t regime : focal_species->profile_nonneutral_regime_history_)
if ((regime >= 1) && (regime <= 3))
regime_tallies[regime - 1]++;
else
regime_tallies_total--;

[content eidosAppendString:@"\n" attributes:optima13_d];

for (int regime = 0; regime < 3; ++regime)
{
[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", (regime_tallies[regime] / (double)regime_tallies_total) * 100.0] attributes:menlo11_d];
[content eidosAppendString:[NSString stringWithFormat:@" of ticks : regime %d (%@)\n", regime + 1, (regime == 0 ? @"no mutationEffect() callbacks" : (regime == 1 ? @"constant neutral mutationEffect() callbacks only" : @"unpredictable mutationEffect() callbacks present"))] attributes:optima13_d];
}


[content eidosAppendString:@"\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_species->profile_mutation_total_usage_] attributes:menlo11_d];
[content eidosAppendString:@" mutations referenced, summed across all ticks\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_species->profile_nonneutral_mutation_total_] attributes:menlo11_d];
[content eidosAppendString:@" mutations considered potentially nonneutral\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%0.2f%%", ((focal_species->profile_mutation_total_usage_ - focal_species->profile_nonneutral_mutation_total_) / (double)focal_species->profile_mutation_total_usage_) * 100.0] attributes:menlo11_d];
[content eidosAppendString:@" of mutations excluded from fitness calculations\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_species->profile_max_mutation_index_] attributes:menlo11_d];
[content eidosAppendString:@" maximum simultaneous mutations\n" attributes:optima13_d];


[content eidosAppendString:@"\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_species->profile_mutrun_total_usage_] attributes:menlo11_d];
[content eidosAppendString:@" mutation runs referenced, summed across all ticks\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_species->profile_unique_mutrun_total_] attributes:menlo11_d];
[content eidosAppendString:@" unique mutation runs maintained among those\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", (focal_species->profile_mutrun_nonneutral_recache_total_ / (double)focal_species->profile_unique_mutrun_total_) * 100.0] attributes:menlo11_d];
[content eidosAppendString:@" of mutation run nonneutral caches rebuilt per tick\n" attributes:optima13_d];
const std::vector<Chromosome *> &chromosomes = focal_species->Chromosomes();

[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", ((focal_species->profile_mutrun_total_usage_ - focal_species->profile_unique_mutrun_total_) / (double)focal_species->profile_mutrun_total_usage_) * 100.0] attributes:menlo11_d];
[content eidosAppendString:@" of mutation runs shared among haplosomes" attributes:optima13_d];
for (Chromosome *focal_chromosome : chromosomes)
{
[content eidosAppendString:@"\n" attributes:optima13_d];
[content eidosAppendString:@"Chromosome " attributes:optima13i_d];
[content eidosAppendString:[NSString stringWithUTF8String:focal_chromosome->Symbol().c_str()] attributes:optima13i_d];
[content eidosAppendString:@":\n" attributes:optima13i_d];
[content eidosAppendString:@"\n" attributes:optima3_d];

{
int64_t power_tallies[20]; // we only go up to 1024 mutruns right now, but this gives us some headroom
int64_t power_tallies_total = (int)focal_chromosome->profile_mutcount_history_.size();

for (int power = 0; power < 20; ++power)
power_tallies[power] = 0;

for (int32_t count : focal_chromosome->profile_mutcount_history_)
{
int power = (int)round(log2(count));

power_tallies[power]++;
}

for (int power = 0; power < 20; ++power)
{
if (power_tallies[power] > 0)
{
[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", (power_tallies[power] / (double)power_tallies_total) * 100.0] attributes:menlo11_d];
[content eidosAppendString:[NSString stringWithFormat:@" of ticks : %d mutation runs per haplosome\n", (int)(round(pow(2.0, power)))] attributes:optima13_d];
}
}
}

[content eidosAppendString:@"\n" attributes:optima8_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_chromosome->profile_mutation_total_usage_] attributes:menlo11_d];
[content eidosAppendString:@" mutations referenced, summed across all ticks\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_chromosome->profile_nonneutral_mutation_total_] attributes:menlo11_d];
[content eidosAppendString:@" mutations considered potentially nonneutral\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%0.2f%%", ((focal_chromosome->profile_mutation_total_usage_ - focal_chromosome->profile_nonneutral_mutation_total_) / (double)focal_chromosome->profile_mutation_total_usage_) * 100.0] attributes:menlo11_d];
[content eidosAppendString:@" of mutations excluded from fitness calculations\n" attributes:optima13_d];


[content eidosAppendString:@"\n" attributes:optima8_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_chromosome->profile_mutrun_total_usage_] attributes:menlo11_d];
[content eidosAppendString:@" mutation runs referenced, summed across all ticks\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%lld", (long long int)focal_chromosome->profile_unique_mutrun_total_] attributes:menlo11_d];
[content eidosAppendString:@" unique mutation runs maintained among those\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", (focal_chromosome->profile_mutrun_nonneutral_recache_total_ / (double)focal_chromosome->profile_unique_mutrun_total_) * 100.0] attributes:menlo11_d];
[content eidosAppendString:@" of mutation run nonneutral caches rebuilt per tick\n" attributes:optima13_d];

[content eidosAppendString:[NSString stringWithFormat:@"%6.2f%%", ((focal_chromosome->profile_mutrun_total_usage_ - focal_chromosome->profile_unique_mutrun_total_) / (double)focal_chromosome->profile_mutrun_total_usage_) * 100.0] attributes:menlo11_d];
[content eidosAppendString:@" of mutation runs shared among haplosomes\n" attributes:optima13_d];
}
}
#endif

Expand All @@ -2147,7 +2161,6 @@ - (void)displayProfileResults
double average_total = (mem_tot_C.totalMemoryUsage + mem_tot_S.totalMemoryUsage) / ddiv;
double final_total = mem_last_C.totalMemoryUsage + mem_last_S.totalMemoryUsage;

[content eidosAppendString:@"\n" attributes:menlo11_d];
[content eidosAppendString:@"\n" attributes:optima13_d];
[content eidosAppendString:@"SLiM memory usage (average / final tick)\n" attributes:optima14b_d];
[content eidosAppendString:@"\n" attributes:optima3_d];
Expand Down
12 changes: 12 additions & 0 deletions core/chromosome.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ class Chromosome : public EidosDictionaryRetained
// a user-defined tag value
slim_usertag_t tag_value_ = SLIM_TAG_UNSET_VALUE;

// PROFILING : Chromosome keeps track of some additional profile information that is per-chromosome
#if (SLIMPROFILING == 1)
#if SLIM_USE_NONNEUTRAL_CACHES
std::vector<int32_t> profile_mutcount_history_; // a record of the mutation run count used in each cycle
int64_t profile_mutation_total_usage_ = 0; // how many (non-unique) mutations were used by mutation runs, summed across cycles
int64_t profile_nonneutral_mutation_total_ = 0; // of profile_mutation_total_usage_, how many were deemed to be nonneutral
int64_t profile_mutrun_total_usage_ = 0; // how many (non-unique) mutruns were used by haplosomes, summed across cycles
int64_t profile_unique_mutrun_total_ = 0; // of profile_mutrun_total_usage_, how many unique mutruns existed, summed across cycles
int64_t profile_mutrun_nonneutral_recache_total_ = 0; // of profile_unique_mutrun_total_, how many mutruns regenerated their nonneutral cache
#endif // SLIM_USE_NONNEUTRAL_CACHES
#endif // (SLIMPROFILING == 1)

Chromosome(const Chromosome&) = delete; // no copying
Chromosome& operator=(const Chromosome&) = delete; // no copying
Chromosome(void) = delete; // no null constructor
Expand Down
Loading

0 comments on commit 90ee0d0

Please sign in to comment.