Skip to content

SCIP 11: Support for exact solving - #1264

Open
Joao-Dionisio wants to merge 28 commits into
scip11from
exact-solving
Open

Joao-Dionisio wants to merge 28 commits into
scip11from
exact-solving

Conversation

@Joao-Dionisio

@Joao-Dionisio Joao-Dionisio commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

So that the eventual PR for SCIP 11 doesn't get too huge. Adding a lot of support for using exact SCIP.
@DominikKamp , can you please take a look at this? Does it work as you would expect?

Most of the LOC changes come from the docstrings of the added methods.

EDIT: Now have an ExactModel class that contains all the exact functionality. That way, we can separate people's concerns.

from pyscipopt import Model, ExactModel

m            = Model()
m_exact = ExactModel()

x            = m.addVar() # adds a normal SCIP variable
x_exact = m_exact.addVar() # adds a rational SCIP variable

@DominikKamp

DominikKamp commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Noticed three issues:

  • trySol() with free option does not use exact function
    Uses SCIPtrySolFree() instead of SCIPtrySolFreeExact().
    => Route the free=True branch to SCIPtrySolFreeExact(), reject free=False.

  • Rational memory leak when any creation fails
    For example in addVar(), addConsLinear(), and aggregateVars() if a later _createRational() and _createBound fails, earlier rationals leak.
    => Free in try and finally.

  • getRowLinear() docstring contradicts behavior
    Says "floating-point LP row" and "Returns: Row" but returns RowExact.
    => Fix the docstring to "exact LP row" and "Returns: RowExact".

The subclassing is good, but should rather be explicitly whitelisted for "safe" methods instead of automatically inherited to prevent future leaks, and remaining real methods should be clearly documented.

@Joao-Dionisio

Joao-Dionisio commented Nov 5, 2026 •

Copy link
Copy Markdown
Member Author

Thank you @DominikKamp !

SCIPtrySolFreeExact() is not yet a public function. I'll work on the other two.

On the subclassing, I'm not sure how the whitelisting would work. We can explicitly do

class ExactModel(Model):
    unsafe_method = None

We can also have

class BaseModel():
    def common_methods() ...

class Model(BaseModel):
    def unsafe_methods(): ....

class ExactModel(BaseModel):
    def exact_methods():...

This last option may be cleaner, but it's also a TON of risky changes. But fortune favors the brave, so I don't know if we should try 🤷

@DominikKamp

Copy link
Copy Markdown
Contributor

The unsafe_method = None approach would be blacklisting but whitelisting is required for addition safety (analogous to the exact flags in SCIP). The BaseModel would be the whitelist and therefore sounds preferable.

@Joao-Dionisio

Copy link
Copy Markdown
Member Author

12k additions and 10k deletions. This will be fun.

Comment thread src/pyscipopt/__init__.py
from pyscipopt.scip import BaseModel as BaseModel
from pyscipopt.scip import Model as Model
from pyscipopt.scip import ExactModel as ExactModel
from pyscipopt.scip import ExactVariable as ExactVariable

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.

Why do we need a separate variable type?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For the variable? Because I felt like there were enough differing methods to justify this, and that's not the case with the other stuff.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's just to tidy things up more nicely.

@DominikKamp

Copy link
Copy Markdown
Contributor

Could you maybe provide a list of what was moved verbatim to rule these out quickly?

@Joao-Dionisio

Joao-Dionisio commented Nov 7, 2026 •

Copy link
Copy Markdown
Member Author

Here you go @DominikKamp . But if you agree with the overall setup (should this be discussed with the group on tuesday?), I'd prefer to do the review myself first, so you don't waste time.

Verbatim

  • Column, Row, NLRow: unchanged, now at the top of model.pxi.
  • Model (model.pxi): 209 of 210 methods identical.
  • BaseModel (scip.pxi, renamed in place): 244 of 253 methods identical.
  • 15 plugin pxi files: only cdef public Model model → BaseModel.

Changed in Model (2)

  • copyLargeNeighborhoodSearch: Model.create → BaseModel.create..

Changed in BaseModel (9)

  • init: calls new _configureScip hook.
  • eq: cast → .
  • create: returns ExactModel when SCIPisExact, else Model.
  • from_ptr: Model → BaseModel.
  • initBendersDefault, addBendersSubproblem, getBendersSubproblem: typed param / cast Model → BaseModel.
  • translateSubSol: typed param Model → BaseModel.
  • _configureScip: new, no-op hook.

Removed from Model (replaced by ExactModel)

  • enableExactSolving, isExact, allowNegSlackExact, branchLPExact, addRowExact.

Rest of scip.pxi (45 lines)

  • Fraction import, PYSCIPOPT_WITH_EXACTSOLVE define.
  • Solution.isExact new; Solution.retransform and Node.getLowerbound dispatch on exactness; Solution.translate(BaseModel).
  • Variable.create returns ExactVariable for exact vars.
  • IIS getSubscip: Model.create → BaseModel.create.
  • The two include lines for model.pxi and exact.pxi.

Other files

  • scip.pxd: BaseModel block (17 attrs, cdef helpers, create), Model(BaseModel): pass, ExactModel(BaseModel): pass, SCIP 11 exact declarations.
  • scip.pyi: mirrors the split; ExactVariable overrides carry # type: ignore[override].
  • init.py: exports BaseModel, ExactModel, ExactVariable.
  • scripts/generate_stubs.py: DISJOINT_BASE_CLASSES has BaseModel instead of Model.

Actually new, needs review

  • exact.pxi (ExactModel, ExactVariable, ColumnExact, RowExact).
  • tests/test_exact.py.
  • tests/test_base_model.py: BASE_MODEL_METHODS pins the classification; the lint there enforces no problem-data doubles on BaseModel.

@Joao-Dionisio Joao-Dionisio changed the title Support for exact solving SCIP 11: Support for exact solving Nov 12, 2026
@Joao-Dionisio

Copy link
Copy Markdown
Member Author

This should be merged after #1292 . Then, the diff should become much nicer.

@Joao-Dionisio Joao-Dionisio added this to the v7.0.0 milestone Nov 15, 2026

This branch has not been deployed

No deployments
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.

2 participants