20 #include <mxx/comm.hpp>
21 #include "CVs/CVManager.h"
22 #include "Drivers/DriverException.h"
23 #include "Loggers/Logger.h"
24 #include "Validator/ObjectRequirement.h"
25 #include "Methods/Method.h"
26 #include "ResourceHandler.h"
35 ResourceHandler::ResourceHandler(
36 mxx::comm&& world, mxx::comm&& comm,
size_t walkerid,
37 const std::vector<Method*>& methods,
CVManager* cvmanager) :
38 world_(std::move(world)), comm_(std::move(comm)), walkerid_(walkerid), nwalkers_(1),
39 methods_(methods), cvmanager_(cvmanager), hook_(nullptr), inputs_(0)
58 CharReaderBuilder rbuilder;
59 CharReader* reader = rbuilder.newCharReader();
64 reader->parse(JsonSchema::Simulation.c_str(),
65 JsonSchema::Simulation.c_str() + JsonSchema::Simulation.size(),
67 validator.
Parse(schema,
"#");
73 auto nwalkers = json.get(
"walkers", 1).asUInt();
74 if(json[
"input"].isArray() && json[
"input"].size() != nwalkers)
75 throw BuildException({
"#/input: Number of inputs do not match requested walkers."});
77 std::vector<std::string> inputs;
78 for(
size_t i = 0; i < nwalkers; ++i)
80 if(json[
"input"].isArray())
81 inputs.push_back(json[
"input"][
static_cast<int>(i)].asString());
83 inputs.push_back(json[
"input"].asString());
88 auto wcomm = mxx::comm(world);
89 if(wcomm.size() % nwalkers != 0)
90 throw BuildException({
"#/walkers: Allocated processors not divisible by number of walkers."});
93 int ppw = wcomm.size()/nwalkers;
94 int walkerid = wcomm.rank()/ppw;
95 auto comm = wcomm.split(walkerid);
100 for(
auto& cv : json[
"CVs"])
104 if(cv.isMember(
"name"))
119 std::vector<Method*> methods;
120 for(
auto& m : json[
"methods"])
123 for(
auto& cv : m[
"cvs"])
132 if(json.isMember(
"logger"))
135 auto* rh =
new ResourceHandler(std::move(world), std::move(comm), walkerid, methods, cvmanager);
136 rh->inputs_ = inputs;
137 rh->nwalkers_ = nwalkers;
Requirements on an object.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
std::vector< std::string > GetErrors()
Get list of error messages.
bool HasErrors()
Check if errors have occured.
Exception to be thrown when building the Driver fails.
Collective variable manager.
static void AddCVtoMap(const std::string &name, unsigned int id)
Register CV name with map.
static int LookupCV(const Json::Value &cv, const std::string &path)
Get CV id from map.
static CollectiveVariable * BuildCV(const Json::Value &json, const std::string &path)
Set up collective variable.
Base class for hooks into the simultion engines.
void SetCVManager(class CVManager *cvmanager)
Sets the current CV manager.
void AddListener(EventListener *listener)
Add a listener to the hook.
void SetSnapshot(class Snapshot *snapshot)
Sets the active snapshot.
Base class for logging SSAGES data.
static Logger * Build(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a Logger from JSON node.
static Method * BuildMethod(const Json::Value &json, const MPI_Comm &world, const MPI_Comm &comm, const std::string &path)
Build a derived method from JSON node.
Class that handles SSAGES resources for a simulation.
ResourceHandler(mxx::comm &&world, mxx::comm &&comm, size_t walkerid, const std::vector< class Method * > &methods, class CVManager *cvmanager)
Constructor.
class Snapshot * snapshot_
Snapshot of system state (pointer).
class CVManager * cvmanager_
Collective variable manager.
~ResourceHandler()
Destructor.
class Hook * hook_
Hook pointer.
std::vector< class Method * > methods_
Vector of advanced sampling methods.
mxx::comm comm_
MPI communicator containing processors for specific walker.
class Logger * logger_
CV logger.
void ConfigureHook(class Hook *hook)
Configure the Hook from given resources.
static ResourceHandler * Build(const Json::Value &json, const MPI_Comm &world)
Build a new ResourceHandler from JSON.
Class containing a snapshot of the current simulation in time.