Skip to content

Add enableDebugSol following discussion on mailing list #1013

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

Merged
merged 7 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

## Unreleased
### Added
- Added recipe for getting local constraints
- More support for AND-Constraints
- Added support for knapsack constraints
- Added isPositive(), isNegative(), isFeasLE(), isFeasLT(), isFeasGE(), isFeasGT(), isHugeValue(), and tests
Expand All @@ -12,6 +11,8 @@
- Wrapped SCIPgetNLPBranchCands
- Added getConsVals() to get coefficients of any linear type constraint
- Generalized getLhs() and getRhs() to additionally support any linear type constraint
- Added recipe for getting local constraints
- Added enableDebugSol() and disableDebugSol() for controlling the debug solution mechanism if DEBUGSOL=true
### Fixed
- Raised an error when an expression is used when a variable is required
- Fixed some compile warnings
Expand Down
6 changes: 4 additions & 2 deletions docs/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ Build with Debug
To use debug information in PySCIPOpt you need to build it with the following command:

.. code-block::

python -m pip install --install-option="--debug" .

export CFLAGS="-UNDEBUG"
export CXXFLAGS="-UNDEBUG"
python -m pip install .

.. note:: Be aware that you will need the debug library of the SCIP Optimization Suite for this to work
(cmake .. -DCMAKE_BUILD_TYPE=Debug).
Expand Down
2 changes: 2 additions & 0 deletions src/pyscipopt/scip.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ cdef extern from "scip/scip.h":
SCIP_Real SCIPgetSolTime(SCIP* scip, SCIP_SOL* sol)

SCIP_RETCODE SCIPsetRelaxSolVal(SCIP* scip, SCIP_RELAX* relax, SCIP_VAR* var, SCIP_Real val)
void SCIPenableDebugSol(SCIP* scip)
void SCIPdisableDebugSol(SCIP* scip)

# Row Methods
SCIP_RETCODE SCIPcreateRow(SCIP* scip, SCIP_ROW** row, const char* name, int len, SCIP_COL** cols, SCIP_Real* vals,
Expand Down
31 changes: 28 additions & 3 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
_SCIP_BOUNDTYPE_TO_STRING = {SCIP_BOUNDTYPE_UPPER: '<=',
SCIP_BOUNDTYPE_LOWER: '>='}

cdef extern from "scip/config.h":
"""
#ifdef WITH_DEBUG_SOLUTION
#define PYSCIPOPT_WITH_DEBUG_SOLUTION 1
#else
#define PYSCIPOPT_WITH_DEBUG_SOLUTION 0
#endif
"""
bint PYSCIPOPT_WITH_DEBUG_SOLUTION

# Mapping the SCIP_RESULT enum to a python class
# This is required to return SCIP_RESULT in the python code
# In __init__.py this is imported as SCIP_RESULT to keep the
Expand Down Expand Up @@ -141,7 +151,6 @@
INFORUNBD = SCIP_STATUS_INFORUNBD

StageNames = {}

cdef class PY_SCIP_STAGE:
INIT = SCIP_STAGE_INIT
PROBLEM = SCIP_STAGE_PROBLEM
Expand Down Expand Up @@ -171,7 +180,6 @@
SUBROOT = SCIP_NODETYPE_SUBROOT
REFOCUSNODE = SCIP_NODETYPE_REFOCUSNODE


cdef class PY_SCIP_PROPTIMING:
BEFORELP = SCIP_PROPTIMING_BEFORELP
DURINGLPLOOP = SCIP_PROPTIMING_DURINGLPLOOP
Expand All @@ -198,7 +206,6 @@
AFTERPROPLOOP = SCIP_HEURTIMING_AFTERPROPLOOP

EventNames = {}

cdef class PY_SCIP_EVENTTYPE:
DISABLED = SCIP_EVENTTYPE_DISABLED
VARADDED = SCIP_EVENTTYPE_VARADDED
Expand Down Expand Up @@ -301,7 +308,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 311 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand Down Expand Up @@ -7756,6 +7763,24 @@
"""
PY_SCIP_CALL(SCIPsetRelaxSolVal(self._scip, NULL, var.scip_var, val))

def enableDebugSol(self):
"""
Enables the debug solution mechanism, which allows tracing back the invalidation of
a debug solution during the solution process of SCIP. It must be explicitly
enabled for the SCIP data structure.
"""
if not PYSCIPOPT_WITH_DEBUG_SOLUTION:
raise RuntimeError("SCIP must be built with `DEBUGSOL=true` to enable the debug solution mechanism.")
SCIPenableDebugSol(self._scip)

def disableDebugSol(self):
"""
Disables the debug solution mechanism.
"""
if not PYSCIPOPT_WITH_DEBUG_SOLUTION:
raise RuntimeError("SCIP must be built with `DEBUGSOL=true` to disable the debug solution mechanism.")
SCIPdisableDebugSol(self._scip)

def getConss(self, transformed=True):
"""
Retrieve all constraints.
Expand Down