SENSEI
A frame work for generic in situ analytics
sensei::PythonAnalysis Class Reference

Loads and executes a Python script impementing the sensei::AnalysisAdaptor API. More...

#include <PythonAnalysis.h>

Inheritance diagram for sensei::PythonAnalysis:
[legend]
Collaboration diagram for sensei::PythonAnalysis:
[legend]

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 PythonAnalysisNew ()
 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
 

Detailed Description

Loads and executes a Python script impementing the sensei::AnalysisAdaptor API.

The script should define the following functions:

def Initialize():
""" Initialization code here """
return
def Execute(dataAdaptor):
""" Use sensei::DataAdaptor API to process data here """
return
def Finalize():
""" Finalization code here """
return

"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:

  1. None. Success is assumed in this case, and processing continues.
  2. An integer status code where 0 indicates to stop in situ processing and non-zero indicates to continue in situ processing.
  3. A data adaptor instance. The data adaptor instance can be used to access the results of the operation. Success is assumed in this case and processing continues.
  4. A tuple containing an integer status code (see 2 above for description of status codes) and a data adaptor instance through which results of the operation may be accessed.

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.

Member Function Documentation

◆ Execute()

bool sensei::PythonAnalysis::Execute ( DataAdaptor data,
DataAdaptor **   
)
overridevirtual

Invoke in situ processing by calling the user provided Python function.

Implements sensei::AnalysisAdaptor.

◆ Finalize()

int sensei::PythonAnalysis::Finalize ( )
overridevirtual

Shut down and clean up the embedded interpreter.

Reimplemented from sensei::AnalysisAdaptor.

◆ Initialize()

int sensei::PythonAnalysis::Initialize ( )

Initialize the interpreter.

One must set file name or module name before initialization.

◆ New()

static PythonAnalysis* sensei::PythonAnalysis::New ( )
static

Creates a new instance of the PythonAnalysis.

◆ SetInitializeSource()

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.

◆ SetScriptFile()

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.

◆ SetScriptModule()

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.


The documentation for this class was generated from the following file: