Skip to content
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

Fix callback for DOSolver #359

Merged
merged 1 commit into from
May 14, 2024
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
91 changes: 52 additions & 39 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ matplotlib = { version = ">=3.3.4", optional = true }
joblib = { version = ">=1.0.1", optional = true }
stable-baselines3 = { version = ">=2.0.0", optional = true }
ray = { extras = ["rllib"], version = ">=2.7.0", optional = true }
discrete-optimization = { version = ">=0.2.3", optional = true }
discrete-optimization = { version = ">=0.3.0", optional = true }
openap = { git = "https://github.com/nhuet/openap.git", tag = "v1.3.1", optional = true }
pygeodesy = { version = ">=23.6.12", optional = true }
unified-planning = { version = ">=1.1.0", python = ">=3.10", optional = true }
Expand Down
14 changes: 5 additions & 9 deletions skdecide/hub/solver/do_solver/do_solver_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(
policy_method_params: PolicyMethodParams,
method: SolvingMethod = SolvingMethod.PILE,
dict_params: Optional[Dict[Any, Any]] = None,
callback: Optional[Callable[[Domain, DOSolver], bool]] = None,
callback: Optional[Callable[[DOSolver], bool]] = None,
):
self.callback = callback
self.method = method
Expand Down Expand Up @@ -209,9 +209,7 @@ def _solve(self, domain_factory: Callable[[], D]) -> None:
if self.callback is None:
callbacks = []
else:
callbacks = [
_DOCallback(callback=self.callback, domain=self.domain, solver=self)
]
callbacks = [_DOCallback(callback=self.callback, solver=self)]
copy_dict_params = deepcopy(self.dict_params)
if "callbacks" in copy_dict_params:
callbacks = callbacks + copy_dict_params.pop("callbacks")
Expand Down Expand Up @@ -258,11 +256,9 @@ def _is_policy_defined_for(self, observation: D.T_agent[D.T_observation]) -> boo
class _DOCallback(Callback):
def __init__(
self,
callback: Callable[[Domain, DOSolver], bool],
domain: Domain,
solver: Solver,
callback: Callable[[DOSolver], bool],
solver: DOSolver,
):
self.domain = domain
self.solver = solver
self.callback = callback

Expand All @@ -280,5 +276,5 @@ def on_step_end(
If `True`, the optimization process is stopped, else it goes on.

"""
stopping = self.callback(self.domain, self.solver)
stopping = self.callback(self.solver)
return stopping
3 changes: 1 addition & 2 deletions tests/scheduling/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,9 @@ def __init__(self, max_iter=2):
self.max_iter = max_iter
self.iter = 0

def __call__(self, domain, solver):
def __call__(self, solver):
self.iter += 1
logger.warning(f"End of iteration #{self.iter}.")
assert isinstance(domain, ToyRCPSPDomain)
assert isinstance(solver, DOSolver)
stopping = self.iter >= self.max_iter
return stopping
Expand Down
Loading