Skip to content

Commit

Permalink
Rename AgentManager to ExperimentManager (rlberry-py#350)
Browse files Browse the repository at this point in the history
* AgentManager -> ExperimentManager search and replace

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename file, add alias

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename file

* add alias

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* search and replace agent_manager -> experiment_manager

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* change test file names

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
RemyDegenne and pre-commit-ci[bot] authored Jul 24, 2023
1 parent e4e7ed5 commit d93f51e
Show file tree
Hide file tree
Showing 61 changed files with 491 additions and 465 deletions.
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Main classes
:template: class.rst


manager.AgentManager
manager.ExperimentManager
manager.MultipleManagers

Evaluation and plot
Expand Down Expand Up @@ -202,7 +202,7 @@ Check Utilities
utils.check_save_load
utils.check_fit_additive
utils.check_seeding_agent
utils.check_agent_manager
utils.check_experiment_manager

Logging Utilities
-----------------
Expand Down
12 changes: 6 additions & 6 deletions docs/basics/DeepRLTutorial/TutorialDeepRL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Imports
.. code:: python
from rlberry.envs import gym_make
from rlberry.manager import plot_writer_data, AgentManager, evaluate_agents
from rlberry.manager import plot_writer_data, ExperimentManager, evaluate_agents
from rlberry.agents.torch import A2CAgent
from rlberry.agents.torch.utils.training import model_factory_from_env
Expand Down Expand Up @@ -149,9 +149,9 @@ default networks are:
.. code:: python
"""
The AgentManager class is compact way of experimenting with a deepRL agent.
The ExperimentManager class is compact way of experimenting with a deepRL agent.
"""
default_agent = AgentManager(
default_agent = ExperimentManager(
A2CAgent, # The Agent class.
(gym_make, dict(id="CartPole-v1")), # The Environment to solve.
fit_budget=3e5, # The number of interactions
Expand Down Expand Up @@ -182,7 +182,7 @@ default networks are:
.. parsed-literal::
[INFO] Running AgentManager fit() for A2C default with n_fit = 1 and max_workers = None.
[INFO] Running ExperimentManager fit() for A2C default with n_fit = 1 and max_workers = None.
INFO: Making new env: CartPole-v1
INFO: Making new env: CartPole-v1
[INFO] Could not find least used device (nvidia-smi might be missing), use cuda:0 instead
Expand Down Expand Up @@ -353,7 +353,7 @@ and bigger batch size to have more stable training.
.. code:: python
tuned_agent = AgentManager(
tuned_agent = ExperimentManager(
A2CAgent, # The Agent class.
(gym_make, dict(id="CartPole-v1")), # The Environment to solve.
init_kwargs=dict( # Where to put the agent's hyperparameters
Expand Down Expand Up @@ -399,7 +399,7 @@ and bigger batch size to have more stable training.
.. parsed-literal::
[INFO] Running AgentManager fit() for A2C tuned with n_fit = 1 and max_workers = None.
[INFO] Running ExperimentManager fit() for A2C tuned with n_fit = 1 and max_workers = None.
INFO: Making new env: CartPole-v1
INFO: Making new env: CartPole-v1
[INFO] Could not find least used device (nvidia-smi might be missing), use cuda:0 instead
Expand Down
10 changes: 5 additions & 5 deletions docs/basics/compare_agents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Compare different agents


Two or more agents can be compared using the classes
:class:`~rlberry.manager.agent_manager.AgentManager` and
:class:`~rlberry.manager.experiment_manager.ExperimentManager` and
:class:`~rlberry.manager.multiple_managers.MultipleManagers`, as in the example below.


Expand All @@ -18,7 +18,7 @@ Two or more agents can be compared using the classes
from rlberry.envs.classic_control import MountainCar
from rlberry.agents.torch.reinforce import REINFORCEAgent
from rlberry.agents.kernel_based.rs_kernel_ucbvi import RSKernelUCBVIAgent
from rlberry.manager import AgentManager, MultipleManagers, plot_writer_data
from rlberry.manager import ExperimentManager, MultipleManagers, plot_writer_data
# Environment constructor and kwargs
Expand All @@ -38,10 +38,10 @@ Two or more agents can be compared using the classes
eval_kwargs = dict(eval_horizon=200)
# Create AgentManager for REINFORCE and RSKernelUCBVI
# Create ExperimentManager for REINFORCE and RSKernelUCBVI
multimanagers = MultipleManagers()
multimanagers.append(
AgentManager(
ExperimentManager(
REINFORCEAgent,
env,
init_kwargs=params["reinforce"],
Expand All @@ -51,7 +51,7 @@ Two or more agents can be compared using the classes
)
)
multimanagers.append(
AgentManager(
ExperimentManager(
RSKernelUCBVIAgent,
env,
init_kwargs=params["kernel"],
Expand Down
10 changes: 5 additions & 5 deletions docs/basics/evaluate_agent.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Evaluate an agent and optimize its hyperparameters
With rlberry_, once you created your agent, it is very easy to train in parallel
several instances of it, analyze the results and optimize hyperparameters.

This is one of the purposes of the :class:`~rlberry.manager.agent_manager.AgentManager` class,
This is one of the purposes of the :class:`~rlberry.manager.experiment_manager.ExperimentManager` class,
as shown in the examples below.

.. code-block:: python
from rlberry.envs import gym_make
from rlberry.agents.torch.reinforce import REINFORCEAgent
from rlberry.manager import AgentManager, plot_writer_data
from rlberry.manager import ExperimentManager, plot_writer_data
# Environment (constructor, kwargs)
Expand All @@ -33,8 +33,8 @@ as shown in the examples below.
eval_kwargs = dict(eval_horizon=500) # parameters to evaluate the agent
# Create AgentManager to fit 4 instances of REINFORCE in parallel.
stats = AgentManager(
# Create ExperimentManager to fit 4 instances of REINFORCE in parallel.
stats = ExperimentManager(
REINFORCEAgent,
env,
init_kwargs=params,
Expand Down Expand Up @@ -87,7 +87,7 @@ For :class:`~rlberry.agents.reinforce.reinforce.REINFORCEAgent`, this method loo
Now we can use the :meth:`optimize_hyperparams` method
of :class:`~rlberry.manager.agent_manager.AgentManager` to find good parameters for our agent:
of :class:`~rlberry.manager.experiment_manager.ExperimentManager` to find good parameters for our agent:

.. code-block:: python
Expand Down
10 changes: 5 additions & 5 deletions docs/basics/experiment_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To setup an experiment with rlberry, you can use yaml files. You'll need:

* yaml files describing the environments and the agents

* A main python script that reads the files and generates :class:`~rlberry.manager.agent_manager.AgentManager` instances to run each agent.
* A main python script that reads the files and generates :class:`~rlberry.manager.experiment_manager.ExperimentManager` instances to run each agent.


This can be done very succinctly as in the example below:
Expand Down Expand Up @@ -89,12 +89,12 @@ This can be done very succinctly as in the example below:
multimanagers = MultipleManagers()
for agent_manager in experiment_generator():
multimanagers.append(agent_manager)
for experiment_manager in experiment_generator():
multimanagers.append(experiment_manager)
# Alternatively:
# agent_manager.fit()
# agent_manager.save()
# experiment_manager.fit()
# experiment_manager.save()
multimanagers.run()
multimanagers.save()
10 changes: 5 additions & 5 deletions docs/basics/multiprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Parallelization in rlberry
==========================

rlberry use python's standard multiprocessing library to execute the fit of agents in parallel on cpus. The parallelization is done via
:class:`~rlberry.manager.AgentManager` and via :class:`~rlberry.manager.MultipleManagers`.
:class:`~rlberry.manager.ExperimentManager` and via :class:`~rlberry.manager.MultipleManagers`.

If a user wants to use a third-party parallelization library like joblib, the user must be aware of where the seeding is done so as not to bias the results. rlberry automatically handles seeding when the native parallelization scheme are used.

Expand All @@ -19,9 +19,9 @@ having practically no parallelization except if the code executed in each thread
Process: spawn or forkserver
----------------------------

To have an efficient parallelization, it is often better to use processes (see the doc on `python's website <https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing>`_) using the parameter :code:`parallelization="process"` in :class:`~rlberry.manager.AgentManager` or :class:`~rlberry.manager.MultipleManagers`.
To have an efficient parallelization, it is often better to use processes (see the doc on `python's website <https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing>`_) using the parameter :code:`parallelization="process"` in :class:`~rlberry.manager.ExperimentManager` or :class:`~rlberry.manager.MultipleManagers`.

This implies that a new process will be launched for each fit of the AgentManager.
This implies that a new process will be launched for each fit of the ExperimentManager.

The advised method of parallelization is spawn (parameter :code:`mp_context="spawn"`), however spawn method has several drawbacks:

Expand All @@ -30,14 +30,14 @@ The advised method of parallelization is spawn (parameter :code:`mp_context="spa
.. code:: python
from rlberry.agents.torch import A2CAgent
from rlberry.manager import AgentManager
from rlberry.manager import ExperimentManager
from rlberry.envs.benchmarks.ball_exploration import PBall2D
n_steps = 1e5
batch_size = 256
if __name__ == "__main__":
manager = AgentManager(
manager = ExperimentManager(
A2CAgent,
(PBall2D, {}),
init_kwargs=dict(batch_size=batch_size, gamma=0.99, learning_rate=0.001),
Expand Down
36 changes: 18 additions & 18 deletions docs/basics/quick_start_rl/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Importing required libraries
from rlberry.agents import UCBVIAgent, AgentWithSimplePolicy
from rlberry.envs import Chain
from rlberry.manager import (
AgentManager,
ExperimentManager,
evaluate_agents,
plot_writer_data,
read_writer_data,
Expand Down Expand Up @@ -149,11 +149,11 @@ module :class:`~rlberry.agents.Agent` for more informations.
Agent Manager
-------------

One of the main feature of rlberry is its :class:`~rlberry.manager.AgentManager`
One of the main feature of rlberry is its :class:`~rlberry.manager.ExperimentManager`
class. Here is a diagram to explain briefly what it does.


.. figure:: agent_manager_diagram.png
.. figure:: experiment_manager_diagram.png
:align: center


Expand Down Expand Up @@ -183,8 +183,8 @@ then spawn agents as desired during the experiment.

.. code:: python
# Create AgentManager to fit 1 agent
ucbvi_stats = AgentManager(
# Create ExperimentManager to fit 1 agent
ucbvi_stats = ExperimentManager(
UCBVIAgent,
(env_ctor, env_kwargs),
fit_budget=100,
Expand All @@ -194,8 +194,8 @@ then spawn agents as desired during the experiment.
)
ucbvi_stats.fit()
# Create AgentManager for baseline
baseline_stats = AgentManager(
# Create ExperimentManager for baseline
baseline_stats = ExperimentManager(
RandomAgent,
(env_ctor, env_kwargs),
fit_budget=100,
Expand All @@ -207,9 +207,9 @@ then spawn agents as desired during the experiment.
.. parsed-literal::
[INFO] Running AgentManager fit() for UCBVI with n_fit = 1 and max_workers = None.
[INFO] Running ExperimentManager fit() for UCBVI with n_fit = 1 and max_workers = None.
[INFO] ... trained!
[INFO] Running AgentManager fit() for RandomAgent with n_fit = 1 and max_workers = None.
[INFO] Running ExperimentManager fit() for RandomAgent with n_fit = 1 and max_workers = None.
[INFO] ... trained!
Expand Down Expand Up @@ -307,8 +307,8 @@ Then, we fit the two agents and plot the data in the writer.

.. code:: python
# Create AgentManager to fit 4 agents using 1 job
ucbvi_stats = AgentManager(
# Create ExperimentManager to fit 4 agents using 1 job
ucbvi_stats = ExperimentManager(
UCBVIAgent2,
(env_ctor, env_kwargs),
fit_budget=50,
Expand All @@ -319,8 +319,8 @@ Then, we fit the two agents and plot the data in the writer.
) # mp_context is needed to have parallel computing in notebooks.
ucbvi_stats.fit()
# Create AgentManager for baseline
baseline_stats = AgentManager(
# Create ExperimentManager for baseline
baseline_stats = ExperimentManager(
RandomAgent2,
(env_ctor, env_kwargs),
fit_budget=5000,
Expand All @@ -330,8 +330,8 @@ Then, we fit the two agents and plot the data in the writer.
)
baseline_stats.fit()
# Create AgentManager for baseline
opti_stats = AgentManager(
# Create ExperimentManager for baseline
opti_stats = ExperimentManager(
OptimalAgent,
(env_ctor, env_kwargs),
fit_budget=5000,
Expand All @@ -344,11 +344,11 @@ Then, we fit the two agents and plot the data in the writer.
.. parsed-literal::
[INFO] Running AgentManager fit() for UCBVIAgent2 with n_fit = 10 and max_workers = None.
[INFO] Running ExperimentManager fit() for UCBVIAgent2 with n_fit = 10 and max_workers = None.
[INFO] ... trained!
[INFO] Running AgentManager fit() for RandomAgent2 with n_fit = 10 and max_workers = None.
[INFO] Running ExperimentManager fit() for RandomAgent2 with n_fit = 10 and max_workers = None.
[INFO] ... trained!
[INFO] Running AgentManager fit() for OptimalAgent with n_fit = 10 and max_workers = None.
[INFO] Running ExperimentManager fit() for OptimalAgent with n_fit = 10 and max_workers = None.
[INFO] ... trained!
Remark that ``fit_budget`` may not mean the same thing among agents. For
Expand Down
26 changes: 13 additions & 13 deletions docs/basics/rlberry how to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Libraries
import pandas as pd
from rlberry.agents import ValueIterationAgent, AgentWithSimplePolicy
from rlberry.envs import GridWorld
from rlberry.manager import AgentManager, evaluate_agents
from rlberry.manager import ExperimentManager, evaluate_agents
.. parsed-literal::
Expand Down Expand Up @@ -86,8 +86,8 @@ our estimation.

.. code:: ipython3
# Create AgentManager to fit 4 agents using 1 job
vi_stats = AgentManager(
# Create ExperimentManager to fit 4 agents using 1 job
vi_stats = ExperimentManager(
ValueIterationAgent,
(env_ctor, env_kwargs),
fit_budget=0,
Expand All @@ -96,8 +96,8 @@ our estimation.
n_fit=1)
vi_stats.fit()
# Create AgentManager for baseline
baseline_stats = AgentManager(
# Create ExperimentManager for baseline
baseline_stats = ExperimentManager(
RandomAgent,
(env_ctor, env_kwargs),
fit_budget=0,
Expand All @@ -108,9 +108,9 @@ our estimation.
.. parsed-literal::
[INFO] Running AgentManager fit() for ValueIteration...
[INFO] Running ExperimentManager fit() for ValueIteration...
[INFO] ... trained!
[INFO] Running AgentManager fit() for RandomAgent...
[INFO] Running ExperimentManager fit() for RandomAgent...
[INFO] ... trained!
Expand Down Expand Up @@ -205,8 +205,8 @@ the variability of our estimation).

.. code:: ipython3
# Create AgentManager to fit 4 agents using 1 job
vi_stats = AgentManager(
# Create ExperimentManager to fit 4 agents using 1 job
vi_stats = ExperimentManager(
ValueIterationAgent2,
(env_ctor, env_kwargs),
fit_budget=1,
Expand All @@ -215,8 +215,8 @@ the variability of our estimation).
n_fit=4)
vi_stats.fit()
# Create AgentManager for baseline
baseline_stats = AgentManager(
# Create ExperimentManager for baseline
baseline_stats = ExperimentManager(
RandomAgent2,
(env_ctor, env_kwargs),
fit_budget=1,
Expand All @@ -227,9 +227,9 @@ the variability of our estimation).
.. parsed-literal::
[INFO] Running AgentManager fit() for ValueIterationAgent2...
[INFO] Running ExperimentManager fit() for ValueIterationAgent2...
[INFO] ... trained!
[INFO] Running AgentManager fit() for RandomAgent2...
[INFO] Running ExperimentManager fit() for RandomAgent2...
[INFO] ... trained!
Expand Down
Loading

0 comments on commit d93f51e

Please sign in to comment.