Skip to content

Update string formatting to f-strings in examples and fix getObjVal() - #1272

Merged
Joao-Dionisio merged 6 commits into
scipopt:masterfrom
adamj34:string-update
Oct 14, 2026
Merged

Joao-Dionisio merged 6 commits into
scipopt:masterfrom
adamj34:string-update

Conversation

@adamj34

@adamj34 adamj34 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Replaces format() with f-string formatting, which I think is a bit nicer to read, especially in examples.

Before updating docs/tutorials/eventhandler.rst I ran it just out of curiosity, and surprisingly I got this lovely error:

Traceback (most recent call last):
  File "src/pyscipopt/scip.pxi", line 2908, in pyscipopt.scip.Model.attachEventHandlerCallback.EventHandler.eventexec
    self.callback(model, event)
  File "/home/nu/PySCIPOpt/play.py", line 4, in print_obj_value
    print("New best solution found with objective value: {}".format(model.getObjVal()))
                                                                    ~~~~~~~~~~~~~~~^^
  File "src/pyscipopt/scip.pxi", line 11633, in pyscipopt.scip.Model.getObjVal
    assert self._bestSol.sol != NULL
AssertionError
Exception ignored in: 'pyscipopt.scip.PyEventExec'
Traceback (most recent call last):
  File "src/pyscipopt/scip.pxi", line 2908, in pyscipopt.scip.Model.attachEventHandlerCallback.EventHandler.eventexec
    self.callback(model, event)
  File "/home/nu/PySCIPOpt/play.py", line 4, in print_obj_value
    print("New best solution found with objective value: {}".format(model.getObjVal()))
  File "src/pyscipopt/scip.pxi", line 11633, in pyscipopt.scip.Model.getObjVal
    assert self._bestSol.sol != NULL
AssertionError: 
[event.c:385] ERROR: Error <0> in function call
[event.c:2443] ERROR: Error <0> in function call
[event.c:1847] ERROR: Error <0> in function call
[primal.c:1083] ERROR: Error <0> in function call
[primal.c:1881] ERROR: Error <0> in function call
[scip_sol.c:4075] ERROR: Error <0> in function call
[heur_trivial.c:169] ERROR: Error <0> in function call
[heur.c:1319] ERROR: Error <0> in function call
[solve.c:377] ERROR: Error <0> in function call
[scip_solve.c:1165] ERROR: Error <0> in function call
[scip_solve.c:2458] ERROR: Error <0> in function call
[scip_solve.c:2710] ERROR: Error <0> in function call
Traceback (most recent call last):
  File "/home/nu/PySCIPOpt/play.py", line 8, in <module>
    m.optimize()
    ~~~~~~~~~~^^
  File "src/pyscipopt/scip.pxi", line 9360, in pyscipopt.scip.Model.optimize
    PY_SCIP_CALL(SCIPsolve(self._scip))
  File "src/pyscipopt/scip.pxi", line 325, in pyscipopt.scip.PY_SCIP_CALL
    raise Exception('SCIP: unspecified error!')
Exception: SCIP: unspecified error!

I guess this is related to #993? Either way, I fixed it in a similar way to how it was done for getVal() there.

@adamj34 adamj34 changed the title Update string formatting to f-strings in examples and fix getObjVal Update string formatting to f-strings in examples and fix getObjVal() Oct 14, 2026
@adamj34
adamj34 marked this pull request as ready for review October 14, 2026 08:25
@Joao-Dionisio
Joao-Dionisio self-requested a review October 14, 2026 12:50
@Joao-Dionisio

Copy link
Copy Markdown
Member

Ahhh I have such a love-hate relationship with both these methods and PySCIPOpt's error handling.

But everything seems correct with your changes! Could you please add a test where this fails without the fix (and similarly for the bug from #993)?

And thank you thank you!

@adamj34

adamj34 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

I've added four new tests that would be failing if the fix was absent from both these methods.

Comment thread CHANGELOG.md Outdated

@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 so much @adamj34 !

@Joao-Dionisio
Joao-Dionisio added this pull request to the merge queue Oct 14, 2026
Merged via the queue into scipopt:master with commit 5e94074 Oct 14, 2026
7 checks passed
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