From 51255d30e5c40ae467d4c3c90ba31452b15cf091 Mon Sep 17 00:00:00 2001 From: Siddharth Krishna Date: Fri, 6 Dec 2024 09:27:50 +0100 Subject: [PATCH 1/4] Set float precision to .10g --- xl2times/transforms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xl2times/transforms.py b/xl2times/transforms.py index 4a1257d..f844262 100644 --- a/xl2times/transforms.py +++ b/xl2times/transforms.py @@ -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 From f9be1bcbc154aeabf837bd6f03fb6be7f2fa10da Mon Sep 17 00:00:00 2001 From: Siddharth Krishna Date: Sat, 7 Dec 2024 09:31:39 +0100 Subject: [PATCH 2/4] Add RelEps=1e-6 to gdxdiff comparison --- utils/run_benchmarks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/run_benchmarks.py b/utils/run_benchmarks.py index e28f5ad..b6e5751 100644 --- a/utils/run_benchmarks.py +++ b/utils/run_benchmarks.py @@ -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, From 847cb24f7b520309dcf7293c420c37943ec4f7c6 Mon Sep 17 00:00:00 2001 From: Siddharth Krishna Date: Sat, 7 Dec 2024 12:25:03 +0100 Subject: [PATCH 3/4] Use same float precision while reading ground truth --- xl2times/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xl2times/__main__.py b/xl2times/__main__.py index df38ff3..cf8a77d 100644 --- a/xl2times/__main__.py +++ b/xl2times/__main__.py @@ -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 @@ -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: From 7480c0b1923a5968e70c6882cfe3657a8a1a6e9d Mon Sep 17 00:00:00 2001 From: Siddharth Krishna Date: Sat, 7 Dec 2024 12:41:26 +0100 Subject: [PATCH 4/4] CI: report size of DD diffile using gdxdump --- utils/run_benchmarks.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/utils/run_benchmarks.py b/utils/run_benchmarks.py index b6e5751..ad4e3da 100644 --- a/utils/run_benchmarks.py +++ b/utils/run_benchmarks.py @@ -128,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"