Use proper doxygen tags in modular simulator
[gromacs.git] / api / include / gmxapi / session.h
blobb71feed4960b22c286aa7ed42301ba199f102b2d
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \file
36 * \brief Launch and manage a GROMACS session.
38 * \author M. Eric Irrgang <ericirrgang@gmail.com>
40 * \ingroup gmxapi
43 #ifndef GROMACS_SESSION_H
44 #define GROMACS_SESSION_H
46 /*! \file
47 * \brief Declarations for a workflow execution session and helper functions.
49 * \ingroup gmxapi
52 #include <memory>
53 #include <string>
55 namespace gmxapi
58 // forward declarations
59 class Context; // defined in gmxapi/context.h
60 class MDModule;
61 class Status; // defined in gmxapi/status.h
62 class Workflow; // implementation detail
64 /*!
65 * \brief Private implementation class for a session.
67 * Actual implementation class may depend on the execution context, but this should be irrelevant to
68 * a client. The implementation details are not exposed in the high-level API, but may be in the
69 * extension API. See developer documentation for details.
71 * \ingroup gmxapi
73 class SessionImpl;
75 /*!
76 * \brief Workflow execution session.
78 * When a workflow is launched in an execution context, the result is a Session object
79 * that serves as a handle to interact with the running workflow. The handle allows dynamic changes
80 * to the workflow, or control or data crossing the API boundary.
82 * Separating run() from construction allows the client to examine the running execution
83 * environment or to retrieve the communicator before beginning long-running computation.
85 * The session should be explicitly `close()`ed before destruction to allow exception
86 * handling during shutdown. The destructor will close() the session if it is not
87 * closed already, but errors may be hidden.
89 * The session owns a Status object that can be shared and retained by client code
90 * for further inspection.
92 * \ingroup gmxapi
94 class Session
96 public:
97 /// A session must be created by launching a workflow in an execution context.
98 Session() = delete;
100 /*! \brief A session cannot be copied, only moved.
102 * For shared ownership of a session, use a shared pointer.
103 * \{
105 Session(const Session&) = delete;
106 Session& operator=(const Session&) = delete;
107 //! \}
110 * \brief Pass ownership of a Session.
112 * \{
114 Session(Session&&) noexcept = default;
115 Session& operator=(Session&&) noexcept = default;
116 //! \}
119 * \brief Construct by taking ownership of an implementation object.
121 * \param impl Concrete object to take ownership of.
123 explicit Session(std::unique_ptr<SessionImpl> impl) noexcept;
126 * \brief Destroy Session.
128 * If the session is still active (has not been closed) then it will be closed
129 * with exceptions suppressed. If possible, problems encountered will be
130 * noted in the Status object, which the client may have retained shared
131 * ownership of.
133 ~Session();
136 * \brief Close a running session.
138 * close() should be called before destroying the Session object so that the
139 * client can catch any exceptions thrown during shut down that may be
140 * unavoidable in the parallel computing environment.
142 * \return status of close() operation.
144 Status close();
147 * \brief Run the current workflow to completion.
149 * The client should examine the Status object for errors and resulting workflow state.
150 * \return the Session's Status after the run.
152 Status run() noexcept;
155 * \brief Check if session is running.
157 * A Session will be "open" from the point of launch until "close" is
158 * called. If this is not true, either an error has occurred or there is
159 * a bug in the implementation.
161 * \return `true` if the session is running, else `false`
163 bool isOpen() const noexcept;
165 /*! \cond internal
166 * \brief Get a non-owning handle to the implementation object.
168 * Get a raw pointer to the implementation object. The pointer is valid only during the lifetime of the Session,
169 * so retain a shared pointer to this Session object or only hold the pointer for the duration of a code block
170 * guaranteed to exist entirely within the lifetime of a Session object.
172 * \return opaque pointer used by gmxapi implementation and extension code.
174 SessionImpl* getRaw() const noexcept;
175 //! \endcond
177 private:
178 //! \brief opaque pointer to implementation
179 std::unique_ptr<SessionImpl> impl_;
183 * \brief Add a uniquely identifiable restraint instance to the MD simulator.
185 * \param session Session with an MD runner to attach a restraint to.
186 * \param restraint wrapped restraint force calculation object.
187 * \return success if restraint was attached successfully, else failure.
189 * \todo Clarify whether we are adding modules generally, adding restraint modules, or adding restraints.
190 * \todo Update for new scheme in which all restraints are managed by a single Restraint module.
191 * \todo Figure out what this object should return to provide more utility and rigorous error checking.
193 Status addSessionRestraint(Session* session, std::shared_ptr<gmxapi::MDModule> restraint);
196 * \brief Launch a workflow in the provided execution context.
198 * \param context Execution environment
199 * \param work Directed acyclic graph defining workflow and data flow.
200 * \return non-unique ownership of the session or nullptr in failure.
202 * The provided context maintains a weak reference to the executing session, while
203 * the session extends the life of the context.
205 * If session fails to launch (nullptr returned) examine the Status of the context
206 * for details.
207 * \ingroup gmxapi
209 std::shared_ptr<Session> launchSession(Context* context, const Workflow& work) noexcept;
212 } // end namespace gmxapi
214 #endif // GROMACS_SESSION_H