Arguments

Config_args

class gaggle.arguments.config_args.ConfigArgs(config_path: str = None)[source]

Bases: object

Argument class that allows to combine all the other arguments together and read from config files for experiments

args_to_config = {'ga_args': GAArgs(population_size=100, crossover='uniform', parent_survival_rate=0.5, mutate_protected=False, mutation='normal', mutation_std=0.05, mutation_chance=0.01, selection='weighted', elitism=0.1, num_parents=20, ga_name='simple', generations=100, k_point=1, tournament_size=3, selection_pressure=0.5, uniform_mutation_min_val=-1.0, uniform_mutation_max_val=1.0, save_best_every=None, save_every_epoch=False, eval_every_generation=None, use_freshness=True), 'individual_args': IndividualArgs(individual_name='nn', param_lower_bound=None, param_upper_bound=None, individual_size=100, model_name='lenet', resolution=32, base_model_weights=None, model_ckpt=None, random_init=True), 'output_dir': OutdirArgs(root=None, name='experiment', folder_number=None), 'problem_args': ProblemArgs(problem_name='cartpole', batch_size=-1, eval_batch_size=-1, dataset_root=None, max_size_train=None, max_size_val=None, seed=1337, steps=1, runs=1, gui=False, stop_on_done=True), 'sys_args': SysArgs(num_workers=8, device='cuda', gpu_id=0, use_dataloader=False, verbose=True)}
config_path: str = None
exists()[source]
get_args()[source]
get_ga_args() GAArgs[source]
get_individual_args() IndividualArgs[source]
classmethod get_keys()[source]

Returns: the list of config keys that will be read in the *.yml file

get_outdir_args() OutdirArgs[source]
get_problem_args() ProblemArgs[source]
get_sys_args() SysArgs[source]
classmethod update(config_key, arg_subclass)[source]

Add or replace one of the argument classes in the args_to_config that will be read in the *.yml file.

Parameters:
  • config_key – key of the argument class to be added/replaced

  • arg_subclass – argument class that will be called when using the given config_key

Notes

arg_subclass needs to be an un-initialized object as the update will initialize it.

gaggle.arguments.config_args.parse_args()[source]

Helper function that parses the argument classes into a list of initialized argument objects with the given CLI argument values.

Returns:

Returns list of [OutdirArgs, SysArgs, IndividualArgs, GAArgs, ProblemArgs, ConfigArgs]

Ga_args

class gaggle.arguments.ga_args.GAArgs(population_size: int = 100, crossover: str = 'uniform', parent_survival_rate: float = 0.5, mutate_protected: bool = False, mutation: str = 'normal', mutation_std: float = 0.05, mutation_chance: float = 0.01, selection: str = 'weighted', elitism: float = 0.1, num_parents: int = 20, ga_name: str = 'simple', generations: int = 100, k_point: int = 1, tournament_size: int = 3, selection_pressure: float = 0.5, uniform_mutation_min_val: float = -1.0, uniform_mutation_max_val: float = 1.0, save_best_every: int = None, save_every_epoch: bool = False, eval_every_generation: int = None, use_freshness: bool = True)[source]

Bases: object

Argument class that contains the arguments relating to the GA algorithms

CONFIG_KEY = 'ga_args'
crossover: str = 'uniform'
elitism: float = 0.1
eval_every_generation: int = None
ga_name: str = 'simple'
generations: int = 100
k_point: int = 1
mutate_protected: bool = False
mutation: str = 'normal'
mutation_chance: float = 0.01
mutation_std: float = 0.05
num_parents: int = 20
parent_survival_rate: float = 0.5
population_size: int = 100
save_best_every: int = None
save_every_epoch: bool = False
selection: str = 'weighted'
selection_pressure: float = 0.5
tournament_size: int = 3
uniform_mutation_max_val: float = 1.0
uniform_mutation_min_val: float = -1.0
use_freshness: bool = True

Individual_args

class gaggle.arguments.individual_args.IndividualArgs(individual_name: str = 'nn', param_lower_bound: float = None, param_upper_bound: float = None, individual_size: int = 100, model_name: str = 'lenet', resolution: int = 32, base_model_weights: str = None, model_ckpt: str = None, random_init: bool = True)[source]

Bases: object

Argument class that contains the arguments relating to individuals

CONFIG_KEY = 'individual_args'
base_model_weights: str = None
get_base_model(*args, **kwargs)[source]

Gets a base model as specified by the self.model_name field

Parameters:
  • *args – args that will get passed down to the model initialization

  • **kwargs – kwargs that will get passed down to the model initialization

Returns:

NN model (nn.Module unless custom model was added using cls.update)

classmethod get_keys()[source]

Gets the list of available NN pre-built models that can be created

Returns:

list of strings of model names

individual_name: str = 'nn'
individual_size: int = 100
model_ckpt: str = None
model_name: str = 'lenet'
models = {'dqn': <class 'gaggle.base_nns.dqn.DQN'>, 'drqn': <class 'gaggle.base_nns.drqn.DRQN'>, 'lenet': <class 'gaggle.base_nns.lenet.LeNet5'>, 'resnet20': <function resnet20>, 'snet_cifar': <class 'gaggle.base_nns.snet.SNetCIFAR'>, 'snet_mnist': <class 'gaggle.base_nns.snet.SNetMNIST'>}
param_lower_bound: float = None
param_upper_bound: float = None
random_init: bool = True
resolution: int = 32
classmethod update(key, model)[source]

Add a new model to the list of models that can be created

Parameters:
  • key – model name that will be used as the dictionary lookup key

  • model – model class object, it needs to not be already initialized

Outdir_args

class gaggle.arguments.outdir_args.OutdirArgs(root: str = None, name: str = 'experiment', folder_number: str = None)[source]

Bases: object

Argument class that contains the arguments relating to the output directory of the experiment

CONFIG_KEY = 'output_dir'
create_folder_name(verbose=False)[source]

Gets and creates a unique folder name

exists()[source]
folder_number: str = None
get_folder_path()[source]

Get an unused folder name in the root directory.

name: str = 'experiment'
root: str = None

Problem_args

class gaggle.arguments.problem_args.ProblemArgs(problem_name: str = 'cartpole', batch_size: int = -1, eval_batch_size: int = -1, dataset_root: str = None, max_size_train: int = None, max_size_val: int = None, seed: int = 1337, steps: int = 1, runs: int = 1, gui: bool = False, stop_on_done: bool = True)[source]

Bases: object

Argument class that contains the arguments relating to problems

CONFIG_KEY = 'problem_args'
batch_size: int = -1
dataset_root: str = None
eval_batch_size: int = -1
gui: bool = False
max_size_train: int = None
max_size_val: int = None
problem_name: str = 'cartpole'
runs: int = 1
seed: int = 1337
steps: int = 1
stop_on_done: bool = True

Sys_args

class gaggle.arguments.sys_args.SysArgs(num_workers: int = 8, device: str = 'cuda', gpu_id: int = 0, use_dataloader: bool = False, verbose: bool = True)[source]

Bases: object

Argument class that contains the arguments relating to system settings and environment variables

CONFIG_KEY = 'sys_args'
device: str = 'cuda'
gpu_id: int = 0
num_workers: int = 8
set_gpu_id(gpu_id: int)[source]
use_dataloader: bool = False
verbose: bool = True