Skip to content

Ban implicit broadcasting over year dimension#841

Merged
tsmbland merged 45 commits into
mainfrom
broadcast_years
May 7, 2026
Merged

Ban implicit broadcasting over year dimension#841
tsmbland merged 45 commits into
mainfrom
broadcast_years

Conversation

@tsmbland
Copy link
Copy Markdown
Collaborator

@tsmbland tsmbland commented May 7, 2026

Follows on from #840

This involved slightly more changes, but still doable. In doing this I realised it would be better to calculate dispatch/consumption/prices year-by-year rather than multiple (2) years at a time. In doing so I think I've fixed up an error with the prices calculation in the first year (using investment year technology parameters). Not that these prices are used, but this this has relevance for #835

tsmbland and others added 30 commits May 1, 2026 15:29
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Base automatically changed from broadcast_regions to main May 7, 2026 13:37
@tsmbland tsmbland marked this pull request as ready for review May 7, 2026 13:55
@tsmbland tsmbland requested a review from Copilot May 7, 2026 13:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the “ban implicit broadcasting” work to the year dimension by adding an explicit broadcast_years helper, updating core model code to calculate key quantities year-by-year (not 2 years at once), and tightening dispatch input validation to avoid hidden shape errors.

Changes:

  • Add broadcast_years and raise an explicit error when xarray tries to implicitly broadcast along year.
  • Refactor sector market variable calculations to compute supply/consumption/costs per-year and then concatenate results.
  • Update multiple call sites and tests to explicitly broadcast/shape data rather than relying on implicit year expansion.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/test_regressions.py Updates regression expectations to use explicit year broadcasting.
tests/test_quantities.py Attempts to force single-year capacity in tests (but introduces a fixture recursion issue).
tests/test_dispatch.py Updates dispatch test inputs to remove year dimension from prices (but introduces a fixture recursion issue).
tests/test_demand_share.py Explicitly broadcasts technologies over capacity years for matching-market logic.
tests/test_constraints.py Removes year selection after maximum_production by selecting capacity year before the call.
tests/conftest.py Refactors technology fixture broadcasting across region/year (but leaves fixed_outputs without year).
src/muse/utilities.py Adds broadcast_years helper to make year expansion explicit.
src/muse/timeslices.py Ensures timeslice fractions are explicitly broadcast over year when needed.
src/muse/sectors/sector.py Computes supply/consumption/costs year-by-year instead of operating on a 2-year block.
src/muse/regressions.py Uses explicit year broadcasting for regression coefficients (but can call broadcast_years on scalars).
src/muse/readers/toml.py Explicitly broadcasts timeslice shares over years when combining with consumption.
src/muse/investments.py Makes retirement profile comparisons explicitly year-broadcast-safe.
src/muse/examples.py Broadcasts per-asset technologies across years for example matching-market generation.
src/muse/dispatch.py Replaces asserts with dimension checks; simplifies merit-order dispatch to operate on per-year inputs.
src/muse/costs.py Makes discounting/lifetime conversion explicit over year via broadcast_years.
src/muse/agents/factories.py Explicitly broadcasts agent shares across capacity years when scaling capacity.
src/muse/agents/agent.py Ensures investments are explicitly broadcast over year before applying retirement profile.
src/muse/main.py Raises a clear error on implicit broadcasting across the year dimension during debug/tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_dispatch.py
Comment thread tests/test_quantities.py
Comment thread tests/conftest.py Outdated
Comment thread src/muse/regressions.py
Comment thread src/muse/utilities.py
@tsmbland tsmbland merged commit 26605b2 into main May 7, 2026
14 checks passed
@tsmbland tsmbland deleted the broadcast_years branch May 7, 2026 15:11
@github-project-automation github-project-automation Bot moved this to ✅ Done in MUSE May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants