SENSEI
A frame work for generic in situ analytics
|
Loads and executes a Python script impementing the sensei::AnalysisAdaptor API. More...
#include <PythonAnalysis.h>
Public Member Functions | |
senseiTypeMacro (PythonAnalysis, AnalysisAdaptor) | |
void | SetScriptFile (const std::string &fileName) |
Set the file to load the Python source code from rank 0 reads and broadcasts to all. More... | |
void | SetScriptModule (const std::string &moduleName) |
Set a module to import Python source code from. More... | |
void | SetInitializeSource (const std::string &source) |
Set a string containing Python source code that will be executed during initialization. More... | |
int | Initialize () |
Initialize the interpreter. More... | |
bool | Execute (DataAdaptor *data, DataAdaptor **) override |
Invoke in situ processing by calling the user provided Python function. More... | |
int | Finalize () override |
Shut down and clean up the embedded interpreter. More... | |
Public Member Functions inherited from sensei::AnalysisAdaptor | |
senseiBaseTypeMacro (AnalysisAdaptor, svtkObjectBase) | |
void | PrintSelf (ostream &os, svtkIndent indent) override |
Prints the current state of the adaptor. More... | |
virtual int | SetCommunicator (MPI_Comm comm) |
Set the MPI communicator to be used by the adaptor. More... | |
MPI_Comm | GetCommunicator () |
returns the MPI communicator to be used for all communication More... | |
virtual void | SetVerbose (int val) |
Set the level of verbosity of console output. More... | |
virtual int | GetVerbose () |
Get the level of verbosity of console output. More... | |
virtual void | SetAsynchronous (int val) |
When set the analysis should buffer the simulation data and run in the background returning to the simulation immediately. More... | |
virtual int | GetAsynchronous () |
Get asynchronous mode. More... | |
virtual void | SetDeviceId (int val) |
Set the device that the analysis should run on. More... | |
virtual int | GetDeviceId () |
Get the device that the analysis should run on. More... | |
virtual void | SetDevicesToUse (int val) |
Set the number of devices to use per node. More... | |
virtual int | GetDevicesToUse () |
Get the number of devices to use per node. More... | |
virtual void | SetDeviceStart (int val) |
Set the first on node device to use in automatic device selection. More... | |
virtual int | GetDeviceStart () |
Get the first device to use. More... | |
virtual void | SetDeviceStride (int val) |
Set the number of devices to skip in automatic device selection. More... | |
virtual int | GetDeviceStride () |
Get the number of devices to skip. More... | |
Static Public Member Functions | |
static PythonAnalysis * | New () |
Creates a new instance of the PythonAnalysis. More... | |
Protected Member Functions | |
PythonAnalysis (const PythonAnalysis &)=delete | |
void | operator= (const PythonAnalysis &)=delete |
Protected Member Functions inherited from sensei::AnalysisAdaptor | |
AnalysisAdaptor (const AnalysisAdaptor &)=delete | |
void | operator= (const AnalysisAdaptor &)=delete |
Additional Inherited Members | |
Public Types inherited from sensei::AnalysisAdaptor | |
enum | { DEVICE_HOST =-1, DEVICE_AUTO =-2 } |
values controling device selection More... | |
Protected Attributes inherited from sensei::AnalysisAdaptor | |
MPI_Comm | Comm |
int | Verbose |
int | DeviceId |
int | DevicesPerNode |
int | DevicesToUse |
int | DeviceStart |
int | DeviceStride |
int | Asynchronous |
Loads and executes a Python script impementing the sensei::AnalysisAdaptor API.
The script should define the following functions:
"Initialize" and "Finalize" are optional, while "Execute" is required. The script is specified at run time either as a module or a file. If a module is specified (see SetScriptModule) the provided module is imported through Python's built in import mechanism. This means that it must be in a directory in the PYTHONPATH
. If a file is specified (see SetScriptFile) the file is read on rank 0 and broadcast to other ranks. Use either the module or the file approach, but not both.
The active MPI communicator is made available to the script through the global variable comm
.
To fine tune run time behavior we provide "initialization source". The initialization source (see SetInitializeSource) is provided in a string and will be executed prior to your script functions. This lets you set global variables that can modify the scripts run time behavior.
The compiled artifacts of this class and the sensei Python module must be findable in both the PYTHONPATH
and the LD_LIBRARY_PATH
(DYLD_LIBRARY_PATH
on Mac OS)
The user provided Execute function returns one of four possible things:
At any point the user provided code may raise an exception if an error occurred. This will be caught and preoprted. An error code will be returned to the simulation indicating to halt in situ processing.
The user provided Execute function should call DataAdaptor::ReleaseData when processing is completed to ensure all resources are released.
|
overridevirtual |
Invoke in situ processing by calling the user provided Python function.
Implements sensei::AnalysisAdaptor.
|
overridevirtual |
Shut down and clean up the embedded interpreter.
Reimplemented from sensei::AnalysisAdaptor.
int sensei::PythonAnalysis::Initialize | ( | ) |
Initialize the interpreter.
One must set file name or module name before initialization.
|
static |
Creates a new instance of the PythonAnalysis.
void sensei::PythonAnalysis::SetInitializeSource | ( | const std::string & | source | ) |
Set a string containing Python source code that will be executed during initialization.
This can be used for instance to set global variables controlling execution. This source will be executed after loading or importing the script (see SetScriptFile and SetScriptModule) and before the script's functions.
void sensei::PythonAnalysis::SetScriptFile | ( | const std::string & | fileName | ) |
Set the file to load the Python source code from rank 0 reads and broadcasts to all.
void sensei::PythonAnalysis::SetScriptModule | ( | const std::string & | moduleName | ) |
Set a module to import Python source code from.
Makes use of Python's import mechanism to load your script. Your script must be in the PYTHONPATH
.