Custom launcher Examples

This page shows specific examples of scripts that customize the VisIt launch process via a customlauncher script. For more information on VisIt's launch scripts, see Launcher Customization.

Grabbing env settings from a sourced bash script

This example shows a specific customlauncher script that can be used to replicate environment settings that are in effect after running a script.

#
# filename: customlauncher
# description: Experimental environment setup customlauncher example.
#
# notes: 
# 1) Replace `your_env.sh' with the path to your desired env script. 
# 2) Install `customlauncher' next to `internallauncher' in visit/<ver>/bin/ dir
#
# (Requires VisIt 2.6.x or later.)
#

import subprocess
import os

class SiteSpecificLauncher(MainLauncher):
    def __init__(self):
        super(SiteSpecificLauncher, self).__init__()

    def Customize(self):
        p = subprocess.Popen(["-c", "source your_env.sh && env " ],
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             shell=True )
        env_lines = p.communicate()[0].split("\n")
        # remove empty pairs
        env_lines = [ e.strip() for e in env_lines if e.count("=") > 0]
        # parse pairs
        env_pairs = [ (e[:e.find("=")],e[e.find("=")+1:]) for e in env_lines]
        for k,v in env_pairs:
            if not k in os.environ.keys():
                # add new env pair to os.environ
                SETENV(k,v)
        # if you need to add additional paths to the PATH env var:
        SETENV("PATH", self.joinpaths([GETENV("PATH"), "/additional/path"]))

# Launcher creation function
def createlauncher():
    return SiteSpecificLauncher()

Setting Environment Values Using Custom Launcher Environment Helpers

For VisIt 2.7.3 and later, the MainLauncher class provides three helpers (SourceEnvScript, LoadEnvModule, and LoadEnvModules) that simplify capturing environment changes.

SourceEnvScript

 self.SourceEnvScript("my_bash_script.sh")

This executes:

source my_bash_script.sh && env

The output of env is used to modify the current environment. Only new environment pairs are added.

 self.SourceEnvScript("my_bash_script.sh",True)

The output of env is used to modify the current environment. All environment pairs are updated.

LoadEnvModule and LoadEnvModules

self.LoadEnvModule("openmpi")
self.LoadEnvModules(["gcc","openmpi"])

These translate to:

source /etc/profile.d/modules.sh && load gcc && env
source /etc/profile.d/modules.sh && load gcc && load openmpi && env


The output of env is used to modify the current environment. Only new environment pairs are added.

self.LoadEnvModule("openmpi",True)
self.LoadEnvModules(["gcc","openmpi"],True)


The output of env is used to modify the current environment. All environment pairs are updated.

Here is an example showing these helpers used in a customlauncher script:

#
# filename: customlauncher
# description: Environment setup customlauncher example w/ new helper functions
#
# notes: 
# 1) Replace `your_env.sh' with the path to your desired env script. 
# 2) Install `customlauncher' next to `internallauncher' in visit/<ver>/bin/ dir
#
# (Requires VisIt 2.7.3 or later.)
#

import subprocess
import os

class SiteSpecificLauncher(MainLauncher):
    def __init__(self):
        super(SiteSpecificLauncher, self).__init__()

    def Customize(self):
        self.SourceEnvScript("your_env.sh")
        self.LoadEnvModules(["gcc","openmpi"],True)
        SETENV("PATH", self.joinpaths([GETENV("PATH"), "/additional/path"]))

# Launcher creation function
def createlauncher():
    return SiteSpecificLauncher()