Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set output float precision & relative epsilon for DD comparison #252

Merged
merged 4 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion utils/run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def run_gams_gdxdiff(
path.join(out_folder, "scenario.gdx"),
path.join(out_folder, "diffile.gdx"),
"Eps=0.000001",
"RelEps=0.000001",
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
Expand All @@ -127,7 +128,21 @@ def run_gams_gdxdiff(
logger.info(res.stdout)
logger.info(res.stderr if res.stderr is not None else "")
if res.returncode != 0:
return f"Diff ({len(res.stdout.splitlines())})"
# Report the number of lines in the gdxdump of the difffile
res = subprocess.run(
["gdxdump", path.join(out_folder, "diffile.gdx")],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=False,
)
if verbose or res.returncode != 0:
logger.info(res.stdout)
logger.info(res.stderr if res.stderr is not None else "")
if res.returncode != 0:
logger.error(f"GAMS gdxdiff failed on {benchmark['name']}")
sys.exit(4)
return str(len(res.stdout.splitlines()))

return "OK"

Expand Down
4 changes: 3 additions & 1 deletion xl2times/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def read_csv_tables(input_dir: str) -> dict[str, DataFrame]:
result = {}
csv_files = list(Path(input_dir).glob("*.csv"))
for filename in csv_files:
result[filename.stem] = pd.read_csv(filename, dtype=str)
result[filename.stem] = pd.read_csv(filename)
return result


Expand Down Expand Up @@ -508,6 +508,8 @@ def run(args: argparse.Namespace) -> str | None:

if args.ground_truth_dir:
ground_truth = read_csv_tables(args.ground_truth_dir)
# Use the same convert_to_string transform on GT so that comparisons are fair
ground_truth = transforms.convert_to_string(config, ground_truth, model)
comparison = compare(tables, ground_truth, args.output_dir)
return comparison
else:
Expand Down
4 changes: 3 additions & 1 deletion xl2times/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2733,7 +2733,9 @@ def convert_to_string(
) -> dict[str, DataFrame]:
for key, value in tables.items():
tables[key] = value.map(
lambda x: str(int(x)) if isinstance(x, float) and x.is_integer() else str(x)
lambda x: (str(int(x)) if x.is_integer() else f"{x:.10g}")
if isinstance(x, float)
else str(x)
)
return tables

Expand Down
Loading