justine18 / performance_experiment

Performance experiment - Pyomo vs JuMP
9 stars 4 forks source link

Include linopy in benchmark #8

Open FabianHofmann opened 1 year ago

FabianHofmann commented 1 year ago

dear @justine18,

thank you very much for the nice comparison. I was wondering whether we could include linopy in the benchmark?

I have prepared some code that should give a good start:

import data_generation as data
import xarray as xr
import pandas as pd
import linopy

cardinality_of_j = 20
n = 10000

# create fixed data and convert to tuples and dicts
J, K, L, M, JKL, KLM = data.create_fixed_data(m=cardinality_of_j)
I, IJK = data.create_variable_data(n=n, j=J, k=K)

jkl_tuple, klm_tuple = data.fixed_data_to_tuples(JKL, KLM)
jkl_dict, klm_dict = data.fixed_data_to_dicts(jkl_tuple, klm_tuple)
ijk_tuple = data.variable_data_to_tuples(IJK)

ijk = pd.DataFrame(ijk_tuple, columns=list("ijk"))
jkl = pd.DataFrame(jkl_tuple, columns=list("jkl"))
klm = pd.DataFrame(klm_tuple, columns=list("klm"))

# here comes the code relevant for linopy
overlaps = pd.merge(pd.merge(ijk, jkl), klm).drop(columns='value')
index = pd.MultiIndex.from_frame(overlaps).rename(list("IJKLM"))

mask = pd.Series(True, index).unstack("I", fill_value=False)
mask = xr.DataArray(mask, dims=["JKLM", "I"])

model = linopy.Model()
x = model.add_variables(lower=0, mask=mask, name='x')
model.add_constraints(x.sum("JKLM") >= 0, name='constraint')

I made a few benchmarks and it took around 7 secs to create the index and model in linopy with n = 300000 and cardinality_of_j = 20. Without the creation of index it took 3.4 secs.

justine18 commented 1 year ago

Hi @FabianHofmann ,

thanks for your request. I have a quick and dirty implementation of your suggested code in PR #9. As I have never worked with LinoPy before, I am missing a few basics here where you can help me out, e.g.

For now it also gives me

Infeasible or unbounded model
Optimization failed:
Status: warning
Termination condition: infeasible_or_unbounded
Solution: 0 primals, 0 duals
Objective: nan
Solver model: available
Solver message: 4

Maybe you can fix this?

FabianHofmann commented 1 year ago

Hey @justine18, thank you for the quick reply! I am happy to help, I will make a proposition how to solve the points. To clarify for myself: What is the aim of running the solving with a time out of 0 seconds? Is it for testing the IO to the solver? If that is the case, that would be solver dependent, as linopy uses python packages from gurobi, cplex and others during the solving process.

justine18 commented 1 year ago

The aim is to test the IO to the solver. As this is indeed solver dependent, I use Gurobi for all modeling frameworks.

justine18 commented 1 year ago

I pushed some preliminary results for a small |I|. I will run the large instances overnight.