def optimise_targets(self): """If any target observations have been made, attempt to optimise them all.""" if not self.should_optimise: return from hypothesis.internal.conjecture.optimiser import Optimiser # We want to avoid running the optimiser for too long in case we hit # an unbounded target score. We start this off fairly conservatively # in case interesting examples are easy to find and then ramp it up # on an exponential schedule so we don't hamper the optimiser too much # if it needs a long time to find good enough improvements. max_improvements = 10 while True: prev_calls = self.call_count any_improvements = False for target, data in list( self.best_examples_of_observed_targets.items()): optimiser = Optimiser(self, data, target, max_improvements=max_improvements) optimiser.run() if optimiser.improvements > 0: any_improvements = True if self.interesting_examples: break max_improvements *= 2 if any_improvements: continue self.pareto_optimise() if prev_calls == self.call_count: break
def new_optimiser(self, example, target): from hypothesis.internal.conjecture.optimiser import Optimiser return Optimiser(self, example, target)