Getting Started with Google Colab
What is Google Colab?
Google Colab (short for “Colaboratory”) is a free online tool that lets you write and run Python code in your web browser. Think of it like Google Docs, but for code!
Why we love it for beginners:
- ✅ No installation needed
- ✅ No setup required
- ✅ Pre-installed with common libraries
- ✅ Free GPU access (for fast computation)
- ✅ Easy sharing with others
- ✅ Automatic saving to Google Drive
Step 1: Open Your First Notebook
Click this link to open the first GenJAX notebook:
📓 Open: Chapter 2 - Your First GenJAX Model
What just happened?
You opened a Jupyter notebook — an interactive document that mixes:
- Text (explanations, like this)
- Code (that you can run)
- Visualizations (graphs and plots)
Think of it as a lab notebook for probability experiments!
Step 2: Make a Copy (So You Can Edit)
When the notebook opens, you’ll see a yellow banner that says “You are using Colab in playground mode.”
Click: “Copy to Drive” (top right, or in the banner)
This creates your own copy that you can edit and save!
Important!
Without copying to Drive, your changes won’t be saved when you close the browser!
Step 3: Understanding the Interface
Let me show you around:
The Notebook Structure
A Colab notebook has cells — little boxes that contain either:
- Text cells (like this explanation)
- Code cells (Python code you can run)
Running Code Cells
See a cell with code like this?
| |
To run it:
- Click on the cell
- Press Shift + Enter (or click the ▶️ play button on the left)
Try it! You should see “Hello, Chibany!” appear below the cell.
Interactive Widgets
Throughout the notebooks, you’ll see sliders and controls that let you change values and instantly see updated results. We’ll use these to explore probability!
Step 4: Install GenJAX
The first code cell in each notebook will look like this:
| |
What this does:
- In Colab notebooks, you use
!pip installto run shell commands pip installmeans “download and install”genjaxis the library we’re installing
To run it:
- Click the cell
- Press Shift + Enter
- Wait for it to finish (you’ll see progress messages)
Tip
You only need to install GenJAX once per session. If you come back later and restart the notebook, you’ll need to run this cell again.
Step 5: Import Required Libraries
After installation, you’ll typically see a cell like:
| |
What this does:
importmeans “load this library so we can use it”- We’re loading JAX (for computation), GenJAX (for probability), and matplotlib (for plotting)
Just run it! You don’t need to understand every line. Think of it like turning on the lights before you start working.
Step 6: Your First Code!
Now you’re ready to run real GenJAX code! In the next chapter, you’ll:
- Write a generative function for Chibany’s meals
- Generate thousands of random days
- Visualize the results
- Use sliders to change probabilities and see what happens
Common Issues & Solutions
“Runtime disconnected”
Problem: Colab disconnects after ~90 minutes of inactivity Solution: Just reconnect and re-run the cells (start to finish)
“Restart Runtime” button
Problem: Something went wrong and you need a fresh start Solution: Click Runtime → Restart runtime → Re-run all cells
Code won’t run
Problem: Cells need to be run in order Solution: Click Runtime → Run all (to run from top to bottom)
Keyboard Shortcuts (Optional)
These can make you faster, but they’re optional:
| Action | Shortcut |
|---|---|
| Run current cell | Shift + Enter |
| Insert cell below | Ctrl + M, B |
| Delete cell | Ctrl + M, D |
| Comment/uncomment line | Ctrl + / |
Quick Reference Card
Save this for later:
Running Code:
- Click cell
- Shift + Enter
Saving Work:
- Auto-saves to Google Drive (if you copied to Drive)
- Manual save: File → Save
Fresh Start:
- Runtime → Restart runtime
Getting Help:
- In code cell, type
?function_nameand run to see documentation - Or just Google your question!
You’re Ready!
Now you have: ✅ Google Colab open ✅ Your own copy of the notebook ✅ GenJAX installed ✅ Basic understanding of the interface
Next steps:
- Chapter 1: Python Essentials → - Learn just enough Python
- Chapter 2: Your First GenJAX Model → - Jump right into coding!
Details
Pro tip: Keep this tab open as a reference while you work through the notebooks!
| ← Previous: Introduction | Next: Python Essentials → |
|---|