4.1. Batch processing

SMITER allows Python scripting and running in batch locally or on remote machines through Job Manager module. Advantage of batch processing is obvious when we require programmatic interface to be applied to similar cases, parameter scanning or when we require larger compute power by processing single or multiple cases at once.

With batch we can load a study in Python that was made with SMITER GUI previously and operate with SMITER codes within the script.

The following example script is able to run a already prepared study file with at least one SMITER case. The following variables should be changed, according to the system you use:

  • studyFileName - Path to the study file
  • compute.setSMARDDApath - Absolute path to SMARDDA directory
  • compute.setCaseDir - Absolute path to where the to run SMITER cases.
#!/usr/bin/env python2
"""This is an example script to run a already prepared study file
with at least one SMITER case.

The following variables should be changed, according to the system you use:

studyFileName - Absolute path to the study file
compute.setSMARDDApath - Absolute path to SMARDDA directory
compute.setCaseDir - Absolute path to where the to run SMITER cases.
"""


import salome
import SMITER_API
import SMITER_BATCH_API
import SMITER_utils
import sys
import os

# Path to the study file, in this case absolute.
this_python_file_location = os.path.dirname(os.path.realpath(__file__))
studyFileName = os.path.join(this_python_file_location, 'batch.hdf')

if salome.myStudy:
    # Close the current study, if running form GUI
    salome.salome_close()

# Open and initialize the study.
salome.salome_init(studyFileName)
# Activate module SMITER and activate CORBA
SMITER_utils._batch_activateModule(salome.myStudy)

# Get the list of cases in the study file.
listOfCases = SMITER_API.getAvailableCases()
print 'List of cases: ', listOfCases

case = listOfCases[0] # In this case there will be only one case.

print 'Creating compute instance.'
compute = SMITER_BATCH_API.ComputeCase() # Create the compute case instance.
compute.setSMARDDApath(os.path.join(os.path.expanduser("~"), 'smiter'))
compute.setCaseDir('/tmp')
# We only need to provide the string name for the case object and pass it on
# to the compute case instance.
print 'Setting case'
compute.findAndSetCase(case)

print 'Starting compute'
# If we wish to save the Powcal results directly to study, the following switch
# enables that
compute.saveToCase = True
compute.compute()


if compute.saveToCase:
    # If we have enabled saving the Powcal results to study, we also have to
    # save the study in the end.
    print 'Saving study'
    salome.myStudyManager.SaveAs(salome.myStudyName, salome.myStudy, False)
    salome.myStudyManager.Close(salome.myStudy)

This batch.py script can then be run from the command line that (so called CLI or Command line interface) by issuing:

$ ./smiter -t study/tutorial/batch.py

The batch.py assumes that the location of the batch.hdf study is located in the same directory as the Python script.

4.1.1. Activating module in SALOME in batch

To activate a module, in this case SMITER, in SALOME batch, the following lines has to be run:

import salome
import SMITER_utils

studyFileName = '/path/to/study/file'
salome.salome_init(studyFileName)

engine = SMITER_utils.getEngine()
component = SMITER_utils.findOrCreateComponent(salome.myStudy)

# The study builder performs the activation of CORBA interface and loading
# whatever data was saved by SMITER module.
studyBuilder = salome.myStudy.NewBuilder()
studyBuilder.LoadWith(component, engine)
# Now SMITER CORBA interface is activated and ready to be used.

This activates the CORBA interface, meaning that you can access to SMITER interface and functions by calling the GetObject function on a SMITER object that is published in object browser. Simply instancing a SMITER engine via SMITER_utils.getEngine() is not enough.

Note

This may not be a correct way for activating a module and its interface, so it is described as a workaround.

To activate GEOM or SMESH module, the respective builder has to be run. The following code is to be used in GUI mode. For batch mode, you only have to activate a study and then perform the following:

# For SMESH
import salome
from salome.smesh import smeshBuilder

sb = smeshBuilder.New()
# Now SMESH CORBA interface can be accessed and used.

# For GEOM
import salome
from salome.geom import geomBuilder
gb = geomBuilder.New()
# Now GEOM CORBA interface can be accessed and used.