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

feat: addition of potentialSet class #1991

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

Conversation

Danbr4d
Copy link
Contributor

@Danbr4d Danbr4d commented Oct 22, 2024

Addition of potentialSet class for easier averaging of potentials.

@Danbr4d Danbr4d changed the title feat: initial addition of potentialSet class feat: addition of potentialSet class Oct 23, 2024
@Danbr4d Danbr4d requested a review from rprospero October 25, 2024 08:36
Danbr4d and others added 3 commits October 25, 2024 13:02
Co-authored-by: Adam Washington <adam.washington@stfc.ac.uk>
@Danbr4d Danbr4d changed the base branch from epsr-averaging to develop October 31, 2024 11:42
Copy link
Contributor

@rprospero rprospero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two bits here. First, I've made some suggestions on the operators. Also, we should probably add a unit test for the averaging. It'll be easier to put it in now while the code is fresh in your mind than six months from now when we're tracking down a bug.

src/classes/potentialSet.cpp Outdated Show resolved Hide resolved
src/classes/potentialSet.h Outdated Show resolved Hide resolved
@Danbr4d Danbr4d requested a review from rprospero November 18, 2024 11:22
Comment on lines +56 to +75
std::map<std::string, EPData> averagedPotentials = potentials;

averagedPotentialsStore.emplace_back(potentials);
// Check if ran the right amount of iterations before averaging
if (averagedPotentialsStore.size() > averagingLength_)
{
averagedPotentialsStore.pop_back();
}

// Average the potentials and replace the map with the new averaged
for (const auto &pots : averagedPotentialsStore)
{
for (auto &&[key, epData] : pots)
{
averagedPotentials[key].ep += epData.ep;
averagedPotentials[key].ep /= averagingLength_.value();
}
}
potentials = averagedPotentials;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this section be the issue? The logic here doesn't quite add up, since you store the current potentials as the beginning of averagePotentials, then add potentials to the store, then immediately remove it if you have exceeded your averaging length (which past a certain point you always will) and then do the sum over all the store potentials. That will give you N+1 sets of potentials contributing to the average, rather than the N you want, and which will always contain the first N potential sets you ever generate at the beginning of the simulation (since you're doing pop_back rather than pop_front. The Averaging class would sort all this out for you, but I have suggested the necessary modifications to clean this up anyway.

@@ -53,6 +53,26 @@ Module::ExecutionResult EPSRManagerModule::process(ModuleContext &moduleContext)
for (auto &&[key, epData] : potentials)
epData.ep /= epData.count;

std::map<std::string, EPData> averagedPotentials = potentials;

averagedPotentialsStore.emplace_back(potentials);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
averagedPotentialsStore.emplace_back(potentials);

Comment on lines +59 to +63
// Check if ran the right amount of iterations before averaging
if (averagedPotentialsStore.size() > averagingLength_)
{
averagedPotentialsStore.pop_back();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check if ran the right amount of iterations before averaging
if (averagedPotentialsStore.size() > averagingLength_)
{
averagedPotentialsStore.pop_back();
}
// Limit data to average to the most recent N-1 sets
while (averagedPotentialsStore.size() >= averagingLength_)
{
averagedPotentialsStore.pop_front();
}

averagedPotentials[key].ep /= averagingLength_.value();
}
}
potentials = averagedPotentials;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
potentials = averagedPotentials;
// Add the current potentials (before averaging) to the average store before we overwrite them
averagePotentialsStore.emplace_back(potentials);
// Set new averaged potentials
potentials = averagedPotentials;

for (auto &&[key, epData] : pots)
{
averagedPotentials[key].ep += epData.ep;
averagedPotentials[key].ep /= averagingLength_.value();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You definitely don't want to do this division every time you add a set of potentials, just once at the end!

@Danbr4d Danbr4d requested a review from trisyoungs December 12, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants