KeyError after adding a variable to the linopy model with define_variables

58 views Asked by At

I'm learning how to use Pypsa and I am not very experienced in python. My current goal is to understand how the optimization problem works (using Cplex solver) and I was trying to add a new variable and constraints with the compact module, but any variable I add to the model with new names get the same error:

return getattr(self, self.components[component_name]["list_name"] + "_t")

KeyError: 'Name_of_the_variable_I_add'

At the moment, my solution was to use an existing name and instead add a new attr like this:

pypsa.optimization.compat.define_variables(n, lb, ub, name="Generator", attr='new_attr', axes=[n.snapshots, n.generators.index])

The optimization find the solution. As far as I understand, in the components.py file the value for the new variable cannot be stored as the list of pypsa names do not have the new variable I am adding. There must be a problem as the example from the documentation declare a new name for a new variable... so I gues it works.

I hope someone can help me figuring out what I am doing wrong. This is also my first time using stackoverflow, apologise for any mistake in posting the question.

0

There are 0 answers