Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split setup_and_run in multiple steps #1251

Merged
merged 1 commit into from
Apr 3, 2025
Merged

Split setup_and_run in multiple steps #1251

merged 1 commit into from
Apr 3, 2025

Conversation

Sbozzolo
Copy link
Member

@Sbozzolo Sbozzolo commented Apr 1, 2025

This commit introduces more structure in ClimaEarth. It splits setup_and_run in three functions:

  • setup, which produces a CoupledSimulation (hence, it was renamed to be CoupledSimulation, since it is just a constructor)
  • run!, which runs the simulation. This is supported by the introduction of step!, to take one single coupling step. This is particularly useful in debugging
  • postprocess, to make plots

The advantage of this separation is that one can now construct a simulation without running it, and step a simulation one step at a time. Both of these are particularly useful in interactive work and debugging.

This commit also renames calendar_dt to diag_calendar_dt to make it clearer that it refers to diagnostics.

Summary by CodeRabbit

  • New Features

    • Introduced a modular simulation lifecycle that separates initialization, execution, iterative stepping, and postprocessing.
    • Enhanced simulation output handling now provides clearer performance reporting and robust result validation.
  • Refactor

    • Streamlined the simulation workflow for improved clarity and consistency in diagnostic scheduling and time management.
    • Maintained legacy functionality while transitioning to a more organized and flexible execution approach.
    • Updated variable naming for better clarity regarding diagnostic periods, including the renaming of calendar_dt to diagnostics_dt.

Copy link

coderabbitai bot commented Apr 1, 2025

Warning

Rate limit exceeded

@Sbozzolo has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 53 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fa267f3 and e85cd7b.

📒 Files selected for processing (6)
  • NEWS.md (1 hunks)
  • experiments/ClimaEarth/run_amip.jl (1 hunks)
  • experiments/ClimaEarth/setup_run.jl (9 hunks)
  • experiments/ClimaEarth/user_io/arg_parsing.jl (7 hunks)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl (2 hunks)
  • experiments/ClimaEarth/user_io/postprocessing.jl (2 hunks)

Walkthrough

The changes refactor the simulation lifecycle by splitting the monolithic setup_and_run function into four distinct functions: CoupledSimulation, run!, postprocess, and step!. The refactoring affects both the core module and experiment scripts, updating method signatures, loop logic, and diagnostic routines. Additionally, the variable calendar_dt is renamed to diagnostics_dt across multiple files, and the postprocessing function is modified to streamline parameter handling and adjust the leaderboard plotting criteria.

Changes

File(s) Change Summary
NEWS.md, ClimaCoupler.jl, experiments/ClimaEarth/{run_amip.jl, setup_run.jl} Split the setup_and_run functionality into four functions (CoupledSimulation, run!, postprocess, and step!), replacing legacy simulation calls and updating method signatures and loop logic. The original setup_and_run remains available.
experiments/ClimaEarth/user_io/{arg_parsing.jl, coupler_diagnostics.jl} Renamed the variable calendar_dt to diagnostics_dt consistently in argument parsing and diagnostics functions. Additionally, updated the signature of coupler_diagnostics_setup to include a new coupled_dt parameter.
experiments/ClimaEarth/user_io/postprocessing.jl Modified the postprocess_sim function by simplifying parameter extraction and altering the leaderboard plotting conditions to depend on the presence of the "pfull" variable and simulation time data.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Sbozzolo Sbozzolo force-pushed the gb/step branch 2 times, most recently from faf50f9 to 74e480e Compare April 1, 2025 17:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/Checkpointer.jl (1)

162-164: Improved file handling with do-block syntax

Restructured restart_model_cache! to use a do block with JLD2.jldopen, which ensures proper file closure and improves code readability.

NEWS.md (2)

11-18: Comprehensive documentation of structural changes

The documentation clearly explains how setup_and_run was split into three separate functions with distinct responsibilities, as well as the addition of the new step! function for debugging purposes.

However, there's a minor grammatical issue:

-`setup_and_run` was split in three functions:
+`setup_and_run` was split into three functions:
🧰 Tools
🪛 LanguageTool

[uncategorized] ~11-~11: The preposition “into” seems more likely in this position than the preposition “in”.
Context: ...l/pull/1251) setup_and_run was split in three functions: - CoupledSimulation,...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_INTO)


24-30: Well-documented cleanup changes

The documentation provides a clear bulleted list of cleanup tasks, making it easy to understand the scope of the changes.

However, there's a minor grammatical issue in the second bullet point:

-`SurfaceModelSimulation`s no longer have a `domain` field, which were unused.
+`SurfaceModelSimulation`s no longer have a `domain` field, which was unused.
🧰 Tools
🪛 LanguageTool

[grammar] ~27-~27: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: .... - SurfaceModelSimulations no longer have a domain field, which were unused. - ...

(SINGULAR_NOUN_VERB_AGREEMENT)

🪛 markdownlint-cli2 (0.17.2)

24-24: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be58a17 and 74e480e.

📒 Files selected for processing (32)
  • NEWS.md (2 hunks)
  • docs/src/timemanager.md (0 hunks)
  • experiments/ClimaEarth/components/land/climaland_bucket.jl (2 hunks)
  • experiments/ClimaEarth/components/land/climaland_integrated.jl (3 hunks)
  • experiments/ClimaEarth/components/ocean/eisenman_seaice.jl (2 hunks)
  • experiments/ClimaEarth/components/ocean/prescr_ocean.jl (3 hunks)
  • experiments/ClimaEarth/components/ocean/prescr_seaice.jl (6 hunks)
  • experiments/ClimaEarth/components/ocean/slab_ocean.jl (2 hunks)
  • experiments/ClimaEarth/components/shared/restore.jl (1 hunks)
  • experiments/ClimaEarth/run_amip.jl (1 hunks)
  • experiments/ClimaEarth/run_cloudless_aquaplanet.jl (4 hunks)
  • experiments/ClimaEarth/run_cloudy_aquaplanet.jl (4 hunks)
  • experiments/ClimaEarth/run_cloudy_slabplanet.jl (6 hunks)
  • experiments/ClimaEarth/run_dry_held_suarez.jl (2 hunks)
  • experiments/ClimaEarth/run_moist_held_suarez.jl (4 hunks)
  • experiments/ClimaEarth/setup_run.jl (14 hunks)
  • experiments/ClimaEarth/test/component_model_tests/prescr_ocean_tests.jl (2 hunks)
  • experiments/ClimaEarth/test/component_model_tests/prescr_seaice_tests.jl (1 hunks)
  • experiments/ClimaEarth/test/component_model_tests/slab_ocean_tests.jl (1 hunks)
  • experiments/ClimaEarth/test/debug_plots_tests.jl (1 hunks)
  • experiments/ClimaEarth/user_io/arg_parsing.jl (7 hunks)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl (2 hunks)
  • experiments/ClimaEarth/user_io/postprocessing.jl (2 hunks)
  • src/Checkpointer.jl (4 hunks)
  • src/Interfacer.jl (5 hunks)
  • src/TimeManager.jl (1 hunks)
  • test/conservation_checker_tests.jl (3 hunks)
  • test/field_exchanger_tests.jl (1 hunks)
  • test/flux_calculator_tests.jl (6 hunks)
  • test/interfacer_tests.jl (3 hunks)
  • test/runtests.jl (0 hunks)
  • test/time_manager_tests.jl (0 hunks)
💤 Files with no reviewable changes (3)
  • test/runtests.jl
  • docs/src/timemanager.md
  • test/time_manager_tests.jl
🧰 Additional context used
🪛 LanguageTool
NEWS.md

[uncategorized] ~11-~11: The preposition “into” seems more likely in this position than the preposition “in”.
Context: ...l/pull/1251) setup_and_run was split in three functions: - CoupledSimulation,...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_INTO)


[grammar] ~27-~27: There seems to be a noun/verb agreement error. Did you mean “has” or “had”?
Context: .... - SurfaceModelSimulations no longer have a domain field, which were unused. - ...

(SINGULAR_NOUN_VERB_AGREEMENT)

🪛 markdownlint-cli2 (0.17.2)
NEWS.md

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


24-24: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


32-32: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: ci 1.11 - windows-latest
  • GitHub Check: ci 1.11 - ubuntu-latest
  • GitHub Check: ci 1.10 - windows-latest
  • GitHub Check: ci 1.10 - macOS-latest
  • GitHub Check: ci 1.10 - ubuntu-latest
  • GitHub Check: test (1.11)
  • GitHub Check: docbuild
🔇 Additional comments (110)
experiments/ClimaEarth/test/debug_plots_tests.jl (1)

78-79: Time step tracking parameter added to support new simulation lifecycle.

Adding Ref(Int(0)) as the time step parameter aligns with the PR objective of splitting setup_and_run. This parameter enables tracking the current simulation step, which is essential for the new step! function that allows executing a single coupling step at a time.

experiments/ClimaEarth/test/component_model_tests/prescr_seaice_tests.jl (1)

103-103: Constructor signature simplified by removing redundant domain parameter.

The removal of the second nothing parameter simplifies the PrescribedIceSimulation constructor, aligning with the PR's objective to enhance the structure of ClimaEarth. This change corresponds with the simplification of the underlying structure where the domain::D field was removed.

experiments/ClimaEarth/test/component_model_tests/prescr_ocean_tests.jl (1)

21-21: Renaming date0 to start_date for improved clarity.

This renaming standardizes date variable naming across the codebase, making the code more readable and consistent. The change has been applied consistently at declaration, constructor call, and when used as a reference date parameter.

Also applies to: 28-28, 45-45

test/field_exchanger_tests.jl (1)

158-158: Time step tracking parameter added to support new simulation lifecycle.

Adding Ref(Int(0)) as the time step parameter aligns with the PR objective of splitting setup_and_run. This parameter enables tracking the current simulation step, which is essential for the new step! function that allows executing a single coupling step at a time.

experiments/ClimaEarth/components/shared/restore.jl (1)

78-78: Improved error message detail in restore! method

The error message has been enhanced to show the actual values that caused the inconsistency, which makes debugging easier when immutable values don't match.

experiments/ClimaEarth/user_io/coupler_diagnostics.jl (4)

6-6: Updated function documentation to reflect parameter change

The documentation string now correctly references diag_calendar_dt instead of calendar_dt, which aligns with the new parameter name in the function signature.


14-14: Added coupled_dt parameter to function signature

This change to coupler_diagnostics_setup adds a new parameter coupled_dt which enables passing the simulation time step to the diagnostics setup. This supports the refactoring goal of better separation between simulation setup and execution.


17-17: Updated parameter name from calendar_dt to diag_calendar_dt

The parameter has been renamed to more clearly indicate its purpose for diagnostics scheduling.


51-51: Passed coupled_dt to diagnostics handler

The coupled_dt parameter is now used when creating the diagnostics handler, ensuring proper time step configuration for diagnostics. This change is part of improving the separation between setup and running phases.

experiments/ClimaEarth/test/component_model_tests/slab_ocean_tests.jl (1)

24-24: Simplified SlabOceanSimulation instantiation

The constructor call has been simplified by removing the second argument (previously nothing). This change aligns with the broader refactoring to improve the simulation object's interface.

experiments/ClimaEarth/run_amip.jl (2)

46-48: Replaced setup_and_run with separated CoupledSimulation and run! calls

This change implements the core refactoring goal of splitting the simulation setup from its execution. Now users can create a simulation object without immediately running it, which enables more interactive workflows and better debugging capabilities.


49-52: Added explicit postprocessing step

The postprocessing has been separated into its own function call, completing the three-part workflow (setup → run → postprocess) outlined in the PR objectives. The retrieval of the conservation_softfail parameter shows proper integration with the existing configuration system.

The TODO comment about removing the conservation_softfail option suggests this may be refactored further in future updates.

experiments/ClimaEarth/components/ocean/prescr_ocean.jl (3)

37-37: Parameter renaming looks good

The parameter name change from date0 to start_date in the documentation is consistent with the broader refactoring effort to improve naming clarity.


54-54: Consistent parameter renaming in function signature

The parameter name change from date0 to start_date in the function signature matches the documentation update above, maintaining consistency.


80-80: Properly updated reference in TimeVaryingInput initialization

The reference to start_date in the SST_timevaryinginput creation correctly uses the renamed parameter, ensuring consistent date handling.

test/interfacer_tests.jl (3)

4-6: Added necessary imports

The added imports for ClimaComms and Dates along with the conditional backend import are necessary for the updated functionality.


31-31: Simplified get_field implementation

The function implementation has been simplified to directly return CC.Spaces.undertype(sim.space)(2) rather than calculating the float type based on the mesh domain.


43-43: Added time tracking parameter to CoupledSimulation

The addition of Ref(Int(0)) as the time tracking parameter to the CoupledSimulation constructor is consistent with the PR's objective of splitting the setup_and_run function and enabling step-by-step simulation execution.

src/Checkpointer.jl (3)

11-11: Optimized imports

The import statement has been refined to only import the specific needed functions ITime and seconds from ClimaUtilities.TimeManager.


103-103: Updated time calculation

Time calculation now uses cs.t[] directly instead of computing from two epoch timestamps. This simplification aligns with the new structure where time is tracked via a reference.


192-198: Improved file handling consistency

Similar to the above change, restart_coupler_fields! now uses a do block with JLD2.jldopen for better resource management and consistent style.

experiments/ClimaEarth/user_io/arg_parsing.jl (6)

71-71: Renamed date parameter for clarity

Parameter name change from date0 to start_date improves code clarity by using a more descriptive name.


75-77: Updated ITime initialization with start_date

All uses of date0 in the ITime constructor have been replaced with start_date, maintaining consistency with the parameter renaming.


102-102: Renamed calendar_dt to diag_calendar_dt for specificity

The variable renaming from calendar_dt to diag_calendar_dt makes its purpose clearer - it specifically relates to diagnostics rather than general calendar handling.

Also applies to: 137-137


198-211: Consistent variable renaming throughout get_diag_period

All instances of calendar_dt have been renamed to diag_calendar_dt within the function, maintaining consistency with the broader renaming pattern.


212-212: Updated return value to match renamed variable

Return statement correctly uses the renamed diag_calendar_dt variable.


286-286: Consistent variable naming in add_extra_diagnostics!

All occurrences of the diagnostic calendar variable now use the more specific name diag_calendar_dt for better clarity.

Also applies to: 289-289, 299-299

src/Interfacer.jl (5)

11-11: Updated imports to support new time handling.

The imports have been updated to include Dates and specifically import ITime and date from ClimaUtilities.TimeManager. These changes support the new time management approach in the CoupledSimulation struct.

Also applies to: 14-14


59-59: Improved time management in CoupledSimulation struct.

The struct has been updated with:

  1. A new type parameter TT for time tracking
  2. Renaming dates::D to start_date::D for clarity
  3. Adding a new field t::TT to track the current simulation time

These changes provide better time tracking capabilities and make the time-related fields more explicit and easier to understand.

Also applies to: 68-69, 74-74


83-83: Simplified the CoupledSimulation constructor.

The constructor has been simplified to use type inference from the arguments. This is a good improvement that reduces boilerplate code while maintaining type safety.


92-92: Updated display of current date in Base.show.

The method now uses current_date(sim) instead of directly accessing date fields, providing a more consistent API for retrieving the current simulation date.


96-104: Added new current_date function for improved time handling.

This function centralizes the logic for retrieving the current date of the simulation, handling both ITime and other time types appropriately. This is a nice improvement for API consistency and makes the code more maintainable.

src/TimeManager.jl (1)

68-74: Simplified callback triggering with improved time access.

The maybe_trigger_callback function has been simplified by removing the explicit t parameter. It now retrieves the time directly from the simulation object using t = cs.t[]. This change makes the function more straightforward and aligns with the new time management approach in CoupledSimulation.

experiments/ClimaEarth/user_io/postprocessing.jl (2)

15-15: Simplified variable extraction from postprocessing_vars.

The function now only extracts the essential conservation_softfail parameter, removing unnecessary extraction of output_default_diagnostics and t_end. This simplification reduces coupling between the components.


32-39: Enhanced leaderboard plotting with data-driven approach.

The leaderboard plotting logic has been improved to:

  1. Check for the availability of "pfull" in the simulation directory
  2. Extract time information from the simulation directory itself
  3. Use the actual end time to determine if enough data is available for the leaderboard

This data-driven approach is more robust as it relies on the actual simulation data rather than passed parameters.

experiments/ClimaEarth/components/land/climaland_integrated.jl (2)

15-15: Streamlined ClimaLandSimulation struct by removing domain dependency.

The D type parameter has been removed from the struct definition, simplifying the type signature. This change reduces coupling between the simulation and specific domain implementations, making the code more flexible.

Also applies to: 27-28


203-203: Simplified ClimaLandSimulation constructor return.

The constructor no longer includes the domain in the return statement, aligning with the struct changes. This is part of the broader effort to reduce domain dependencies across simulation structures.

experiments/ClimaEarth/components/ocean/slab_ocean.jl (3)

10-10: Structure signature updated for better design

The structure signature has been simplified by removing the domain type parameter D, aligning with other simulation types in the codebase. This change follows the PR's goal of streamlining domain management across simulation objects.


17-17: Structure declaration properly updated

The structure declaration correctly implements the signature change, removing the D type parameter while maintaining the inheritance relationship with Interfacer.OceanModelSimulation.


101-101: Constructor call updated correctly

The constructor call has been properly updated to remove the space parameter, aligning with the removal of the domain field from the structure. This maintains consistency with the new simplified design.

experiments/ClimaEarth/run_moist_held_suarez.jl (5)

222-223: Start date handling simplified

The date0 variable has been removed and replaced with direct usage of start_date, simplifying the date management. This is part of the PR's goal to enhance clarity in time-related data management.


228-228: Schedule checkpoint initialization streamlined

The schedule_checkpoint now directly references start_date instead of date0, creating a more direct and streamlined approach to checkpoint scheduling.


248-249: CoupledSimulation construction improved

The constructor now uses Ref(start_date) instead of a dates dictionary and adds a reference to the current simulation time with Ref(tspan[1]). This change follows the PR's goal of enhancing the clarity of time management by using a more direct reference.

Also applies to: 254-254


311-312: Time update mechanism simplified

The mechanism for updating the current time has been changed from updating a date structure (cs.dates.date[]) to a more straightforward time representation (cs.t[] = t). This aligns with the PR's goal of simplifying time management.


329-329: Callback trigger updated for new time management

The callback trigger has been updated to not pass the time parameter t, reflecting the change in how time is managed internally in the CoupledSimulation object.

experiments/ClimaEarth/run_dry_held_suarez.jl (5)

185-186: Start date handling simplified

Similar to the changes in run_moist_held_suarez.jl, the date0 variable has been removed and replaced with direct usage of start_date, simplifying the date management.


191-191: Schedule checkpoint initialization streamlined

The schedule_checkpoint now directly references start_date instead of date0, creating a more direct and streamlined approach to checkpoint scheduling.


198-198: CoupledSimulation construction improved

The constructor now uses Ref(start_date) instead of a dates dictionary and adds a reference to the current simulation time with Ref(tspan[1]). This matches the changes made in run_moist_held_suarez.jl for consistency.

Also applies to: 204-204


237-238: Time update mechanism simplified

The mechanism for updating the current time has been changed from updating a date structure to a more straightforward time representation (cs.t[] = t). This aligns with the PR's goal of simplifying time management.


246-246: Callback trigger updated for new time management

The callback trigger has been updated to not pass the time parameter t, reflecting the change in how time is managed internally in the CoupledSimulation object.

NEWS.md (2)

9-9: Clear PR reference in heading

The heading properly references the PR number and title, making it easy to track the changes back to their source.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


21-22: Clear explanation of variable renaming

The documentation clearly explains the renaming of calendar_dt to diag_calendar_dt, providing the reasoning behind the change - to make it clearer that it refers to diagnostics.

test/flux_calculator_tests.jl (7)

66-69: Type parameter simplification looks good

Good refactoring to remove the domain type parameter D and field from TestOcean. This simplifies the type definition and aligns with the PR goal of making the component structure more modular.


96-99: Type parameter simplification looks good

Good refactoring to remove the domain type parameter D and field from DummySurfaceSimulation3. This is consistent with the changes made to other simulation structures.


193-193: Constructor update correctly reflects type changes

Good update to the TestOcean constructor call to reflect the removal of the domain field, passing only the necessary parameters.


196-196: Consistent constructor call update

This change correctly matches the updated type structure for TestOcean.


272-272: Constructor update correctly reflects type changes

The constructor call for DummySurfaceSimulation3 has been properly updated to reflect the type parameter changes.


283-284: Constructor parameter structure updated correctly

Updated initialization of surface_sim correctly reflects the removal of the domain parameter from DummySurfaceSimulation3.


305-305: Using Ref for time tracking

Good change to use Ref(Int(0)) for time tracking, which aligns with the modular approach in the PR. This facilitates easier state management in the split simulation workflow.

experiments/ClimaEarth/components/ocean/eisenman_seaice.jl (3)

10-11: Updated docstring correctly documents type parameters

Good update to the docstring to reflect the removal of the domain type parameter, maintaining consistency between code and documentation.


18-21: Type simplification consistent with PR objectives

The removal of the domain type parameter and field from EisenmanIceSimulation is consistent with the changes made to other simulation structures, supporting the PR's goal of creating a more modular codebase.


89-89: Constructor call updated correctly

The constructor call for EisenmanIceSimulation has been properly updated to remove the domain parameter, reflecting the structural changes to the type.

experiments/ClimaEarth/run_cloudless_aquaplanet.jl (7)

216-217: Simplified date handling

Good simplification of date handling by directly initializing start_date as a DateTime object instead of using an intermediate date0 variable. This improves code clarity.


222-223: Schedule parameter update

Correctly updated schedule_checkpoint to use the simplified date handling approach, passing start_date directly to the schedule constructor.


225-226: Schedule parameter update

Correctly updated schedule_albedo to use the simplified date handling approach, consistent with the changes to schedule_checkpoint.


249-250: CoupledSimulation structure updated for improved state management

Good update to the CoupledSimulation structure using Ref(start_date) for date tracking and Ref(tspan[1]) for time tracking. This approach allows for better state management in the modular simulation workflow.

Also applies to: 255-256


312-314: Simplified time tracking

Good simplification of time tracking by directly updating cs.t[] instead of using a more complex date structure. This change makes the code more straightforward and easier to understand.


318-319: Simplified callback trigger

Updated the water albedo callback trigger to rely solely on the cs object without requiring the time parameter, which streamlines the callback interface.


333-334: Simplified callback trigger

Updated the checkpoint callback trigger to use the simplified interface, consistent with the water albedo callback changes.

experiments/ClimaEarth/run_cloudy_aquaplanet.jl (6)

235-236: Simplified date handling

Good simplification of date handling by directly initializing start_date as a DateTime object. This change is consistent with the modifications in other files and improves code clarity.


241-242: Schedule parameter update

Correctly updated schedule_checkpoint to use the simplified date handling approach, passing start_date directly to the schedule constructor.


244-245: Schedule parameter update

Correctly updated schedule_albedo to use the simplified date handling approach, consistent with the changes to schedule_checkpoint.


267-268: CoupledSimulation structure updated for improved state management

Good update to the CoupledSimulation structure using Ref(start_date) for date tracking and Ref(tspan[1]) for time tracking. This approach allows for better state management in the modular simulation workflow.

Also applies to: 273-274


330-331: Simplified time tracking

Good simplification of time tracking by directly updating cs.t[] instead of using a more complex date structure. This change makes the code more straightforward and easier to understand.


348-349: Simplified callback trigger

Updated the checkpoint callback trigger to use the simplified interface, which streamlines the callback system.

experiments/ClimaEarth/components/ocean/prescr_seaice.jl (6)

14-14: Docstring reflects updated type parameters.
It now denotes {P, I} instead of {P, D, I}. Make sure the docstring elsewhere clarifies that the domain parameter was removed for simplicity.


66-66: start_date parameter added to constructor.
This aligns with the broader transition from date0 to start_date. Looks good.


88-88: Repeated addition of start_date parameter.
Consistent with the removal of date0 usage. No issues found.


108-108: Setting reference_date to start_date.
The re-labeled argument enhances clarity and consistency. Good change.


148-148: Constructor call updated to reflect the new signature.
The removal of the domain argument here matches the struct changes. Implementation is correct.


30-30:

❓ Verification inconclusive

Struct simplified by removing the domain parameter.
Removing D from the type signature is consistent with the refactoring. Ensure all references to the previous D type are removed or updated across the codebase.

Run the following script to confirm no references to a domain field remain:


🏁 Script executed:

#!/bin/bash
ast-grep --pattern $'struct PrescribedIceSimulation { domain: $_, $$$ }'

Length of output: 73


Below is an additional check to further verify that no leftover references to a domain: field exist. Please run the following script to search all Julia files for any mention of “domain:”:

Once you confirm that this search returns no results, you can be assured that all remnants of the removed D domain parameter have been successfully eliminated. Here’s the final rewritten review comment:


Refactoring Verified: Confirm Removal of domain References

The struct in experiments/ClimaEarth/components/ocean/prescr_seaice.jl has been simplified by removing the domain parameter (previously part of the type signature as D). This change is consistent with the intended refactoring. However, please be sure to manually verify that there are no leftover references to a domain field anywhere in the codebase (for example, by running the provided rg command).


🏁 Script executed:

#!/bin/bash
rg "domain:" -n --glob "*.jl"

Length of output: 347


Refactoring Verification: Mixed domain References Detected

In experiments/ClimaEarth/components/ocean/prescr_seaice.jl the struct definition has been simplified by removing the D (domain) type parameter as expected. However, a subsequent search uncovered that some files still include references to domain::D:

  • test/flux_calculator_tests.jl:31
  • experiments/ClimaEarth/components/atmosphere/climaatmos.jl:31

Please review these instances to confirm whether they are meant to remain or if they require updating for consistency with the refactoring.

experiments/ClimaEarth/setup_run.jl (17)

38-38: New import of CoupledSimulation.
Brings the newly refactored type into scope. No issues.


66-66: Added start_date to function parameters.
Ensures the function can properly handle the new date-based logic. Looks fine.


86-93: Refactored docstring and convenience constructor.

  1. Docstring is updated to highlight the new usage of CoupledSimulation(config_file)/CoupledSimulation(config_dict).
  2. The actual function that takes config_file now delegates to the config_dict version.

Everything is coherent.


96-97: CoupledSimulation(config_dict::AbstractDict) definition.
Creating a dedicated function for direct dictionary input is a good modular approach.


115-115: Insertion of start_date in argument destructuring.
Part of the global rename from date0 to start_date. This matches the updated code style.


123-132: Additional parameters: diag_calendar_dt, evolving_ocean, use_coupler_diagnostics, output_dir_root.
These expansions align with the more flexible configuration approach. Watch for consistent usage in downstream logic.


302-302: Passing start_date to PrescribedOceanSimulation.
Ensures the ocean simulation can align with the simulation’s initial date. Correct usage.


516-518: Constructing a CoupledSimulation with Ref(start_date).
Storing start_date in a Ref can help avoid copying in closure contexts. Valid design choice.


524-524: Ref(tspan[1])
Similarly placing tspan[1] into a Ref. Maintains consistency for time references. No concerns.


599-600: Return statement for CoupledSimulation.
Neatly terminates the setup function. Looks good.


602-618: Refined docstring and early steps for run!(cs::CoupledSimulation).
These lines detail the function’s purpose and precompilation steps. The guard for 2-step precompilation is a good performance measure.


630-635: While-loop replaced with a cs.t[] <= cs.tspan[end] condition.
Clearly expresses the time-based iteration. Straightforward approach.


638-644: Logging simulation time metrics.
Sensible approach to measure performance. The SYPD logic is consistent with typical climate-model reporting.


649-650: Writing SYPD result to sypd.txt.
Straightforward I/O with correct usage of open. No issues.


654-654: Writing walltime_per_atmos_step.
Same approach as above. No concerns.


658-658: Storing CPU memory usage.
Ensures resource usage is tracked. Fine approach.


664-668: Closing all diagnostics gracefully before returning.
Good housekeeping step. No issues.

experiments/ClimaEarth/run_cloudy_slabplanet.jl (5)

175-176: Replacing date0 with start_date.
Incorporating a DateTime object is consistent with the new approach.


279-279: Using start_date in the checkpoint schedule.
References the updated schedule approach. This is consistent with the new naming convention.


282-282: Using start_date in the albedo schedule.
Mirrors the checkpoint logic. Looks good.


367-367: cs.t[] = t
Direct assignment to track current time in the coupler. Straightforward approach.


371-371: Invoking TimeManager.maybe_trigger_callback with cs.
Uses the new function signature. Ensures albedo updates happen at the correct times.

experiments/ClimaEarth/components/land/climaland_bucket.jl (3)

21-22: Documentation updated to reflect removed domain type parameter

The documentation has been correctly updated to reflect the simplified type signature of BucketSimulation after removing the domain type parameter.


31-39: Streamlined struct definition by removing domain dependency

The BucketSimulation struct has been appropriately simplified by removing the domain type parameter and field, aligning with the PR's goal of making the simulation object more modular. This change is consistent with the broader restructuring that enables constructing a simulation without immediately executing it.


236-236: Constructor return simplified to match updated struct

The constructor return statement now correctly omits the domain parameter, matching the simplified struct definition. This completes the domain removal refactoring, making the simulation object more focused on the model, integrator, and area fraction.

test/conservation_checker_tests.jl (4)

23-24: Cleaner field implementation for TestAtmos

The field implementations have been improved:

  • Water field now uses the simpler ones(s.i.space) instead of redundant multiplication
  • Energy field properly uses space-consistent type with CC.Spaces.undertype(s.i.space)(1e6)

These changes improve code clarity and ensure type consistency.


30-32: Improved TestOcean field implementations

The TestOcean field implementations are now more efficient and type-safe:

  • Water field uses explicit zeros instead of ones .* 0
  • Energy and area_fraction fields properly use the underlying space type with CC.Spaces.undertype

These changes ensure consistent numeric types and cleaner code.


38-40: Cleaned up TestLand field implementations

The TestLand field implementations have been improved for clarity and type consistency:

  • Energy and water fields now use explicit zeros instead of ones .* 0
  • Area fraction properly uses space-consistent type with CC.Spaces.undertype

These changes improve code clarity and numerical stability.


79-79: Time tracking added to CoupledSimulation

A time reference parameter has been added to the CoupledSimulation constructor, enabling explicit time tracking. This is an essential change that supports the PR's goal of splitting setup_and_run into separate functions (setup, run!, and postprocess), allowing users to construct a simulation without immediately executing it.

Also applies to: 159-159

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
NEWS.md (1)

11-11: Minor grammar fix needed

Change "was split in three functions" to "was split into three functions" for correct preposition usage.

-`setup_and_run` was split in three functions:
+`setup_and_run` was split into three functions:
🧰 Tools
🪛 LanguageTool

[uncategorized] ~11-~11: The preposition “into” seems more likely in this position than the preposition “in”.
Context: ...l/pull/1251) setup_and_run was split in three functions: - CoupledSimulation,...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_INTO)

experiments/ClimaEarth/user_io/coupler_diagnostics.jl (1)

6-6: Update function signature documentation

The documentation should include the new coupled_dt parameter that was added to the function signature.

-    coupler_diagnostics_setup(fields, output_dir, start_date, t_start, diag_calendar_dt)
+    coupler_diagnostics_setup(fields, output_dir, start_date, t_start, diag_calendar_dt, coupled_dt)
experiments/ClimaEarth/setup_run.jl (1)

670-690: Improve documentation for postprocess function

Unlike other functions, postprocess lacks a documented signature and description. Consider adding a documentation string to maintain consistency with the other functions.

+"""
+    postprocess(cs, conservation_softfail)
+
+Process the results after a simulation has completed, including generating
+plots, checking conservation, and other diagnostics.
+"""
 function postprocess(cs, conservation_softfail)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74e480e and 148b2d1.

📒 Files selected for processing (6)
  • NEWS.md (1 hunks)
  • experiments/ClimaEarth/run_amip.jl (1 hunks)
  • experiments/ClimaEarth/setup_run.jl (8 hunks)
  • experiments/ClimaEarth/user_io/arg_parsing.jl (6 hunks)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl (2 hunks)
  • experiments/ClimaEarth/user_io/postprocessing.jl (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • experiments/ClimaEarth/user_io/postprocessing.jl
  • experiments/ClimaEarth/user_io/arg_parsing.jl
🧰 Additional context used
🪛 LanguageTool
NEWS.md

[uncategorized] ~11-~11: The preposition “into” seems more likely in this position than the preposition “in”.
Context: ...l/pull/1251) setup_and_run was split in three functions: - CoupledSimulation,...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_INTO)

🪛 markdownlint-cli2 (0.17.2)
NEWS.md

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: ci 1.11 - windows-latest
  • GitHub Check: ci 1.11 - macOS-latest
  • GitHub Check: ci 1.11 - ubuntu-latest
  • GitHub Check: ci 1.10 - windows-latest
  • GitHub Check: ci 1.10 - macOS-latest
  • GitHub Check: ci 1.10 - ubuntu-latest
🔇 Additional comments (11)
NEWS.md (1)

9-22: Good documentation for the new functionality

The PR documentation clearly explains the split of setup_and_run into multiple functions and the renaming of calendar_dt to diag_calendar_dt, which will help users understand the changes.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~11-~11: The preposition “into” seems more likely in this position than the preposition “in”.
Context: ...l/pull/1251) setup_and_run was split in three functions: - CoupledSimulation,...

(AI_EN_LECTOR_REPLACEMENT_PREPOSITION_IN_INTO)

🪛 markdownlint-cli2 (0.17.2)

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

experiments/ClimaEarth/user_io/coupler_diagnostics.jl (3)

14-14: Correctly updated function signature

Function signature has been properly updated to reflect the parameter rename from calendar_dt to diag_calendar_dt and to add the new coupled_dt parameter.


17-17: Correctly updated variable usage

Variable reference has been properly updated to use diag_calendar_dt instead of calendar_dt.


51-51: Properly added the new parameter to handler creation

The dt = coupled_dt parameter is now correctly passed to the DiagnosticsHandler constructor.

experiments/ClimaEarth/run_amip.jl (2)

46-52: Successfully refactored to use the new simulation execution flow

The code has been properly refactored to use the new execution flow, separating simulation setup, running, and postprocessing into distinct steps:

  1. Creating the simulation with CoupledSimulation
  2. Running the simulation with run!
  3. Postprocessing with postprocess

This enhances clarity and modularity, allowing users more flexibility in how they execute simulations.


50-51: Consider addressing the TODO comment

There's a TODO comment about potentially removing the conservation_softfail option. It would be beneficial to create a follow-up issue to track this if it isn't addressed in this PR.

Consider creating a GitHub issue to track the potential removal of the conservation_softfail option.

experiments/ClimaEarth/setup_run.jl (5)

86-94: Well-documented constructor function

The new CoupledSimulation constructor functions are well-documented, clearly explaining their purpose and functionality.


97-600: Successfully implemented CoupledSimulation constructor

The implementation of the CoupledSimulation constructor effectively encapsulates all the setup logic that was previously in setup_and_run. The code is well-structured and maintains all the necessary initialization steps for the coupled simulation.


602-668: Well-implemented run! function with timing and diagnostics

The run! function effectively handles:

  1. Optional precompilation for more accurate timing
  2. Execution of simulation steps within the time span
  3. Performance metrics (SYPD, walltime per step)
  4. Proper resource cleanup (diagnostic writers)

This separation of execution logic from setup improves code organization and maintainability.


692-710: Successfully updated setup_and_run for backward compatibility

The setup_and_run function has been updated to use the new structure while maintaining backward compatibility, which is excellent for existing code that uses this function.


712-776: Well-implemented step! function

The step! function successfully encapsulates all the logic for a single coupling step, allowing for more fine-grained control over simulation execution, which is particularly valuable for debugging.

@Sbozzolo Sbozzolo force-pushed the gb/step branch 2 times, most recently from f208714 to f2e7019 Compare April 3, 2025 18:30
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (10)
NEWS.md (3)

9-10: Use setext heading for consistency with the rest of the document.
The code uses an atx heading (###) here, whereas markdownlint recommends setext style.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


16-17: Clarify usage context for step!.
Consider adding a brief note about how step! is typically called (e.g., debugging, partial progress). This can guide users reading release notes.


19-19: Consider marking setup_and_run as deprecated for future releases.
If the new set of functions is preferred, you may want to officially deprecate setup_and_run to direct users toward CoupledSimulation(...) + run!.

experiments/ClimaEarth/user_io/postprocessing.jl (2)

15-15: Consider logging all extracted postprocessing variables for transparency.
Currently, only conservation_softfail is captured from postprocessing_vars. If others are present, logging or verifying them could help diagnose missing parameters.


31-39: Use a more robust check for generating the leaderboard.
The logic currently hinges on the presence of "pfull" and a 3-month threshold. If other variables or conditions are needed in future, consider making them configurable or using a more flexible approach.

experiments/ClimaEarth/setup_run.jl (5)

85-93: Docstring for CoupledSimulation constructor.
This is a concise introduction. Consider adding a short example usage snippet to guide users.


495-502: Coupler diagnostics setup.
This block is straightforward. If these diagnostics can fail silently when misconfigured, consider implementing validation for required parameters.


615-618: Precompilation step.
Nice practice for performance. If precompilation overhead is significant, consider making it more configurable (e.g., user toggles).


630-669: Coupling loop logic.
Overall logic is clear. Consider adding partial-progress checkpoints or logging if the run is long.


722-723: Docstring for step!.
Brief but effective. A usage example snippet would further illustrate typical calls.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 148b2d1 and f2e7019.

📒 Files selected for processing (6)
  • NEWS.md (1 hunks)
  • experiments/ClimaEarth/run_amip.jl (1 hunks)
  • experiments/ClimaEarth/setup_run.jl (8 hunks)
  • experiments/ClimaEarth/user_io/arg_parsing.jl (6 hunks)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl (2 hunks)
  • experiments/ClimaEarth/user_io/postprocessing.jl (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl
  • experiments/ClimaEarth/run_amip.jl
  • experiments/ClimaEarth/user_io/arg_parsing.jl
🧰 Additional context used
📓 Path-based instructions (1)
`*`: # CodeRabbit Style Guide (CliMA Inspired)

Leverage CodeRabbit for code reviews aligning with CliMA's practices.

I. Key Areas for CodeRabbit:

  • Style: Naming (Titl...

*: # CodeRabbit Style Guide (CliMA Inspired)

Leverage CodeRabbit for code reviews aligning with CliMA's practices.

I. Key Areas for CodeRabbit:

  • Style: Naming (TitleCase, lowercase_with_underscores), line length (<78), indentation (4 spaces), import order.
  • DRY: Flag duplicated code; encourage modularization.
  • Docstrings: Flag missing docstrings for modules, structs, functions.
  • Tests: Detect missing unit tests (if configured).
  • Complexity: Report on cyclomatic complexity.

II. Conventions (CodeRabbit Can Help):

  • Naming: Follow CliMA/CMIP conventions. Avoid l, O, I as single-char vars.
  • Unicode: Human review needed. Acceptable chars.

III. Documentation (CodeRabbit Flags Deficiencies):

  • Docstrings: Describe purpose, inputs, outputs, examples.

IV. Testing (CodeRabbit: Missing Tests):

  • Unit tests required for new/modified code.

V. CodeRabbit Config:

  • .coderabbit.yaml: Customize language, line length, tests.

VI. Workflow:

  • Review CodeRabbit's suggestions; investigate, provide context, address issues, improve config.

VII. Abandoned Code: Delete or clearly mark as deprecated.

VIII. Reviewer Responsibilities: Ensure adherence to best practices.

  • NEWS.md
🪛 markdownlint-cli2 (0.17.2)
NEWS.md

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: ci 1.11 - windows-latest
  • GitHub Check: ci 1.11 - macOS-latest
  • GitHub Check: ci 1.11 - ubuntu-latest
  • GitHub Check: ci 1.10 - windows-latest
  • GitHub Check: ci 1.10 - macOS-latest
  • GitHub Check: ci 1.10 - ubuntu-latest
🔇 Additional comments (9)
NEWS.md (2)

11-14: Good summary of the newly separated functions.
The bullet points read clearly, reflecting the new modular approach. No further issues observed.


21-23: Rename from calendar_dt to diag_calendar_dt is clear and consistent.
No issues found. The improved naming clarifies this parameter's usage.

experiments/ClimaEarth/setup_run.jl (7)

38-38: New import for CoupledSimulation.
This addition clarifies the usage of the new constructor. No issues spotted.


123-132: Ensure clarity of newly added parameters.
Properties like diag_calendar_dt and use_coupler_diagnostics are newly exposed. Verify that default values or usage instructions are documented so users clearly understand them.


516-516: Initialization of cs = CoupledSimulation{FT}.
The approach of parameterizing on FT for floating types is consistent with broader Clima practices.


599-600: Return and finalize the constructor.
Everything appears cohesive. Just ensure that any post-initialization tasks are handled correctly before returning cs.


602-614: Docstring and signature for run!.
This clarifies the new run workflow. Good usage of docstring headings.


671-699: postprocess function.
The layering of logic into a separate call within run_amip.jl or other scripts is a good approach for modularity. Looks good.


702-720: setup_and_run function expansions.
These changes unify the approach for config-based or direct dictionary-based setups, which is helpful. No major concerns.

run!(cs)

# Postprocessing
# TODO: Remove this option?
Copy link
Member

Choose a reason for hiding this comment

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

We can remove it, but let's do it in a separate PR so we can get this one in today. conservation_softfail is used for 3 regular CI runs, and some longruns. The longruns are mostly soft fails anyway, and if any regular CI slabplanets fail conservation we can make them soft fail in the pipeline, which will increase visibility of which ones fail conservation rather than hiding it away with this argument.

@Sbozzolo Sbozzolo force-pushed the gb/step branch 2 times, most recently from 7bc7649 to 596b2fb Compare April 3, 2025 20:23
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
NEWS.md (2)

9-10: Use setext headings to satisfy markdownlint.

The static analysis tool warns that a setext heading style is expected here. Consider switching from the “atx” style (###) to a setext heading (underlined with dashes) for consistency.

-### Split `setup_and_run` in multiple functions. PR[#1251](...)
+Split `setup_and_run` in multiple functions. PR[#1251](...)
+----------------------------------------------------------
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)


11-14: Clarify reference to four functions instead of three.

Here, the text says "split into three functions" but then also mentions the newly introduced step!. Consider updating it to avoid confusion (it's effectively four functions now).

-`setup_and_run` was split into three functions:
+`setup_and_run` was split into four functions:
experiments/ClimaEarth/setup_run.jl (1)

85-94: Consider adding usage examples in the docstring.

The docstring clearly describes purpose and arguments. Adding a small usage snippet can further clarify how to call these constructors.

 """
     CoupledSimulation(config_file)
     CoupledSimulation(config_dict)
 
 Set up a `CoupledSimulation` as prescribed by the given input.
 This struct is defined in the Interfacer module and contains all information
 about component models, diagnostics, timestepping, output directories, etc
 needed to run a coupled simulation.
+ 
+ # Example Usage:
+ # cs = CoupledSimulation("path/to/config.yml")
+ # or
+ # cs = CoupledSimulation(config_dict)
 """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2e7019 and 596b2fb.

📒 Files selected for processing (6)
  • NEWS.md (1 hunks)
  • experiments/ClimaEarth/run_amip.jl (1 hunks)
  • experiments/ClimaEarth/setup_run.jl (9 hunks)
  • experiments/ClimaEarth/user_io/arg_parsing.jl (7 hunks)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl (2 hunks)
  • experiments/ClimaEarth/user_io/postprocessing.jl (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • experiments/ClimaEarth/run_amip.jl
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl
  • experiments/ClimaEarth/user_io/postprocessing.jl
  • experiments/ClimaEarth/user_io/arg_parsing.jl
🧰 Additional context used
📓 Path-based instructions (1)
`*`: # CodeRabbit Style Guide (CliMA Inspired)

Leverage CodeRabbit for code reviews aligning with CliMA's practices.

I. Key Areas for CodeRabbit:

  • Style: Naming (Titl...

*: # CodeRabbit Style Guide (CliMA Inspired)

Leverage CodeRabbit for code reviews aligning with CliMA's practices.

I. Key Areas for CodeRabbit:

  • Style: Naming (TitleCase, lowercase_with_underscores), line length (<78), indentation (4 spaces), import order.
  • DRY: Flag duplicated code; encourage modularization.
  • Docstrings: Flag missing docstrings for modules, structs, functions.
  • Tests: Detect missing unit tests (if configured).
  • Complexity: Report on cyclomatic complexity.

II. Conventions (CodeRabbit Can Help):

  • Naming: Follow CliMA/CMIP conventions. Avoid l, O, I as single-char vars.
  • Unicode: Human review needed. Acceptable chars.

III. Documentation (CodeRabbit Flags Deficiencies):

  • Docstrings: Describe purpose, inputs, outputs, examples.

IV. Testing (CodeRabbit: Missing Tests):

  • Unit tests required for new/modified code.

V. CodeRabbit Config:

  • .coderabbit.yaml: Customize language, line length, tests.

VI. Workflow:

  • Review CodeRabbit's suggestions; investigate, provide context, address issues, improve config.

VII. Abandoned Code: Delete or clearly mark as deprecated.

VIII. Reviewer Responsibilities: Ensure adherence to best practices.

  • NEWS.md
🪛 markdownlint-cli2 (0.17.2)
NEWS.md

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: ci 1.11 - windows-latest
  • GitHub Check: ci 1.11 - macOS-latest
  • GitHub Check: ci 1.11 - ubuntu-latest
  • GitHub Check: ci 1.10 - windows-latest
  • GitHub Check: ci 1.10 - macOS-latest
  • GitHub Check: ci 1.10 - ubuntu-latest
🔇 Additional comments (25)
NEWS.md (3)

16-18: No issues found.


19-19: No issues found.


21-23: Renaming reference looks good.

experiments/ClimaEarth/setup_run.jl (22)

38-38: No issues found on the import line.


95-97: No issues found.


101-101: No issues found.


127-128: No issues found.


135-135: No issues found.


163-163: No issues found.


514-514: No issues found.


596-598: No issues found.


611-616: No issues found.


628-629: No issues found.


631-633: No issues found.


636-636: No issues found.


641-642: No issues found.


644-644: No issues found.


647-648: No issues found.


653-653: No issues found.


700-706: No issues found.


707-711: No issues found.


712-715: No issues found.


719-726: No issues found on the docstring block.


728-770: No issues found in the step! logic.


772-783: No issues found.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
NEWS.md (1)

9-9: Update heading style to match document convention

The heading style used here (ATX style with ###) doesn't match the setext style used for other headings in the document.

-### Split `setup_and_run` in multiple functions. PR[#1251](https://github.com/CliMA/ClimaCoupler.jl/pull/1251)
+Split `setup_and_run` in multiple functions. PR[#1251](https://github.com/CliMA/ClimaCoupler.jl/pull/1251)
+-----------------------------------------------------
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 596b2fb and fa267f3.

📒 Files selected for processing (6)
  • NEWS.md (1 hunks)
  • experiments/ClimaEarth/run_amip.jl (1 hunks)
  • experiments/ClimaEarth/setup_run.jl (9 hunks)
  • experiments/ClimaEarth/user_io/arg_parsing.jl (7 hunks)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl (2 hunks)
  • experiments/ClimaEarth/user_io/postprocessing.jl (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • experiments/ClimaEarth/user_io/coupler_diagnostics.jl
  • experiments/ClimaEarth/run_amip.jl
  • experiments/ClimaEarth/user_io/arg_parsing.jl
🧰 Additional context used
📓 Path-based instructions (1)
`*`: # CodeRabbit Style Guide (CliMA Inspired)

Leverage CodeRabbit for code reviews aligning with CliMA's practices.

I. Key Areas for CodeRabbit:

  • Style: Naming (Titl...

*: # CodeRabbit Style Guide (CliMA Inspired)

Leverage CodeRabbit for code reviews aligning with CliMA's practices.

I. Key Areas for CodeRabbit:

  • Style: Naming (TitleCase, lowercase_with_underscores), line length (<78), indentation (4 spaces), import order.
  • DRY: Flag duplicated code; encourage modularization.
  • Docstrings: Flag missing docstrings for modules, structs, functions.
  • Tests: Detect missing unit tests (if configured).
  • Complexity: Report on cyclomatic complexity.

II. Conventions (CodeRabbit Can Help):

  • Naming: Follow CliMA/CMIP conventions. Avoid l, O, I as single-char vars.
  • Unicode: Human review needed. Acceptable chars.

III. Documentation (CodeRabbit Flags Deficiencies):

  • Docstrings: Describe purpose, inputs, outputs, examples.

IV. Testing (CodeRabbit: Missing Tests):

  • Unit tests required for new/modified code.

V. CodeRabbit Config:

  • .coderabbit.yaml: Customize language, line length, tests.

VI. Workflow:

  • Review CodeRabbit's suggestions; investigate, provide context, address issues, improve config.

VII. Abandoned Code: Delete or clearly mark as deprecated.

VIII. Reviewer Responsibilities: Ensure adherence to best practices.

  • NEWS.md
🪛 markdownlint-cli2 (0.17.2)
NEWS.md

9-9: Heading style
Expected: setext; Actual: atx

(MD003, heading-style)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: ci 1.11 - windows-latest
  • GitHub Check: ci 1.11 - macOS-latest
  • GitHub Check: ci 1.11 - ubuntu-latest
  • GitHub Check: ci 1.10 - windows-latest
  • GitHub Check: ci 1.10 - macOS-latest
  • GitHub Check: ci 1.10 - ubuntu-latest
🔇 Additional comments (11)
NEWS.md (1)

11-22: Well-documented changes with clear explanations

The documentation clearly explains the split of the monolithic function into four distinct components, which improves modularity and facilitates debugging. The renaming of calendar_dt to diagnostics_dt also enhances code clarity.

experiments/ClimaEarth/user_io/postprocessing.jl (2)

15-15: Simplified parameter extraction

Parameter handling has been simplified to only extract what's needed.


31-41: Improved leaderboard plotting logic

The new implementation checks for the presence of required data rather than relying on configuration flags, which is more robust. The comment about pressure requirement is helpful as requested in previous reviews.

experiments/ClimaEarth/setup_run.jl (8)

85-94: Good documentation for CoupledSimulation constructor

The docstring clearly explains the purpose of this function and follows the previous reviewer's suggestion for more descriptive documentation.


95-98: Simple delegation pattern implemented correctly

This version of the constructor takes a file path and delegates to the version that takes a dictionary, following best practices for constructor delegation.


101-598: Extracted logic from setup_and_run to CoupledSimulation

This refactoring cleanly separates initialization from execution, improving modularity. The implementation preserves all functionality while making the codebase more maintainable.


600-666: Well-structured run! function with performance tracking

The function includes precompilation, timing, appropriate error handling, and performance metrics. It also correctly manages resources by closing diagnostic writers.


638-643: Simulated years per day calculation fixed

Following previous reviewer feedback, the SYPD calculation has been corrected to avoid dividing by walltime twice.


668-697: Clean postprocess function implementation

The function clearly separates postprocessing logic and handles conservation checks appropriately.


707-717: Simplified setup_and_run function

The refactored function now delegates to the more modular components, making it easier to understand and maintain.


728-783: Well-structured step! function for simulation advancement

The implementation handles model updates, flux calculations, and communication barriers in a logical sequence. The code is well-commented and organized.

This commit introduces more structure in ClimaEarth. It splits
`setup_and_run` in three functions:
- `setup`, which produces a `CoupledSimulation` (hence, it was renamed
to be `CoupledSimulation`, since it is just a constructor)
- `run!`, which runs the simulation. This is supported by the
introduction of `step!`, to take one single coupling step. This is
particularly useful in debugging
- `postprocess`, to make plots

The advantage of this separation is that one can now construct a
simulation without running it, and step a simulation one step at a time.
Both of these are particularly useful in interactive work and debugging.

This commit also renames `calendar_dt` to `diag_calendar_dt` to make it
clearer that it refers to diagnostics.
@Sbozzolo Sbozzolo enabled auto-merge April 3, 2025 22:19
@Sbozzolo Sbozzolo merged commit 91facd1 into main Apr 3, 2025
12 checks passed
@Sbozzolo Sbozzolo deleted the gb/step branch April 3, 2025 22:36
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