schrodinger.tasks.cli module¶
- schrodinger.tasks.cli.get_input_group(parser: argparse.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:
object
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
andskipParamArg
in thecustomizeParamArgs
method and/or be implementingcustomizeParser
andprocessCustomNamespace
.For more control, subclasses can instead reimplement
makeParser
andmakeTaskFromNamespace
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
andget_job_spec_from_args
functions available. There is no need to instantiate the class. This behavior can be disabled by settingADD_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
.- TaskClass = NotImplemented¶
- ADD_MODULE_FUNCTIONS = True¶
- updateParamArg(param: schrodinger.models.parameters.CompoundParam, name: str = None, **kwargs) None ¶
- Parameters
param – An atomic abstract task input param. For example,
MyTask.input.coord.x
.name – Desired name of the argparse argument. If not provided, the argument will be optional and named according to the param’s name. For example,
-coord.x
.kwargs – kwargs for
argparse.ArgumentParser.add_argument
- skipParamArg(param: schrodinger.models.parameters.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: schrodinger.models.parameters.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: schrodinger.tasks.tasks.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.
- 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.
- customizeParamArgs() None ¶
Make calls to
updateParamArg
andskipParamArg
here prior to parser creation in order to customize how auto-generated arguments are defined.
- customizeParser(parser: argparse.ArgumentParser) None ¶
Modify the parser in-place after all atomic params in the task input have been added as arguments (excluding nonstandard params).
- processCustomNamespace(task: schrodinger.tasks.tasks.AbstractTask, namespace: argparse.Namespace) None ¶
Process the parsed namespace to populate the task input with desired values.
- makeParser() argparse.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() argparse.ArgumentParser ¶
Create the base parser to which all task input params will be added.
- makeTaskFromArgs(argv: list[str]) schrodinger.tasks.tasks.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: argparse.Namespace) schrodinger.tasks.tasks.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]) schrodinger.job.launchapi.JobSpecification ¶
This method will automatically be added to the module as
get_job_spec_from_args
.
- classmethod getInstance()¶
- __init__()¶