Skip to content
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

Include examples in readthedocs #2382

Closed
wants to merge 77 commits into from
Closed

Conversation

quaquel
Copy link
Member

@quaquel quaquel commented Oct 17, 2024

This updates conf.py to create markdown files for including the examples in the documentation. It also cleans up some warning on RTD, which happened while debugging the code. In this process, this also fixes #2360.

It currently only covers the basic examples because the advanced examples are not fully cleaned yet.

Copy link
Member

@tpike3 tpike3 left a comment

Choose a reason for hiding this comment

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

This is awesome!

This also epitomizes to me why we want those seminal models in the main repo so we can ensure they are current with whatever Mesa version we are on.

To run the model interactively, run ``mesa runserver`` in this directory. e.g.

```
$ mesa runserver
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be updated to the new visualization approach

* ``agents.py``: Defines the behavior of an individual cell, which can be in two states: DEAD or ALIVE.
* ``model.py``: Defines the model itself, initialized with a random configuration of alive and dead cells.
* ``portrayal.py``: Describes for the front end how to render a cell.
* ``st_app.py``: Defines an interactive visualization using Streamlit.
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be updated for new set agents and app

To run the model interactively, run ``mesa runserver`` in this directory. e.g.

```
$ mesa runserver
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be updated with Solara

docs/index.md Show resolved Hide resolved
import altair as alt
import numpy as np
import pandas as pd
import streamlit as st
Copy link
Member

Choose a reason for hiding this comment

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

Do we still want to use streamlit or update to Solara?

Copy link
Member Author

Choose a reason for hiding this comment

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

in my view, we standardize all examples on solara

To run the model interactively, run ``mesa runserver`` in this directory. e.g.

```
$ mesa runserver
Copy link
Member

Choose a reason for hiding this comment

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

Update to Solara?


For more information about this model, read the NetLogo's web page: http://ccl.northwestern.edu/netlogo/models/VirusonaNetwork.

JavaScript library used in this example to render the network: [d3.js](https://d3js.org/).
Copy link
Member

Choose a reason for hiding this comment

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

This could be removed

@@ -0,0 +1,61 @@
# Virus on a Network
Copy link
Member

Choose a reason for hiding this comment

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

Why are these in two places?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure what you mean?

Copy link
Member

Choose a reason for hiding this comment

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

The old one wasn’t removed, so there are now two Readme files.

@quaquel
Copy link
Member Author

quaquel commented Oct 19, 2024

@tpike3, I agree with most of your comments regarding the content of the examples, but can we leave that for a separate PR and focus this one on just including the examples in the docs in the first place? The updated conf.py ensures that any updates in the readme, agent.py, model.py, and app.py result in an updated page in the docs.

@EwoutH
Copy link
Member

EwoutH commented Oct 20, 2024

One question, why does it add so much additional files? Aren't all/most of those files in the repo already?

@quaquel
Copy link
Member Author

quaquel commented Oct 20, 2024

  1. It updates conf.py, 6 associated autogenerated example markdown files in docs, and 2 templates to create these markdown files (9 files in total)
  2. It renames the readme files to all have the same format (case sensitive) and makes similar name changes to some other files.
  3. I updated some files here and there in the docs because there are many warnings on RTD. These changes removed most of those allowing me to better debug the updates to conf.py.

@EwoutH
Copy link
Member

EwoutH commented Oct 20, 2024

Thanks for the explanation. I will be honest, I don't like these monster PRs that do multiple things and are quite far away from an atomic change. There's a big chance something slips up in there. I also do recognize real-world development flows and practical limitations.

6 associated autogenerated example markdown files in docs

Is there anyway we can not keep these files in our history, since they are autogenerated from existing content and thus 100% duplicate. I suspect this will trigger (huge) CI issues and changesets when updating examples or working on other stuff.

I see two options:

  1. Build then in Sphinx / RTD and don't generated them in git at all
  2. (automatically) add them to the .gitignore.

For me 1 is preferred, but 2 is also acceptable.

The other files are fine, renames and cleanups look good. Ideally the warnings cleanup would be a separate PR, but I do recognize how this goes so for now its fine from my part.

@quaquel
Copy link
Member Author

quaquel commented Oct 20, 2024

Is there anyway we can not keep these files in our history, since they are autogenerated from existing content and thus 100% duplicate. I suspect this will trigger (huge) CI issues and changesets when updating examples or working on other stuff.

conf.py handles all this so there should not be a problem. I prefer to have them in the history because otherwise rtd has to first regenerate the md files and then regenerate the html pages every single time. Having them in git speeds up the building of docs because they are only recreated by RTD if the associated example Python files are updated.

@EwoutH
Copy link
Member

EwoutH commented Oct 20, 2024

But that means every time I update an example, the all the changes will be duplicate into the PR diff. I find that to be a major downside.

Can't we cache them elsewhere, and just hash the source files and templates use to check for cache hits?

Sorry to make this PR more complicated, but this duplication is something I really really would like to avoid.

@quaquel
Copy link
Member Author

quaquel commented Oct 20, 2024

But that means every time I update an example, the all the changes will be duplicate into the PR diff. I find that to be a major downside.

This only happen if you build the docs yourself locally and commit those changes. Also there is a single md file per example, so I am not sure what the problem is.

@quaquel
Copy link
Member Author

quaquel commented Oct 20, 2024

Can't we cache them elsewhere, and just hash the source files and templates use to check for cache hits?

The simpler solution would be to just always rebuild the md files and ignore them via gitignore, but I fail to see what the problem is with the current solution as explained above.

@EwoutH
Copy link
Member

EwoutH commented Oct 20, 2024

The simpler solution would be to just always rebuild the md files and ignore them via gitignore

That's a totally acceptable solution for me right now. We can add caching later if that seems to be needed.

I fail to see what the problem is with the current solution as explained above.

Basically, each change to the examples would have a completely duplicate diff, as both the example itself and generated readme is changed in exactly the same way.

@quaquel
Copy link
Member Author

quaquel commented Oct 20, 2024

Basically, each change to the examples would have a completely duplicate diff, as both the example itself and generated readme is changed in exactly the same way.

I guess you mean markdown rather than readme. As indicated, this only happens if you build the docs locally. Who does that other than when developing and testing doc-related things? Note that this approach has been used for the workbench for several years. Have you ever run into this potential diff problem there?

I am happy to change it but I still fail to see the problem here.

@EwoutH
Copy link
Member

EwoutH commented Oct 20, 2024

But if these files are tracked/included in git, but not updated in a PR, when are they updated? And why does this PR have them?

(signing off for today, will reply tomorrow)

@quaquel
Copy link
Member Author

quaquel commented Oct 20, 2024

But if these files are tracked/included in git, but not updated in a PR, when are they updated? And why does this PR have them?

If not updated in the PR, conf.py during building the docs on RTD will overwrite the existing files (depending on timestamps, basically if agent.py, model.py, or readme.md is newer than the exising <example_name>.md file, the md file will be overwritten). They are here because I tested conf.py locally.

Regardless, I have made the change you requested. The example related markdown files are now in gitignore and conf.py just allways creates them on RTD when building docs.

@EwoutH
Copy link
Member

EwoutH commented Oct 21, 2024

They are here because I tested conf.py locally.

Okay, so they are only generated within Sphinx / Readthedocs, and not tracked in git by default. So it’s already like the preferred solution I proposed.

When committing, please check which files you want to include in the PR and which files are just local because you tested / experimented with some things.

Two remaining points, then we can properly review:

  • There are two Readme files that are now duplicated. I think instead of rename you did copy and rename.
  • The same happened to the st_app.py I think. I think it would be good to keep the different name for the Streamlit app, since then users recognize it’s different. We might add a SolaraViz in the future called app.py, and then it would be nice to include both. I would say: Check for both app.py and st_app.py if they exist, and if they do, include them.

@quaquel
Copy link
Member Author

quaquel commented Oct 21, 2024

It's a bit more complicated than you make it out to be. But I don't want to continue arguing the point.

I don't see two readme files that are identical, neither in my IDE nor in my file explorer. Please can you be explicit which files according to you are duplicated?

Including both app and st_app if they both exist and only either one, if they exist, is tricky with string templates. I actually experimented with trying to get that to work but it did not render nicely. So happy to take yet another stab at it but it's not entirely trivial as far as I can tell. Moreover, from a future proofing point of view, my preference would be to standardize on app.py and only showcase solara visualizations.

If there is any file duplication, it happened after rebasing because of the examples --> mesa.examples move. This rebase broke somehow GitHub Desktop and I had to resort to the command line.

@EwoutH
Copy link
Member

EwoutH commented Oct 21, 2024

May I clean up the PR?

@quaquel
Copy link
Member Author

quaquel commented Oct 21, 2024

go ahead

@EwoutH
Copy link
Member

EwoutH commented Oct 21, 2024

I tried doing a proper rebase, but the git threw a few errors I never have seem before. So I ported the changes over manually in #2392.

@quaquel
Copy link
Member Author

quaquel commented Oct 21, 2024

solved via #2392

@quaquel quaquel closed this Oct 21, 2024
@quaquel quaquel deleted the docs branch October 24, 2024 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Release notes label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Experimental documentation
4 participants