I've solved a model and output the results to filename
from pyomo.environ import *
model = ConcreteModel()
# declared variables
...
# solved model
...
# display results
model.display(filename)
Now, this program has finished running. I'd like to do some post-processing of the results in filename
. Is there an easy way to read filename
and put all the solution information back into model
for post-processing of the solution?
I'm trying to plot many of the variables that I have solved for with matplotlib. I'd like to separate the "solution of the model" code and the "post-processing of the model" code, because I'd like to be able to post-process the model in many different ways that I won't be able to decide at runtime. So, I'd like to solve model
, call model.display(filename)
, read all the data from filename and input back into the pyomo model, and do some plotting of the results.
I am currently writing my own parser for filename
, but I wanted to know if there is an available method with pyomo to do this.
A good way to do what you want is to pickle (i.e., serialize) the model after solution, then subsequent programs can restore the model and use it. For some discussion of pickling a Pyomo model, see this Stackoverflow post: How to save (pickle) a model instance in pyomo