Skip to content

Commit

Permalink
gmxapi-62 Stop condition hook task 1
Browse files Browse the repository at this point in the history
Work in progress. This commit will be rewritten soon. Don't merge into
anything but a temporary integration branch.
  • Loading branch information
eirrgang committed May 18, 2018
1 parent 4fb7a84 commit d363e92
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ configure_file(gmxapi/version.in.h gmxapi/version.h)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/gmxapi/md)
#configure_file(gmxapi/md/runnerstate.h gmxapi/md)
configure_file(gmxapi/md/mdmodule.h gmxapi/md)
configure_file(gmxapi/md/mdsignals.h gmxapi/md)

# Add to install target: copy the public API headers from the source directory
# into the gmxapi header subdirectory.
Expand Down Expand Up @@ -71,6 +72,7 @@ target_sources(
mdmodule.cpp
session-impl.h
session.cpp
mdsignals.cpp
status.cpp
system.cpp
system-impl.h
Expand Down
56 changes: 56 additions & 0 deletions src/api/cpp/gmxapi/md/mdsignals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Created by Eric Irrgang on 5/18/18.
//

/* WARNING
* This whole file is not intended to make it into a public release and is not part of the gmxapi API. It is for
* prototyping only. Please don't let it slip into a release without serious design considerations.
*/

#ifndef GROMACS_SIGNALS_H
#define GROMACS_SIGNALS_H

#include <memory>

namespace gmxapi {

namespace md
{

enum class signals {
STOP
};

} // end namespace md


class Session; // defined in gmxapi/session.h

/*!
* \brief Proxy for signalling function objects.
*
* Objects of this type are simple callables that issue a specific signal.
*/
class Signal
{
public:
class SignalImpl;
explicit Signal(std::unique_ptr<SignalImpl>&& signal);

void operator()();

private:
std::unique_ptr<SignalImpl> impl_;
};

/*!
* \brief Get a function object that issues a signal to the currently active MD runner.
*
* \param session pointer to the active Session.
* \return Callable function object handle
*/
Signal getMdrunnerSignal(Session* session, md::signals signal);

} // end namespace md

#endif //GROMACS_SIGNALS_H
11 changes: 11 additions & 0 deletions src/api/cpp/gmxapi/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ class Session

bool isOpen() const noexcept;

/*! \internal
* \brief Get a non-owning handle to the implementation object.
*
* Get a raw pointer to the implementation object. The pointer is valid only during the lifetime of the Session,
* so retain a shared pointer to this Session object or only hold the pointer for the duration of a code block
* guaranteed to exist entirely within the lifetime of a Session object.
*
* \return opaque pointer used by gmxapi implementation and extension code.
*/
SessionImpl* getRaw() const noexcept;

private:
friend
Status setSessionRestraint(Session* session,
Expand Down
79 changes: 79 additions & 0 deletions src/api/cpp/mdsignals.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// Created by Eric Irrgang on 5/18/18.
//



#include <gromacs/compat/make_unique.h>
#include "gmxapi/md/mdsignals.h"

#include "gromacs/mdlib/simulationsignal.h"
#include "programs/mdrun/runner.h"

#include "gmxapi/session.h"

#include "session-impl.h"

namespace gmxapi {

class Signal::SignalImpl
{
public:
virtual void call() = 0;


};

Signal::Signal(std::unique_ptr<gmxapi::Signal::SignalImpl>&& impl) :
impl_{std::move(impl)}
{
}

void Signal::operator()()
{
impl_->call();
}

class StopSignal : public Signal::SignalImpl
{
public:
explicit StopSignal(gmx::Mdrunner* runner) : runner_{runner} {};

static Signal create(gmx::Mdrunner* runner)
{
auto impl = gmx::compat::make_unique<StopSignal>(runner);
auto signal = gmxapi::Signal(std::move(impl));
return signal;
}

void call() override
{
auto signals = runner_->signals();
signals->at(eglsSTOPCOND).sig = true;
}

private:
gmx::Mdrunner* runner_;
};


Signal getMdrunnerSignal(Session* session, md::signals signal)
{
// if (signal == md::signals::STOP)
// {
assert(session);

auto impl = session->getRaw();
assert(impl);

auto runner = impl->getRunner();
assert(runner);

return StopSignal::create(runner);
// }
// else
// {
// }
}

} // end namespace gmxapi
8 changes: 8 additions & 0 deletions src/api/cpp/session-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace gmxapi

// Forward declaration
class MpiContextManager; // Locally defined in session.cpp
class ContextImpl; // locally defined in context.cpp

/*!
* \brief Implementation class for executing sessions.
Expand Down Expand Up @@ -71,6 +72,13 @@ class SessionImpl
std::unique_ptr<gmx::Mdrunner> runner);

Status setRestraint(std::shared_ptr<gmxapi::MDModule> module);

/*!
* \brief API implementation function to retrieve the current runner.
*
* \return non-owning pointer to the current runner or nullptr if none.
*/
gmx::Mdrunner* getRunner();
private:
/*!
* \brief Private constructor for use by create()
Expand Down
15 changes: 15 additions & 0 deletions src/api/cpp/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ Status SessionImpl::setRestraint(std::shared_ptr<gmxapi::MDModule> module)
return status;
}

gmx::Mdrunner *SessionImpl::getRunner()
{
gmx::Mdrunner * runner{nullptr};
if (runner_)
{
runner = runner_.get();
}
return runner;
}

Session::Session(std::unique_ptr<SessionImpl>&& impl) noexcept :
impl_{std::move(impl)}
{
Expand Down Expand Up @@ -206,6 +216,11 @@ Status setSessionRestraint(Session *session,
return status;
}

SessionImpl *Session::getRaw() const noexcept
{
return impl_.get();
}

std::shared_ptr<Session> launchSession(Context* context, const Workflow& work) noexcept
{
auto session = context->launch(work);
Expand Down
25 changes: 25 additions & 0 deletions src/gromacs/context/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
#add_library(restraint OBJECT
# restraintpotential.h
# restraintpotential.cpp
# vectortype.h
# manager.cpp
# manager.h
# restraintfunctor-impl.cpp
# restraintfunctor-impl.h
# restraintcalculation.h
# restraintcalculation.cpp
# restraintcalculation-impl.h
# restraintmdmodule.h
# restraintmdmodule.cpp
# restraintmdmodule-impl.h)
#set_target_properties(restraint PROPERTIES POSITION_INDEPENDENT_CODE ON)
#
#set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} $<TARGET_OBJECTS:restraint> PARENT_SCOPE)
#
#gmx_install_headers(restraintpotential.h
# vectortype.h)
#
#if (BUILD_TESTING)
# add_subdirectory(tests)
#endif()
20 changes: 19 additions & 1 deletion src/gromacs/restraint/restraintpotential.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,25 @@ class IRestraintPotential
double t) = 0;


// An update function to be called on the simulation master rank/thread periodically by the Restraint framework.
/*!
* \brief Call-back hook for restraint implementations.
*
* An update function to be called on the simulation master rank/thread periodically
* by the Restraint framework.
* Receives the same input as the evaluate() method, but is only called on the master
* rank of a simulation to allow implementation code to be thread-safe without knowing
* anything about the domain decomposition.
*
* \param v position of the first site
* \param v0 position of the second site
* \param t simulation time
*
* \internal
* We give the definition here because we don't want plugins to have to link against
* libgromacs right now (complicated header maintenance and no API stability guarantees).
* But once we've had plugin restraints wrap themselves in a Restraint template, we can set update = 0
* \todo: Provide gmxapi facility for plugin restraints to wrap themselves with a default implementation to let this class be pure virtual.
*/
virtual void update(gmx::Vector v,
gmx::Vector v0,
double t) { (void)v; (void)v0; (void)t; };
Expand Down

0 comments on commit d363e92

Please sign in to comment.