bootleg.utils.parser package — Bootleg v1.1.0dev1 documentation (original) (raw)
Submodules¶
bootleg.utils.parser.bootleg_args module¶
Bootleg default configuration parameters.
In the json file, everything is a string or number. In this python file, if the default is a boolean, it will be parsed as such. If the default is a dictionary, True and False strings will become booleans. Otherwise they will stay string.
bootleg.utils.parser.emm_parse_args module¶
Overrides the Emmental parse_args.
bootleg.utils.parser.emm_parse_args.parse_args(parser: Optional[argparse.ArgumentParser] = None) → Tuple[argparse.ArgumentParser, Dict][source]¶
Parse args.
Overrides the default Emmental parser to add the “emmental.” level to the parser so we can parse it correctly with the Bootleg config.
Parameters
parser – Argument parser object, defaults to None.
Returns
The updated argument parser object.
bootleg.utils.parser.emm_parse_args.parse_args_to_config(args: bootleg.utils.classes.dotted_dict.DottedDict) → Dict[str, Any][source]¶
Parse the Emmental arguments to config dict.
Parameters
args – parsed namespace from argument parser.
Returns: Emmental config dict.
bootleg.utils.parser.parser_utils module¶
Bootleg parser utils.
Parses a Booleg input config into a DottedDict of config values (with defaults filled in) for running a model.
bootleg.utils.parser.parser_utils.add_nested_flags_from_config(parser, config_dict, parser_hierarchy, prefix)[source]¶
Add flags from config file, keeping the hierarchy the same.
When a lower level is needed, parser.add_argument_group is called. Note, we append the parent key to the –param option (via prefix parameter).
Parameters
- parser – arg parser to add options to
- config_dict – raw config dictionary
- parser_hierarchy – Dict to add parser hierarhcy to
- prefix – prefix to add to arg parser
bootleg.utils.parser.parser_utils.flatten_nested_args_for_parser(args, new_args, groups, prefix)[source]¶
Flatten all parameters to be passed as a single list to arg parse.
bootleg.utils.parser.parser_utils.get_boot_config(config, parser_hierarchy=None, parser=None, unknown=None)[source]¶
Return a parsed Bootleg config from config.
Config can be a path to a config file or an already loaded dictionary.
The high level work flow
- Reads Bootleg default config (config_args) and addes params to a arg parser, flattening all hierarchical values into “.” values
E.g., data_config -> word_embeddings -> layers becomes –data_config.word_embedding.layers
- Flattens the given config values into the “.” format
- Adds any unknown values from the first arg parser that parses the config script. Allows the user to add –data_config.word_embedding.layers to command line that overwrite values in file
- Parses the flattened args w.r.t the arg parser
- Reconstruct the args back into their hierarchical form
Parameters
- config – model specific config
- parser_hierarchy – Dict of hierarchy of config (or None)
- parser – arg parser (or None)
- unknown – unknown arg values passed from command line to be added to config and overwrite values in file
bootleg.utils.parser.parser_utils.is_json(value)[source]¶
Return True if json.
bootleg.utils.parser.parser_utils.is_number(s)[source]¶
Return True is string is a number.
Load commented json file.
bootleg.utils.parser.parser_utils.merge_configs(config_l, config_r, new_config=None)[source]¶
Merge two dotted dict configs.
bootleg.utils.parser.parser_utils.or_none(default)[source]¶
Return or None function.
bootleg.utils.parser.parser_utils.parse_boot_and_emm_args(config_script, unknown=None)[source]¶
Merge the Emmental config with the Bootleg config.
As we have an emmental: … level in our config for emmental commands, we need to parse those with the Emmental parser and then merge the Bootleg only config values with the Emmental ones.
Parameters
- config_script – config script for Bootleg and Emmental args
- unknown – unknown arg values passed from command line to overwrite file values
Returns: parsed merged Bootleg and Emmental config
bootleg.utils.parser.parser_utils.reconstructed_nested_args(args, names, parser_hierarchy, prefix)[source]¶
Reconstruct the arguments and pass them to the necessary subparsers.
bootleg.utils.parser.parser_utils.recursive_keys(dictionary)[source]¶
Recursively yields all keys of dict.
Module contents¶
Parser init.