Search code examples
pyomo

Pyomo AbstractModel() DataPortal Class not recognizing my data in ".xlsx" file


I have a very "big pyomo abstract model", which I am trying to solve using Pyomo v6.4x on my MSI windows machine.

According to the instructions on the website, https://pyomo.readthedocs.io/en/stable/working_abstractmodels/data/dataportals.html, the following excerpt of my code should have worked.

# Kindly note that all the model components, including:
1) Index sets
2) parameters
3) variables
4) Objective
5) Constraints, have been properly pre-declared and initialized.

# create the model object
model = pyo.AbstractModel('(test model)')

# define solver
opt = pyo.SolverFactory('solver')

# create data portal object & read/load the data
data = pyo.DataPortal(model=model)
data.load(filename="../data/input/test_data.xlsx", range="Dtable", param='d', format='array')
instance = model.create_instance(data)
results = opt.solve(instance)

However, I am getting the error OSError: Unknown file format 'xlsx' each time I run my Python script.


Solution

  • There are some known issues with the Pyomo DataPortal so I would recommend using a package like Pandas to read the Excel file and use the data to populate a Pyomo ConcreteModel. You can find an example here:

    https://github.com/Pyomo/pyomo/blob/main/examples/pyomobook/overview-ch/wl_excel.py