Working in the lab · Chapter 5 of 14

Notebooks

Cells, ⇧↵, Run all, %pip, outputs in the file.

~2 min read6 sectionssame text as the guide inside the lab
All chapters

Keys are written for macOS, the way the lab prints them — on Windows and Linux read as Ctrl, as Alt, as Shift, as Enter.Keys are shown for Windows / Linux to match your platform — on a Mac, Ctrl is and Alt is . Every binding: Keyboard shortcuts.

An .ipynb file opens as cells, not JSON. Create one with New file… and a name ending in .ipynb — the lab writes a valid empty notebook, never a corrupt one.

Running cells

  • ⇧↵ runs the cell and moves to the next one (adding a new cell at the end).
  • ⌘↵ runs the cell and stays.
  • The ▶ in a cell's gutter does the same; the bracket beside it counts executions ([3]).
  • Toolbar: + Code, + Markdown, Run all (sequential — cell 3 sees what cell 2 defined), Stop, Clear outputs, Restart (fresh interpreter, variables gone).

Cells share one kernel and one namespace with each other — define x in a cell and read it in the next, exactly Jupyter's contract. (▶ Run file on a .py runs that file as a fresh module: it sees the project tree, not your notebook's variables.) Before each run the project tree is synced into the kernel, so a cell can import ansatz from the file next to the notebook.

Cell tools

Hover a cell for its actions on the right: edit a rendered markdown cell (or double-click it), md / py convert between markdown and code, ↑ ↓ move, + add a cell below, delete. A markdown cell renders on ⇧↵ and stays rendered until you edit it.

Outputs

Text, tracebacks, matplotlib figures and rich results render under the cell. Outputs are saved into the file with the notebook — that is what makes a shared notebook arrive with its plots, and why Clear outputs exists.

Packages

%pip install <name> in a cell installs pure-Python packages into the kernel for this session. Compiled scientific packages (qiskit, scipy, pennylane…) have no browser build; the kernel refuses them with a plain sentence rather than a resolver traceback. numpy and matplotlib are already there.

The Run rail while a notebook is open

It steps back: "Cells run from the notebook's own toolbar" and shows the Machines — code names reference so a cell that names a machine can copy the codename exactly.

Persistence

A notebook saves like any file — autosave, ⌘S, conflict handling. If a notebook's JSON is unreadable the view says so and shows the raw text under a warning bar so you can fix or replace it.

Related: Python in the browser · Sharing & GitHub