0

I am using Pyomo and I have the following lines

outputVariables_list = [model.param1, model.variable1]
optimal_values_list = [[pyo.value(model_item[key]) for key in model_item] for model_item in outputVariables_list] 

When I run it I get a warning that I don't understand:

WARNING: DEPRECATED: Using __getitem__ to return a set value from its
    (ordered) position is deprecated.  Please use at()  (deprecated in 6.1,
    will be removed in 7.0)

I tried the following line but this led to an error:

optimal_values_list = [[pyo.at(model_item[key]) for key in model_item] for model_item in outputVariables_list]

Further, I tried to use pyo.value(model_item.at[key]) and pyo.value(model_item.at(key) and both lead to AttributeError: 'IndexedParam' object has no attribute 'at'

Do you know how to solve this problem?

Edit: the full list of pyomo components that I use can be seen in the following line (the name indicates if it is a parameter, variable or set): outputVariables_list_BT2 = [model.param_helpTimeSlots_BT2, model.variable_heatGenerationCoefficient_SpaceHeating_BT2, model.variable_heatGenerationCoefficient_DHW_BT2, model.variable_help_OnlyOneStorage_BT2, model.variable_temperatureBufferStorage_BT2, model.variable_usableVolumeDHWTank_BT2, model.variable_electricalPowerTotal_BT2, model.variable_pvGeneration_BT2, model.variable_windPowerAssigned_BT2, model.param_heatDemand_In_W_BT2, model.param_DHWDemand_In_W_BT2, model.param_electricalDemand_In_W_BT2, model.param_pvGenerationNominal_BT2, model.param_outSideTemperature_In_C, model.param_windAssignedNominal_BT2, model.param_COPHeatPump_SpaceHeating_BT2, model.param_COPHeatPump_DHW_BT2, model.param_electricityPrice_In_Cents, model.set_timeslots]

Reminder: Hi all, I still have 2 question about this issue:

  1. What I don't understand is that Pyomo tells me to use "at" instead of 2__getitem__", but this not work as I get errors when using at. This is a quite confusing recommendation.

  2. Is there a way how to surpress the warnings by telling pyomo just not to display them? The set I am using always has a natural order (timeslots), so the warning does not seem to be relevant for my application, and the dataframes look exactly how they should. I just have to make sure not to update pyomo to version 7.0. So in this case ignoring the warnings seem to be a good option if I can't manage to use "at" as it is recommended by Pyomo (but which does not work so far)

Can anyone help me on these questions? I'll appreciate every further comment

PeterBe
  • 700
  • 1
  • 17
  • 37
  • Can you edit your question with enough toy data to make the error reproducible in a small example? It isn't clear from what you've posted what the exact data types are that you are working with. The fundamental problem is that `pyomo` is complaining that you are trying to index a set with `[]` and it isn't clear where that is happening right now. – AirSquid Mar 09 '23 at 02:56
  • @AirSquid: Thanks Air for your comment. I added the list of all pyomo elements that I use – PeterBe Mar 09 '23 at 03:03
  • None of that helps to reproduce the error you are having... Can you gin up a small example? It still isn't clear where the fundamental problem is. Ideally, if you are looking for help with an error, you should post a question that somebody can copy exactly what you post and reproduce the error. I think you could make such an example with a small set or two because there is no indication of what the sets are or which line of code causes this error. – AirSquid Mar 09 '23 at 03:05
  • My code has 3000 lines and I can't share all of it or make a small example of it. I just wanted to ask if someone has a clue as to wh y this problem occurs in Pyomo and what is wrong about the lines of code that I am using. – PeterBe Mar 09 '23 at 03:07
  • OK. It isn't necessary to post *all of the code* but I think you could probably reproduce this error with 10 lines of code or less in a toy example. As stated, the issue you are hitting on here is that somewhere you are indexing a set with `[]` and it isn't clear where that is happening right now. – AirSquid Mar 09 '23 at 03:09
  • I can't give a minimal exaple as it would still have several hundreds line of codes. In my posted code at the end I use a set `model.set_timeslots` so maybe it has something to do with this set. – PeterBe Mar 09 '23 at 03:10
  • Likely so. This is the problem with posting example code that doesn't relate to the problem. If that is an indexed set (set of sets) then that is likely the problem – AirSquid Mar 09 '23 at 03:13
  • How can I tackle this issue? I want to adress the set and I also have parameters and variables in the outputVariablesList – PeterBe Mar 09 '23 at 03:20
  • It isn't clear what your objective here is. The parameters and sets are known before you do anything so.....? getting the values out of the variables is easy. Perhaps you need to re-ask a more focused question on what you **exactly** are trying to do. – AirSquid Mar 09 '23 at 03:26
  • Thanks for your answer Air. I want to store the values in a pandas dataframe by using `results_BT2 = pd.DataFrame(optimal_values_list_BT2)`. Actually it works without problems but still I get the warning and I don't understand why I get the warning while everything works as it should. Further, the warning says "deprecated in 6.1, will be removed in 7.0" so if i upgrade pyomo the code might yields errors – PeterBe Mar 09 '23 at 03:30
  • 1
    @AirSquid: Thanks Air for your comments. Any comment on my last comment? I'll highly appreciate every further comment from you. – PeterBe Mar 10 '23 at 04:41
  • As stated earlier, your problem is that you are iterating a **set** with brackets. it isn't clear why you have the set in your data gathering efforts. Take a look at this answer I did a while back and see if part of it answers your question about extracting to a Dataframe. https://stackoverflow.com/questions/67491499/how-to-extract-indexed-variable-information-in-pyomo-model-and-build-pandas-data/67494352#67494352. – AirSquid Mar 13 '23 at 00:23
  • @AirSquid: Thanks Air for your comment. Actually I want to print all variables in a pandas dataframe and use the set as an index. So I have the following code: `results_BT2 = pd.DataFrame(optimal_values_list_BT2); results_BT2= results_BT2.T; results_BT2 = results_BT2.rename(columns = {0:'timeslot', ...);cols = ['set_timeslots'] results_BT2.set_index('set_timeslots', inplace=True);`. Because of this I need to have the structure posted above. Unfortunately i get the warning all the time although the output is correct – PeterBe Mar 13 '23 at 01:22

0 Answers0