Skip to content

Replace SCIP constant classes with IntEnum and IntFlag - #1286

Merged
Joao-Dionisio merged 8 commits into
scipopt:masterfrom
jonathanberthias:runtime-enums
Nov 15, 2026
Merged

Joao-Dionisio merged 8 commits into
scipopt:masterfrom
jonathanberthias:runtime-enums

Conversation

@jonathanberthias

Copy link
Copy Markdown
Contributor

SCIP constants are currently exposed as plain integers grouped in classes. This prevents type checkers from distinguishing different constant families and leaves enum-related methods incompletely typed.

This PR replaces those classes with standard-library IntEnum and IntFlag classes, using IntFlag for event and timing masks. It updates the stubs, converts enum-valued getters to return enum members, and adjusts the existing tests.

Stage and event names now use .name directly. StageNames and EventNames remain available with integer keys for backward compatibility.

Fixes #1275.

@Joao-Dionisio

Copy link
Copy Markdown
Member

Thank you @jonathanberthias! A couple of things:

  • Can you please add a CHANGELOG entry?
  • Can the things that take these as input also be changed in the stubs? Like includeHeur, etc.
  • There is a minor slowdown in comparison with master, but it shouldn't be a big deal.

@jonathanberthias

Copy link
Copy Markdown
Contributor Author

Thanks for the review @Joao-Dionisio! Indeed I had missed a few spots, should be better now 🤞

@Joao-Dionisio Joao-Dionisio added this to the v6.4.0 milestone Nov 15, 2026
@Joao-Dionisio

Joao-Dionisio commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Thank you @jonathanberthias! I took the liberty of changing the code a bit, because it was inconsistent across Python versions, regarding the output. str(model.getStage()) gave PY_SCIP_STAGE.SOLVED on 3.9/3.10 but 10 on 3.11+, since IntEnum.__str__ changed in 3.11. I think the names are nicer, so I added:

from enum import Enum, Flag, IntEnum, IntFlag

def _format(self, spec):
    return str(self) if not spec else int.__format__(self, spec)

class _ScipEnum(IntEnum):
    __str__ = Enum.__str__
    __format__ = _format

class _ScipFlag(IntFlag):
    __str__ = Flag.__str__
    __format__ = _format

class PY_SCIP_STAGE(_ScipEnum): ...
class PY_SCIP_EVENTTYPE(_ScipFlag): ...

Let me know if you're alright with this, please :)

I also added stubs to the plugins.

@jonathanberthias

Copy link
Copy Markdown
Contributor Author

Let me know if you're alright with this, please :)

This is a great idea! I guess this is what you meant here, I didn't think of the string representation 🤦

I was hesitant to type the plugins in case some users test types exactly, but I guess the same applies to all methods that return enum members now so it's the right call I would say. Very nice job 🎉

@Joao-Dionisio Joao-Dionisio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @jonathanberthias , and very nice job to you too as well!!

@Joao-Dionisio
Joao-Dionisio added this pull request to the merge queue Nov 15, 2026
Merged via the queue into scipopt:master with commit 37d44b8 Nov 15, 2026
7 checks passed
@jonathanberthias
jonathanberthias deleted the runtime-enums branch November 15, 2026 23:15
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.

Making enums type-checking friendly

2 participants