Defining custom math within the model definition #485
brynpickering
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Custom math functionality introduced in #414 allows a user to update the base math file with data in other files. However, this custom math exists in a mutually exclusive set of files to the rest of the model definition (these YAMLs can only define model components - variables, constraints, etc. - as top-level keys). So, if you want to define a constraint for a specific technology, you have to construct a suitable
where
string ([my_tech] in techs
) or slice components inside the math expression (flow_out[techs=my_tech, node=my_node]
). This could potentially be circumvented by defining math expressions inside the model definition, and then constructing suitable custom math from that.I could only really see it working if quite verbose syntax is allowed, e.g.:
Model def
which would translate to an equivalent custom math syntax of:
Math def
Things we'd need to allow
foreach
still needs to be there as you need to be able to add dimensions over which to iterate (in the above case, timesteps is a key one that is otherwise missing).skipping or deactivating base math needs to be there as new expressions can easily clash with base constraints. On that note, should it also be possible to "update" an existing math expression for the tech in question? E.g.:
Model def
Can be successfully parsed as:
Math def
constraints
,variables
, etc.), so that this can also work:Model def
Sticking points that come to mind
Model def
This should lead to something like:
Math def
But I don't really know how that would be implemented internally without a lot of potential for edge cases coming in and destroying everything.
how do we handle multiple techs/nodes referring to the same constraint name? If
tech1
andtech2
reference the same constraint in their custom math, we can create expression list elements for each withwhere: [tech1] in techs
for the first, andwhere: [tech2] in techs
for the second. That probably works OK, but we would need to make sure they have matchingforeach
(and maybe some other things need to be coherent between them that I haven't thought of yet).We would be doing string concatenation of the
where
string, which would require special attention to avoid creating strings that no longer make sensenot [tech1, tech2] in techs and [tech1] in techs
.The level of nesting this leads to hurts my eyes, so maybe it's just a bad idea to try and shoehorn it in...
Summary
It could work, but need to come up with a neater way of defining it to a. mitigate edge cases and b. make it visually cleaner.
Beta Was this translation helpful? Give feedback.
All reactions