I work with oemof and want to receive dual variables for 3 busses. Since a while I got a warning:
16:51:06-WARNING-Reassigning the non-component attribute rc
on block (model).Model with a new Component
with type <class ‘pyomo.core.base.suffix.Suffix’>.
This is usually indicative of a modelling error.
To avoid this warning, explicitly delete the attribute:
del Model.rc
The model can be solved. But I don’t know why this warning appears. Besides I just have one time in the Code, when I create it.
om.receive_duals()
and later I use 3 functions to store the duals:
def get_el_prices_from_duals(om, datetime_index):
el_prices_list = []
constr = [c for c in om.component_objects(po.Constraint, active = True) if c.name == "Bus.balance"][0]
# duals for el
el_prices_list = [om.dual[constr[index]] for index in constr if index[0].label == "b_el"]
el_prices = pd.DataFrame(data= el_prices_list, index= datetime_index, columns = ["electricity price"])
return el_prices
Has anybody an idea?
It’s not solved by deleting like proposed.
I have come across the same problem as ChJa did in 2020. I called the receive_duals function in this way:
model = solph.Model(energysystem)
attributes=dir(model)
model.receive_duals()
model.solve(solver="gurobi", solve_kwargs={"tee": solver_verbose})
My model has become quite large and I feel like this is the only way to receive the actual costs the optimisation has resulted in. Currently, I calculate the cost using the predefined cost and the resulting flow values, however, it would be great to see the actual optimisation outcome to validate my results.
thanks for your reply! The optimisation seem to work but I first come across the following warning:
WARNING: Reassigning the non-component attribute dual on block (model).Model
with a new Component with type <class 'pyomo.core.base.suffix.Suffix'>.
This is usually indicative of a modelling error. To avoid this warning,
explicitly delete the attribute:
del Model.dual
WARNING: Reassigning the non-component attribute rc on block (model).Model
with a new Component with type <class 'pyomo.core.base.suffix.Suffix'>.
This is usually indicative of a modelling error. To avoid this warning,
explicitly delete the attribute:
del Model.rc
and if I want to process the results, a KeyError in the duals function of the results block is raised:
File ~\anaconda3\envs\testenv\lib\site-packages\oemof\solph\processing.py:247, in <listcomp>(.0)
242 grouped = groupby(
243 sorted(model.BusBlock.balance.iterkeys()), lambda p: p[0]
244 )
245 for bus, timesteps in grouped:
246 duals = [
--> 247 model.dual[model.BusBlock.balance[bus, t]]
248 for _, t in timesteps
249 ]
250 df = pd.DataFrame({"duals": duals}, index=result_index[:-1])
251 if (bus, None) not in result.keys():
File ~\anaconda3\envs\testenv\lib\site-packages\pyomo\common\collections\component_map.py:70, in ComponentMap.__getitem__(self, obj)
68 return self._dict[id(obj)][1]
69 except KeyError:
---> 70 raise KeyError("Component with id '%s': %s"
71 % (id(obj), str(obj)))
KeyError: "Component with id '2387848988800': BusBlock.balance[bH2,0]"