hector icon indicating copy to clipboard operation
hector copied to clipboard

Hector crashing with various NBP constraints

Open dawnlwoodard opened this issue 1 year ago • 0 comments

Describe the bug When running Hector with an NBP constraint, seemingly many constraints break the model by the second half of the century, and some break far earlier. I have just pulled and build the most up-to-date Hector as of the day I submitted this issue.

To Reproduce

Here's bash code, essentially doing what the test suite does, to replicate this. First one (with the test constraint) works, the other two fail. The first one that fails just sets NBP to 1.0 Pg C/yr out through 2060. The second sets NBP to the NBP that is produced by running Hector without a constraint under the same climate scenario, so I know the values are reasonable.

#!/bin/bash
  
HECTOR=./src/hector
INPUT=./inst/input

echo "---------- Running: default test NBP ----------"
sed 's/;[[:space:]]*NBP_constrain=csv:tables\/nbp_constraint.csv/NBP_constrain=csv:tables\/nbp_constraint.csv/' $INPUT/hector_ssp245.ini > $INPUT/hector_ssp245_nbp.ini
if [[ $(diff -q $INPUT/hector_ssp245.ini $INPUT/hector_ssp245_nbp.ini | wc -c) -eq 0 ]]; then exit 1; fi
$HECTOR $INPUT/hector_ssp245_nbp.ini
rm $INPUT/hector_ssp245_nbp.ini

echo "---------- Running: constant 1.0 PgC/yr NBP for 2000:2060  ----------"
sed 's/;[[:space:]]*NBP_constrain=csv:tables\/nbp_constraint.csv/NBP_constrain=csv:tables\/nbp_constant.csv/' $INPUT/hector_ssp245.ini > $INPUT/hector_ssp245_nbp.ini
if [[ $(diff -q $INPUT/hector_ssp245.ini $INPUT/hector_ssp245_nbp.ini | wc -c) -eq 0 ]]; then exit 1; fi
$HECTOR $INPUT/hector_ssp245_nbp.ini
rm $INPUT/hector_ssp245_nbp.ini


echo "---------- Running: Hector's output NBP under SSP245 as constraint for 2000:2100 under SSP245  ----------"
sed 's/;[[:space:]]*NBP_constrain=csv:tables\/nbp_constraint.csv/NBP_constrain=csv:tables\/nbp_output.csv/' $INPUT/hector_ssp245.ini > $INPUT/hector_ssp245_nbp.ini
if [[ $(diff -q $INPUT/hector_ssp245.ini $INPUT/hector_ssp245_nbp.ini | wc -c) -eq 0 ]]; then exit 1; fi
$HECTOR $INPUT/hector_ssp245_nbp.ini
rm $INPUT/hector_ssp245_nbp.ini

Running this works fine for the top one but the bottom two fail by apparently driving carbon values negative.

Error from running with the constant constraint: image

Error from running with the output constraint: image

The following R code (duplicating the constant constraint) also fails after 2050:

library(hector)
rcp <- "ssp245"
scenario_file <- paste0("input/hector_",rcp,".ini")
ini_file <- system.file(scenario_file, package="hector")

core <- hector::newcore(ini_file, suppresslogging = FALSE)
hector::run(core,runtodate = 2100)

for (i in 2001:2100){
    setvar(core,i,"NBP_constrain",1.0,"Pg C/yr")
    hector::run(core,runtodate = i)
}

which results in R unhelpfully crashing entirely: image

Supporting Files Here are the relevant constraint files. Putting them in the input/tables folder with the other constraints will allow the bash script to run.

nbp_constraint.csv

nbp_output.csv

nbp_constant.csv

dawnlwoodard avatar Jul 26 '22 22:07 dawnlwoodard