schrodinger.tasks.remote_modules module¶
This module provides a way to make copies of modules and import the copies in a different build (i.e. on a remote machine).
This is especially useful when developing code that is meant to be run on another machine, such as a remote job host or on an LD instance, where the remote build would not have the latest changes needed to run the code.
To use, call write_modules_config() on the launch machine, and then call activate_modules() on the remote machine before importing the modules.
The replacement affects all downstream imports, including imports made in other modules, so indirect dependencies can be addressed as well.
- schrodinger.tasks.remote_modules.write_modules_config(modules_list, parent_dir=None, modules_dir=None, zip=False)¶
- Given a list of modules, copy the modules to a directory and write a json file mapping the module fullnames to the local filepaths of the modules. - The resulting directory can be loaded in to “activate” the modules so that the copied modules are imported instead of the original modules. - If zip is set to True, the modules dir will be zipped and given the filename <modules_dir>.zip. To activate the modules on the remote machine, you must call activate_modules with zip=True. - Example: - from schrdinger.tasks import remote_modules - # modules to replace from schrodinger.models import diffy from schrodinger.models import jsonable - remote_modules.write_modules_config([diffy, jsonable]) - Parameters
- modules_list – the list of modules to copy and load remotely 
- parent_dir – the directory into which the module dir should be created. Typically, this would be the launch dir/task dir. 
- modules_dir – name of the modules dir. Default is ‘.remote_modules’ 
- zip – whether to zip the modules dir 
 
- Returns
- a dictionary mapping module fullnames to the copied files. The filenames are relative to the modules dir. 
 
- schrodinger.tasks.remote_modules.activate_modules(modules_dir=None, zip=False)¶
- Activate the modules in the given modules dir. This will add a _FileBasedModuleFinder to sys.meta_path so that the modules in the given modules dir are imported instead of the original modules. - The replacement affects all downstream imports, including imports made in other modules. - Example:
- # assume a modules dir has been created with write_modules_config() as # in the example above from schrodinger.tasks import remote_modules remote_modules.activate_remote_modules() - # these imports will now import the copies from the modules dir instead # of the original modules in the build from schrodinger.models import diffy from schrodinger.models import jsonable 
 - Parameters
- modules_dir – name of the modules dir. Default is ‘.remote_modules’. If zip=True, this will still be the name of the directory, without the ‘.zip’ extension. 
 
- schrodinger.tasks.remote_modules.get_activated_module_names()¶