schrodinger.tasks.cli module

schrodinger.tasks.cli.get_input_group(parser: ArgumentParser)

Get the standard task input group from a parser. Allows users to add custom arguments to the input group even if they don’t map directly to a task input param.

class schrodinger.tasks.cli.CLI

Bases: FuncChainMixin

The command line interface for a task class. Subclass this class to define custom command line interfaces for task classes.

By default, the CLI will generate argparse arguments for all atomic params in the task input. Subclasses can customize the arguments by calling updateParamArg and skipParamArg in the customizeParamArgs method and/or by implementing customizeParser and customProcessParsedArgs.

For more control, subclasses can instead reimplement makeParser and makeTaskFromNamespace to create completely custom parser and namespace processing.

Defining a CLI subclass in a module is enough to turn it into a command line script with both main and get_job_spec_from_args functions available. There is no need to instantiate the class. This behavior can be disabled by setting ADD_MODULE_FUNCTIONS = False.

Example usage:

# foo.py
class FooTask(jobtasks.ComboJobTask):
    ...

class FooCLI(CLI):
    TaskClass = FooTask

A command line interface is available now at $SCHRODINGER/run foo.py -h.

Task preprocessors can be defined directly on a CLI subclass using the @tasks.preprocessor decorator. The CLI will automatically install these preprocessors on the task instance before running it.

TaskClass = NotImplemented
ADD_MODULE_FUNCTIONS = True
inCustomizeParamArgs()
customizeParamArgs() None

A param arg is a parser argument that corresponds to a param in the task. See customizeParser for adding non-param args.

The following methods can be called from this method to customize param args:

updateParamArg(param: CompoundParam, positional_order: int = None, **kwargs) None
Parameters:
  • param – The param for which we want to customize the argument. For example, MyTask.input.coord.x.

  • positional_order – When specified, makes the argument positional and sets its order relative to other positional args.

  • kwargs – kwargs for argparse.ArgumentParser.add_argument

skipParamArg(param: CompoundParam) None

Omit the param and any of its children from the auto-generated argparse arguments. :param param: An abstract task input param

flattenParamArgs(param: CompoundParam) None

Flatten the argument name for the specified param and its children in the auto-generated argparse arguments. E.g. -x instead of -coord.x and -baz instead of -foo.bar.baz.

makeCmd(task: AbstractTask) list[str]

Return a command that invokes this CLI using inputs from the given task instance. Expects the task to have already run preprocessing.

customizeParser(parser: ArgumentParser) None

Use this method to add additional arguments that do not correspond directly to any one input param. If custom arguments are added, override customProcessParsedArgs to consume the values of these custom arguments after they have been parsed.

customProcessParsedArgs(task: AbstractTask, namespace: Namespace) None

Process the parsed namespace to populate the task input with desired values.

defineJobControlOptions() list[schrodinger.utils.cmdline.Options]

Return a list of job control options to add to the auto-generated argument parser. Subclasses may override to specify desired flags.

makeParser() ArgumentParser

Make the argument parser.

Subclasses can reimplement this method to create a completely custom parser that doesn’t get populated with any auto-generated arguments.

createBaseParser() ArgumentParser

Create the base parser to which all task input params will be added.

makeTaskFromArgs(argv: list[str]) AbstractTask

Make a task instance from command-line arguments.

makeArgsFromTask(task) list[str]

Make a list of cmdline arguments from a task instance.

makeOptionalArgsFromTask(task)

Make optional args from a task instance. Only param-mapped arguments are generated in the default implementation. Override to include additional arguments.

makePositionalArgsFromTask(task)

Make positional args from a task instance. Only param-mapped arguments are generated in the default implementation. Override to include additional arguments.

makeTaskFromNamespace(namespace: Namespace) AbstractTask

Make and populate a task instance from a namespace of parsed args.

If makeParser is reimplemented, then this method should also be reimplemented to handle the custom namespace.

main(argv: list[str] = None) int

This method serves as the main function, and will be added to the module’s namespace as main.

getJobSpecFromArgs(argv: list[str]) JobSpecification

This method will automatically be added to the module as get_job_spec_from_args.

makeJobSpecBuilder(task: AbstractTask, argv: list[str]) JobSpecificationArgsBuilder

Make the job spec args builder from the given task and args. Override this method in a subclass to customize the job spec builder.

classmethod getInstance()
__init__()