diff --git a/utils/run_benchmarks.py b/utils/run_benchmarks.py index e28f5ad..ad4e3da 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, @@ -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" 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: 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