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

Restart ffs #46

Open
wants to merge 3 commits into
base: release-0.9
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
1 change: 1 addition & 0 deletions Examples/User/ForwardFlux/GROMACS/ADP/Template_Input.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"nInterfaces" : 5,
"computeInitialFlux" : true,
"N0Target" : 100,
"NLastSuccessful": 100,
"outputDirectoryName" : "FFSoutput",
"saveTrajectories" : true
}
Expand Down
1 change: 1 addition & 0 deletions Examples/User/ForwardFlux/LAMMPS/ADP/Template_Input.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"nInterfaces" : 5,
"computeInitialFlux" : true,
"N0Target" : 100,
"NLastSuccessful": 100,
"outputDirectoryName" : "FFSoutput",
"saveTrajectories" : true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"interfaces" : [],
"nInterfaces" : 5,
"N0Target" : 100,
"NLastSuccessful": 100,
"computeInitialFlux" : true,
"outputDirectoryName" : "FFSoutput",
"saveTrajectories" : true
Expand Down
4 changes: 4 additions & 0 deletions schema/Methods/forwardflux.method.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"type" : "integer",
"minimum" : 1
},
"NLastSuccessful" : {
"type" : "integer",
"minimum" : 1
},
"trials" : {
"type" : "array",
"minItems" : 1,
Expand Down
15 changes: 12 additions & 3 deletions src/Methods/DirectForwardFlux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace SSAGES
// Else check the FFS interfaces
else
{
CheckForInterfaceCrossings(snapshot, cvmanager);
CheckForInterfaceCrossings(snapshot, cvmanager);
//FluxBruteForce(snapshot,cvs);
}
// Other modes?
Expand Down Expand Up @@ -287,18 +287,27 @@ namespace SSAGES
unsigned int npicks = _M[0];
std::vector<unsigned int> picks;
picks.resize(npicks);

// if the initial flux has already been realized or
// we've got more than _N0Target configurations for zero surface
if (_current_interface == 0)
_N[_current_interface]=_N0Target;

//if the calculation starts from a non-zero surface (for restart)
if (_N[_current_interface] == 0)
_N[_current_interface]=_NLastSuccessful;

if(IsMasterRank(world_))
{
std::uniform_int_distribution<int> distribution(0,_N[0]-1);
std::uniform_int_distribution<int> distribution(0,_N[_current_interface]-1);
for (unsigned int i=0; i < npicks ; i++)
picks[i] = distribution(_generator);
}
MPI_Bcast(picks.data(),npicks,MPI_UNSIGNED,0,world_);

//set correct attempt index if a given ID is picked twice
std::vector<unsigned int> attempt_count;
attempt_count.resize(_N[0],0);
attempt_count.resize(_N[_current_interface],0);

//each proc adds to the queue
for (unsigned int i=0; i < npicks ; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/Methods/DirectForwardFlux.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ namespace SSAGES
DirectForwardFlux(const MPI_Comm& world,
const MPI_Comm& comm,
double ninterfaces, std::vector<double> interfaces,
unsigned int N0Target, std::vector<unsigned int> M,
unsigned int N0Target, unsigned int NLastSuccessful, std::vector<unsigned int> M,
bool initialFluxFlag, bool saveTrajectories,
unsigned int currentInterface, std::string output_directory, unsigned int frequency)
: ForwardFlux(world, comm, ninterfaces, interfaces, N0Target, M,
: ForwardFlux(world, comm, ninterfaces, interfaces, N0Target, NLastSuccessful, M,
initialFluxFlag, saveTrajectories, currentInterface, output_directory, frequency) {}

//! Post-integration hook.
Expand Down
3 changes: 2 additions & 1 deletion src/Methods/ForwardFlux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ namespace SSAGES
throw BuildException({"The size of \"interfaces\" and \"trials\" must be equal to \"nInterfaces\". See documentation for more information"});

auto N0Target = json.get("N0Target", 1).asInt();
auto NLastSuccessful = json.get("NLastSuccessful", 1).asInt();
auto initialFluxFlag = json.get("computeInitialFlux", true).asBool();
auto saveTrajectories = json.get("saveTrajectories", true).asBool();
auto currentInterface = json.get("currentInterface", 0).asInt();
Expand All @@ -673,7 +674,7 @@ namespace SSAGES

if(flavor == "DirectForwardFlux")
{
return new DirectForwardFlux(world, comm, ninterfaces, interfaces, N0Target, M, initialFluxFlag, saveTrajectories, currentInterface, output_directory, freq);
return new DirectForwardFlux(world, comm, ninterfaces, interfaces, N0Target, NLastSuccessful, M, initialFluxFlag, saveTrajectories, currentInterface, output_directory, freq);
}
else
{
Expand Down
20 changes: 15 additions & 5 deletions src/Methods/ForwardFlux.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ namespace SSAGES
//! Number of configurations to store at lambda0, target
unsigned int _N0Target;

//! Number of configurations stored at last achived interface, for restart
unsigned int _NLastSuccessful;

//! Flux of trajectories out of state A. Denoted PhiA0 over h_A in Allen2009.
double _fluxA0;

Expand Down Expand Up @@ -272,6 +275,7 @@ namespace SSAGES
* \param ninterfaces Number of interfaces.
* \param interfaces Vector of interfaces.
* \param N0Target Required number of initial configurations.
* \param NLastSuccessful The number of stored configurations at last achieved interface.
* \param M Vector of trials.
* \param initialFluxFlag Flag for first step of this method.
* \param saveTrajectories Flag to save flux trajectories.
Expand All @@ -284,10 +288,10 @@ namespace SSAGES
ForwardFlux(const MPI_Comm& world,
const MPI_Comm& comm,
double ninterfaces, std::vector<double> interfaces,
unsigned int N0Target, std::vector<unsigned int> M,
unsigned int N0Target, unsigned int NLastSuccessful, std::vector<unsigned int> M,
bool initialFluxFlag, bool saveTrajectories,
unsigned int currentInterface, std::string output_directory, unsigned int frequency) :
Method(frequency, world, comm), _ninterfaces(ninterfaces), _interfaces(interfaces), _N0Target(N0Target),
Method(frequency, world, comm), _ninterfaces(ninterfaces), _interfaces(interfaces), _N0Target(N0Target), _NLastSuccessful(NLastSuccessful),
_M(M), _initialFluxFlag(initialFluxFlag), _saveTrajectories(saveTrajectories), _current_interface(currentInterface),
_output_directory(output_directory), _generator(1), iteration_(0)
{
Expand Down Expand Up @@ -349,17 +353,23 @@ namespace SSAGES
std::cerr << "\n";
MPI_Abort(world_, EXIT_FAILURE);
}

// This is to generate an artificial Lambda0ConfigLibrary, Hadi's code does this for real
// THIS SHOULD BE SOMEWHERE ELSE!!!

if (!_initialFluxFlag)
{
_N0Target = NLastSuccessful;
}

Lambda0ConfigLibrary.resize(_N0Target);
std::normal_distribution<double> distribution(0,1);
for (unsigned int i = 0; i < _N0Target ; i++)
{
Lambda0ConfigLibrary[i].l = 0;
Lambda0ConfigLibrary[i].l = _current_interface;
Lambda0ConfigLibrary[i].n = i;
Lambda0ConfigLibrary[i].a = 0;
Lambda0ConfigLibrary[i].lprev = 0;
Lambda0ConfigLibrary[i].lprev = _current_interface;
Lambda0ConfigLibrary[i].nprev = i;
Lambda0ConfigLibrary[i].aprev = 0;
//FFSConfigID ffsconfig = Lambda0ConfigLibrary[i];
Expand Down