Package: rlax
RLaxRLax (pronounced "relax") is a library built on top of JAX that exposes
useful building blocks for implementing reinforcement learning agents. Full
documentation can be found atrlax.readthedocs.io.InstallationYou can install the latest released version of RLax from PyPI via:pipinstallrlaxor you can install the latest development version from GitHub:pipinstallgit+https://github.com/deepmind/rlax.gitAll RLax code may then be just in time compiled for different hardware
(e.g. CPU, GPU, TPU) usingjax.jit.In order to run theexamples/you will also need to clone the repo and
install the additional requirements:optax,haiku, andbsuite.ContentThe operations and functions provided are not complete algorithms, but
implementations of reinforcement learning specific mathematical operations that
are needed when building fully-functional agents capable of learning:Values, including both state and action-values;Values for Non-linear generalizations of the Bellman equations.Return Distributions, aka distributional value functions;General Value Functions, for cumulants other than the main reward;Policies, via policy-gradients in both continuous and discrete action spaces.The library supports both on-policy and off-policy learning (i.e. learning from
data sampled from a policy different from the agent's policy).See file-level and function-level doc-strings for the documentation of these
functions and for references to the papers that introduced and/or used them.UsageSeeexamples/for examples of using some of the functions in RLax to
implement a few simple reinforcement learning agents, and demonstrate learning
on BSuite's version of the Catch environment (a common unit-test for
agent development in the reinforcement learning literature):Other examples of JAX reinforcement learning agents usingrlaxcan be found inbsuite.BackgroundReinforcement learning studies the problem of a learning system (theagent),
which must learn to interact with the universe it is embedded in (theenvironment).Agent and environment interact on discrete steps. On each step the agent selects
anaction, and is provided in return a (partial) snapshot of the state of the
environment (theobservation), and a scalar feedback signal (thereward).The behaviour of the agent is characterized by a probability distribution over
actions, conditioned on past observations of the environment (thepolicy). The
agents seeks a policy that, from any given step, maximises the discounted
cumulative reward that will be collected from that point onwards (thereturn).Often the agent policy or the environment dynamics itself are stochastic. In
this case the return is a random variable, and the optimal agent's policy is
typically more precisely specified as a policy that maximises the expectation of
the return (thevalue), under the agent's and environment's stochasticity.Reinforcement Learning AlgorithmsThere are three prototypical families of reinforcement learning algorithms:those that estimate the value of states and actions, and infer a policy byinspection(e.g. by selecting the action with highest estimated value)those that learn a model of the environment (capable of predicting the
observations and rewards) and infer a policy viaplanning.those that parameterize a policy that can be directlyexecuted,In any case, policies, values or models are just functions. In deep
reinforcement learning such functions are represented by a neural network.
In this setting, it is common to formulate reinforcement learning updates as
differentiable pseudo-loss functions (analogously to (un-)supervised learning).
Under automatic differentiation, the original update rule is recovered.Note however, that in particular, the updates are only valid if the input data
is sampled in the correct manner. For example, a policy gradient loss is only
valid if the input trajectory is an unbiased sample from the current policy;
i.e. the data are on-policy. The library cannot check or enforce such
constraints. Links to papers describing how each operation is used are however
provided in the functions' doc-strings.Naming Conventions and Developer GuidelinesWe define functions and operations for agents interacting with a single stream
of experience. The JAX constructvmapcan be used to apply these same
functions to batches (e.g. to supportreplayandparalleldata generation).Many functions consider policies, actions, rewards, values, in consecutive
timesteps in order to compute their outputs. In this case the suffix_tandtm1is often to clarify on which step each input was generated, e.g:q_tm1: the action value in thesourcestate of a transition.a_tm1: the action that was selected in thesourcestate.r_t: the resulting rewards collected in thedestinationstate.discount_t: thediscountassociated with a transition.q_t: the action values in thedestinationstate.Extensive testing is provided for each function. All tests should also verify
the output ofrlaxfunctions when compiled to XLA usingjax.jitand when
performing batch operations usingjax.vmap.Citing RLaxRLax is part of theDeepMind JAX Ecosystem, to cite RLax please use
theDeepMind JAX Ecosystem citation.