Skip to content

Commit

Permalink
Generate MILESTONYR and modify gams scaffold to include it (#119)
Browse files Browse the repository at this point in the history
This PR generates MILESTONYR (but does not implement the alternative
method from #97).

In order for this to pass regression tests, we also need to add
`milestonyr.dd` to each demo in
olejandro/demos-dd#1 (if they are correctly
generated?)

Fixes #97 (right?)
  • Loading branch information
siddharth-krishna authored Sep 16, 2023
1 parent ab4c510 commit 60cb2ff
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["times_reader"]

[project]
name = "times-excel-reader"
version = "0.1.0"
Expand Down
3 changes: 2 additions & 1 deletion times_reader/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ def convert_parameter(tablename: str, df: DataFrame):

sets = {m.times_name for m in config.times_xl_maps if "VALUE" not in m.col_map}

# Compute map fname -> tables: right now ALL_TS -> ts.dd, rest -> output.dd
# Compute map fname -> tables: put ALL_TS and MILESTONYR in separate files
tables_in_file = {
"ts.dd": ["ALL_TS"],
"milestonyr.dd": ["MILESTONYR"],
"output.dd": [t for t in config.dd_table_order if t != "ALL_TS"],
}

Expand Down
1 change: 1 addition & 0 deletions times_reader/config/times_mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ G_YRFR[REG,ALL_TS,VALUE] = ~FI_T(Region,TimeSlice,VALUE,Attribute:G_YRFR)
IRE_FLO[REG,DATAYEAR,PRC,COM,TSLVL,IE,COM,VALUE] = ~TODO(TODO)
IRE_FLOSUM[REG,DATAYEAR,PRC,COM,TSLVL,IE,COM,IO,VALUE] = ~TODO(Region,Year,TechName,CommName,TimeSlice,TODO-IE,CommName,TODO-IO,TODO-IRE_FLOSUM)
IRE_PRICE[REG,DATAYEAR,PRC,COM,TSLVL,REG,IE,CUR,VALUE] = ~FI_T(Region,Year,TechName,CommName,TimeSlice,Region,Other_Indexes,Curr,VALUE,Attribute:IRE_PRICE)
MILESTONYR[YEAR] = ~TimePeriods(M)
MODLYEAR[DATAYEAR,TEXT] = ModelYear(Year,Year)
NCAP_AFA[REG,DATAYEAR,PRC,BD,VALUE] = ~FI_T(Region,Year,TechName,LimType,VALUE,Attribute:NCAP_AFA)
NCAP_AFC[REG,DATAYEAR,PRC,COM_GRP,TSLVL,VALUE] = ~FI_T(Region,Year,TechName,Other_Indexes,TimeSlice,VALUE,Attribute:NCAP_AFC)
Expand Down
2 changes: 1 addition & 1 deletion times_reader/gams_scaffold/scenario.run
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $ BATINCLUDE initmty.mod
$IF NOT DECLARED REG_BNDCST $Abort "You need to use TIMES v2.3.1 or higher"

$BATINCLUDE output.dd
SET MILESTONYR /2005,2006/;
$BATINCLUDE milestonyr.dd

$ SET VEDAVDD 'YES'

Expand Down
10 changes: 6 additions & 4 deletions utils/run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def run_gams_gdxdiff(
f.write(f"$BATINCLUDE {file}.dd\n")
continue
f.write(line)
# TODO also get milestone years from benchmarks.yml
# Create link to TIMES source
if not path.exists(path.join(dd_folder, "source")):
symlink(times_folder, path.join(dd_folder, "source"), True)
Expand Down Expand Up @@ -271,7 +270,7 @@ def run_all_benchmarks(
benchmark,
times_folder=times_folder,
skip_csv=True,
run_gams=True,
run_gams=run_gams,
out_folder="out-main",
verbose=verbose,
)
Expand Down Expand Up @@ -400,15 +399,18 @@ def run_all_benchmarks(
print(f"ERROR: could not find {args.run} in {args.benchmarks_yaml}")
sys.exit(1)

runtime, _, _, _, _ = run_benchmark(
runtime, gms, acc, cor, add = run_benchmark(
benchmarks_folder,
benchmark,
times_folder=args.times_dir,
run_gams=args.dd,
skip_csv=args.skip_csv,
verbose=args.verbose,
)
print(f"Ran {args.run} in {runtime:.2f}s")
print(
f"Ran {args.run} in {runtime:.2f}s. {acc}% ({cor} correct, {add} additional).\n"
f"GAMS: {gms}"
)
else:
run_all_benchmarks(
benchmarks_folder,
Expand Down

0 comments on commit 60cb2ff

Please sign in to comment.