RLPack
 
Loading...
Searching...
No Matches
rlpack.utils.setup.Setup Class Reference

This class sets up all the necessary objects that are required to run any configuration. More...

+ Inheritance diagram for rlpack.utils.setup.Setup:
+ Collaboration diagram for rlpack.utils.setup.Setup:

Public Member Functions

def __init__ (self)
 
Union[Activation, List[Activation]] get_activation (self, Union[str, List[str]] activation_name, Union[Dict[str, Any], List[Dict[str, Any]]] activation_args)
 This method retrieves the activation to be supplied for the models. More...
 
Agent get_agent (self, str agent_name, *args, **kwargs)
 This method retrieves the agent given the agent name. More...
 
def get_agent_model_args (self, str agent_name)
 
Distribution get_distribution_class (self, str distribution)
 
LossFunction get_loss_function (self, str loss_function_name, Dict[str, Any] loss_function_args)
 This method retrieves the Loss Function to be supplied for the models. More...
 
LRScheduler get_lr_scheduler (self, pytorch.optim.Optimizer optimizer, Optional[str] lr_scheduler_name=None, Optional[Dict[str, Any]] lr_scheduler_args=None)
 This method retrieves the lr_scheduler to be supplied for the models if LR Scheduler is requested. More...
 
List[str] get_model_args (self, str model_name)
 
List[pytorch.nn.Module] get_models (self, str model_name, str agent_name, *args, **kwargs)
 This method automatically retrieves the given model(s) required by the agent. More...
 
pytorch.optim.Optimizer get_optimizer (self, List[pytorch.Tensor] params, str optimizer_name, Dict[str, Any] optimizer_args)
 This method retrieves the optimizer given by the "optimizer" key in the argument optimizer_args. More...
 
def __init__ (self)
 
def __init__ (self)
 

Additional Inherited Members

- Static Public Member Functions inherited from rlpack.utils.base.register.Register
def get_prefix_path ()
 Gets prefix path for rlpack package, from python installation. More...
 
- Data Fields inherited from rlpack.utils.base.register.Register
 activation_init_args
 The activation initialization arguments when using in-built models. More...
 
 activation_map
 The mapping between given keyword and PyTorch activation function class. More...
 
 agent_args
 The mapping between given keyword and agent agents' arguments. More...
 
 agent_args_default
 The mapping between given keyword and agent agent's default arguments. More...
 
 agent_init_args
 The mandatory agent initialisation arguments. More...
 
 agents
 The mapping between given keyword and agents models. More...
 
 distributions_map
 The mapping between given keyword and PyTorch Distribution class. More...
 
 loss_function_map
 The mapping between given keyword and PyTorch loss function class. More...
 
 lr_scheduler_init_args
 The LR Scheduler initialization arguments. More...
 
 lr_scheduler_map
 The mapping between given keyword and PyTorch LR Scheduler class. More...
 
 mandatory_distributed_agents
 
 mandatory_distribution_required_agents
 
 mandatory_keys
 The tuple for mandatory keys (or keyword arguments) always expected. More...
 
 model_args
 The mapping between given keyword and in-built models' arguments. More...
 
 model_args_default
 The mapping between given keyword and in-built model's default arguments. More...
 
 model_args_to_optimize
 The mapping between keyword and agents' model arguments to wrap optimizer with. More...
 
 model_init_args
 The model initialization arguments when using in-built models. More...
 
 models
 The mapping between given keyword and in-built models. More...
 
 optimizer_init_args
 The optimizer initialization arguments for given models. More...
 
 optimizer_map
 The mapping between given keyword and PyTorch optimizer class. More...
 
- Data Fields inherited from rlpack.utils.base.internal_code_register.InternalCodeRegister
 norm_mode_codes
 The mapping between given keyword and normalisation method codes. More...
 
 norm_to_mode_codes
 The mapping between given keyword and normalisation quantity (apply_norm_to) codes. More...
 
 prioritization_strategy_codes
 The mapping between prioritization strategy keywords and prioritization strategy codes. More...
 

Detailed Description

This class sets up all the necessary objects that are required to run any configuration.

Constructor & Destructor Documentation

◆ __init__()

def rlpack.utils.setup.Setup.__init__ (   self)

Member Function Documentation

◆ get_activation()

Union[Activation, List[Activation]] rlpack.utils.setup.Setup.get_activation (   self,
Union[str, List[str]]  activation_name,
Union[Dict[str, Any], List[Dict[str, Any]]]  activation_args 
)

This method retrieves the activation to be supplied for the models.

If list is passed, list of initialized activation objects are retrieved.

Parameters
activation_nameUnion[str, List[str]]: The activation name to be used.
activation_argsDUnion[Dict[str, Any], List[Dict[str, Any]]]: A dictionary with keyword arguments for to-be initialized activation function.
Returns
Union[Activation, List[Activation]]: The initialized activated function.

◆ get_agent()

Agent rlpack.utils.setup.Setup.get_agent (   self,
str  agent_name,
args,
**  kwargs 
)

This method retrieves the agent given the agent name.

Parameters
agent_namestr: The agent to retrieve.
argsThe additional positional arguments for the model.
kwargsThe additional keyword arguments required by the model.
Returns
Agent: The initialized agent.

◆ get_agent_model_args()

def rlpack.utils.setup.Setup.get_agent_model_args (   self,
str  agent_name 
)

◆ get_distribution_class()

Distribution rlpack.utils.setup.Setup.get_distribution_class (   self,
str  distribution 
)

◆ get_loss_function()

LossFunction rlpack.utils.setup.Setup.get_loss_function (   self,
str  loss_function_name,
Dict[str, Any]   loss_function_args 
)

This method retrieves the Loss Function to be supplied for the models.

Parameters
loss_function_namestr: The loss function's name to be used.
loss_function_argsDict[str, Any]: A dictionary with keyword arguments for to-be initialized loss function. :return (LossFunction): The initialized loss function.

◆ get_lr_scheduler()

LRScheduler rlpack.utils.setup.Setup.get_lr_scheduler (   self,
pytorch.optim.Optimizer  optimizer,
Optional[str]   lr_scheduler_name = None,
Optional[Dict[str, Any]]   lr_scheduler_args = None 
)

This method retrieves the lr_scheduler to be supplied for the models if LR Scheduler is requested.

Parameters
optimizerpytorch.optim.Optimizer: The optimizer to wrap the lr scheduler around.
lr_scheduler_namestr: The LR Scheduler's name to be used.
lr_scheduler_argsDict[str, Any]: A dictionary with keyword arguments for to-be initialized LR Scheduler.
Returns
Activation: The initialized lr_scheduler.

◆ get_model_args()

List[str] rlpack.utils.setup.Setup.get_model_args (   self,
str  model_name 
)
Parameters
model_namestr: The model name for which we want to obtain the args.
Returns
List[str]: The list of model arguments.

◆ get_models()

List[pytorch.nn.Module] rlpack.utils.setup.Setup.get_models (   self,
str  model_name,
str  agent_name,
args,
**  kwargs 
)

This method automatically retrieves the given model(s) required by the agent.

Parameters
model_namestr: The initialized model for the supplied model_name.
agent_namestr: The agent name for which models are requested.
argsAdditional positional arguments for the model.
kwargsAdditional keyword arguments for the model.
Returns
List[pytorch.nn.Module]: The list of models required by the supplied agent.

◆ get_optimizer()

pytorch.optim.Optimizer rlpack.utils.setup.Setup.get_optimizer (   self,
List[pytorch.Tensor]  params,
str  optimizer_name,
Dict[str, Any]  optimizer_args 
)

This method retrieves the optimizer given by the "optimizer" key in the argument optimizer_args.

Parameters
paramsList[pytorch.Tensor]: The model parameters to wrap the optimizer.
optimizer_namestr: The optimizer name to be used.
optimizer_argsDict[str, Any]: A dictionary with keyword arguments for to-be initialized optimizer.
Returns
pytorch.optim.Optimizer: The initialized optimizer.