Factory
- class unified_planning.engines.Factory(environment: Environment)[source]
Bases:
objectClass that manages all the different
Enginesclasses and handles the operation modes available in the library.- property engines: List[str]
Returns the list of the available
Enginesnames.
- 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
EngineClass 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
MetaEngineClass 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([], version=None), 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 aParallelengine.e.g.OneshotPlanner(names=['tamer', 'tamer'], params=[{'heuristic': 'hadd'}, {'heuristic': 'hmax'}]) - using
problem_kindandoptimality_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([], version=3), 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_kindandanytime_guarantee.e.g.AnytimePlanner(problem_kind=problem.kind, anytime_guarantee=INCREASING_QUALITY)
An
AnytimePlanneris a planner that returns anIteratorof solutions. Depending on the givenanytime_guaranteeparameter, 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_QUALITYorOPTIMAL_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([], version=None), 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 aParallelengine.e.g.PlanValidator(names=['tamer', 'tamer'], params=[{'opt1': 'val1'}, {'opt2': 'val2'}]) - using
problem_kindandplan_kindparameters.e.g.PlanValidator(problem_kind=problem.kind, plan_kind=plan.kind)
- Compiler(*, name: str | None = None, names: Sequence[str] | None = None, params: Dict[str, Any] | Sequence[Dict[str, Any]] | None = None, problem_kind: ProblemKind = ProblemKind([], version=3), 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_kindandcompilation_kindparameters.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_kindandcompilation_kindsparameters.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_kindthrough 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_guaranteeparameters.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([], version=3), 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_kindandoptimality_guarantee.e.g.PlanRepairer(problem_kind=problem.kind, plan_kind=plan.kind, optimality_guarantee=SOLVED_OPTIMALLY)
- ActionSelector(problem: AbstractProblem, *, name: str | None = None, params: Dict[str, str] | None = None) Engine[source]
Returns an ActionSelector. There are two ways to call this method:
- using
problem_kindthrough the problem field.e.g.ActionSelector(problem) - using
name(the name of a specific action selector) and eventually someparams(engine dependent options).e.g.ActionSelector(problem, name='xxx')
- PortfolioSelector(*, name: str | None = None, params: Dict[str, Any] | None = None, problem_kind: ProblemKind = ProblemKind([], version=3), 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_kindandoptimality_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
Truewrites the supported_kind of the engines. defaults toTrue.show_credits – If
Truewrites the credits of the engines. defaults toFalse.full_credits – If
Truewrites a longer version of the credits; ignored ifshow_creditsisFalse; 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_modeisONESHOT_PLANNER,REPLANNER,PLAN_REPAIRERorPORTFOLIO_SELECTOR.anytime_guarantee – An engine is returned only if it satisfies this
anytime_guarantee. This parameter can be specified only if theoperation_modeisANYTIME_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_modeisPLAN_VALIDATORorPLAN_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_modeisCOMPILER.
- Returns:
The list of engines names that satisfy all the given requirements.