# G-FAIR G-FAIR is a GAMS implementation of the FAIR simple climate model (`FAIR.gms`, with its includes in `Model/`, `experiments/` and `input/`). The repository also holds the Monte Carlo pipeline of the SAI paper in `Paper_SAI/`: it samples the uncertain parameters, runs FAIR once per draw and gas, prices the results, and draws the figures. ## Replicating the Monte Carlo simulations ### The pipeline | Stage | Script | Reads | Writes | |---|---|---|---| | 1. Sample | `Paper_SAI/Sampling/Generate_montecarlo.R` | `Paper_SAI/all_parameters.R` | `Paper_SAI/Sampling//id_montecarlo.csv` | | 2. Run FAIR | `Paper_SAI/Sampling/Run_montecarlo.R` | `id_montecarlo.csv`, `FAIR.gms`, `input/RCPs_consolidated.gdx` | `Paper_SAI/Results//*.gdx` | | 3. Price the runs | `Paper_SAI/Sampling/Analyze_montecarlo.R` | `id_montecarlo.csv`, the `.gdx` runs | `npc_output.csv`, `scc_output.csv`, `sccnosrm_output.csv` and the discard lists, in `Paper_SAI/Sampling//` | | 4. Pulse responses | `Paper_SAI/Sampling/Analyze_montecarlo_pulse_effects.R` | the `.gdx` runs, `dropped_srmnopulse_scenarios.csv` from stage 3 | `pulse_effects_*.csv` in `Paper_SAI/Sampling//` | | 5. Figures | `Paper_SAI/Plots/*.R` | the CSVs from stages 3 and 4, `input/data/*.parquet` | `Paper_SAI/Figures/*.pdf` and `*.png` | `` and `` are folder names you choose on the command line; their parent folders are fixed. Start the names with `Montecarlo` and `Results`: those prefixes are git-ignored. Every distribution, grid, economic constant, cluster setting and figure setting lives in one file, `Paper_SAI/all_parameters.R`. All scripts source it. ### Software Versions installed on the Windows workstation used for the pipeline, recorded on 12 October 2026. The raw GAMS outputs kept on that machine are stamped with the same GAMS build. | Component | Version | |---|---| | Operating system | Windows 11 Pro x64 (build 26200) | | R | 4.5.2 (2025-10-31, ucrt) | | GAMS | 51.1.0 (build 2d039df5, 13 Sep 2025), Windows x64 | | NLP solver | CONOPT3, version 3.17R. Set in `FAIR.gms` (`option nlp = conopt3`) and used for every FAIR solve | | CNS solver | CONOPT, version 4.38.1. The GAMS default, used once per run to fit the thermal response to ECS and TCR (`input/pre_find_Qs.gms`) | The GAMS licence must include CONOPT. R packages (all from CRAN unless noted): | Package | Version | Used by | |---|---|---| | docopt | 0.7.2 | stages 1–4 (command-line options) | | dplyr, stringr | 1.1.4, 1.6.0 | stages 1–4 | | qrng, spacefillr | 0.0-11, 0.4.0 | stage 1 (Owen-scrambled Sobol sequence) | | data.table | 1.17.8 | stages 3–4, figures | | witchtools | 0.4.13 (GitHub `witch-team/witchtools@ca25326`) | stages 3–4, `Figure_2.R` | | gdxtools | 0.7.1 (GitHub `lolow/gdxtools@c9c2c57`) | stages 3–4, `Figure_2.R` | | tidyverse | 2.0.0 (ggplot2 4.0.3, tidyr 1.3.1, purrr 1.2.0, tibble 3.3.0, readr 2.1.6) | stage 4, figures | | ggpubr, patchwork, scales | 0.6.2, 1.3.2, 1.4.0 | figures | | gsaot | 1.1.1 | `Figure_1_add2_add3.R` (optimal-transport sensitivity indices) | | mgcv, viridisLite | 1.9-3, 0.4.3 | `Figure_1_add2_add3.R` (GAM smooths, colour scale) | | arrow, countrycode | 22.0.0, 1.6.1 | `Figure_2.R` | | ragg | 1.5.0 | PNG previews of the figures | ```r install.packages(c("docopt", "dplyr", "stringr", "qrng", "spacefillr", "data.table", "tidyverse", "ggpubr", "patchwork", "scales", "gsaot", "mgcv", "viridisLite", "arrow", "countrycode", "ragg", "remotes")) remotes::install_github("witch-team/witchtools") remotes::install_github("lolow/gdxtools") ``` ### Where each script runs | Script | Machine | Launch from | Needs | |---|---|---|---| | `Generate_montecarlo.R` | any machine with R | anywhere | R packages only, no GAMS | | `Run_montecarlo.R` | workstation, or an LSF cluster with `--hpc T` | **the repository root** | `gams` on the `PATH` with a CONOPT licence. It calls `gams FAIR.gms`, whose includes and inputs use paths relative to the root | | `Analyze_montecarlo.R`, `Analyze_montecarlo_pulse_effects.R` | the machine that holds the `.gdx` runs | anywhere | `gams` on the `PATH`: gdxtools reads the runs through GAMS's GDX library. With `--hpc T` it uses `HPC_GAMS_PATH` instead | | `Figure_1_add2_add3.R`, `Additional_figure_1.R`, `Additional_figure_4.R` | workstation | anywhere | R built with cairo and the Arial font, for the PDF export | | `Figure_2.R` | workstation | anywhere | as above, plus `gams` on the `PATH` (the script initialises gdxtools) | "Anywhere" works because each script finds `Paper_SAI/all_parameters.R` from its own location. The commands below are all written to be run from the repository root. ### 1. Get the code and the inputs The inputs (`*.gdx`, `*.csv`, `*.parquet`, `*.xlsx`) are stored with Git LFS. ```sh git lfs install git clone https://github.com/PietroAndreoni/G-FAIR.git cd G-FAIR ``` The inputs are already built. The scripts that built them are `input/consolidate_data_ar5.R` (RCP emissions and forcing, into `input/RCPs_consolidated.gdx`) and `input/consolidate_data_harmsen_2019.R` (non-CO2 abatement cost curves, into `input/data/harmsen_nonco2_*.parquet`). Two optional checks of the sampling helpers run in a few seconds: ```sh Rscript Paper_SAI/Utilities/test_montecarlo_utils.R Rscript Paper_SAI/Utilities/test_fit_distribution.R ``` ### 2. Sample The paper uses two samples, both drawn with the defaults: an Owen-scrambled Sobol sequence with seed 123. ```sh # Main sample: 8,192 draws over all 19 parameters (Fig. 1, Additional Figs. 1-4) Rscript Paper_SAI/Sampling/Generate_montecarlo.R -o Montecarlo_main -n 8192 # Base sample: 1,024 draws at the fixed policy scenario, for pulses in 2025 and 2050 (Fig. 2) Rscript Paper_SAI/Sampling/Generate_montecarlo.R -o Montecarlo_base -n 1024 --base T --angle na ``` `--base T` fixes the policy scenario (RCP4.5, 10 K per millennium cooling, deployment from 2025 to 2400), the discount rate (2%), and the value of a statistical life with its income elasticity. It also cuts the upper 1% tail of the log-normal parameters. `--angle na` keeps the SAI angle uncertain. Add `--diagnostics T` for a PDF comparing the drawn and target distributions. With the package versions above, these two commands regenerate exactly the samples behind the archived results. ### 3. Run FAIR Run from the repository root, with `gams` on the `PATH`. ```sh # Main sample: both gases (CO2 and CH4) for each draw Rscript Paper_SAI/Sampling/Run_montecarlo.R -i Montecarlo_main --res Results_main -s 1 -e 5246 # Base sample: CH4 only Rscript Paper_SAI/Sampling/Run_montecarlo.R -i Montecarlo_base --res Results_base --base T ``` `-s` and `-e` select the first and last row of `id_montecarlo.csv`. The archived main results cover rows 1 to 5,246; leave `-e` out to run all 8,192. Each GAMS call solves one draw for one gas and writes seven `.gdx` files: the historical run, the baseline, the emission pulse, SAI alone, SAI with the pulse, SAI adjusted to mask the pulse, and the masked run with SAI terminated. Re-running the command skips draws whose last file already exists, so an interrupted batch can simply be restarted. Draws that GAMS could not solve are listed in `problematic_scenarios.csv` in the results folder. A call takes about 10 seconds on the workstation, so run serially the main sample needs roughly 28 hours (10,492 calls) and the base sample roughly 5.5 hours (2,048 calls). On this workstation GAMS exits with code 112 after a successful solve and leaves empty scratch folders (`225a`, `225b`, …) in the root. `Run_montecarlo.R` treats 112 as solved (`SOLVE_OK_STATUS`), and the folders can be deleted. **On a cluster.** `--hpc T` submits each call through LSF (`bsub`), with the queue, project, memory and GAMS path set by the `HPC_*` constants in `all_parameters.R`. These are preconfigured for CMCC's Juno cluster and GAMS 40.4; the R version on the cluster is not recorded in this repository. Add `-p T` to submit without waiting for each job, `-m` to cap the jobs per invocation (default 100) and `-q` to pick the queue. Pass `--hpc T` to the two analysis scripts as well: they then load the GDX library from `HPC_GAMS_PATH` and write their console output to `r_console*.log` in the output folder. ### 4. Analyse ```sh # Main sample Rscript Paper_SAI/Sampling/Analyze_montecarlo.R -i Montecarlo_main -o Montecarlo_main --res Results_main Rscript Paper_SAI/Sampling/Analyze_montecarlo_pulse_effects.R -o Montecarlo_main --res Results_main # Base sample Rscript Paper_SAI/Sampling/Analyze_montecarlo.R -i Montecarlo_base -o Montecarlo_base --res Results_base ``` `-i` is the folder holding `id_montecarlo.csv`, `-o` the folder for the output CSVs (both under `Paper_SAI/Sampling/`), and `--res` the folder with the `.gdx` runs (under `Paper_SAI/Results/`). Several run folders can be joined with `-`, for example `--res Results_a-Results_b`, so do not use `-` inside a folder name. `Analyze_montecarlo.R` computes the net present cost of each draw and the social cost of the pulse with and without SAI. It records every draw it drops, with the reason, in `discarded_runs.csv`. `Analyze_montecarlo_pulse_effects.R` extracts the temperature and forcing response to the pulse. Run it after `Analyze_montecarlo.R` and with the same `-o`, so that it can apply the same drop list. It selects one real run per percentile, so it needs a realistic sample: it fails on a two-draw test. Its diagnostic plots go to `Rplots.pdf` in the folder you launch it from; `--plot F` turns them off. ### 5. Figures The result folders are git-ignored, so the repository holds neither the raw runs nor the analysis CSVs. By default the figure scripts read two archived folders, `Paper_SAI/Results/Results_16072026` (main) and `Paper_SAI/Results/Results_base_16072026` (base). To plot your own runs, point two environment variables at your output folders, using absolute paths or paths relative to the folder you launch from. `MC_RESULTS_FIG3` keeps an older figure number in its name: it feeds Fig. 2. ```sh # bash export MC_RESULTS_MAIN=Paper_SAI/Sampling/Montecarlo_main export MC_RESULTS_FIG3=Paper_SAI/Sampling/Montecarlo_base ``` ```powershell # PowerShell $env:MC_RESULTS_MAIN = "Paper_SAI/Sampling/Montecarlo_main" $env:MC_RESULTS_FIG3 = "Paper_SAI/Sampling/Montecarlo_base" ``` ```sh Rscript Paper_SAI/Plots/Figure_1_add2_add3.R Rscript Paper_SAI/Plots/Figure_2.R Rscript Paper_SAI/Plots/Additional_figure_1.R Rscript Paper_SAI/Plots/Additional_figure_4.R ``` | Script | Figures | Sample | Files written to `Paper_SAI/Figures/` | |---|---|---|---| | `Figure_1_add2_add3.R` | Fig. 1, Additional Figs. 2 and 3 | main, draws with ID ≤ 4,096 | `fig_1`, `extended_fig_2`, `extended_fig_3` | | `Figure_2.R` | Fig. 2 | base, plus the Harmsen abatement cost curves | `fig_2` | | `Additional_figure_1.R` | Additional Fig. 1 | main, pulse responses from stage 4 | `extended_fig_1` | | `Additional_figure_4.R` | Additional Fig. 4 | main | `extended_fig_4` | Each figure is saved as a vector PDF and a PNG preview at its final print size (180 mm wide, 5–7 pt Arial, RGB), following the Nature guide to preparing final artwork. The sizes and the save helper are in section 10 of `all_parameters.R`. ### The archived results behind the paper figures | | Main (`Results_16072026`) | Base (`Results_base_16072026`) | |---|---|---| | Analysed on | 16 July 2026 (pulse responses 20 July) | 17 July 2026 | | Sample | Sobol, seed 123, 8,192 draws | Sobol, seed 123, 1,024 draws × 2 pulse years | | Draws run | rows 1 to 5,246 | all 2,048 rows | | Gases | CO2 and CH4 | CH4 | | Draws kept | 4,632 with both gases, of which 3,490 have ID ≤ 4,096 | 2,048 | In the main sample, 614 of the 5,246 draws were dropped: FAIR was infeasible for 604, and for 10 the total cost of the SAI-only world reached world output by the year of the pulse. Draws where that happens later are kept, with their time series cut at that year. `discarded_runs.csv` lists every case with its reason.