Skip to content

Commit

Permalink
Handle loading/saving CSV files with out-of-test-set problems
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-caron committed Sep 2, 2024
1 parent 6c7953b commit 1ea1c47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added

- Add `results_path` argument to the `main` function
- Results: Handle loading/saving CSV files with out-of-test-set problems
- Special handling to get CVXOPT version number properly

### Changed
Expand Down
14 changes: 11 additions & 3 deletions qpbenchmark/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,23 @@ def __init__(self, csv_path: str, test_set: TestSet):
logging.info(f"Loading existing results from {csv_path}")
df = pandas.concat([df, pandas.read_csv(csv_path)])
Results.check_df(df)

# Filter out problems from the CSV that are in the test set
problems = set(problem.name for problem in test_set)
test_set_df = df[df["problem"].isin(problems)]
complementary_df = df[~df["problem"].isin(problems)]

self.__complementary_df = complementary_df
self.csv_path = csv_path
self.df = df
self.df = test_set_df
self.test_set = test_set

def write(self) -> None:
"""Write results to their CSV file for persistence."""
logging.debug(f"Test set results written to {self.csv_path}")
self.df = self.df.sort_values(by=["problem", "solver", "settings"])
self.df.to_csv(self.csv_path, index=False)
save_df = pandas.concat([self.df, self.__complementary_df])
save_df = save_df.sort_values(by=["problem", "solver", "settings"])
save_df.to_csv(self.csv_path, index=False)

def has(self, problem: Problem, solver: str, settings: str) -> bool:
"""Check if results contain a given run of a solver on a problem.
Expand Down

0 comments on commit 1ea1c47

Please sign in to comment.