Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/coin or cbc interface #213

Merged
merged 21 commits into from
Mar 17, 2021

Conversation

braceal
Copy link
Contributor

@braceal braceal commented Jun 16, 2020

Here is the PR promised in #212

Includes: optlang expression parsing bug fix, coinor_cbc interface, coinor_cbc test suite, and unittest interface update (changed assertEquals to assertEqual to remove depreciation warning).

Special note: I fixed an optlang bug in expression_parsing.py and wrote a short test case exposing it. It has to do with a linear objective with only a constant term. The expression was always being parsed as 0 instead of the constant term. The test case is test_constant_objective in the coinor_cbc test suite (this can be moved to a more appropriate location).

Currently passing 93/103 tests. The failing tests are:

Name change tests
ConstraintTestCase::test_change_constraint_name
ModelTestCase::test_change_constraint_name
VariableTestCase::test_change_name
test_changing_variable_names_is_reflected_in_the_solver

Changing variable/constraint names is not natively supported in MIP (python CBC interface)

Dual tests
test_integer_batch_duals
test_integer_constraint_dual
test_integer_variable_dual

Just need to know the rule on when to throw an exception

Other
test_indicator_constraint_support
test_timeout - MIP timeout setting is flaky around 0 seconds. Timeout should work for longer problems though

There are a couple small features I would like to add before a merge such as presolve, etc. I am also going to add a few more test cases which solve different example problems. But I wanted to post the code for review.

Documentation also needs to be written.

@cdiener
Copy link
Member

cdiener commented Aug 12, 2020

This looks good! I wouldn't stress about the mip dependency issue. Python 2.7 and 3.4 are deprecated Python versions anyway and will probably be removed from the CI soon. Do all tests pass now or are you skipping some? The name changing would probably have to work since other tools like cobrapy depend on that. You would usually manage that by an internal mapping of variable/constraint IDs to solver IDs. This way if you change the variable name you would simply update the id in the mapping but maintain the solver ID...

@Midnighter Midnighter closed this Sep 27, 2020
@cdiener
Copy link
Member

cdiener commented Sep 27, 2020

I don't think this should have been closed either...

@braceal
Copy link
Contributor Author

braceal commented Sep 27, 2020

Sorry for my absence. I don't think this should be closed either, the variable/constraint name changing is the last feature to add before it can be released. I've tested it with cobrapy integration and it seems to work fine and this branch is currently being used for a Flux Balance Analysis app in Kbase. I'm currently on another project, but I can try to have this finished by the end of the year.

If anyone else wants to finish this, please do. I think it is very close.

There are a few other updates that are on a separate branch where I tested the cobrapy, OSQP and COINOR-CBC together. Here is the separate branch: https://github.com/braceal/optlang/tree/test/coinor-cbc_osqp
Here is the compare: braceal/optlang@feature/coin-or-cbc-interface...braceal:test/coinor-cbc_osqp

@Midnighter
Copy link
Member

Sorry, I know what happened now. I had activated auto-deletion of head branches after merge. @KristianJensen's PR actually merged devel into master. Then devel got deleted and thus all feature branches based on devel got automatically closed and deleted. My apologies. I have removed the setting and will bring back the branches/PRs.

@Midnighter Midnighter reopened this Sep 28, 2020
Copy link
Member

@cdiener cdiener left a comment

Choose a reason for hiding this comment

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

Seems to fail due to some incompatibilities with symengine. Might have to adjust tests as well since with symengine you might get expressions like 0.0 + x which often do not evaluate equal to x.

src/optlang/coinor_cbc_interface.py Outdated Show resolved Hide resolved
src/optlang/coinor_cbc_interface.py Show resolved Hide resolved
@carrascomj
Copy link
Member

MIP does not support python2, so this may be a good chance to consider removing support for it in optlang too.

@braceal
Copy link
Contributor Author

braceal commented Mar 16, 2021

I just recalled, I left a TODO to handle before merge. @cdiener I think this had to do with cobrapy pickle files, do you know what the correct behavior should be here?

https://github.com/braceal/optlang/blob/feature/coin-or-cbc-interface/src/optlang/coinor_cbc_interface.py#L536

@cdiener
Copy link
Member

cdiener commented Mar 16, 2021

That looks good it's the same as in https://github.com/braceal/optlang/blob/feature/coin-or-cbc-interface/src/optlang/osqp_interface.py#L625-L631 right? The configuration needs to pickle the tolerances as well. Cobrapy pickles will be regenerated with new optlang releases so that will work.

@braceal
Copy link
Contributor Author

braceal commented Mar 16, 2021

Ok great, thanks for reviewing! Yes, I agree the logic is the same as in the link you posted. The TODO can probably be removed then.

Copy link
Member

@cdiener cdiener left a comment

Choose a reason for hiding this comment

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

I think this should behave like the other optional solvers. You can use the tox sections to only install mip for Python 3 so it will not run the cbc tests for Python 2.

setup.cfg Outdated Show resolved Hide resolved
src/optlang/coinor_cbc_interface.py Outdated Show resolved Hide resolved
@cdiener
Copy link
Member

cdiener commented Mar 17, 2021

Fails because there are f-strings in test_coinor_cbc_interface.py and that will trigger a syntax error on Python 2 when the file is read.

@carrascomj
Copy link
Member

Ups, I didn't see that. Working on it!

@carrascomj
Copy link
Member

If the requested changes were solved for you @cdiener, I think this can be merged.

Copy link
Member

@cdiener cdiener left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for carrying this to the finish line.

@carrascomj carrascomj merged commit 502917d into opencobra:devel Mar 17, 2021
@braceal
Copy link
Contributor Author

braceal commented Mar 17, 2021

Thank you both so much for seeing this through to completion! @cdiener @carrascomj 🎉

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.

5 participants