Example #1
0
def dump():
    ckpt_dir = [
        os.path.join('/home/ekumar/master_thesis/code/hythe-src/checkpoints/',
                     ck) for ck in
        os.listdir("/home/ekumar/master_thesis/code/hythe-src/checkpoints/")
    ]
    eval_criteria = {"goal_reached": lambda x: x}
    print(ckpt_dir)
    demos_dir = os.path.join('/home/ekumar/demos/')
    list_of_demos = []
    for cdir in ckpt_dir:
        print(f"Extracting result {cdir}")
        result = BenchmarkResult.load_results(cdir)
        democ = DemonstrationCollector()
        democ._collection_result = result
        democ._directory = demos_dir
        demos = democ.ProcessCollectionResult(eval_criteria)
        list_of_demos.extend(demos)
    # make the demonstrations dir in the exp root
    os.makedirs(
        "/home/ekumar/output/experiments/exp_c76fc949-e95f-4774-91ba-6bec575ada37/demonstrations/generated_demonstrations"
    )
    to_pickle(
        list_of_demos,
        "/home/ekumar/output/experiments/exp_c76fc949-e95f-4774-91ba-6bec575ada37/demonstrations/generated_demonstrations",
        "demonstrations")
    collector = DemonstrationCollector.load(
        "/home/ekumar/output/experiments/exp_c76fc949-e95f-4774-91ba-6bec575ada37/demonstrations/generated_demonstrations"
    )
    print("Total demonstations found:",
          len(collector.GetDemonstrationExperiences()))
    return
Example #2
0
    def merge_checkpoint_benchmark_results(checkpoint_dir):
        checkpoint_files = glob.glob(os.path.join(checkpoint_dir, "**/*.ckpnt"), recursive=True)
        merged_result_filename = BenchmarkRunner.get_merged_result_filename(checkpoint_dir)
        if os.path.exists(merged_result_filename):
          merged_result = BenchmarkResult.load_results(filename=merged_result_filename)
        else:
          merged_result = BenchmarkResult(file_name=merged_result_filename)
        # merge all checkpoints with new results
        for checkpoint_file in checkpoint_files:
          loaded_result = BenchmarkResult.load(os.path.abspath(checkpoint_file))
          merged_result.extend(loaded_result, file_level=True)
          logging.info("Extending with checkpoint {}".format(checkpoint_file))

        # delete checkpoints
        for checkpoint_file in checkpoint_files:
          if "merged_result" in checkpoint_file:
            continue
          os.remove(checkpoint_file)
          logging.info("Removed old checkpoint file {}".format(checkpoint_file))
        return merged_result