Skip to content

Generalzie pyomo model handling#55

Merged
fletchapin merged 39 commits into
we3lab:mainfrom
avdudchenko:generalzie_pyomo_model_handling
Jul 24, 2026
Merged

Generalzie pyomo model handling#55
fletchapin merged 39 commits into
we3lab:mainfrom
avdudchenko:generalzie_pyomo_model_handling

Conversation

@avdudchenko

@avdudchenko avdudchenko commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Fix issue with pyomo model handling.

Right now its assumed pyomo model has a variable t on it which is used for indexing the consumption variable, this is not necessarly true and complicates model handling.

Here we update the costing to automatically extract index set from the consumption variable, and use it through out. This removes the need to find a model.t var or for user to create it.

This additionally fixes tests:

  • removes Gurobi as dependency and uses scip for tests -> user can decide on solver of choice
  • fixes mixing approx in some tests.
  • extends tests to cover linux/windows and 3.11, 3.12., 3.13 python versions.

@avdudchenko
avdudchenko marked this pull request as ready for review July 13, 2026 18:29
@avdudchenko
avdudchenko requested review from dalyw and fletchapin July 13, 2026 18:29
Comment thread .github/workflows/test_and_lint.yml
Comment thread eeco/tests/test_costs.py
Comment thread eeco/tests/test_costs.py
Comment thread eeco/utils.py Outdated
Comment thread eeco/tests/test_utils.py
Comment thread eeco/utils.py Outdated

@fletchapin fletchapin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! I left a few minor comments, and I can just fix them myself if that's easiest. Then we should be ready to merge

Comment thread eeco/tests/test_utils.py
Comment thread eeco/costs.py Outdated
Comment thread eeco/costs.py Outdated
Comment thread eeco/costs.py Outdated
Comment thread eeco/utils.py Outdated
Comment thread eeco/utils.py Outdated
Comment thread eeco/costs.py Outdated

@fletchapin fletchapin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the changes! There is just one bug remaining that I noticed. With the new type checking, our assumption that IndexedExpression was a subclass of Expression was incorrect, so we'll have to update that logic accordingly.

Comment thread eeco/tests/test_costs.py Outdated
Comment thread eeco/utils.py Outdated
if (not check_nonindexed_python_type(expression2)) and (
len(expression2) > 1
):
# TODO: replace model.t with better way to get dimensions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this comment, since we are completing the to-do :)

Comment thread eeco/utils.py Outdated
Comment thread eeco/utils.py Outdated
)


def check_indexed_python_type(input_var):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to have this single indexed type might as well add a "dataframe like" checker that checks Pandas, Polars, etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be pedantic, I would say that lists are an indexed Python type (that we treat differently), so I might rename the function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we only support numpy arrays anyway, so I changed it to check_indexed_np_array.

I think if we need a df/polars check it would be a different function entirely as places where we accept np_array, we do not accept df/polars (e.g. I think if you get np.array there it will fail...

Comment thread eeco/costs.py Outdated
Comment thread eeco/costs.py Outdated
for key, var in consumption_data_dict.items():
if isinstance(var, dict):
for svar in var.values():
if isinstance(svar, (cp.Expression, pyo.Var, pyo.Param)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if it's obvious and I missed it, but why is this check different than the one on L1662? (https://github.com/we3lab/eeco/pull/55/changes#diff-0122b06abba34b1b9a0a5d73a537d39f7fad05573275d50358d5b19fc8f60d35R1662)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh, i missed this some how...

Comment thread eeco/utils.py Outdated
@fletchapin
fletchapin merged commit 2f6711c into we3lab:main Jul 24, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants