Refactor: decouple electricity disagg from main cornerstone pipeline - #558
Merged
Conversation
Contributor
Author
|
The decoupling re-structuring happens in these files:
The rest are renaming functions so that their use is more clearly indicated in the name. |
jvendries
marked this pull request as ready for review
July 30, 2026 20:03
bl-young
approved these changes
Jul 31, 2026
bl-young
left a comment
Member
There was a problem hiding this comment.
looks fine - thanks for the cleanup. I might recommend you clarify in the commit to main that this is a true refactor, e.g.
refactor: Decouple electricity disagg from main cornerstone pipeline
jvendries
force-pushed
the
jv_electricity_decouple
branch
from
July 31, 2026 16:08
1d42ed5 to
f2b6050
Compare
Contributor
Author
Edited PR title to make it clear this is a true refactor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

cc:
Closes:
What changed? Why?
Electricity imports in
cornerstone_disagg_pipeline.pyare now lazy — moved inside their respective flag-gated branches (electricity_reallocation_enabled(),electricity_disaggregation_enabled(),electricity_mixed_units_enabled()). Previously,electricity_disaggregation.pyandelectricity_end_use_mapping.pywere loaded unconditionally at import time, meaning waste-only and canonical v0.3 configs pulled in electricity modules unnecessarily.Module-level lazy facade functions (
build_end_use_map,electricity_end_use_retail_prices_cents_kwh,classify_industry_end_use,build_end_use_map_resolved) and a__getattr__hook forEND_USE_MAPPING_REVIEW_STATUSare introduced incornerstone_disagg_pipeline.py. These facades delegate toelectricity_end_use_mappingon first call without loading it at import time, while preserving existing@patchtargets.In
cornerstone_year_scaling.py, the correction imports are moved inside theif electricity_disaggregation_enabled():block rather than before it.In
cache_reset.py, top-level imports of electricity helpers are removed. Electricity@cacheclears are now handled by_clear_electricity_caches_if_loaded(), which usessys.modules.get(...)to flush caches only when those modules are already loaded — ensuring multi-config processes (e.g. switching from a flag-on run to v0.3) still clear stale caches without ever importing electricity modules in a v0.3-only process.The
monetary_disagg_report.mdis updated to reflect the renamed correction functions.Several internal functions and symbols have been renamed to better reflect their purpose:
table_2_4_prices_cents_kwh→electricity_end_use_retail_prices_cents_kwhacross all call sites, imports, mock patches, and test assertions. The new name makes clear that the source is EIA Electric Power Annual Table 2.4 (average retail prices to ultimate customers) and that the result is used to build class-specific MWh/$ conversion factors._table83_purchased_power_expenses→_iou_utility_gtd_operating_expenses_weights_from_table83_expenses→_normalize_gtd_expense_weightsbuild_electricity_ugo305_scaling_ratios→build_electricity_detail_GO_growth_ratiosutilities_summary_ratio_22→utilities_summary_q_growth_ratioapply_electricity_d7_scaling_correction_to_A→rescale_electricity_children_to_detail_GO_growth_Aapply_electricity_d7_scaling_correction_to_q→rescale_electricity_children_to_detail_GO_growth_qTesting
cornerstone_disagg_pipelineandcache_resetunder a v0.3 config (all electricity flags false) does not loadelectricity_disaggregationorelectricity_end_use_mappingintosys.modules.clear_all_publish_caches()still flushes electricity caches in processes where those modules were previously loaded by a flag-on run.cornerstone_disagg_pipeline.electricity_end_use_retail_prices_cents_kwhcontinue to intercept calls correctly via the lazy facade.