def test_find_first(): global counter wfs = [counted_sqr(x) for x in range(10)] w = find_first(is_sixteen, wfs) result = run_single(w) assert result == 16 assert counter == 5 wfs = [counted_sqr(x) for x in range(10)] w = find_first(is_sixteen, wfs) result = run_process(w, n_processes=1, registry=base) assert result == 16 wfs = [display_sqr(x) for x in range(10)] w = find_first(is_sixteen, wfs) with NCDisplay() as display: result = run_logging(w, n_threads=2, display=display) assert result == 16
def run( wf: object, runner: str = 'parallel', n_processes: int = 1, cache: str = 'cache.db', ) -> Any: """Run a workflow `wf` using `runner` and `n_processes` number of threads/process.""" runner = runner.lower() if isinstance(wf, Results): wf = gather_dict(**wf.state) if runner == 'display': with NCDisplay() as display: return run_logging(wf, n_processes, display) elif runner == 'serial': return run_single(wf) else: return run_provenance(wf, n_threads=n_processes, db_file=cache, registry=registry, echo_log=False, always_cache=False)
result = json.loads(p.stdout) return result # , p.stderr def error_filter(xcptn): if isinstance(xcptn, subprocess.CalledProcessError): return xcptn.stderr else: return None if __name__ == '__main__': command = Command('e⁻Scatter', './escat', 'sp', '-no-png', '-machine', depth='-n', multiplicity='-m', scaling='-x', ball_size='-s', hilbert='-H', random='-R') sizes = [i * 0.05 for i in range(20)] a = command(depth=10, multiplicity=3, scaling=0.5, ball_size=0.01, hilbert=True) b = command(depth=10, multiplicity=3, scaling=0.5, ball_size=0.01, random=True) work = noodles.gather(a, b) with SimpleDisplay(error_filter) as display: result = noodles.run_logging(work, 1, display) for line in result: print(json.dumps(line, indent=2))
command = Command('e⁻Scatter', './escat', 'sp', '-no-png', '-machine', depth='-n', multiplicity='-m', scaling='-x', ball_size='-s', hilbert='-H', random='-R') sizes = [i * 0.05 for i in range(20)] a = command(depth=10, multiplicity=3, scaling=0.5, ball_size=0.01, hilbert=True) b = command(depth=10, multiplicity=3, scaling=0.5, ball_size=0.01, random=True) work = noodles.gather(a, b) with SimpleDisplay(error_filter) as display: result = noodles.run_logging(work, 1, display) for line in result: print(json.dumps(line, indent=2))
def error_filter(xcptn): if isinstance(xcptn, subprocess.CalledProcessError): return xcptn.stderr else: return None if __name__ == "__main__": # Problem definition dimensions = 10 evaluator = Rastrigin(dimensions=dimensions) # Evolutionary Algorithm config = { 'population_size': 40, # mu 'offspring': 40, # lamda 'generations': 10, 'initial_sigma': 0.01, 'learning_rate': 1.0 / np.sqrt(dimensions) } ea = EA(config=config, fitness_evaluator=evaluator) g = ea.next_generation(ea.initialize()) print("╭─(Running evolution...)") with SimpleDisplay(error_filter) as display: answer = run_logging(g, 1, display) # answer = run_single(g) for i in answer.individuals: print(i.fitness)
def test_single_node(): with Display() as display: assert run_logging(g(5), 1, display) == 5