calliope-project / calliope

A multi-scale energy systems modelling framework
https://www.callio.pe
Apache License 2.0
276 stars 89 forks source link

Custom constraints sum() slicing seems to fail inconsistently #590

Closed jmorrisnrel closed 2 months ago

jmorrisnrel commented 2 months ago

What happened?

I've been working on testing v0.7 with some of the features we regularly use and have had some issues trying to recreate certain 0.6 group constraints. I've narrowed the issue down to a specific sum() expression I'm doing in a custom constraint which seems to not calculate correctly. Below is the constraint definition I've been using flow_max_share is defined in parameters in the YAML:

flow_out_share:
    description: >
      Limit total combined technology annual energy production across all
      possible deployment sites.
    where: flow_max_share
    equations:
      - expression: >
          sum(flow_out[techs=PV_Tech,carriers=Power], over=[nodes, timesteps]) <= $total_carrier_flow_out
    sub_expressions:
      total_carrier_flow_out:
        - expression:  sum(flow_out[carriers=Power], over=[nodes, timesteps, techs]) * flow_max_share

The sub expression sum sum(flow_out[carriers=Power], over=[nodes, timesteps, techs]) is the one that doesn't seem to calculate correctly. If I add a techs slice to the expression and specify a tech the constraint seems to calculate correctly, and manually entering a value instead of the sum also works, but specifying a sum with just the carrier slice seems to fail. The constraint doesn't have an effect no matter what comparison operator I use and produces the same result (which isn't the result that equals would produce).

Adding a tech slice like this works:

flow_out_share:
    description: >
      Limit total combined technology annual energy production across all
      possible deployment sites.
    where: flow_max_share
    equations:
      - expression: >
          sum(flow_out[techs=PV_Tech,carriers=Power], over=[nodes, timesteps]) <= $total_carrier_flow_out
    sub_expressions:
      total_carrier_flow_out:
        - expression:  sum(flow_out[techs=Natural_Gas,carriers=Power], over=[nodes, timesteps]) * flow_max_share

Which operating systems have you used?

Version

v0.7.0-dev

Relevant log output

No response

jmorrisnrel commented 2 months ago

This was because I forgot transmission was included in the sum() if I didn't specify a slice without transmission. Applying a slice to just the supply/conversion tech results in a working constraint. I'll be sure to add a global expression for non-transmission techs to our default configs to make configuring constraints like this easier.