Conversation
- Add `NetworkEpidemicModel` backend to `math_explorer/src/epidemiology/networks.rs` - Generate random geometric graphs based on threshold distance. - Implement step simulation with $\beta$ (transmission) and $\gamma$ (recovery). - Expose node states (Susceptible, Infected, Recovered). - Add `NetworkPropagationTool` to `math_explorer_gui/src/tabs/epidemiology/network_propagation.rs`. - Render nodes, edges, and statistics dynamically using `egui`. - Encapsulate parameters natively through the new tool struct. - Mark 'Network Propagation' as completed in `todo_gui.md`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
…agation - Change the `step` method loop to use `next_states.iter_mut().enumerate()` to adhere to strict CI clippy standards. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements the requested “Network Propagation” feature in the Epidemiology GUI by adding a new tool that visualizes and steps a simple network-based epidemic simulation, backed by new network-generation/propagation logic in math_explorer.
Changes:
- Add
NetworkPropagationToolto the Epidemiology tab and mark the roadmap item complete. - Introduce
NetworkEpidemicModel+NodeStateinmath_explorer::epidemiology::networksfor geometric graph initialization and S/I/R propagation steps. - Minor formatting-only changes in unrelated GUI files (imports / line wrapping).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
todo_gui.md |
Marks “Network Propagation” feature as completed. |
math_explorer_gui/src/tabs/epidemiology/network_propagation.rs |
New GUI tool: controls + network visualization + stepping the backend model. |
math_explorer_gui/src/tabs/epidemiology/mod.rs |
Registers the new tool in the Epidemiology tab tool list. |
math_explorer/src/epidemiology/networks.rs |
Adds the backend network epidemic model and node state enum. |
math_explorer_gui/src/tabs/battery_degradation/lifetime_estimator.rs |
Import formatting only. |
math_explorer_gui/src/tabs/ai/attention_maps.rs |
Formatting only (line wrapping). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pub struct NetworkEpidemicModel { | ||
| pub num_nodes: usize, | ||
| pub states: Vec<NodeState>, | ||
| pub positions: Vec<[f32; 2]>, | ||
| pub adjacency: Vec<Vec<usize>>, | ||
| pub beta: f64, | ||
| pub gamma: f64, | ||
| } |
| impl NetworkEpidemicModel { | ||
| pub fn new(num_nodes: usize, beta: f64, gamma: f64) -> Self { | ||
| let mut model = Self { | ||
| num_nodes, | ||
| states: vec![NodeState::Susceptible; num_nodes], | ||
| positions: vec![[0.0, 0.0]; num_nodes], | ||
| adjacency: vec![vec![]; num_nodes], | ||
| beta, | ||
| gamma, | ||
| }; | ||
| model.initialize_geometric_graph(); | ||
| model | ||
| } |
| let connection_radius = 60.0; | ||
| for i in 0..self.num_nodes { | ||
| for j in (i + 1)..self.num_nodes { | ||
| let dx = self.positions[i][0] - self.positions[j][0]; | ||
| let dy = self.positions[i][1] - self.positions[j][1]; | ||
| let dist = (dx * dx + dy * dy).sqrt(); | ||
| if dist < connection_radius { | ||
| self.adjacency[i].push(j); | ||
| self.adjacency[j].push(i); | ||
| } | ||
| } | ||
| } |
| pub fn initialize_geometric_graph(&mut self) { | ||
| let mut rng = rand::thread_rng(); | ||
| self.states = vec![NodeState::Susceptible; self.num_nodes]; | ||
| self.positions = vec![[0.0, 0.0]; self.num_nodes]; | ||
| self.adjacency = vec![vec![]; self.num_nodes]; | ||
|
|
||
| // Random geometric graph | ||
| let radius = 200.0; | ||
| for i in 0..self.num_nodes { | ||
| let angle = rng.r#gen_range(0.0..TAU); | ||
| let r = radius * rng.r#gen_range(0.0f32..1.0f32).sqrt(); | ||
| self.positions[i] = [r * angle.cos(), r * angle.sin()]; | ||
| } | ||
|
|
||
| let connection_radius = 60.0; | ||
| for i in 0..self.num_nodes { | ||
| for j in (i + 1)..self.num_nodes { | ||
| let dx = self.positions[i][0] - self.positions[j][0]; | ||
| let dy = self.positions[i][1] - self.positions[j][1]; | ||
| let dist = (dx * dx + dy * dy).sqrt(); | ||
| if dist < connection_radius { | ||
| self.adjacency[i].push(j); | ||
| self.adjacency[j].push(i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Start with one infected | ||
| if self.num_nodes > 0 { | ||
| let start_idx = rng.r#gen_range(0..self.num_nodes); | ||
| self.states[start_idx] = NodeState::Infected; | ||
| } | ||
| } | ||
|
|
||
| pub fn step(&mut self) { | ||
| let mut next_states = self.states.clone(); | ||
| let mut rng = rand::thread_rng(); | ||
|
|
||
| for (i, next_state) in next_states.iter_mut().enumerate().take(self.num_nodes) { | ||
| match self.states[i] { | ||
| NodeState::Susceptible => { | ||
| // Check infected neighbors | ||
| let infected_neighbors = self.adjacency[i] | ||
| .iter() | ||
| .filter(|&&j| self.states[j] == NodeState::Infected) | ||
| .count(); | ||
| for _ in 0..infected_neighbors { | ||
| if rng.r#gen::<f64>() < self.beta { | ||
| *next_state = NodeState::Infected; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| NodeState::Infected => { | ||
| if rng.r#gen::<f64>() < self.gamma { | ||
| *next_state = NodeState::Recovered; | ||
| } | ||
| } | ||
| NodeState::Recovered => {} | ||
| } | ||
| } | ||
| self.states = next_states; | ||
| } |
| #[derive(Clone, Copy, PartialEq, Debug)] | ||
| pub enum NodeState { | ||
| Susceptible, | ||
| Infected, | ||
| Recovered, | ||
| } | ||
|
|
||
| pub struct NetworkEpidemicModel { | ||
| pub num_nodes: usize, | ||
| pub states: Vec<NodeState>, | ||
| pub positions: Vec<[f32; 2]>, | ||
| pub adjacency: Vec<Vec<usize>>, | ||
| pub beta: f64, | ||
| pub gamma: f64, | ||
| } |
This PR fulfills the "Network Propagation" feature request from
todo_gui.mdwhile adhering to the Glassblower persona's strict architectural directives:NetworkEpidemicModelwithinmath_explorer.NetworkPropagationTool) cleanly implementsEpidemiologyTool, importing backend states for its UI.gencalls to prevent 2024 rust edition keywords bugs, keeping types strongly coupled.PR created automatically by Jules for task 377825193403949821 started by @fderuiter