machetli¶
-
machetli.search(initial_state, successor_generator, evaluator_path, environment=None, deterministic=False)[source]¶ Start a Machetli search and return the resulting state.
The search is started from the initial state and successor generators are then used to create transformed instances. Each instance created this way is evaluated with the given evaluator that checks if the behavior we are interested in is still present in the transformed instance. The search always commits to the transformation of the first instance where the evaluator succeeds (first-choice hill climbing).
- Parameters
initial_state – is a dictionary describing the instance you want to simplify. The internal format of this dictionary has to match what the successor generators expect. Modules that include successor generators also provide a function to create an initial state in the correct format.
successor_generator – is a single
SuccessorGeneratoror a list of SuccessorGenerators. If a list [s1, …, sn] is given, the search first tries all successors from s1, then from s2, and so on.evaluator_path – is the path to a Python file that is used to check if the behaviour that the search is analyzing is still present in the state. Please refer to the user documentation on how to write an evaluator.
environment – determines how the search should be executed. If no environment is specified, a
LocalEnvironmentis used that executes everything in sequence on the local machine. Alternatively, an implementation ofSlurmEnvironmentcan be used to parallelize the search on a cluster running the Slurm engine.deterministic – When evaluating successors in parallel, situations can occur that are impossible in a sequential environment, as results arrive not necessarily in the order in which the jobs are started: for example, if a state has successors [s1, s2, s3], a successful result for s3 could be available before results for s1 are available. Additionally, if the evaluation of s2 throws an exception, a sequential evaluation would never have evaluated s3. By allowing a non-deterministic successor choice (default) the search commits to the first successfully evaluated successor even if it would not have come first in a sequential order. If the order of the successor generators is important in your case, you can force a deterministic order. The search then simulates sequential execution.
- Returns
the last state where the evaluator was successful, i.e., all successors of the resulting state no longer have the evaluated property.
Note
The initial state is never checked to have the evaluated property. If the result of the search is identical to the initial state, this can have two reasons:
The initial state is minimal with respect to the evaluated property and the used successor generators. In this case, you can try repeating the search with additional successor generators.
The initial state does not have the property and neither does any of its successors. (If a successor has the property despite the initial state not having it, Machetli will nevertheless minimize the task as intended.) If you started from an instance that should have the property, this could indicate a bug in your evaluator script, which either doesn’t reproduce the property correctly, or fails to recognize it.
- Example
1 2 3 4 5 6 7
initial_state = sas.generate_initial_state("bugged.sas") evaluator_path = "./evaluator.py" result = search(initial_state, [sas.RemoveVariables(), sas.RemoveOperators()], evaluator_path) sas.write_file(result, "result.sas")