-
Notifications
You must be signed in to change notification settings - Fork 39
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
UP-BFGP interface v0.2.0, few-shot engine and BFGP++ generalized planner v0.1.0 #514
base: master
Are you sure you want to change the base?
Changes from all commits
214d8e7
f40bebb
a7845b5
a686b55
5a1fd84
8b0dade
f1a9214
e8f565b
276de7e
d9e9bc6
debd833
091277d
d62eb42
acc82dd
3d8fc5d
2c727d7
223c1e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2022 AIPlan4EU project | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from warnings import warn | ||
import unified_planning as up | ||
from abc import ABC, abstractmethod | ||
from typing import IO, Optional, Callable, List | ||
|
||
|
||
class FewshotPlannerMixin(ABC): | ||
"""Base class to be extended by an :class:`~unified_planning.engines.Engine` that is also a `FewshotPlanner`.""" | ||
|
||
@staticmethod | ||
def is_fewshot_planner() -> bool: | ||
return True | ||
|
||
def solve( | ||
self, | ||
problems: List["up.model.AbstractProblem"], | ||
heuristic: Optional[Callable[["up.model.state.State"], Optional[float]]] = None, | ||
timeout: Optional[float] = None, | ||
output_stream: Optional[IO[str]] = None, | ||
) -> List["up.engines.results.PlanGenerationResult"]: | ||
""" | ||
This method takes a list of `AbstractProblem`s and returns a list of `PlanGenerationResult`, | ||
which contains information about the solution to the problems given by the generalized planner. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain how this is different from calling a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main purpose of a |
||
|
||
:param problems: is the list of `AbstractProblem`s to solve. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have any assumption on the structure of these problems? What happens if they come from radically different domains? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have such assumptions we need to make them explicit in the OM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It assumes the domain is shared for all instances. |
||
:param heuristic: is a function that given a state returns its heuristic value or `None` if the state is a | ||
dead-end, defaults to `None`. | ||
:param timeout: is the time in seconds the generalized planner has to solve all problems, defaults to `None`. | ||
:param output_stream: is a stream of strings where the planner writes his output (and also errors) while it is | ||
solving the problem; defaults to `None`. | ||
:return: a list of `PlanGenerationResult` created by the generalized planner; a data structure containing the | ||
:class:`~unified_planning.plans.Plan` found and some additional information about it. | ||
|
||
The only required parameter is `problems` but the generalized planner should warn the user if `heuristic`, | ||
`timeout` or `output_stream` are not `None` and the generalized planner ignores them. | ||
""" | ||
assert isinstance(self, up.engines.engine.Engine) | ||
for problem in problems: | ||
# Check whether the GP planner supports each input problem | ||
if not self.skip_checks and not self.supports(problem.kind): | ||
msg = f"We cannot establish whether {self.name} can solve problem {problem.name}!" | ||
if self.error_on_failed_checks: | ||
raise up.exceptions.UPUsageError(msg) | ||
else: | ||
warn(msg) | ||
# Solve all problems | ||
return self._solve(problems, heuristic, timeout, output_stream) | ||
|
||
@abstractmethod | ||
def _solve( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also this method neds to be renamed to avoid clash with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Commented above) |
||
self, | ||
problems: List["up.model.AbstractProblem"], | ||
heuristic: Optional[Callable[["up.model.state.State"], Optional[float]]] = None, | ||
timeout: Optional[float] = None, | ||
output_stream: Optional[IO[str]] = None, | ||
) -> List["up.engines.results.PlanGenerationResult"]: | ||
"""Method called by the FewshotPlannerMixin.solve method.""" | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rename this method, otherwise it would conflict with the
OneshotPlanner
Operation Mode, making it impossible to have an engine supporting bothFewshotPlanner
andOneshotPlanner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a OneshotPlanner a specialization of a FewshotPlanner, so if some software could do both, then it is a FewshotPlanner, i.e. a OneshotPlanner is a FewshotPlanner that always works with one instance.