Argument Parsing¶
Each of the scripts from Defining and Sequencing the Work uses argument utilities that are
described here. Arguments are single command like args, that would be passed
in something like --do-this-thing
or --location-id 101
as flags.
We use the argparse
package to interpret these arguments and to define
which arguments are allowed for which scripts.
Arguments are building blocks for argument lists. Each script has an argument list that defines the arguments that can be passed to it that’s included at the top of the script.
Arguments¶
There are general arguments and specific arguments that we define here so we don’t have to use them over and over.
-
exception
cascade_at.executor.args.args.
CascadeArgError
[source]¶ Bases:
cascade_at.core.CascadeATError
-
class
cascade_at.executor.args.args.
IntArg
(*args, **kwargs)[source]¶ Bases:
cascade_at.executor.args.args._Argument
An integer argument.
-
class
cascade_at.executor.args.args.
FloatArg
(*args, **kwargs)[source]¶ Bases:
cascade_at.executor.args.args._Argument
A float argument.
-
class
cascade_at.executor.args.args.
StrArg
(*args, **kwargs)[source]¶ Bases:
cascade_at.executor.args.args._Argument
A string argument.
-
class
cascade_at.executor.args.args.
BoolArg
(*args, **kwargs)[source]¶ Bases:
cascade_at.executor.args.args._Argument
A boolean argument.
-
class
cascade_at.executor.args.args.
ListArg
(*args, **kwargs)[source]¶ Bases:
cascade_at.executor.args.args._Argument
A list argument. Passed in as an
nargs +
type of argument toargparse
.
-
class
cascade_at.executor.args.args.
ModelVersionID
[source]¶ Bases:
cascade_at.executor.args.args.IntArg
The Model Version ID argument is the only task argument, meaning an argument that makes the commands that it is used in unique across workflows.
-
class
cascade_at.executor.args.args.
ParentLocationID
[source]¶ Bases:
cascade_at.executor.args.args.IntArg
A parent location ID argument.
-
class
cascade_at.executor.args.args.
SexID
[source]¶ Bases:
cascade_at.executor.args.args.IntArg
A sex ID argument.
-
class
cascade_at.executor.args.args.
DmCommands
[source]¶ Bases:
cascade_at.executor.args.args.ListArg
A dismod commands argument, based off of the list argument.
-
class
cascade_at.executor.args.args.
DmOptions
[source]¶ Bases:
cascade_at.executor.args.args.ListArg
A dismod options argument, based off of the list argument. Arguments need to be passed in as a list, but then look like
KEY=VALUE=TYPE
. So, if you wanted the options to look like this{'kind': 'random'}
, you would pass on the command-linekind=random=str
.
-
class
cascade_at.executor.args.args.
NSim
[source]¶ Bases:
cascade_at.executor.args.args.IntArg
Number of simulations argument. Defaults to 1.
-
class
cascade_at.executor.args.args.
NPool
[source]¶ Bases:
cascade_at.executor.args.args.IntArg
Number of threads for a multiprocessing pool argument, defaults to 1, which is no multiprocessing.
-
class
cascade_at.executor.args.args.
LogLevel
[source]¶ Bases:
cascade_at.executor.args.args.StrArg
Logging level argument. Defaults to “info”.
Argument List¶
Argument lists are made up of arguments, and are defined at the top of each of the Defining and Sequencing the Work scripts. The reason that they’re helpful is because we can then use those lists to parse command line arguments and at the same time use them to validate arguments in Cascade Operations. This makes building new cascade operations much less error-prone. It also has a method to convert an argument list into a task template command for Utilizing Jobmon.
Argument Encoding¶
When we are defining arguments to an operation, we don’t want to write as if we were writing something on the command line, especially with things like dictionaries and lists of dismod database commands.
The following functions are helpful for encoding and decoding dismod option dictionaries to be used with the dismod database and dismod commands to run on a dismod database.
-
cascade_at.executor.args.arg_utils.
encode_options
(options)[source]¶ Encode an option dict into a command line string that cascade_at can understand.
- Returns
- Return type
List of strings that can be passed to the command line..
-
cascade_at.executor.args.arg_utils.
parse_options
(option_list)[source]¶ Parse a key=value=type command line arg that comes in a list.
- Returns
- Return type
Dictionary of options with the correct types.