Skip to main content

thrust_rl/
tutorials.rs

1//! Guided tutorial series: from `cargo add thrust-rl` to a trained,
2//! deployed policy.
3//!
4//! Each tutorial is a single Markdown file under [`docs/tutorials/`] whose
5//! `rust` code blocks are pulled in here with `#[doc = include_str!(...)]`.
6//! Because they are rendered as rustdoc, every code block is compiled and
7//! run as a doc-test by `cargo test --features training` — so the copy-paste
8//! code in the prose can never rot out of sync with the library API. This is
9//! the CI-enforced mechanism the tutorial series is built on.
10//!
11//! The Markdown files are the single source of truth: read them in
12//! [`docs/tutorials/`] (rendered nicely on GitHub) or here on docs.rs. The
13//! series is ordered by concept dependency — see
14//! [`docs/tutorials/README.md`] for the full dependency-ordered outline.
15//!
16//! [`docs/tutorials/`]: https://github.com/rjwalters/thrust/tree/main/docs/tutorials
17//! [`docs/tutorials/README.md`]: https://github.com/rjwalters/thrust/blob/main/docs/tutorials/README.md
18//!
19//! # Landed tutorials
20//!
21//! - [`tutorial_01_first_agent`](crate::tutorials::tutorial_01_first_agent) —
22//!   Your first agent (SimpleBandit + actor-critic; the rollout → loss → update
23//!   loop).
24//! - [`tutorial_02_cartpole_ppo`](crate::tutorials::tutorial_02_cartpole_ppo) —
25//!   Solving CartPole with PPO (`EnvPool`, GAE, the config surface, reading
26//!   learning curves).
27//! - [`tutorial_03_dqn`](crate::tutorials::tutorial_03_dqn) — Off-policy
28//!   training with DQN (replay buffer, target network, ε-annealing, Double-DQN,
29//!   Polyak soft updates; when to prefer DQN over PPO).
30//! - [`tutorial_04_sac`](crate::tutorials::tutorial_04_sac) — Continuous
31//!   control with SAC (Box action spaces, tanh squashing, automatic entropy
32//!   tuning, twin critics; reusing the off-policy replay + Polyak machinery for
33//!   continuous actions).
34//! - [`tutorial_05_memory`](crate::tutorials::tutorial_05_memory) — Memory and
35//!   POMDPs with recurrent PPO (`FlickeringCartPole`, LSTM policy, recurrent
36//!   rollouts and hidden-state handling; when an LSTM earns its cost vs. a
37//!   memoryless MLP baseline).
38//! - [`tutorial_06_own_env`](crate::tutorials::tutorial_06_own_env) — Writing
39//!   your own environment (implementing the `Environment` trait from scratch;
40//!   the seeding/determinism contract behind `clone_state` / `restore_state`).
41//! - [`tutorial_07_wasm`](crate::tutorials::tutorial_07_wasm) — Train in Rust,
42//!   run in the browser (exporting a trained `MlpBurnPolicy` to the
43//!   `InferenceModel` JSON format, the Burn→inference weight transpose, and
44//!   wiring the JSON into the WASM demo).
45
46/// Tutorial 1 — Your first agent.
47///
48/// See the rendered Markdown at
49/// [`docs/tutorials/01-your-first-agent.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/01-your-first-agent.md).
50#[doc = include_str!("../docs/tutorials/01-your-first-agent.md")]
51pub mod tutorial_01_first_agent {}
52
53/// Tutorial 2 — Solving CartPole with PPO.
54///
55/// See the rendered Markdown at
56/// [`docs/tutorials/02-cartpole-ppo.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/02-cartpole-ppo.md).
57#[doc = include_str!("../docs/tutorials/02-cartpole-ppo.md")]
58pub mod tutorial_02_cartpole_ppo {}
59
60/// Tutorial 3 — Off-policy training with DQN.
61///
62/// See the rendered Markdown at
63/// [`docs/tutorials/03-dqn.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/03-dqn.md).
64#[doc = include_str!("../docs/tutorials/03-dqn.md")]
65pub mod tutorial_03_dqn {}
66
67/// Tutorial 4 — Continuous control with SAC.
68///
69/// See the rendered Markdown at
70/// [`docs/tutorials/04-sac-continuous.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/04-sac-continuous.md).
71#[doc = include_str!("../docs/tutorials/04-sac-continuous.md")]
72pub mod tutorial_04_sac {}
73
74/// Tutorial 5 — Memory and POMDPs with recurrent PPO.
75///
76/// See the rendered Markdown at
77/// [`docs/tutorials/05-memory-pomdps.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/05-memory-pomdps.md).
78#[doc = include_str!("../docs/tutorials/05-memory-pomdps.md")]
79pub mod tutorial_05_memory {}
80
81/// Tutorial 6 — Writing your own environment.
82///
83/// See the rendered Markdown at
84/// [`docs/tutorials/06-your-own-env.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/06-your-own-env.md).
85#[doc = include_str!("../docs/tutorials/06-your-own-env.md")]
86pub mod tutorial_06_own_env {}
87
88/// Tutorial 7 — Train in Rust, run in the browser.
89///
90/// See the rendered Markdown at
91/// [`docs/tutorials/07-wasm-deploy.md`](https://github.com/rjwalters/thrust/blob/main/docs/tutorials/07-wasm-deploy.md).
92#[doc = include_str!("../docs/tutorials/07-wasm-deploy.md")]
93pub mod tutorial_07_wasm {}