Repository navigation
Unify utility functionality for time structure iterators - #112
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cestry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n trees Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
trulsf
approved these changes
Nov 4, 2026
trulsf
left a comment
Member
There was a problem hiding this comment.
Looks fine. I think the docs update on recommended usage of indexing is a good addition. Even if users are not reading the docs, it may help in the behavior of coding agents.
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.
This PR came up as I was a bit uncertain regarding which iteration utilities we included for the different time structures. Most of the work was done by me in #23 but we never really unified it. The work was done by Claude but with extensive review from my side.
Summary
strat_periods,repr_periods,opscenarios, andstrategic_scenariosare indexable:getindexwith aBoundsErrorcheck, plus genericfirstindex,eachindex, andkeys.lastindex(and with itx[end]andlast) exists only for iterators of strategic and representative periods.It is not defined for scenario iterators (scenarios are not ordered) or for the nodes of a
TwoLevelTree(a tree has several last nodes).Single*periods andStratNode, delegategetindexandeachindexto the structure they contain.SimpleTimesandCalendarTimescheck the index againstlen.StratReprPeriodandStratNodeReprPeriodcompare by strategic period, then by representative period.StratNodes,n1 < n2holds only ifn1is an ancestor ofn2.islessis unchanged, sosortstays reliable and puts ancestors first.withprev,withnext,chunk, andchunk_durationforwardIteratorSize, so they also work over iterators without a length (e.g.Iterators.filter).isfirstis defined for partitions.The guards against tree nodes in
chunkandchunk_durationalso catch calls with keywords.TimeStructInnerIter,TimeStructOuterIter, andisfirst.Changes in behaviour
<,<=, and>=betweenStratNodes now consider only ancestors. This fixesstart_timeandend_timewith aTwoLevelTree.It also changes the results of downstream code that compares nodes across branches. For example, the
CO2Storagecapacity constraint inEnergyModelsCO2with aTwoLevelTreenow sums over the ancestors only, which is correct.remaining(n, ::TwoLevelTree)for nodes other than the root now sums the node and its descendants. It is still not correct and is left as is.sort(repr_periods(::TwoLevel))now follows the order of iteration; before, it interleaved strategic periods.getindexofSimpleTimesandCalendarTimesthrows aBoundsErrorbeyondlen; before, it returned a period.eachindexof all iterators isBase.OneTo(length(x)); before, some methods used the length of internal vectors, which is wrong whenlenis smaller.