JuMP design question

Hi,

I am building a model which is made up of smaller models. The smaller model definition can be found here: JuMP: which solver should I use for my problem?

For context, the model linked above is a heat pump h which consumes a certain electrical power P_t^{(h)} at each timestep t.

Now I also have an electricity grid model defined in JuMP, which consists of buses and lines. I want to add a heat pump to each bus, electrically this is simple but I am not sure how to do it in JuMP.

I guess this comment JuMP Multiple Models Design Question - #2 by odow would be the right way to include the submodels in the larger model? It’s an older comment so I am not sure it still applies.

Read Design patterns for larger models · JuMP

You cannot embed models inside other models.

I read that, but I cannot make the connection from the knapsack example to my problem. There is a lot happening in that tutorial I can’t figure out which part of it I need.

I’d say you need all of it :smile:

Perhaps you could post a small example of what you would like to do, and then we can show how it should be written.

Okay that’s disappointing, I thought I could just add one model to the other. That would save me a lot of time and rewriting :slight_smile: there should be a level of modularity possible here I think.

Seems like the main task now is to rewrite the heat pump model into functions that add the constraints, variables and objectives separately to the ‘main’ electrical model?

Yes. Exactly this.

Don’t build subcomponents as JuMP models. Build them as function which add components to an existing JuMP model, and use either a naming convention, or an external data structure to manage the relevant variables and connections between components.

If you’re building an energy system model, take a look at the design of PowerSimulations.jl, and read through (and watch the videos) of Open Energy Modeling at JuMP-dev | JuMP

I’ll point you particularly to:

1 Like

I get it, thanks for explaining. Submodels are possible in pyomo, I was expecting a similar mechanic in JuMP :slight_smile:

Thanks for the resources, appreciate the help. It’s becoming clearer to me what to do now.

We’re discussing this in Explore namespace ideas · Issue #3791 · jump-dev/JuMP.jl · GitHub

Note that its a different design choice. But Pyomos approach is not obviously better. There are a number of trade offs to consider. JuMPs approach is different but people have demonstrated you can easily build large and highly flexible models with it.

1 Like