Skip to content

Wrap captureCons and releaseCons#1221

Open
Joao-Dionisio wants to merge 7 commits into
masterfrom
expose-captureCons-releaseCons
Open

Wrap captureCons and releaseCons#1221
Joao-Dionisio wants to merge 7 commits into
masterfrom
expose-captureCons-releaseCons

Conversation

@Joao-Dionisio
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Python-level wrappers for SCIP’s constraint reference counting so advanced users can explicitly capture/release constraints, and updates typing/tests/changelog accordingly.

Changes:

  • Added Model.captureCons() and Model.releaseCons() wrappers in the Cython layer.
  • Added a unit test covering basic usage and TypeError behavior.
  • Updated the type stub (scip.pyi) and CHANGELOG.md to reflect the new API.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/test_cons.py Adds a new test for captureCons()/releaseCons() and invalid input handling.
src/pyscipopt/scip.pyi Exposes the new methods in the public type stub.
src/pyscipopt/scip.pxi Implements the new wrappers around SCIPcaptureCons / SCIPreleaseCons.
CHANGELOG.md Documents the newly added API methods under “Unreleased”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pyscipopt/scip.pxi Outdated
Comment thread src/pyscipopt/scip.pxi
Comment thread tests/test_cons.py
Joao-Dionisio and others added 2 commits May 21, 2026 13:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@DominikKamp
Copy link
Copy Markdown
Contributor

Could this also be done for variables to avoid asymmetry?

@Joao-Dionisio
Copy link
Copy Markdown
Member Author

@DominikKamp done

Comment thread src/pyscipopt/scip.pxi Outdated
Comment thread src/pyscipopt/scip.pxi Outdated
Comment thread src/pyscipopt/scip.pxd Outdated
Comment thread src/pyscipopt/scip.pxi

Returns
-------
int
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.

This seems incomplete.

Comment thread src/pyscipopt/scip.pxi

Returns
-------
int
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.

This seems incomplete.

Comment thread src/pyscipopt/scip.pxi Outdated
Comment thread src/pyscipopt/scip.pxi Outdated
Comment thread tests/test_cons.py Outdated
Comment thread tests/test_vars.py Outdated
Comment thread CHANGELOG.md Outdated
Copy link
Copy Markdown
Contributor

@DominikKamp DominikKamp left a comment

Choose a reason for hiding this comment

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

I do not understand, what the changes in scip.pyi have to do with captures, otherwise this looks okay.

@Joao-Dionisio Joao-Dionisio requested a review from DominikKamp May 21, 2026 15:06
@mmghannam
Copy link
Copy Markdown
Member

What is the use case that this enables? are you sure you want to expose memory handling? misuse of these can expose memory unsafety and memory leaks.

Copy link
Copy Markdown
Contributor

@DominikKamp DominikKamp left a comment

Choose a reason for hiding this comment

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

This looks okay, but maybe wait until the usecase is reliable. So far this only introduces user unsafety. The memory should be fine since proper programs do not leave captures unreleased, same for events.

@Joao-Dionisio
Copy link
Copy Markdown
Member Author

Joao-Dionisio commented May 21, 2026

@mmghannam the usecase is scip#201, but apparently it's still being discussed.

@mmghannam @DominikKamp , in the in-person meeting Marc (Pfetsch) wished for an I_KNOW_WHAT_I_AM_DOING flag in SCIP, but then what if we add something similar to PySCIPOpt? Like, have a secondary model class that inherits from the main model, but also has these more scary methods. We can even have it in a separate file, so that people really need to do from pyscipopt.scary_methods import crazyModel.

Perhaps such a separation would make sense also for more advanced use cases. For example, we've add users thinking they had to use addConsKnapsack(), because they didn't know that SCIP upgrades constraints. Perhaps if such methods were only declared in an "advanced user model", these errors would diminish.

Does this make any sense or is it time for me to go to bed?

@DominikKamp
Copy link
Copy Markdown
Contributor

Maybe there could be a base class with elementary functionality, but for these functions a warning label should be sufficient, so better go to bed at first.

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.

4 participants