{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0f30fc19",
   "metadata": {},
   "source": [
    "# Outlook\n",
    "\n",
    "In this notebook we code the clipped version of the [Proximal Policy\n",
    "Optimization (PPO)](https://arxiv.org/pdf/1707.06347.pdf) algorithm.\n",
    "\n",
    "The PPO algorithm is explained in [this\n",
    "video](https://www.youtube.com/watch?v=uRNL93jV2HE) and you can also read\n",
    "[the corresponding\n",
    "slides](http://pages.isir.upmc.fr/~sigaud/teach/ps/10_ppo.pdf).\n",
    "\n",
    "It is also a good idea to have a look at the [spinning up\n",
    "documentation](https://spinningup.openai.com/en/latest/algorithms/ppo.html)\n",
    "and, for the many details that make PPO work in practice, at [The 37\n",
    "implementation details of\n",
    "PPO](https://iclr-blog-track.github.io/2022/03/25/ppo-implementation-details/)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "47df88da",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "**On Colab**: run the installation cell below (generated automatically,\n",
    "pinned versions). **Locally**: install the environment with `uv sync`, no\n",
    "need for this cell."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2d9918dc",
   "metadata": {
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "import torch\n",
    "import torch.nn as nn\n",
    "import torch.nn.functional as F\n",
    "from dataclasses import dataclass, replace\n",
    "from torch import Tensor\n",
    "from torch.utils.tensorboard import SummaryWriter\n",
    "from tqdm.auto import tqdm\n",
    "from rl_mind.profiles import Profile\n",
    "from rl_mind.core import Actor, StochasticAction, TensorStruct\n",
    "from rl_mind.nn import build_mlp\n",
    "from rl_mind.env import VecEnv\n",
    "from rl_mind.data import Rollout, minibatches\n",
    "from rl_mind.collectors import RolloutCollector\n",
    "from rl_mind.evaluation import Evaluator\n",
    "from rl_mind.notebook import run_directory, setup_tensorboard, silence_known_warnings\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27ccad0d",
   "metadata": {},
   "source": [
    "## The `rl_mind` toolkit\n",
    "\n",
    "The `rl_mind` package ([documentation](https://master-dac.isir.upmc.fr/rl/rl-mind/)),\n",
    "installed with the practicals, provides a small set of *typed* helpers used\n",
    "throughout the RL notebooks. For this notebook, the important ones are:\n",
    "\n",
    "- `VecEnv` runs several copies of a gymnasium environment in parallel,\n",
    "  using torch tensors;\n",
    "- `Rollout` is a fixed-length segment of interaction with `B` parallel\n",
    "  environments: all its tensors have shape `[T, B, ...]`, and\n",
    "  `next_obs[t]` is always the true successor of `obs[t]` (the *final*\n",
    "  observation when an episode ends at step `t`);\n",
    "- `RolloutCollector` runs an actor in a `VecEnv` and returns `Rollout`s;\n",
    "- `minibatches` iterates over random minibatches of a batch of data, using\n",
    "  each sample exactly once;\n",
    "- `Evaluator` periodically evaluates an actor and keeps a copy of the best\n",
    "  one."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29754ef9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# pygame and tensorboard still use the deprecated `pkg_resources` API\n",
    "silence_known_warnings()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d771b4fa",
   "metadata": {},
   "source": [
    "# PPO\n",
    "\n",
    "PPO is an *on-policy* policy-gradient algorithm: it collects a fixed-size\n",
    "rollout with the current policy, then performs **several epochs** of\n",
    "gradient updates on this data. Reusing the same samples several times\n",
    "would normally push the policy too far from the one that collected the\n",
    "data; PPO-clip prevents this by *clipping* the policy improvement.\n",
    "\n",
    "More precisely, PPO-clip maximizes:\n",
    "\n",
    "$$\n",
    "L^{CLIP}(\\theta)=\\hat{\\mathbb{E}}_t\\left[\\min \\left(r_t(\\theta)\n",
    "\\hat{A}_t,\\ \\operatorname{clip}\\left(r_t(\\theta), 1-\\epsilon,\n",
    "1+\\epsilon\\right) \\hat{A}_t\\right)\\right]\n",
    "$$\n",
    "\n",
    "where $\\hat{A}_t$ is the advantage and\n",
    "\n",
    "$$r_t(\\theta) = \\frac{\\pi_\\theta\\left(a_t \\mid\n",
    "s_t\\right)}{\\pi_{\\theta_{\\text{old}}}\\left(a_t \\mid s_t\\right)}$$\n",
    "\n",
    "is the probability ratio between the current policy and the policy that\n",
    "collected the data. Note that we do not need to keep a copy of the old\n",
    "policy: it is enough to have stored the log-probabilities of the actions\n",
    "when they were sampled — which is exactly what the `StochasticAction`\n",
    "returned by the policy contains."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "27ae3f48",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "## Definition of the agents\n",
    "\n",
    "### The policy\n",
    "\n",
    "The policy maps a state to a **distribution** over the (discrete)\n",
    "actions. During training (`forward`), the action is *sampled* and its\n",
    "log-probability is stored in the returned `StochasticAction`; during\n",
    "evaluation (`act`), we take the most probable action."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f85d07dc",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [],
   "source": [
    "class DiscretePolicy(Actor[StochasticAction]):\n",
    "    \"\"\"A stochastic policy for discrete actions, $\\\\pi(a|s)$\"\"\"\n",
    "\n",
    "    def __init__(self, obs_dim: int, hidden: tuple[int, ...], n_actions: int):\n",
    "        super().__init__()\n",
    "        self.model = build_mlp([obs_dim, *hidden, n_actions])\n",
    "\n",
    "    def dist(self, obs: Tensor) -> torch.distributions.Categorical:\n",
    "        \"\"\"The distribution over actions for a batch of observations\"\"\"\n",
    "        return torch.distributions.Categorical(logits=self.model(obs))\n",
    "\n",
    "    def forward(self, obs: Tensor) -> StochasticAction:\n",
    "        dist = self.dist(obs)\n",
    "        action = dist.sample()\n",
    "        return StochasticAction(value=action, log_prob=dist.log_prob(action))\n",
    "\n",
    "    def act(self, obs: Tensor) -> Tensor:\n",
    "        return self.model(obs).argmax(-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3c4147b",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "### The critic $V(s)$\n",
    "\n",
    "As in A2C, PPO uses a value function $V(s)$, learned by regression\n",
    "towards the observed returns; it is used to compute the advantages."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6ac1ff9c",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [],
   "source": [
    "class ValueNetwork(nn.Module):\n",
    "    \"\"\"The value network $V(s)$\"\"\"\n",
    "\n",
    "    def __init__(self, obs_dim: int, hidden: tuple[int, ...]):\n",
    "        super().__init__()\n",
    "        self.model = build_mlp([obs_dim, *hidden, 1])\n",
    "\n",
    "    def forward(self, obs: Tensor) -> Tensor:\n",
    "        \"\"\"Compute $V(s)$ for a batch: `[..., obs_dim] -> [...]`\"\"\"\n",
    "        return self.model(obs).squeeze(-1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f88dfd08",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "## Generalized Advantage Estimation (GAE)\n",
    "\n",
    "The advantage $\\hat{A}_t$ is estimated with\n",
    "[GAE](https://arxiv.org/abs/1506.02438), a geometric average of $n$-step\n",
    "advantage estimators controlled by $\\lambda$ ($\\lambda = 0$ gives the\n",
    "one-step temporal difference, $\\lambda = 1$ the Monte-Carlo estimate):\n",
    "\n",
    "$$\\hat{A}_t = \\delta_t + \\gamma \\lambda\\, \\hat{A}_{t+1}, \\qquad\n",
    "\\delta_t = r_{t} + \\gamma V(s_{t+1}) - V(s_t)$$\n",
    "\n",
    "The recursion is computed backwards over the rollout. Two subtleties at\n",
    "episode boundaries (this is where `terminated` / `truncated` matter):\n",
    "\n",
    "- when $s_{t+1}$ is a **terminal** state, $V(s_{t+1})$ must not be used in\n",
    "  $\\delta_t$ (no bootstrap);\n",
    "- the recursion must not propagate across episode boundaries (`done`),\n",
    "  whether terminated or truncated.\n",
    "\n",
    "Write the backward recursion below. `rollout.terminated[t]` and\n",
    "`rollout.done[t]` are boolean tensors of shape `[B]`, so `(~x).float()` is\n",
    "the mask that zeroes out the corresponding term."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "080a9b1b",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [],
   "source": [
    "def compute_gae(\n",
    "    gamma: float, lam: float, rollout: Rollout, values: Tensor, next_values: Tensor\n",
    ") -> Tensor:\n",
    "    \"\"\"Compute the GAE advantages over a rollout\n",
    "\n",
    "    :param gamma: The discount factor\n",
    "    :param lam: The GAE $\\\\lambda$ parameter\n",
    "    :param rollout: The rollout (tensors `[T, B]`)\n",
    "    :param values: $V(s_t)$, shape `[T, B]`\n",
    "    :param next_values: $V(s_{t+1})$, shape `[T, B]`\n",
    "    :return: The advantages, shape `[T, B]`\n",
    "    \"\"\"\n",
    "    # Compute the GAE advantages (backward recursion over time)\n",
    "\n",
    "    advantages = torch.zeros_like(rollout.reward)\n",
    "    # The running advantage, one value per environment\n",
    "    gae = torch.zeros_like(rollout.reward[0])\n",
    "    for t in reversed(range(rollout.reward.shape[0])):\n",
    "        # the TD error, without bootstrap on terminal states\n",
    "        delta = ...\n",
    "        # accumulate, but not across episode boundaries\n",
    "        gae = ...\n",
    "        advantages[t] = gae\n",
    "    return advantages\n",
    "    assert False, 'Not implemented yet'\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c650d113",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "## The training data\n",
    "\n",
    "After collecting a rollout, we compute the advantages and flatten\n",
    "everything into one batch of `T*B` samples: this is exactly the data PPO\n",
    "trains on during its inner optimization epochs. The `returns` field\n",
    "($\\hat{A}_t + V(s_t)$) is the regression target of the critic."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dfdfb90d",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [],
   "source": [
    "@dataclass(frozen=True)\n",
    "class PPOBatch(TensorStruct):\n",
    "    \"\"\"The data PPO trains on (all shapes `[N, ...]`)\n",
    "\n",
    "    :param obs: The observations\n",
    "    :param action: The actions that were played\n",
    "    :param old_log_prob: The log-probabilities of these actions *when they\n",
    "        were sampled* (i.e. under the old policy)\n",
    "    :param advantage: The GAE advantages\n",
    "    :param returns: The regression targets for the critic\n",
    "    \"\"\"\n",
    "\n",
    "    obs: Tensor\n",
    "    action: Tensor\n",
    "    old_log_prob: Tensor\n",
    "    advantage: Tensor\n",
    "    returns: Tensor"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e00b090f",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "## Hyper-parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "05d30c0c",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "outputs": [],
   "source": [
    "@dataclass(frozen=True)\n",
    "class PPOClipConfig:\n",
    "    env_name: str = \"CartPole-v1\"\n",
    "    seed: int = 1\n",
    "\n",
    "    #: Number of rollouts (updates)\n",
    "    max_updates: int = Profile.pick(100, fast_test=3)\n",
    "    #: Number of parallel training environments\n",
    "    n_envs: int = 8\n",
    "    #: Rollout length (per environment)\n",
    "    n_steps: int = 128\n",
    "\n",
    "    #: Discount factor\n",
    "    gamma: float = 0.99\n",
    "    #: GAE lambda\n",
    "    gae_lam: float = 0.95\n",
    "\n",
    "    #: PPO clipping parameter $\\epsilon$\n",
    "    epsilon: float = 0.2\n",
    "    #: Maximum number of optimization epochs over each rollout\n",
    "    opt_epochs: int = 10\n",
    "    #: Stop the epochs early when the KL to the old policy exceeds this\n",
    "    #: (the \"trust region\"); `None` disables the check\n",
    "    target_kl: float | None = 0.02\n",
    "    #: Minibatch size\n",
    "    batch_size: int = 64\n",
    "    #: Normalize the advantages in each minibatch\n",
    "    normalize_advantage: bool = True\n",
    "    #: Entropy bonus coefficient\n",
    "    entropy_coef: float = 0.0\n",
    "\n",
    "    actor_hidden: tuple[int, ...] = (64, 64)\n",
    "    critic_hidden: tuple[int, ...] = (64, 64)\n",
    "    lr: float = 1e-3\n",
    "\n",
    "    #: Steps between two evaluations, and number of evaluation episodes\n",
    "    eval_interval: int = Profile.pick(8_000, fast_test=1_000)\n",
    "    n_eval_envs: int = 10"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e601fcf",
   "metadata": {
    "lines_to_next_cell": 2
   },
   "source": [
    "## Main training loop\n",
    "\n",
    "Note the structure: collect a rollout (with the *current* policy), compute\n",
    "the advantages **once** (no gradient), then run several epochs of\n",
    "minibatch updates on this frozen data. `minibatches` partitions the data\n",
    "randomly, using each sample exactly once per epoch.\n",
    "\n",
    "**How many epochs?** Each epoch moves $\\pi_\\theta$ further away from the\n",
    "$\\pi_{\\theta_{\\text{old}}}$ that collected the data, and the objective is\n",
    "only a valid local approximation while the two stay close — the *trust\n",
    "region*. Clipping bounds the *per-sample* ratio, but nothing stops the\n",
    "policy as a whole from drifting after several epochs. So on top of the\n",
    "`opt_epochs` limit, we monitor the KL divergence to the old policy and stop\n",
    "as soon as it exceeds `cfg.target_kl`. The estimator used below,\n",
    "\n",
    "$$\\widehat{\\operatorname{KL}} = \\hat{\\mathbb{E}}_t\\big[(r_t(\\theta) - 1) -\n",
    "\\log r_t(\\theta)\\big]$$\n",
    "\n",
    "is unbiased, always positive, and has a much lower variance than the naive\n",
    "$-\\hat{\\mathbb{E}}_t[\\log r_t(\\theta)]$.\n",
    "\n",
    "You have two things to write in the loop below: the **PPO-clip policy\n",
    "loss**, and the **trust-region stopping criterion**. Useful torch\n",
    "functions:\n",
    "\n",
    "- [`torch.clamp`](https://pytorch.org/docs/stable/generated/torch.clamp.html)\n",
    "  computes $\\min(\\max(x, m), M)$;\n",
    "- [`torch.minimum`](https://pytorch.org/docs/stable/generated/torch.minimum.html)\n",
    "  computes the element-wise minimum of two tensors;\n",
    "- `dist.log_prob(actions)` and `dist.entropy()` where `dist =\n",
    "  policy.dist(obs)`.\n",
    "\n",
    "Remember that the ratio $r_t(\\theta)$ is more conveniently computed from\n",
    "the *difference of log-probabilities* (keep that difference around — the KL\n",
    "estimator needs it too), and that we *minimize* the negated objective."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c4ed6c6d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def run_ppo_clip(cfg: PPOClipConfig) -> Evaluator:\n",
    "    torch.manual_seed(cfg.seed)\n",
    "    # same_step_reset: every row of the rollout is a valid transition\n",
    "    env = VecEnv(cfg.env_name, cfg.n_envs, seed=cfg.seed, same_step_reset=True)\n",
    "\n",
    "    policy = DiscretePolicy(env.observation_dim, cfg.actor_hidden, env.n_actions)\n",
    "    critic = ValueNetwork(env.observation_dim, cfg.critic_hidden)\n",
    "    policy_optimizer = torch.optim.Adam(policy.parameters(), lr=cfg.lr)\n",
    "    critic_optimizer = torch.optim.Adam(critic.parameters(), lr=cfg.lr)\n",
    "\n",
    "    collector = RolloutCollector(env, policy)\n",
    "    run_dir = run_directory(f\"ppo-clip-{cfg.env_name}-S{cfg.seed}\")\n",
    "    writer = SummaryWriter(run_dir)\n",
    "    evaluator = Evaluator(\n",
    "        VecEnv(cfg.env_name, cfg.n_eval_envs, seed=cfg.seed + 100),\n",
    "        every=cfg.eval_interval,\n",
    "        run_dir=run_dir,\n",
    "        writer=writer,\n",
    "    )\n",
    "\n",
    "    pbar = tqdm(range(cfg.max_updates))\n",
    "    for update in pbar:\n",
    "        rollout = collector.collect(cfg.n_steps)\n",
    "\n",
    "        # Compute the advantages and returns (once per rollout, no gradient)\n",
    "        with torch.no_grad():\n",
    "            values = critic(rollout.obs)\n",
    "            next_values = critic(rollout.next_obs)\n",
    "            advantage = compute_gae(\n",
    "                cfg.gamma, cfg.gae_lam, rollout, values, next_values\n",
    "            )\n",
    "\n",
    "        flat = rollout.flatten()\n",
    "        data = PPOBatch(\n",
    "            obs=flat.obs,\n",
    "            action=flat.action.value,\n",
    "            old_log_prob=flat.action.log_prob,\n",
    "            advantage=advantage.flatten(),\n",
    "            returns=(advantage + values).flatten(),\n",
    "        )\n",
    "\n",
    "        # Inner optimization loop: several epochs over the same rollout, for\n",
    "        # as long as the policy stays within the trust region\n",
    "        epochs_done = 0\n",
    "        for epoch in range(cfg.opt_epochs):\n",
    "            epoch_kl = []\n",
    "            for mb in minibatches(data, cfg.batch_size):\n",
    "                # Compute the PPO-clip policy loss (and the entropy bonus)\n",
    "\n",
    "                dist = policy.dist(mb.obs)\n",
    "                # The log-ratio, then the probability ratio, between the\n",
    "                # current policy and the policy that collected the data\n",
    "                log_ratio = ...\n",
    "                ratio = ...\n",
    "                advantage_mb = ...  # normalized if cfg.normalize_advantage\n",
    "                policy_loss = ...\n",
    "                loss = policy_loss - cfg.entropy_coef * dist.entropy().mean()\n",
    "                assert False, 'Not implemented yet'\n",
    "\n",
    "\n",
    "                policy_optimizer.zero_grad()\n",
    "                loss.backward()\n",
    "                policy_optimizer.step()\n",
    "\n",
    "                # Critic update: regression towards the returns\n",
    "                critic_loss = F.mse_loss(critic(mb.obs), mb.returns)\n",
    "                critic_optimizer.zero_grad()\n",
    "                critic_loss.backward()\n",
    "                critic_optimizer.step()\n",
    "\n",
    "                # How far the policy has moved, on this minibatch\n",
    "                with torch.no_grad():\n",
    "                    epoch_kl.append(((ratio - 1) - log_ratio).mean().item())\n",
    "\n",
    "            # Stop the epochs when the policy left the trust region\n",
    "\n",
    "            # `epoch_kl` holds one KL estimate per minibatch: compare their\n",
    "            # mean to `cfg.target_kl` (when it is not None) and `break`\n",
    "            assert False, 'Not implemented yet'\n",
    "\n",
    "\n",
    "        writer.add_scalar(\"train/epochs\", epochs_done, collector.steps)\n",
    "        writer.add_scalar(\"loss/policy\", policy_loss.item(), collector.steps)\n",
    "        writer.add_scalar(\"loss/critic\", critic_loss.item(), collector.steps)\n",
    "        if result := evaluator.run_if_needed(collector.steps, policy):\n",
    "            pbar.set_description(\n",
    "                f\"eval={result.mean:6.1f} best={evaluator.best_reward:6.1f}\"\n",
    "            )\n",
    "\n",
    "    return evaluator"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "225d354e",
   "metadata": {},
   "source": [
    "## Launching tensorboard to visualize the results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b732622",
   "metadata": {},
   "outputs": [],
   "source": [
    "setup_tensorboard()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a508a35f",
   "metadata": {},
   "outputs": [],
   "source": [
    "ppo_config = PPOClipConfig()\n",
    "ppo_clip = run_ppo_clip(ppo_config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b033306f",
   "metadata": {},
   "outputs": [],
   "source": [
    "ppo_clip.visualize_best()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ce1cdcd",
   "metadata": {},
   "source": [
    "# Learning curve"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d5dac76",
   "metadata": {},
   "outputs": [],
   "source": [
    "steps = [result.step for result in ppo_clip.history]\n",
    "means = torch.tensor([result.mean for result in ppo_clip.history])\n",
    "stds = torch.tensor([float(result.rewards.std()) for result in ppo_clip.history])\n",
    "plt.plot(steps, means)\n",
    "plt.fill_between(steps, means - stds, means + stds, alpha=0.2)\n",
    "plt.xlabel(\"steps\")\n",
    "plt.ylabel(\"cumulated reward\")\n",
    "plt.title(\"PPO-clip on CartPole-v1\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f29eb561",
   "metadata": {},
   "source": [
    "## Exercises\n",
    "\n",
    "- Set `epsilon` to a large value (e.g. 100, i.e. no clipping) and\n",
    "  compare the learning curves: you should observe the instability that\n",
    "  clipping prevents.\n",
    "- Compare `opt_epochs=1` with `opt_epochs=10`: the whole point of PPO is\n",
    "  to be able to reuse the collected data several times.\n",
    "- Play with the trust region: `target_kl=None` (no early stopping),\n",
    "  `target_kl=0.01` (very conservative). Look at the `train/epochs` curve in\n",
    "  tensorboard to see how many epochs actually run, and relate it to the\n",
    "  learning curve. With `opt_epochs=1` the criterion never triggers — that\n",
    "  configuration is essentially A2C with a clipped objective.\n",
    "- Try a harder environment (e.g. `LunarLander-v3`), or a continuous-action\n",
    "  environment by replacing the `DiscretePolicy` with a Gaussian policy\n",
    "  returning a `StochasticAction`."
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "notebook_metadata_filter": "metadata"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "metadata": {
   "practical_description": "The clipped surrogate objective, on discrete actions",
   "practical_name": "PPO, clipped"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
