Skip to content

CpSolver.Solve() callback breaking argument change #4988

@ThomSerg

Description

@ThomSerg

What version of OR-Tools and what language are you using?
Version: main/9.15.6755
Language: Python

Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)
CP-SAT

With the latest release of the Python API, there seem to have been an unintended breaking change to the CpSolver.Solve() arguments. .Solve() has been marked deprecated in favor of .solve(), with the former still forwarding the calls to the latter. But it seems like a mistake has been made here, accidentally renaming argument solution_callback to callback.

Minimal reproducible example:

from ortools.sat.python.cp_model import CpModel, CpSolver, CpSolverSolutionCallback

class MyCallback(CpSolverSolutionCallback):
    def on_solution_callback(self):
        print("Solution found!")

# Create model
model = CpModel()
x = model.new_int_var(0, 5, 'x')
y = model.new_int_var(0, 5, 'y')
model.add(x < y)

# Solve with callback
solver = CpSolver()
solver.parameters.enumerate_all_solutions = True
solver.Solve(model, solution_callback=MyCallback()) # <- instead of a deprecation warning, has become a breaking change
solver.solve(model, solution_callback=MyCallback()) # <- still works fine
TypeError: CpSolver.Solve() got an unexpected keyword argument 'solution_callback'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions