Skip to content

[WIP] Automatically run calibration setup during CES calibration - #2292

Closed
lecfab with Copilot wants to merge 1 commit into
developfrom
copilot/auto-run-calibration-setup
Closed

lecfab with Copilot wants to merge 1 commit into
developfrom
copilot/auto-run-calibration-setup

Conversation

Copilot AI commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor
  • Add setupLocalCalibration() helper function to scripts/start/run.R (top-level, testable)
  • Call setupLocalCalibration(cfg$remind_folder) in the calibrate branch before the iteration loop
  • Add tests in tests/testthat/test_01-run.R
  • Update tutorials/12_Calibrating_CES_Parameters.md to mention automatic setup
Original prompt

Goal

Automatically run the equivalent of make set-local-calibration when REMIND is executing a CES calibration run.

Repo

  • Repository: remindmodel/remind

Current behavior

  • CES calibration runs are handled in scripts/start/run.R under the branch cfg$gms$CES_parameters == "calibrate".
  • Setting up local calibration collection currently requires a manual step: make set-local-calibration, which runs ./scripts/utils/set-local-calibration.sh to create calibration_results/, initialize a local git repo, install hooks, and create calibration_results/.Rprofile_calibration_results.
  • scripts/utils/set-local-calibration.sh currently fails if calibration_results/ already exists.

Desired behavior

  • Only when cfg$gms$CES_parameters == "calibrate":
    • If calibration_results/ already exists: do nothing.
    • If calibration_results/ does not exist: automatically run the equivalent of make set-local-calibration (i.e., execute ./scripts/utils/set-local-calibration.sh).
  • The setup should occur early enough in the calibration run that subsequent workflow is ready for collecting calibration outputs.

Implementation details

  1. Update scripts/start/run.R:
    • In the else if (cfg$gms$CES_parameters == "calibrate") branch, before starting iterations, check for presence of calibration_results directory.
    • If missing, invoke ./scripts/utils/set-local-calibration.sh.
    • Handle non-zero exit codes by stopping with a clear error message.
    • Ensure this is only executed for CES calibration runs; do not affect CES_parameters == "load" or other modes.
  2. Add/adjust tests if the repository has test coverage for start scripts:
    • Prefer a unit/integration test in tests/testthat that verifies the call is attempted when the directory is absent, and skipped when present.
    • If running the real shell script is too heavy for tests, mock the system call (e.g., via withr::with_envvar + wrapper function, or refactor into a small helper to allow mocking).
  3. Update documentation (optional but preferred):
    • Update tutorials/12_Calibrating_CES_Parameters.md to mention that local calibration setup is now automatic when running CES calibration, while make set-local-calibration remains available as a manual command.

Acceptance criteria

  • Running a CES calibration with no calibration_results/ directory automatically creates it and sets up the local git/hook structure (same effect as make set-local-calibration).
  • Running a CES calibration when calibration_results/ already exists does not attempt to re-run setup and does not fail.
  • Non-calibration runs are unchanged.
  • CI/tests (if present) pass.

Notes

  • The Makefile target is:
    • set-local-calibration: @./scripts/utils/set-local-calibration.sh
  • The setup script currently appends to .gitignore and initializes a git repo within calibration_results/; this is acceptable behavior per user confirmation.

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI requested a review from lecfab February 23, 2026 13:34
Copilot stopped work on behalf of lecfab due to an error February 23, 2026 13:34
@lecfab lecfab closed this Feb 23, 2026
Copilot stopped work on behalf of lecfab due to an error February 23, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants