Skip to content

docs(examples): units connect to buses through numbered ports, listed by one relation that also masks the output efficiency - #948

Draft
FBumann wants to merge 3 commits into
claude/gallant-franklin-6ndbd1from
claude/gallant-franklin-6ndbd1-connection-example
Draft

FBumann wants to merge 3 commits into
claude/gallant-franklin-6ndbd1from
claude/gallant-franklin-6ndbd1-connection-example

Conversation

@FBumann

@FBumann FBumann commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Prompt: COuld we add a proper "connection" relation somewhere? (Where: "New example".)

Note

The following content was generated by AI.

What this changes

A new gallery example, "Units with ports" (examples/connection.yaml). One relation lists the bus and role of each unit port, masks efficiency to the output ports, and the balance groups through it by bus. Stacked on #945.

relations:
  connection:
    key: [unit, port]
    values: [bus, role]
    missing: absent
parameters:
  efficiency:
    dims: [unit, port, snapshot]
    where: "connection[role] == 'output'"
    missing: 1
expressions:
  injection:
    dims: [unit, port, snapshot]
    cases:
      draws: { when: "connection[role] == 'input'", expression: -flow }
    otherwise: efficiency * flow
constraints:
  balance:
    dims: [bus, snapshot]
    expression: supply + sum(injection, over=[unit, port], by=connection[bus]) == load

$$\mathit{supply}_{b,t} + \sum_{u,, p ,:, \mathrm{connection.bus}(u, p) = b} \mathit{injection}_{u,p,t} = \mathrm{load}_{b,t}$$

What the example shows, method, gates, and what was not done

What it shows:

  • The relation is keyed by port, not by bus, so two ports of one unit may attach to one bus (Branch components with multiple ports at one bus PyPSA/PyPSA#2015).
  • A parameter's mask that reads a relation's value column. efficiency has coordinates only at the output ports, and missing: 1 fills only those. The legend prints: only where $\mathrm{connection.role}(u, p) = \text{'output'}$, $1$ where the data has no row.
  • A case that reads the same column. An input port puts -flow into its bus. Outside connection, no case claims the coordinate, and efficiency is absent there, so injection is absent and the balance adds only real ports.

Files:

  • the spec, examples/connection.yaml
  • its page, docs/examples/connection.md. The YAML and math block was written by python -m tools.gallery, not by hand.
  • a row in MODELS in tools/gallery.py
  • the nav entry in mkdocs.yml
  • a bullet in docs/examples/index.md
  • the page added to .prettierignore, as a generated page.

Gates on the head, f18b1d7, which merges #945's head after main reached it through #894. The merge had no conflict. With pixi:

  • pixi run lint passes.
  • pixi run test passes: 3131 passed, 1 skipped. The new spec adds 11 tests through the suite's SPECS corpus.
  • pixi run docs-build passes.
  • compile-tex failed on every document because the container could not download the TeX bundle. CI compiles connection.tex with the rest.

Earlier, on #945's ff91d15 plus this commit, python -m tools.gallery wrote every other page back unchanged.

With #949. A trial merge of #949 (the case-check fixes) into this head conflicts only in CHANGELOG.md, and pytest gives 3143 passed, 1 skipped.

Not done:

Why

The gallery had no spec where one relation is both the map a balance groups through and the mask of a parameter. This is the pattern #944 needs for connections, written with relations as they are.


Generated by Claude Code

… by one relation that also masks the output efficiency

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0113aUbLChfQVBrVR5FVQnJq
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0113aUbLChfQVBrVR5FVQnJq
@read-the-docs-community

read-the-docs-community Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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