You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@hellemo was working on improving model construction. A major issue is related to the extraction of input and output resources, especially of links. As outlined in #110, we access the field every single time period in model construction. this is especially an issue with respect to the Link resources as they are calculated through the connected nodes. Three solutions were proposed:
Personally speaking, I think it is something which is quite relevant for each subtype of AbstractElement or comparable (i.e., TransmissionMode). In all situations, it boils down to provide a fast approach for the functions inputs and outputs although, due to the design of Direct, this is redirected to link_res.
I personally think that we can work with the approach outlined in #110. I do not necessarily think that we need memoization or caching although it could potentially speed it up slightly later. The only places where we need these functions with a lot of calculations are variables_flow and constraints_couple. For both functions, new methods have to be defined when users create new subtypes of AbstractElement. What are your thoughts?
Important
The approach with link_res is internal within EnergyModelsBase as a fall back if no resources are specified. All Links in packages within this group have specific methods, e.g., (DhPipe or CapacityCostLink. This implies in my opinion that we should not focus specifically on this method, but instead on inputs and outputs.
more invasive change of the constraints construction
does not benefit all users of the functions as the cache is explicit and on the outside
I think I lean towards #112 as it keeps the native formulation and gets the performance benefit without taking on additional dependencies, but any of three should be ok.
I agree with respect to leaning towards #112. However, #112 does not yet include caching/memoizing for inputs and outputs of nodes. The question is whether any caching/memoizing of these parameters do make sense? Is accessing dictionaries faster than the field access function? Have you tested it out?
I think the main win is from avoiding the repeated calculation of the intersection, so probably less potential for gains on plain inputs/outputs, but can have a look.
EDIT: A quick test suggests dictionary lookups would not help for inputs/outputs, rather make it slower. It's indeed the intersection that is expensive.
Activity
JulStraus commentedon Oct 19, 2026
Personally speaking, I think it is something which is quite relevant for each subtype of
AbstractElementor comparable (i.e.,TransmissionMode). In all situations, it boils down to provide a fast approach for the functionsinputsandoutputsalthough, due to the design ofDirect, this is redirected tolink_res.I personally think that we can work with the approach outlined in #110. I do not necessarily think that we need memoization or caching although it could potentially speed it up slightly later. The only places where we need these functions with a lot of calculations are
variables_flowandconstraints_couple. For both functions, new methods have to be defined when users create new subtypes ofAbstractElement. What are your thoughts?Important
The approach with
link_resis internal withinEnergyModelsBaseas a fall back if no resources are specified. AllLinks in packages within this group have specific methods, e.g., (DhPipeorCapacityCostLink. This implies in my opinion that we should not focus specifically on this method, but instead oninputsandoutputs.hellemo commentedon Oct 21, 2026
For #110 it think the main would be:
pro:
con:
I think I lean towards #112 as it keeps the native formulation and gets the performance benefit without taking on additional dependencies, but any of three should be ok.
JulStraus commentedon Oct 21, 2026
I agree with respect to leaning towards #112. However, #112 does not yet include caching/memoizing for inputs and outputs of nodes. The question is whether any caching/memoizing of these parameters do make sense? Is accessing dictionaries faster than the field access function? Have you tested it out?
hellemo commentedon Oct 21, 2026
I think the main win is from avoiding the repeated calculation of the intersection, so probably less potential for gains on plain inputs/outputs, but can have a look.
EDIT: A quick test suggests dictionary lookups would not help for inputs/outputs, rather make it slower. It's indeed the intersection that is expensive.
espenbodal commentedon Oct 28, 2026
#112 looks like a good solution to me. I don't have much more to add than what already has been mentioned.
JulStraus commentedon Oct 28, 2026
@hellemo It seems that we align with respect to #112. I will do a short review on it now That implies we can close #110 and #111.