Skip to content

Commit

Permalink
Updating LRE script to avoid recalculating solution files
Browse files Browse the repository at this point in the history
  • Loading branch information
max-radin committed Dec 13, 2024
1 parent fc5abfd commit 5498304
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions scripts/compute_all_LREs_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,37 @@ def get_lqre(

return results

def get_solved_problem_uuids(config: dict[str, Any], output_dir: str) -> set[str]:
existing_output_files = os.listdir(args.output_dir)
print(output_dir)
print(existing_output_files)
logging.info(f"parsing {len(existing_output_files)} files in the output directory")
solved_problem_uuids = []
for s in existing_output_files:
with (open(os.path.join(args.output_dir, s), "r")) as f:
solution = json.load(f)
if (
solution["solver_details"]["solver_uuid"] == config["solver_uuid"]
and json.dumps(
solution["solver_details"]["algorithm_details"][
"algorithm_description"
],
sort_keys=True,
)
== json.dumps(config["algorithm_description"], sort_keys=True)
and json.dumps(
solution["solver_details"]["algorithm_details"][
"algorithm_parameters"
],
sort_keys=True,
)
== json.dumps(config["algorithm_parameters"], sort_keys=True)
):
solved_problem_uuids.append(solution["problem_instance_uuid"])
logging.info(
f"found {len(solved_problem_uuids)} existing solutions for this solver."
)
return set(solved_problem_uuids)

def main(args: argparse.Namespace) -> None:

Expand All @@ -243,12 +274,20 @@ def main(args: argparse.Namespace) -> None:
for p in problem_instance_files:
logging.info(f"file: {p}")

solved_problem_uuids = get_solved_problem_uuids(config, args.output_dir)

for problem_instance_file_name in problem_instance_files:
problem_instance_path = os.path.join(input_dir, problem_instance_file_name)
logging.info(f"parsing {problem_instance_path}")
with open(problem_instance_path, "r") as jf:
problem_instance = json.load(jf)

if problem_instance["problem_instance_uuid"] in solved_problem_uuids:
logging.info(
f"skipping {problem_instance['problem_instance_uuid']} because it already has a solution with the same solver UUID and algorithm details."
)
continue

resource_estimate = get_lqre(
problem_instance, args.sftp_username, args.sftp_key_file, config=config
)
Expand Down

0 comments on commit 5498304

Please sign in to comment.