Skip to content

Add --debug-log logs for internal model state - #352

Merged
Alomir merged 19 commits into
masterfrom
copilot/create-debug-output-option
Jul 20, 2026
Merged

Add --debug-log logs for internal model state#352
Alomir merged 19 commits into
masterfrom
copilot/create-debug-output-option

Conversation

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Adds a new CLI option to emit per-timestep debug logs for SIPNET internal state. When enabled, the run produces structured envi, fluxes, and trackers logs with headers derived from the current global state structs.

  • CLI and output lifecycle

    • Adds --debug-log <prefix> to configure debug log output with an arbitrary prefix/path.
    • Opens and closes:
      • <prefix>_envi.log
      • <prefix>_fluxes.log
      • <prefix>_trackers.log
    • Keeps existing output behavior unchanged when the option is unset.
  • Per-timestep debug logging

    • Extends model output flow to write one row per timestep to each debug file.
    • All debug logs begin with year day time, matching sipnet.out.
  • Structured field coverage

    • *_envi.log: one column per envi field, using the field name directly.
    • *_fluxes.log: one column per fluxes field, using the field name directly.
    • *_trackers.log: one column per trackers field with t. prefix, plus phenologyTrackers fields with pt. prefix.
  • Config and documentation

    • Registers the new option in context/config handling and CLI help text.
    • Documents the new debug-output behavior in the user guide.
  • Focused coverage

    • Adds an infrastructure test that runs SIPNET with --debug-output, verifies all three files are created, checks representative headers, and confirms row counts match sipnet.out.

Example:

./sipnet -i sipnet.in --debug-log debug/run1

Outputs:

debug/run1_envi.log
debug/run1_fluxes.log
debug/run1_trackers.log

Copilot AI linked an issue Jul 14, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add command-line option for debug output files Add --debug-output logs for internal model state Jul 14, 2026
Copilot AI requested a review from Alomir July 14, 2026 16:39
@Alomir

Alomir commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

@copilot:

  • Please refactor as much new output code as makes sense into two new files, debug_log.h and debug_log.c

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot:

  • Please refactor as much new output code as makes sense into two new files, debug_log.h and debug_log.c

Addressed in 92f1533.

@Alomir

Alomir commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

@copilot Please remove the shouldSkipConfigEntry check and always print DEBUG_OUTPUT_PREFIX in the config dump

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please remove the shouldSkipConfigEntry check and always print DEBUG_OUTPUT_PREFIX in the config dump

Addressed in 97befcd.

@Alomir

Alomir commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

@copilot please rename --debug-output to --debug-log

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please rename --debug-output to --debug-log

Addressed in ce63d03.

@Alomir

Alomir commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

@copilot Please change all new names such as debugOutput and DEBUG_OUTPUT to line up with previous rename of --debug-output to --debug-log. Don't forget the name of the new test file.

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please change all new names such as debugOutput and DEBUG_OUTPUT to line up with previous rename of --debug-output to --debug-log. Don't forget the name of the new test file.

Addressed in ef3a6b6.

@Alomir

Alomir commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

@copilot:

  • debugOutputPrefix never made it into the codebase - don't worry about it for backwards compatibility in src/common/context.c
  • Please add debug_log.c and the new test file to CMakeLists.txt

Copilot AI commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot:

  • debugOutputPrefix never made it into the codebase - don't worry about it for backwards compatibility in src/common/context.c
  • Please add debug_log.c and the new test file to `CMakeL...

Addressed in 546171e.

@Alomir
Alomir marked this pull request as ready for review July 14, 2026 21:02
@Alomir
Alomir requested a review from dlebauer as a code owner July 14, 2026 21:02
Copilot AI review requested due to automatic review settings July 14, 2026 21:02
@Alomir
Alomir requested review from mdietze and mswilburn as code owners July 14, 2026 21:02
@Alomir Alomir changed the title Add --debug-output logs for internal model state Add --debug-log logs for internal model state Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional per-timestep “debug state” logging facility to SIPNET, wiring a new CLI flag through context handling and the model loop to emit additional structured outputs for internal state.

Changes:

  • Adds --debug-log <prefix> CLI support plus DEBUG_LOG_PREFIX context/config plumbing.
  • Introduces src/sipnet/debug_log.{c,h} and integrates header/state row emission into runModelOutput().
  • Adds an infrastructure test and updates smoke expected config dumps/docs to reflect the new context key.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/smoke/russell_3/sipnet.config Updates expected config dump to include DEBUG_LOG_PREFIX.
tests/smoke/russell_2/sipnet.config Updates expected config dump to include DEBUG_LOG_PREFIX.
tests/smoke/russell_1/sipnet.config Updates expected config dump to include DEBUG_LOG_PREFIX.
tests/smoke/niwot/sipnet.config Updates expected config dump to include DEBUG_LOG_PREFIX.
tests/sipnet/test_sipnet_infrastructure/testDebugLogFiles.c Adds infrastructure test verifying debug log creation/headers/row counts.
tests/sipnet/test_sipnet_infrastructure/Makefile Registers the new infrastructure test and cleans its artifacts.
src/sipnet/sipnet.h Extends runModelOutput() API to accept debug log file handles.
src/sipnet/sipnet.c Emits debug headers/rows and initializes/frees debug field arrays.
src/sipnet/frontend.c Initializes/opens/closes debug log files and passes them into the model run.
src/sipnet/debug_log.h Declares debug logging API and DebugLogFiles handles.
src/sipnet/debug_log.c Implements debug logging (headers + per-timestep rows).
src/sipnet/cli.c Adds --debug-log argument parsing and help text.
src/common/context.h Adds debugLogPrefix to the global context struct.
src/common/context.c Registers DEBUG_LOG_PREFIX in context initialization.
Makefile Adds debug_log.c to the build.
docs/user-guide/running-sipnet.md Documents the new debug log feature (but needs key-name correction).
docs/user-guide/model-inputs.md Documents the new option (but had inconsistent formatting).
CMakeLists.txt Adds debug_log.c and the new test to the CLion/IDE build config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sipnet/debug_log.c Outdated
Comment thread src/sipnet/debug_log.c
Comment thread src/sipnet/debug_log.c
Comment thread docs/user-guide/running-sipnet.md Outdated
Comment thread docs/user-guide/model-inputs.md Outdated
Comment thread src/sipnet/cli.c
@Alomir

Alomir commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Note: copilot review comments above are valid, will fix tomorrow

Alomir and others added 4 commits July 20, 2026 11:35
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@Alomir Alomir left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@Alomir
Alomir merged commit dedf28c into master Jul 20, 2026
12 checks passed
@Alomir
Alomir deleted the copilot/create-debug-output-option branch July 20, 2026 16:06
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.

Create option for debug output files

4 participants