concepts.dm.crow.planners.regression_dependency#
Dependencies for the regression planning.
The CROW Regression planner provides a way to visualize the dependencies between the regression rules and statements.
Recall that a CROW-generated plan is roughly a tree where leaf nodes corresponds to “primitive” statements such as calling a controller function or setting a variable or making an assertion, whereas the internal nodes correspond to “achieve” statements that is like a function call in other programming languages.
Therefore, we can visualize the dependencies between the statements in the plan as a tree structure. We use the following rules to transform the plan into a dependency graph:
- achieve x has two cases:
If x is already achieved at the state where this statement is executed, then this statement will be translated into an “assert” statement.
- If x has not been achieved, and the planner translates x into a “behavior function call” statement with derived_from pointing to the original achieve x statement,
and the additional_info field containing the note that how the subsequences corresponding to x is serialized. All subsequent statements that are derived from this achieve x statement will be connected to this statement in the dependency graph. The additional_info field will contain the serialized subsequences: if no promotion is needed, it will state that the refinement is “sequential”, that is, the planner executes the statements after other subgoals are achieved. If promotion is needed, it will state that the refinement is “promoted”.
behavior() statements will be translated into a “behavior function call” statement. The additional_info field will contain the serialized information.
assert x statements will be left as is.
do x statements will be left as is.
let x statements will be left as is.
bind x where cond(x) statements will be translated into an assignment statement. The derived_from field will point to the original bind statement.
- if cond(x): y else: z statements will be translated into an assertion statement followed by the body of the if statement. The derived_from field will point to the original if statement.
Depending on whether the condition is satisfied, the planner will translate the condition into either an assert` or assert not statement. The additional_info field also contains the result of the condition evaluation.Q
while cond(x) do y statements will be translated into a sequence of assert cond(x); y; assert cond(x); y; …; assert not cond(x) statements. The derived_from field will point to the original while statement.
foreach x: T: y statements will be translated into a sequence of let x = …; y; let x = …; y; … statements. The derived_from field will point to the original foreach statement.
Note that it is not recommended to visualize this tree structure as a typical “tree” because of the promotion mechanism. Instead, we should roughly consider it as a layered graph. The leaf nodes correspond to the primitive statements, and they are ordered left-to-right in the same order as they are executed. Then, we build the internal nodes layer by layer, while edge-crossing is allowed, to indicate that some subgoals have been “promoted” to an earlier time.
To use this module, you need to first generate the trace of the regression planner, which is a sequence of RegressionTraceStatement objects. This can be turned on by setting include_dependency_trace=True in the CrowRegressionPlanner constructor.
Then, given the result of the plan, you can use the recover_dependency_graph_from_trace function to recover the dependency graph from the trace.
import concepts.dm.crow as crow
planner = crow.crow_regression(problem.domain, problem, include_dependency_trace=True, return_planner=True)
planner.main()
for r in planner.results:
graph = crow.recover_dependency_graph_from_trace(r.trace, r.scopes)
graph.render_graphviz('graph.pdf')
The graph is rendered using graphviz. You can either specify a filename to the render_graphviz function to save the graph to a file (in PNG or PDF or DOT format). If the filename is not specified, the graph will be saved to a temporary PDF file and opened in the default PDF viewer.
Note that in order to use this feature, you need to have graphviz installed. You can install it by running pip install graphviz. The graphviz package also requires the graphviz binary to be installed on your system. You can install it by running brew install graphviz on macOS or sudo apt-get install graphviz on Ubuntu.
The cdl-plan tool also provides a command –visualize-dependency-graph. If this flag is set, the tool will generate a PDF visualization of the dependency graph and open it in the default PDF viewer.
cdl-plan blocksworld-problem-sussman-with-pragma.cdl --visualize-dependency-graph
Functions
|
Classes
|
|
|
RegressionTraceStatement(stmt: 'SupportedCrowExpressionType', scope_id: int = None, new_scope_id: Optional[int] = None, additional_info: Optional[str] = None, scope: Optional[dict] = None, new_scope: Optional[dict] = None, derived_from: Optional[ForwardRef('SupportedCrowExpressionType')] = None) |