Skip to content

12: the course's Explore section, built on the package - #2

Merged
yamierick merged 1 commit into
mainfrom
notebook12/explore
Oct 22, 2026
Merged

yamierick merged 1 commit into
mainfrom
notebook12/explore

Conversation

@yamierick

Copy link
Copy Markdown
Contributor

Stacked on #1. The base is ci/clean-machine-ci: this PR needs that one's energy extra and its changes to test_energy.py. Merge #1 first; GitHub will then retarget this PR to main.

Why

On 20 Oct the REE 4301 course copy of Module 0 gained an Explore section, which teaching-code's notebook 12 lacked. Apart from that, the two copies share the same model and the same numbers (checked 22 Oct). The course's Exercises F.1 and F.2 were already here, as the last two "Where to take this next" bullets.

What

New cells after the agreement assertion (the code standard keeps helper functions out of the teaching section):

  • a slider for the battery day;
  • a slider for the build decision;
  • an edit-and-run cell where the student writes a gurobipy constraint;
  • a cell that moves the demand peak;
  • the course's six reflection questions.

How they're built:

  • The sliders use the package. They call energy.day_network and energy.solve_day instead of rebuilding the model inline. Each one first checks that, at the table's own numbers, it reproduces what the student built by hand ($18,132.63 for the day; the Part F build).
  • The constraint exercise works on a copy of Part B's model, so nothing above it changes. Until the student writes the line, the cell says the answer is still Part B's.
  • The committed figure uses line styles and markers as well as colour, and prints a sentence describing what it shows.

Supporting changes:

  • energy.day_profiles(peak_hour=19). The default still reproduces the CSV exactly; tested.
  • ipywidgets added to the energy extra.
  • Notebook 12's README: describes Explore; drops the stale claim that the ESM repo is private and its link 404s; warns against building the kernel's venv in a Temp folder.

Evidence

  • Re-executed under PyPSA 1.4.0 (it last ran on 1.3.0). All 21 original code cells give identical output, apart from the version line.
  • Student paths run on a scratch copy:
    • with the constraint written: $1,549.80, and the price falls to $0.00 because solar becomes marginal;
    • with the battery at 0 MW and the peak moved to 13:00: it solves.
  • Gate:
    • base suite: 182 passed;
    • tests/test_energy.py in the energy venv with ORTEACH_REQUIRE_PYPSA=1: 12/12;
    • notebook and seed checks clean; ruff clean.

Machine note (not in the diff)

The orteach-energy kernel's venv had been built in AppData\Local\Temp, which Windows cleaned out. It's been rebuilt at C:\Users\jonesec\dev\venvs\orteach-energy.

🤖 Generated with Claude Code

…ckage

On 2026-10-20 the REE 4301 course copy of Module 0
(Tools/build_toy_lp_notebook.py in the course folder) gained an "Explore -
for your reflection" section: sliders for the battery day and for the build
decision, a cell where the student writes a gurobipy constraint, and one
that moves the demand peak, with six reflection questions. This notebook
had none of it. The model and every number are otherwise the same in both
copies (compared 2026-10-22). The course's Exercises F.1 and F.2 were
already here as the last two "Where to take this next" bullets.

What changed in the port, and why:

- The course version defines its slider functions in the teaching section
  and rebuilds the networks inline. Here they sit after the agreement
  assertion, below "Now the streamlined version" (Part 3), and call
  energy.day_network / energy.solve_day, which that assertion has just
  compared with the hand-built model. Each explorer first checks that, at
  the table's own numbers, it reproduces the hand-built result: Part E's
  $18,132.63 day and Part F's build (Part 3, "a check that the wrapper
  reproduces the hand-built result").
- The deliberate blank works on a copy of Part B's model, so the cells
  above are untouched. Until the student writes the line, it prints Part
  B's answer and says it is still Part B's (Part 5: a blank fails with a
  message). Checked with the line written: $1,549.80, solar 30, gas 70,
  shadow price $0.00, because solar is now on the margin, which is what
  question 5 asks.
- The one figure committed (the move-the-peak call) uses line style and
  marker as well as colour, and its cell prints a sentence saying what it
  shows, generated from the solve. The figure sentence does not name
  charging hours, because this notebook teaches that those are a tie.
- energy.day_profiles takes peak_hour (default 19, which still reproduces
  the CSV exactly) so moving the peak does not need a second copy of the
  demand formula in the notebook. Tested.

Also: ipywidgets joins the energy extra; the folder README says what
Explore is and drops two stale claims (that energy-system-modeling is
private and 404s; it has been public since 2026-09-13), and says to keep
the venv out of Temp. The orteach-energy venv had been built in
AppData\Local\Temp, which Windows cleaned, leaving a kernel registration
that pointed at nothing. It is rebuilt from `.[dev,energy]`.

Re-executed under PyPSA 1.4.0 / pandas 3.1.0 (was 1.3.0): all 21 original
code cells produce identical output apart from the version line.

Gate: 182 passed (base); 12/12 tests/test_energy.py in the energy venv
with ORTEACH_REQUIRE_PYPSA=1; 17 notebooks and 11 seeds clean; ruff clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yamierick
yamierick changed the base branch from ci/clean-machine-ci to main October 22, 2026 18:54
@yamierick
yamierick merged commit c196059 into main Oct 22, 2026
2 checks passed
@yamierick
yamierick deleted the notebook12/explore branch October 22, 2026 18:56
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.

1 participant