Skip to content

Convert markdown tutorial to jupyter tutorial #101 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

reyan-singh
Copy link
Collaborator

@reyan-singh reyan-singh commented Mar 24, 2025

Converted the introductory tutorial (/mesa-frames/docs/general/user-guide) from Markdown to Jupyter format, Please Review and let me know if any other files to be converted

Now code is able to run and execute in the tutorial itself and in case of success/error it is able to show the output

NOTE: I tried to run the code and all the cells above the "Running the code" cell were able to run on tutorial itself but I found when I tried to run the "Running the code" cell it gives an error, good part is I am able to see the output(error) there itself

so looks like Example code has a few error and may need fixes , would you like to create a new issue to fix the Tutorial code.

Summary by CodeRabbit

  • Documentation
    • Added an introductory tutorial that guides users through implementing a wealth distribution simulation using the Boltzmann Wealth Model.
    • The tutorial includes step-by-step instructions for setting up the simulation, executing the model, and reviewing performance comparisons between pandas and Polars data handling approaches.
    • Enhanced the documentation functionality by enabling execution of Jupyter notebooks during the build process.
    • Updated navigation to reflect the new Jupyter notebook format for the tutorial.

Inital commit to convert exisitng tutorial format from md to jupyter tutorial
Copy link

codecov bot commented Mar 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@d7756a5). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #135   +/-   ##
=======================================
  Coverage        ?   91.78%           
=======================================
  Files           ?       11           
  Lines           ?     1680           
  Branches        ?        0           
=======================================
  Hits            ?     1542           
  Misses          ?      138           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adamamer20
Copy link
Member

try building the documentation to see if it gives a correct output. in case of errors, make the necessary adjustments

Error is fixed for tutorial "Running the model" cell, which used to display distribution stats
@reyan-singh
Copy link
Collaborator Author

try building the documentation to see if it gives a correct output. in case of errors, make the necessary adjustments

@adamamer20 "running the model" cell tutorial example is fixed, looking into performance comparison

Updated Performance comparison code for support for jupyter based markdown page
@reyan-singh
Copy link
Collaborator Author

@adamamer20 updated the tutorial page along with running code, please review and suggest if missing anything

Copy link
Contributor

coderabbitai bot commented Apr 1, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces an introductory tutorial for the Boltzmann Wealth Model using the mesa-frames library. The notebook explains the model's functionality, simulates wealth distribution among agents, and demonstrates the implementation of several new classes for managing agents and model behavior. It includes variants for both pandas and Polars data handling, provides concise and native implementations, and introduces a helper function to run the simulation over specified steps. The tutorial further presents performance comparisons between the two backends, emphasizing the improved efficiency of the mesa-frames approach.

Changes

File(s) Change Summary
docs/general/user-guide/2_introductory-tutorial.ipynb Added a new tutorial notebook introducing the Boltzmann Wealth Model. New classes created: MoneyModelDF, MoneyAgentPandas, MoneyAgentPolars, MoneyAgentPolarsConcise, MoneyAgentPolarsNative, MoneyAgentPandasConcise, MoneyAgentPandasNative, MoneyAgent, MoneyModel. A new function run_simulation is also added to execute the model.
mkdocs.yml Updated the mkdocs-jupyter plugin configuration to set execute: true, enabling the execution of Jupyter notebooks during documentation build.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant U as User
    participant RS as run_simulation
    participant M as MoneyModelDF
    participant A as MoneyAgent (Multiple Variants)
    
    U->>RS: Invoke simulation(model_class, n_agents, n_steps)
    RS->>M: Instantiate MoneyModelDF with agent data
    M->>A: Initialize agents (pandas/Polars variations)
    loop Simulation Steps
        M->>A: Agents execute give_money operations
    end
    M-->>RS: Return final wealth distribution
    RS-->>U: Provide simulation results and performance stats

Poem

I'm a hopping rabbit, coding with delight,
Scurrying through models both day and night.
With pandas and Polars in a gentle dance,
Money flows in code with each simulation chance.
Cheers from CodeRabbit—let's crunch data just right!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
docs/general/user-guide/2_introductory-tutorial.ipynb (2)

22-23: Remove unused imports.

The imports of attr.validators and numba don't appear to be used anywhere in the notebook.

-from attr.validators import instance_of
-from numba import typeof

from mesa_frames import ModelDF, AgentSetPandas, AgentSetPolars

453-453: Remove unused variable assignment.

The assignment a=1 is never used in the code.

n_agents_list = [100000, 300000, 500000, 700000]
n_steps = 100
-a=1
print("Execution times:")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2022dc and b5d957d.

📒 Files selected for processing (1)
  • docs/general/user-guide/2_introductory-tutorial.ipynb (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (windows, 3.12)
🔇 Additional comments (11)
docs/general/user-guide/2_introductory-tutorial.ipynb (11)

27-39: LGTM! ModelDF implementation looks good.

The MoneyModelDF class is well-structured with clear initialization, step, and run_model methods that will work with both pandas and Polars implementations.


67-82: LGTM! MoneyAgentPandas implementation is correct.

The implementation properly handles agent selection, money transfer, and wealth updates using pandas operations.


103-118: LGTM! MoneyAgentPolars implementation is correct.

The implementation correctly adapts the pandas approach to use Polars-specific methods like group_by, len(), and with_replacement.


139-148: LGTM! Code for running the model is clear and functional.

The code correctly shows how to instantiate the model with a chosen agent class, run it for 100 steps, and display the final wealth distribution statistics.


204-262: LGTM! Polars concise implementation with clear comments.

The MoneyAgentPolarsConcise class is well-commented with alternative approaches, making it educational for users learning the API.


264-297: LGTM! Native Polars implementation looks efficient.

The MoneyAgentPolarsNative class uses Polars' native operations for better performance.


300-340: LGTM! Pandas concise implementation with clear comments.

Similar to the Polars implementation, the MoneyAgentPandasConcise class is well-documented with alternative approaches.


343-373: LGTM! Native pandas implementation follows good practices.

The MoneyAgentPandasNative class correctly uses pandas' native operations for performance.


392-428: LGTM! Standard Mesa implementation for comparison.

The traditional Mesa implementation is correctly structured for performance comparison.


486-567: LGTM! Performance comparison output is comprehensive.

The documentation of performance results is thorough and clearly demonstrates the speed advantages of mesa-frames over the original mesa implementation.


575-583: LGTM! Excellent conclusion summarizing key findings.

The conclusion effectively summarizes the performance advantages of using mesa-frames, especially with the Polars backend.

@adamamer20 adamamer20 self-requested a review April 1, 2025 11:34
Copy link
Member

@adamamer20 adamamer20 left a comment

Choose a reason for hiding this comment

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

The documentation seems to build correctly but the overall objective is to have the notebook be executed when the documentation is being built and give the output.
Follow the necessary steps from the reference here: https://github.com/danielfrg/mkdocs-jupyter#readme

Adding execute to true  in yml to make sure the notebooks run
 when doc is build and generate output
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
mkdocs.yml (2)

47-48: Enable Execution in mkdocs-jupyter Plugin

The updated configuration now explicitly sets execute: true for the mkdocs-jupyter plugin. This is a crucial change ensuring that when the documentation is built, any embedded Jupyter notebooks (such as the newly converted introductory tutorial) will be executed to generate live outputs. Please verify that executing these notebooks during build does not introduce performance issues or side effects in your documentation pipeline.


107-114: Verify Navigation File References

Although not part of the explicit diff, the navigation section still references the tutorial as user-guide/2_introductory-tutorial.md. Since this PR’s objective is to convert the tutorial to Jupyter Notebook format, please confirm that the navigation entry is updated to reflect the correct file extension (e.g., .ipynb) if applicable. This will ensure that users are directed to the executable notebook rather than an outdated markdown file.

🧰 Tools
🪛 YAMLlint (1.35.1)

[warning] 111-111: wrong indentation: expected 6 but found 4

(indentation)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5d957d and 7a9b19b.

📒 Files selected for processing (1)
  • mkdocs.yml (1 hunks)

@reyan-singh
Copy link
Collaborator Author

The documentation seems to build correctly but the overall objective is to have the notebook be executed when the documentation is being built and give the output. Follow the necessary steps from the reference here: https://github.com/danielfrg/mkdocs-jupyter#readme

@adamamer20 Updated config in yml to make sure the notebooks run when doc is build and generate output

reyan-singh and others added 5 commits April 1, 2025 20:05
updating refernce to 2_introductory-tutorial.ipynb in yml file
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
fixed mesa example code to run
Updating indentation as find pre-check failing with unexpected unindented whereas code running successfully in local system
@reyan-singh
Copy link
Collaborator Author

@adamamer20 fix's are done and passed all checks

@adamamer20
Copy link
Member

Now it's ready to be merged!
I made some changes to the tutorial because there were some issues to the implementations both for mesa and mesa-frames. I also added an open in colab button which is always nice for user interaction.

@adamamer20
Copy link
Member

I will ask a review from coderabbit to test it out a bit

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@adamamer20 I'll review this PR for you. Let me first check what files have been changed so I can provide a comprehensive review.


🏁 Script executed:

#!/bin/bash
# Get the list of files changed in this PR
git diff --name-status main...HEAD

Length of output: 70


@adamamer20 I encountered an issue with the git command. Let me try a different approach to identify the files changed in this PR.


🏁 Script executed:

#!/bin/bash
# List all branches to understand the repository structure
git branch -a

# Let's look at the PR files directly using GitHub CLI
gh pr view 135 --json files --jq '.files[].path'

Length of output: 224


@adamamer20 Thanks for the information. I've identified the files changed in this PR. Now I'll examine the specific changes to conduct a proper review.


🏁 Script executed:

#!/bin/bash
# Check the changes to README.md
git diff main...coderabbit_135 -- README.md

# Check the changes to mkdocs.yml
git diff main...coderabbit_135 -- mkdocs.yml

# Look at the new Jupyter notebook file
cat docs/general/user-guide/2_introductory-tutorial.ipynb

Length of output: 15017


@adamamer20 I'll continue examining the files. Let me check if there was an original markdown file and see the configuration changes in mkdocs.yml.


🏁 Script executed:

#!/bin/bash
# Let's try to check if there's an original markdown file that was replaced
find docs/general/user-guide -name "*.md" | grep introductory-tutorial

# Let's examine mkdocs.yml to understand configuration changes
cat mkdocs.yml

# Let's check README.md changes
cat README.md

Length of output: 10307


@adamamer20 I'm continuing my review of this PR by checking the original markdown content to understand what was converted to the Jupyter notebook format.


🏁 Script executed:

#!/bin/bash
# Let's fetch the original markdown file content to compare
cat docs/general/user-guide/2_introductory-tutorial.md

Length of output: 5475


@adamamer20 I've completed my review of this PR which converts the markdown tutorial to a Jupyter notebook format. Here's my assessment:

What I Like

  • The conversion to Jupyter notebook format makes the tutorial interactive, allowing users to execute code and see immediate results
  • The addition of the "Open in Colab" badge is excellent for accessibility
  • The notebook includes expanded content compared to the original markdown, with multiple implementation approaches
  • The performance comparison section is thorough and demonstrates the advantages of mesa-frames over traditional mesa
  • The mkdocs.yml configuration was properly updated with execute: true to ensure notebooks run during documentation build

Improvements

  • The notebook implementation includes proper execution outputs, making it easier for users to understand expected results
  • Code examples are well-organized with clear explanations between cells
  • The tutorial structure is logical, taking users from basic setup through advanced performance comparisons

Suggestions

  • Consider removing the original markdown file to avoid duplication and potential maintenance confusion
  • Add a brief explanation at the beginning of the notebook about why Jupyter format was chosen over markdown (interactive capabilities)
  • Consider adding some visualizations (charts/graphs) of the wealth distribution for better illustration

Overall, this PR represents a significant improvement to the documentation. The tutorial is now more interactive and educational, providing a better experience for users learning the mesa-frames library.

🐰 CodeRabbit is happy to help with testing the new interactive documentation!

@adamamer20 adamamer20 added the docs Improvements or additions to documentation label Apr 18, 2025
@adamamer20 adamamer20 added this to the 0.1.0-stable milestone Apr 18, 2025
@adamamer20 adamamer20 self-requested a review April 18, 2025 17:03
@adamamer20 adamamer20 merged commit ac2a962 into projectmesa:main Apr 18, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants