Search code examples
pyomo

Load Pyomo data command files directly to Python data structures


Given a Pyomo model and corresponding data command file input.dat, I would like to verify the model I built with a 3rd party tool. To be more specific, it is a network flow model with the topology defined in the data command file. The strategy would then be to load the topology from that input.dat and use it as an input to the 3rd party tool.

The actual question: Is there a way to load the topology defined in the Pyomo input.dat directly into Python data structures (e.g. sets, dicts, etc.) instead of round tripping through Pyomo data structures (pyomo.environ.Set et al.) and then building the Python data structures from the Pyomo data structures - for the sake of convenience? Is there maybe an undocumented or unofficial internal API function that does this?


Solution

  • You might be able to do this using the DataPortal infrastructure in Pyomo. See the documentation here: https://pyomo.readthedocs.io/en/latest/working_abstractmodels/data/dataportals.html