Skip to content

Add Google Colab integration to documentation and tutorials#1754

Open
nishantraghuvanshi wants to merge 1 commit intobrian-team:masterfrom
nishantraghuvanshi:feat/add-google-colab-links
Open

Add Google Colab integration to documentation and tutorials#1754
nishantraghuvanshi wants to merge 1 commit intobrian-team:masterfrom
nishantraghuvanshi:feat/add-google-colab-links

Conversation

@nishantraghuvanshi
Copy link

This commit adds Google Colab support alongside existing Binder integration,
making it easier for users to try Brian2 in the cloud without local installation.

Changes:

  • Added Google Colab badge to README.md in Quickstart section
  • Added Google Colab badge to docs_sphinx/index.rst alongside Binder
  • Updated text to mention both Binder and Google Colab services
  • Added Colab environment detection to all 3 tutorial notebooks
  • Notebooks now auto-install Brian2 when running in Google Colab

The implementation uses direct GitHub→Colab linking (no separate repository
needed like brian2-binder). Tutorial notebooks detect the Colab environment
and automatically install Brian2, providing a seamless user experience.

Addresses #1214

  This commit adds Google Colab support alongside existing Binder integration,
  making it easier for users to try Brian2 in the cloud without local installation.

  Changes:
  - Added Google Colab badge to README.md in Quickstart section
  - Added Google Colab badge to docs_sphinx/index.rst alongside Binder
  - Updated text to mention both Binder and Google Colab services
  - Added Colab environment detection to all 3 tutorial notebooks
  - Notebooks now auto-install Brian2 when running in Google Colab

  The implementation uses direct GitHub→Colab linking (no separate repository
  needed like brian2-binder). Tutorial notebooks detect the Colab environment
  and automatically install Brian2, providing a seamless user experience.

  Addresses brian-team#1214
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@mstimberg
Copy link
Member

Hi @nishantraghuvanshi, thanks for your work on this! I need to have a closer look at this, but I think I'd prefer having this a bit more automized. In our current documentation, we have links to open the three tutorials on binder.org: https://brian2.readthedocs.io/en/stable/resources/tutorials/index.html and we also add an automatic banner to open each example, see e.g. https://brian2.readthedocs.io/en/stable/examples/COBAHH.html
With your approach, how would you actually open e.g. Tutorial 2 in collab?

The advantage of a separate repository is that we can add the header with the !pip install brian2 automatically instead of including it manually in every notebook. And this part could also be added when we convert the examples from .py to .ipynb. There might also be existing things we can reuse, see e.g. https://sphinx-book-theme.readthedocs.io/en/stable/content/launch.html and the discussion here: pydata/pydata-sphinx-theme#1422
But as I said, I need to think about this a bit more, I don't have the perfect solution in my sleeve 😊

@nishantraghuvanshi
Copy link
Author

nishantraghuvanshi commented Jan 27, 2026

Hi @mstimberg, thanks a lot for the detailed feedback. You bring up some great points, so I gave this a bit more thought. Here's what I think could work well:

1. Proposed solution: two-part automation

My current idea is to automate both the badges and the installation step.

Part 1: automated badges (via Sphinx)

  • Use either sphinx-book-theme or the PyData theme launch buttons.
  • Configure this once in conf.py so Colab badges are generated automatically for all tutorial and example pages. That way, users can open any notebook in Colab directly from the docs.

Part 2: automated installation (separate repository)

  • Create a brian2-colab repository, similar to brian2-binder
  • Set up a small pipeline that:
    1. pulls notebooks from the main brian2 repo.
    2. injects a !pip install brian2 cell at the top.
    3. pushes the result to brian2-colab.
  • The Colab badges would then point to this repo instead of the main one.

2. Alternative: build-time injection

If maintaining a separate repository feels like too much overhead, I could instead look into injecting the installation cell during the existing .py → .ipynb conversion or as part of the docs build process. That said, the separate-repo approach feels quite clean and consistent with how brian2-binder already works.

3. A few questions before I proceed

  1. Separate repo: would you be open to creating a brian2-colab repository? I’m happy to set it up and handle the automation.
  2. Sphinx integration: would you prefer sphinx-book-theme, or should I try to integrate this with the current Brian2 theme?
  3. Scope for this PR: would you rather I
    • implement the full solution (separate repo + Sphinx badges), or
    • start with a minimal version and iterate from there?

I’m flexible and happy to go with whatever fits best into Brian2's workflow, just wanted to run this by you first.

Thanks again for taking the time to review this!

P.S. I'm also working on issue #1219 (Statements substitution), please do give your suggestions on that if you have the time. Thanks

@mstimberg
Copy link
Member

Hi again, sorry for not being more reactive on this issue. I'm still a bit hesitant, since we are thinking about overhauling the documentation system more globally (see e.g. #610) , and I don't want you to work on something that becomes obsolete soon. Having a separate repository is certainly a possibility, but it would be a bit different from the brian2-binder repository: for collab, we'd actually need the notebooks in the repo, whereas the brian2-binder repository only creates the notebooks as part of the postBuild. Sorry, I still need to think about ithe best approach for a bit…

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