machetli.sas — SAS+ Files¶
This package allows transforming SAS+ input files. Usually, in a Machetli script you will use it in the following way:
from machetli import sas
initial_state = sas.generate_initial_state("path/to/problem.sas")
successor_generators = [sas.RemoveOperators(), ...]
You can then start your Machetli search using the initial SAS+
problem initial_state and a set of SAS+ successor
generators successor_generators. Finally, write out your result
using
sas.write_files(result, "path/to/result-problem.sas")
where result is the value returned by the
search function.
The successor generators described below denote possible transformations.
-
class
machetli.sas.MergeOperators[source]¶ For each pair of operators, generate a successor where these two operators are merged into one. Specifically, these operators are removed and instead a new operator is added that is equivalent to executing the two operators in sequence. Cases where this is not possible (e.g., with conflicting prevail conditions) are skipped.
-
class
machetli.sas.RemoveGoals[source]¶ For each goal condition, generate a successor where this goal condition is removed. The order of the successors is randomized
-
class
machetli.sas.RemoveOperators[source]¶ For each operator, generate a successor where this operator is removed. The order of the successors is randomized.
-
class
machetli.sas.RemovePrePosts[source]¶ For each precondition/effect pair in each operator, generate a successor where this pair is removed. This essentially ignores the variable in the operator. The order in which operators are considered is randomized, as is the order of precondition/effect pairs of the same operator, but all successors stemming from the same operator follow consecutively.
-
class
machetli.sas.RemoveVariables[source]¶ For each variable, generate a successor where this variable is compiled away by removing it from the initial state as well as every place where it is mentioned in the prevail condition, effect condition, effect fact, or goal. The order of the successors is randomized.
-
class
machetli.sas.SetUnspecifiedPreconditions[source]¶ For each operator and each variable on which this operator has an effect but no precondition, and for each possible value of this variable, generate a successor with an additional precondition on the variable. This limits the situations where the operator can be applied, potentially limiting branching in the search. The order in which operators are considered is randomized, as is the order of effects of the same operator, but all successors stemming from the same operator follow consecutively.
-
machetli.sas.generate_initial_state(sas_file: Union[pathlib.Path, str]) → dict[source]¶ Parse the SAS+ task defined in the SAS+ file sas_file and return an initial state containing the parsed SAS+ task.
- Returns
a dictionary pointing to the SAS+ task specified in the file sas_file.
-
machetli.sas.run_evaluator(evaluate)[source]¶ Load the state passed to the script via its command line arguments, then run the given function evaluate on the SAS+ file encoded in the state, and exit the program with the appropriate exit code. If the function returns
True, useEXIT_CODE_BEHAVIOR_PRESENT, otherwise useEXIT_CODE_BEHAVIOR_NOT_PRESENT. In addition to running the evaluator, this function creates the SAS+ file as ‘task.sas’ in the current directory.This function is meant to be used as the main function of an evaluator script. Instead of a path to the state, the command line arguments can also be paths to a SAS+ file. This is meant for testing and debugging the evaluator directly on SAS+ input.
- Parameters
evaluate – is a function taking the filename of a SAS+ file as input and returning
Trueif the specified behavior occurs for the given instance, andFalseif it doesn’t. Other ways of exiting the function (exceptions,sys.exitwith exit codes other thanEXIT_CODE_BEHAVIOR_PRESENTorEXIT_CODE_BEHAVIOR_NOT_PRESENT) are treated as failed evaluations by the search.