feat: make output dimension names configurable via DimNames#101
Conversation
The four structural output dims (cluster, timestep, period, segment) were hard-coded and reserved, so callers whose own dims collide with them (notably multi-period models with a `period` slice dim) had to rename before/after every call. Add a frozen `DimNames` config, passed as `aggregate(..., dim_names=)` and stored on `ClusteringResult` so `apply()`, `disaggregate()`, and the JSON round-trip reproduce the chosen names. `dim_names=None` reproduces today's names. The reserved-name check now validates the resolved output names against the actual input dims (raising on any collision) instead of blanket- reserving four literals; this also closes a latent gap where `segment` was not reserved. `from_dict` defaults missing `dim_names` to today's names for old blobs. Closes #99 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 49 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #99.
Summary
The four structural output dims (
cluster,timestep,period,segment) were hard-coded and reserved, forcing downstream wrappers (e.g. flixopt) to rename their own dims before/after every call — most painfully when a caller's slice dim is literally namedperiod(multi-period optimization models).This adds a frozen
DimNamesconfig, mirroring the existingClusterConfig/ExtremeConfig/SegmentConfigstyle:dim_names=None(default) reproduces today's names exactly.ClusteringResult, soapply(),disaggregate(), and the JSON round-trip all reproduce them.AggregationResultviaresult.dim_names.Changes
_dim_names.py(new) —DimNames(cluster, timestep, period, segment);__post_init__enforces uniqueness;as_tuple()helper._core.py—aggregate(dim_names=None); threaded through_aggregate_single/_result_from_tsamand the_*_to_dabuilders. Replaced the blanket_RESERVED_DIMSset with_validate_dim_names, which validates the resolved output names against the actual input dims and raises on any collision._clustering.py—ClusteringResultstoresdim_names; all_build_*properties,apply/_apply_single,disaggregate/_disaggregate_single, andto_dict/from_dictuse it.from_dictdefaults missing keys to today's names for old blobs._result.py— addedresult.dim_names;n_clusters/n_timesteps_per_periodand the slice-view/disaggregate paths read the configured names.__init__.py— exportsDimNames.docs/data-model.md— new "Custom output dimension names" section.test/test_aggregate.py— 10 new tests (period-collision resolved, apply/disaggregate/JSON round-trips, legacy-blob backcompat, uniqueness, segmentation).Behavior-change note
segmentis now part of the reserved/collision set. Previously_RESERVED_DIMSonly heldcluster/timestep/period, so an input dim namedsegmentslipped through (a latent collision bug with segmented runs). Now a non-segmented run with an input dim literally namedsegmenterrors by default; passDimNames(segment=...)to free it. Practically,segmentas an output axis only labelsClusteringResult.segment_centers, which isNonefor all current tsam configs — so the reserve mainly closes the collision gap.Verification
pytest test/— 537 passed, 4 skippedmypy src/— cleanruff check/ruff format— clean🤖 Generated with Claude Code