Factory
- class unified_planning.engines.Factory(environment: Environment)[source]
Bases:
object
Class that manages all the different
Engines
classes and handles the operation modes available in the library.- property engines: List[str]
Returns the list of the available
Engines
names.
- engine(name: str) Type[Engine] [source]
Returns a specific Engine class.
- Parameters:
name – The name of the engine in the factory.
- Returns:
The engine Class.
- property preference_list: List[str]
Returns the current list of preferences.
- add_engine(name: str, module_name: str, class_name: str)[source]
Adds an
Engine
Class to the factory, given the module and the class names.- Parameters:
name – The name of the added engine Class in the factory.
module_name – The name of the module in which the engine Class is defined.
class_name – The name of the engine Class.
- add_meta_engine(name: str, module_name: str, class_name: str)[source]
Adds a
MetaEngine
Class to the Factory, given the module and the class names.- Parameters:
name – The name of the added meta engine Class in the factory.
module_name – The name of the module in which the meta engine Class is defined.
class_name – The name of the meta engine Class.
- configure_from_file(config_filename: str | None = None)[source]
Reads a configuration file and configures the factory.
The following is an example of configuration file:
[global] engine_preference_list: fast-downward fast-downward-opt enhsp enhsp-opt tamer
[engine <engine-name>] module_name: <module-name> class_name: <class-name>
If not given, the configuration is read from the first up.ini or .up.ini file located in any of the parent directories from which this code was called or, otherwise, from one of the following files: ~/up.ini, ~/.up.ini, ~/.uprc.
- Parameters:
config_filename – The path of the file containing the wanted configuration.
- property environment: Environment
Returns the environment in which this factory is created
- OneshotPlanner(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, Any] | Sequence[Dict[str, Any]] | None = None, problem_kind: ProblemKind = ProblemKind([]), optimality_guarantee: OptimalityGuarantee | str | None = None) Engine [source]
Returns a oneshot planner. There are three ways to call this method:
- using
name
(the name of a specific planner) andparams
(planner dependent options).e.g.OneshotPlanner(name='tamer', params={'heuristic': 'hadd'})
- using
names
(list of specific planners name) andparams
(list of planner dependent options) to get aParallel
engine.e.g.OneshotPlanner(names=['tamer', 'tamer'], params=[{'heuristic': 'hadd'}, {'heuristic': 'hmax'}])
- using
problem_kind
andoptimality_guarantee
.e.g.OneshotPlanner(problem_kind=problem.kind, optimality_guarantee=SOLVED_OPTIMALLY)
- AnytimePlanner(*, name: str | None = None, params: Dict[str, str] | None = None, problem_kind: ProblemKind = ProblemKind([]), anytime_guarantee: AnytimeGuarantee | str | None = None) Engine [source]
Returns a anytime planner. There are two ways to call this method:
- using
name
(the name of a specific planner) andparams
(planner dependent options).e.g.AnytimePlanner(name='tamer', params={'heuristic': 'hadd'})
- using
problem_kind
andanytime_guarantee
.e.g.AnytimePlanner(problem_kind=problem.kind, anytime_guarantee=INCREASING_QUALITY)
An
AnytimePlanner
is a planner that returns anIterator
of solutions. Depending on the givenanytime_guarantee
parameter, every plan being generated is:strictly better in terms of quality than the previous one (
INCREASING_QUALITY
);optimal (
OPTIMAL_PLANS
);just a different plan, with no specific guarantee (
None
).
It raises an exception if the problem has no optimality metrics and anytime_guarantee is equal to
INCREASING_QUALITY
orOPTIMAL_PLAN
.
- PlanValidator(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, str] | Sequence[Dict[str, str]] | None = None, problem_kind: ProblemKind = ProblemKind([]), plan_kind: PlanKind | str | None = None) Engine [source]
Returns a plan validator. There are three ways to call this method:
- using
name
(the name of a specific plan validator) andparams
(plan validator dependent options).e.g.PlanValidator(name='tamer', params={'opt': 'val'})
- using
names
(list of specific plan validators name) andparams
(list of plan validators dependent options) to get aParallel
engine.e.g.PlanValidator(names=['tamer', 'tamer'], params=[{'opt1': 'val1'}, {'opt2': 'val2'}])
- using
problem_kind
andplan_kind
parameters.e.g.PlanValidator(problem_kind=problem.kind, plan_kind=plan.kind)
- Compiler(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, str] | Sequence[Dict[str, str]] | None = None, problem_kind: ProblemKind = ProblemKind([]), compilation_kind: CompilationKind | str | None = None, compilation_kinds: Sequence[CompilationKind | str] | None = None) Engine [source]
Returns a compiler or a pipeline of compilers.
To get a compiler there are two ways to call this method:
- using
name
(the name of a specific compiler) andparams
(compiler dependent options).e.g.Compiler(name='tamer', params={'opt': 'val'})
- using
problem_kind
andcompilation_kind
parameters.e.g.Compiler(problem_kind=problem.kind, compilation_kind=GROUNDING)
To get a pipeline of compilers there are two ways to call this method:
- using
names
(the names of the specific compilers),params
(compilers dependent options) andcompilation_kinds
.e.g.Compiler(names=['up_quantifiers_remover', 'up_grounder'], params=[{'opt1': 'val1'}, {'opt2': 'val2'}], compilation_kinds=[QUANTIFIERS_REMOVING, GROUNDING])
- using
problem_kind
andcompilation_kinds
parameters.e.g.Compiler(problem_kind=problem.kind, compilation_kinds=[QUANTIFIERS_REMOVING, GROUNDING])
- SequentialSimulator(problem: AbstractProblem, *, name: str | None = None, params: Dict[str, str] | None = None) Engine [source]
Returns a sequential simulator. There are two ways to call this method:
- using
problem_kind
through the problem field.e.g.SequentialSimulator(problem)
- using
name
(the name of a specific simulator) and eventually someparams
(simulator dependent options).e.g.SequentialSimulator(problem, name='sequential_simulator')
- Replanner(problem: AbstractProblem, *, name: str | None = None, params: Dict[str, str] | None = None, optimality_guarantee: OptimalityGuarantee | str | None = None) Engine [source]
Returns a Replanner. There are two ways to call this method:
- using
problem
(with its kind) andoptimality_guarantee
parameters.e.g.Replanner(problem, optimality_guarantee=SOLVED_OPTIMALLY)
- using
name
(the name of a specific replanner) andparams
(replanner dependent options).e.g.Replanner(problem, name='replanner[tamer]')
- PlanRepairer(*, name: str | None = None, params: Dict[str, Any] | None = None, problem_kind: ProblemKind = ProblemKind([]), plan_kind: PlanKind | str | None = None, optimality_guarantee: OptimalityGuarantee | str | None = None) Engine [source]
Returns a plan repairer. There are two ways to call this method:
- using
name
(the name of a plan repairer) and eventuallyparams
.e.g.PlanRepairer(name='xxx')
- using
problem_kind
,plan_kind
andoptimality_guarantee
.e.g.PlanRepairer(problem_kind=problem.kind, plan_kind=plan.kind, optimality_guarantee=SOLVED_OPTIMALLY)
- PortfolioSelector(*, name: str | None = None, params: Dict[str, Any] | None = None, problem_kind: ProblemKind = ProblemKind([]), optimality_guarantee: OptimalityGuarantee | str | None = None) Engine [source]
Returns a portfolio selector. There are two ways to call this method:
- using
name
(the name of a specific portfolio) and eventuallyparams
(portfolio dependent options).e.g.PortfolioSelector(name='ibacop')
- using
problem_kind
andoptimality_guarantee
.e.g.PortfolioSelector(problem_kind=problem.kind, optimality_guarantee=SOLVED_OPTIMALLY)
- print_engines_info(stream: ~typing.IO[str] = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, *, operation_mode: ~unified_planning.engines.engine.OperationMode | str | None = None, show_supported_kind: bool = True, show_credits: bool = False, full_credits: bool = True)[source]
Writes the info of all the installed engines in the given stream; the default stream is the stdout.
- Parameters:
stream – The
IO[str]
where all the engine’s info are written; defaults to sys.stdout.operation_mode – If specified, writes info about the engines that support that OperationMode.
show_supported_kind – If
True
writes the supported_kind of the engines. defaults toTrue
.show_credits – If
True
writes the credits of the engines. defaults toFalse
.full_credits – If
True
writes a longer version of the credits; ignored ifshow_credits
isFalse
; defaults toTrue
.
- get_all_applicable_engines(problem_kind: ProblemKind, operation_mode: OperationMode = OperationMode.ONESHOT_PLANNER, *, optimality_guarantee: OptimalityGuarantee | str | None = None, anytime_guarantee: AnytimeGuarantee | str | None = None, plan_kind: PlanKind | str | None = None, compilation_kind: CompilationKind | str | None = None) List[str] [source]
- Returns all the engine names installed that are able to handle all the given requirements.Since the semantic of the parameters given to this function depends on the chosen
OperationMode
, an user must have clear their meaning in the Operation Mode context.- Parameters:
problem_kind – An engine is returned only if it supports this
problem_kind
.operation_mode – An engine is returned only if it implements this
operation_mode
; defaults toONESHOT_PLANNER
.optimality_guarantee – An engine is returned only if it satisfies this
optimality_guarantee
. This parameter can be specified only if theoperation_mode
isONESHOT_PLANNER
,REPLANNER
,PLAN_REPAIRER
orPORTFOLIO_SELECTOR
.anytime_guarantee – An engine is returned only if it satisfies this
anytime_guarantee
. This parameter can be specified only if theoperation_mode
isANYTIME_PLANNER
.plan_kind – An engine is returned only if it is able to handle this
plan_kind
. This parameter can be specified only if theoperation_mode
isPLAN_VALIDATOR
orPLAN_REPAIRER
.compilation_kind – An engine is returned only if it is able to handle this
compilation_kind
. This parameter can be specified only if theoperation_mode
isCOMPILER
.
- Returns:
The list of engines names that satisfy all the given requirements.