Skip to content

feat: Grid World RL Visualization#657

Merged
fderuiter merged 1 commit intomainfrom
feat/grid-world-2286339306623554352
Mar 18, 2026
Merged

feat: Grid World RL Visualization#657
fderuiter merged 1 commit intomainfrom
feat/grid-world-2286339306623554352

Conversation

@fderuiter
Copy link
Owner

Implemented Grid World visualization tool for the Reinforcement Learning module under Artificial Intelligence. Integrates TabularQAgent with UI rendering for deterministic Q-Learning execution on a simple grid layout with a goal and traps.

  • Added grid_world.rs to tabs/ai/
  • Registered GridWorldTool in AiTab via ai/mod.rs
  • Implemented environment struct implementing MarkovDecisionProcess traits
  • Passed pre-commit checks: fmt, clippy, tests.

PR created automatically by Jules for task 2286339306623554352 started by @fderuiter

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fderuiter fderuiter marked this pull request as ready for review March 18, 2026 23:57
Copilot AI review requested due to automatic review settings March 18, 2026 23:57
@fderuiter fderuiter merged commit 504a95c into main Mar 18, 2026
1 check passed
@fderuiter fderuiter deleted the feat/grid-world-2286339306623554352 branch March 18, 2026 23:57
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Grid World reinforcement learning visualization to the AI tab in math_explorer_gui, integrating a simple deterministic grid environment with a tabular Q-learning agent and UI rendering.

Changes:

  • Added a new GridWorldTool (environment + Q-learning stepping/training + grid rendering) under math_explorer_gui/src/tabs/ai/.
  • Registered the new tool in the AI tab module/tool list.
  • Minor formatting-only adjustments in existing GUI code and marked the Grid World roadmap item complete.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
todo_gui.md Marks the Grid World visualization roadmap item as completed.
math_explorer_gui/src/tabs/battery_degradation/lifetime_estimator.rs Import formatting cleanup.
math_explorer_gui/src/tabs/ai/mod.rs Exposes grid_world module and registers GridWorldTool in AiTab.
math_explorer_gui/src/tabs/ai/grid_world.rs New Grid World RL visualization tool + MDP environment + Q-learning stepping/training UI.
math_explorer_gui/src/tabs/ai/attention_maps.rs Formatting-only cleanup (line wrapping).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +198 to +207
if ui.button("Train (100 Episodes)").clicked() {
for _ in 0..100 {
let mut temp_steps = 0;
while !self.env.is_terminal(&self.current_state) && temp_steps < 100 {
self.step_agent();
temp_steps += 1;
}
self.reset_episode();
}
}
}
if ui.button("Reset Agent").clicked() {
self.agent = TabularQAgent::new(0.1, 0.9, 0.1);
self.reset_episode();
use math_explorer::ai::reinforcement_learning::{
algorithms::TabularQAgent, Action, MarkovDecisionProcess, State,
};
use std::hash::Hash;
Comment on lines +118 to +143
let agent = TabularQAgent::new(0.1, 0.9, 0.1);
Self {
current_state: env.start,
env,
agent,
episodes: 0,
total_reward: 0.0,
steps: 0,
}
}
}

impl GridWorldTool {
fn step_agent(&mut self) {
if self.env.is_terminal(&self.current_state) {
self.reset_episode();
return;
}

let actions = self.env.actions(&self.current_state);
if actions.is_empty() {
return;
}

if let Some(action) = self.agent.select_action(&self.current_state, &actions) {
let mut expected_next = self.current_state;
Comment on lines +143 to +161
let mut expected_next = self.current_state;
match action {
Move::Up => expected_next.y -= 1,
Move::Down => expected_next.y += 1,
Move::Left => expected_next.x -= 1,
Move::Right => expected_next.x += 1,
}

let is_valid = expected_next.x >= 0
&& expected_next.x < self.env.width
&& expected_next.y >= 0
&& expected_next.y < self.env.height;

let next_state = if is_valid {
expected_next
} else {
self.current_state
};

traps: vec![GridState { x: 2, y: 2 }, GridState { x: 3, y: 2 }],
gamma: 0.9,
};
let agent = TabularQAgent::new(0.1, 0.9, 0.1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants