def test_recover_then_rerun(mapped_doubler): m = mapped_doubler.map([1], tag='load-then-rerun') m.wait(timeout=180) loaded = htmap.load('load-then-rerun') loaded.rerun() assert list(loaded) == [2]
def test_load_then_rerun(mapped_doubler): m = mapped_doubler.map([1], tag="load-then-rerun") m.wait() loaded = htmap.load("load-then-rerun") loaded.rerun() assert list(loaded) == [2]
def _cli_load(tag: str) -> htmap.Map: with make_spinner(text=f'Loading map {tag}...') as spinner: try: return htmap.load(tag) except Exception as e: spinner.fail() click.echo(f'ERROR: could not find a map with tag {tag}', err=True) click.echo(f'Your map tags are:', err=True) click.echo(_tag_list(), err=True) sys.exit(1)
def _cli_load(tag: str) -> htmap.Map: with make_spinner(text=f"Loading map {tag}...") as spinner: try: return htmap.load(tag) except Exception as e: spinner.fail() logger.exception(f"Could not find a map with tag {tag}") click.echo(f"ERROR: could not find a map with tag {tag}", err=True) click.echo(f"Your map tags are:", err=True) click.echo(_fmt_tag_list(), err=True) sys.exit(1)
def main(tag, outdir): with make_spinner(f"loading map {tag}...") as spinner: map = htmap.load(tag) spinner.succeed(f"loaded map {tag}") if outdir is None: outdir = Path.cwd() outdir = Path(outdir) outpath = outdir / f"{tag}.sims" try: with si.utils.BlockTimer() as timer: with gzip.open(outpath, mode="wb") as f: pickle.dump(len(map), f) for sim in tqdm(map, desc="pickling sims...", total=len(map)): pickle.dump(sim, f) print(f"pickled sims from {tag} (took {timer.wall_time_elapsed})") except: if outpath.exists(): outpath.unlink()
def test_loaded_map_is_same_object_as_previously_created_map(): map = htmap.map(lambda x: x, range(1), tag='singleton') recovered = htmap.load('singleton') assert recovered is map
def test_load_on_bad_tag_raises_tag_not_found(): with pytest.raises(htmap.exceptions.TagNotFound): htmap.load('no-such-tag')
def test_load_shortcut(mapped_doubler): result = mapped_doubler.map(range(3), tag='load-shortcut') loaded = htmap.load('load-shortcut') assert loaded is result
def test_can_be_recovered_after_retag(mapped_doubler): m = mapped_doubler.map(range(1), tag='old') m.retag('new') htmap.load('new')
import htmap as ht if __name__ == "__main__": future = ht.load("test-1") for result in future: print(result)
def test_can_be_recovered_after_retag(mapped_doubler): m = mapped_doubler.map(range(1), tag="old") m.retag("new") htmap.load("new")