argparse

Consistent CLI argument parsing across graphnet.

class graphnet.utilities.argparse.Options(*options)[source]

Bases: object

Class to handle standard argument options to ArgumentParser.

Construct Options.

Parameters:

options (str | Tuple[str, Any])

contains(option)[source]

Check if option is present.

Return type:

bool

Parameters:

option (str)

pop_default(option)[source]

Return the default value for option, if any, and remove entry.

Return type:

Optional[Any]

Parameters:

option (str)

class graphnet.utilities.argparse.ArgumentParser(usage, description)[source]

Bases: ArgumentParser

Class for parsing command-line arguments.

Construct ArgumentParser.

Parameters:
  • usage (str | None)

  • description (str | None)

standard_arguments: Dict[str, Dict[str, Any]] = {'batch-size': {'default': 128, 'help': 'Batch size to use for training (default: %(default)s)', 'type': <class 'int'>}, 'dataset-config': {'default': '/home/runner/.local/lib/python3.10/configs/datasets/training_example_data_sqlite.yml', 'help': 'Path to dataset config file (default: %(default)s)'}, 'early-stopping-patience': {'default': 5, 'help': 'Number of epochs with no improvement in validation loss after which to stop training (default: %(default)s)', 'type': <class 'int'>}, 'gpus': {'default': None, 'help': 'Indices of GPUs to use for training (default: %(default)s)', 'nargs': '+', 'type': <class 'int'>}, 'max-epochs': {'default': 50, 'help': 'Maximum number of epochs to train (default: %(default)s)', 'type': <class 'int'>}, 'model-config': {'default': '/home/runner/.local/lib/python3.10/configs/models/example_energy_reconstruction_model.yml', 'help': 'Path to model config file (default: %(default)s)'}, 'num-workers': {'default': 10, 'help': 'Number of workers to fetch data (default: %(default)s)', 'type': <class 'int'>}}
with_standard_arguments(*args)[source]

Add standard, named arguments to the ArgumentParser.

Standard argument is given, but can be overwritten as a tuple.

Return type:

ArgumentParser

Parameters:

args (str | Tuple[str, Any])