Skip to content

Fixed the issue of incorrect time step advancement and enhanced error/warning messages.#127

Merged
SongshGeo merged 4 commits intomasterfrom
dev
Nov 9, 2025
Merged

Fixed the issue of incorrect time step advancement and enhanced error/warning messages.#127
SongshGeo merged 4 commits intomasterfrom
dev

Conversation

@SongshGeo
Copy link
Copy Markdown
Collaborator

@SongshGeo SongshGeo commented Nov 9, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Prevented duplicate module layers when re-creating modules.
  • Improvements

    • Step setter validates input and advances time only by the computed delta.
    • Model loop no longer forces automatic time advancement.
    • Time driver end-time handling now enforces strict type normalization and validation.
    • Marker visualization returns geometry objects for improved rendering precision.
    • Configuration return type updated for more consistent config handling.

…d TimeDriver classes

This commit enhances the `Experiment` and `TimeDriver` classes by updating type annotations and improving docstrings for clarity. The `hydra_config` property in `Experiment` now returns a `HydraConf` object, and the `end_at` setter in `TimeDriver` has been refactored to normalize the end time input. Additionally, the `array_cells` method in `PatchModule` has been updated to return a numpy array, and the `merge_parameters` function in `args.py` now uses `cast` for better type safety. These changes aim to improve code readability and maintainability while ensuring compliance with typing standards.
…e class

This commit updates the `BaseNature` class to check for the existence of a module in the `layers` before adding it. This change prevents duplicate layers from being added, enhancing the integrity of the layer management process. The code now ensures that only unique modules are added, improving overall functionality and maintainability.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 9, 2025

Walkthrough

The PR tightens type annotations and config typing, changes time-step handling to apply deltas, normalizes end-time handling with strict types, prevents duplicate spatial layers, adjusts patch array/iterator types, and returns Matplotlib Path objects for built-in markers.

Changes

Cohort / File(s) Summary
Configuration & args
abses/core/experiment.py, abses/utils/args.py
Add HydraConf import and change Experiment.hydra_config return type to HydraConf. Use cast to ensure the merged config is returned as DictConfig.
Model & time driver
abses/core/model.py, abses/core/time_driver.py
steps setter now computes delta from previous steps and advances time only by delta; run_model no longer auto-advances time each loop. TimeDriver adds _end_dt and refactors end_at setter to strict normalization (None/int/parsed DateTime) with TypeError on invalid types.
Spatial / patch
abses/space/nature.py, abses/space/patch.py
create_module avoids adding duplicate layers. array_cells type hint changed to np.ndarray; dynamic_var return widened to `np.ndarray
Visualization / markers
abses/viz/customize_marker.py
get_marker now returns a Matplotlib Path for built-in markers via MarkerStyle(symbol).get_path(); Font Awesome icon handling unchanged for custom icons.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as Model.run_model
    participant Model as Model
    participant Time as TimeDriver

    Note over Runner,Model: Old flow (before)
    Runner->>Model: for each step -> call model.step()
    Model->>Time: Time.go()  -- (advance every iteration)
    Model->>Model: update state

    Note over Runner,Model: New flow (after)
    Runner->>Model: set steps = N (or increment)
    Model->>Time: compute delta = steps - prev_steps
    alt delta > 0
        Model->>Time: Time.go(delta)  -- (advance by delta)
    else delta <= 0
        Note right of Time: no advancement
    end
    Runner->>Model: for each step -> call model.step()  -- no automatic Time.go()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay extra attention to abses/core/model.py (delta computation and removal of implicit time advancement).
  • Review abses/core/time_driver.py for correct normalization and edge-case handling of end_at.
  • Check abses/space/patch.py coord_iter behavior and iteration order.
  • Verify downstream consumers handle Path return in abses/viz/customize_marker.py.

Poem

🐇 I nudge the clock by deltas small and neat,
Layers stay lonely — duplicates retreat.
Types now stricter, endpoints set with care,
Markers trade strings for paths with flair.
Hop, run, simulate — the world aligns in beat.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title focuses on time step advancement but the changeset includes multiple substantial changes across 6 files affecting time handling, type hints, layer management, marker visualization, and configuration imports. Revise the title to accurately reflect all major changes, such as: 'Refactor time handling, type hints, and add validation improvements across multiple modules' or provide a more comprehensive summary of the complete changeset.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b4cbbe6 and ae46993.

📒 Files selected for processing (1)
  • abses/core/model.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • abses/core/model.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Tests 3.13 on windows-latest
  • GitHub Check: Tests 3.11 on windows-latest
  • GitHub Check: Tests 3.12 on macos-latest
  • GitHub Check: Tests 3.13 on macos-latest
  • GitHub Check: Tests 3.12 on windows-latest
  • GitHub Check: Tests 3.11 on ubuntu-latest
  • GitHub Check: Tests 3.13 on ubuntu-latest
  • GitHub Check: nbmake
  • GitHub Check: Tests 3.12 on ubuntu-latest
  • GitHub Check: Tests 3.11 on macos-latest
  • GitHub Check: nbmake

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebd7155 and b4cbbe6.

📒 Files selected for processing (7)
  • abses/core/experiment.py (2 hunks)
  • abses/core/model.py (1 hunks)
  • abses/core/time_driver.py (2 hunks)
  • abses/space/nature.py (1 hunks)
  • abses/space/patch.py (3 hunks)
  • abses/utils/args.py (2 hunks)
  • abses/viz/customize_marker.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (.cursorrules)

**/*.py: For any Python file, add typing annotations to every function and class, including explicit return types (use None where appropriate)
Add descriptive docstrings to all Python functions and classes; follow PEP 257 conventions and update existing docstrings as needed

Files:

  • abses/core/experiment.py
  • abses/core/time_driver.py
  • abses/utils/args.py
  • abses/space/nature.py
  • abses/viz/customize_marker.py
  • abses/core/model.py
  • abses/space/patch.py
🧬 Code graph analysis (2)
abses/core/time_driver.py (1)
abses/utils/time.py (2)
  • is_positive_int (25-30)
  • parse_datetime (33-60)
abses/core/model.py (4)
abses/core/base_module.py (1)
  • time (189-195)
abses/core/base_variable.py (1)
  • time (129-135)
abses/core/protocols.py (2)
  • time (256-256)
  • go (69-69)
abses/core/time_driver.py (1)
  • go (234-238)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Tests 3.12 on windows-latest
  • GitHub Check: Tests 3.11 on windows-latest
  • GitHub Check: Tests 3.11 on macos-latest
  • GitHub Check: Tests 3.13 on windows-latest
  • GitHub Check: Tests 3.13 on macos-latest
  • GitHub Check: Tests 3.12 on ubuntu-latest
  • GitHub Check: Tests 3.13 on ubuntu-latest
  • GitHub Check: Tests 3.12 on macos-latest
  • GitHub Check: Tests 3.11 on ubuntu-latest
  • GitHub Check: nbmake
  • GitHub Check: nbmake
🔇 Additional comments (11)
abses/space/nature.py (1)

85-86: LGTM! Duplicate prevention improves robustness.

The conditional check prevents duplicate layer additions when a module is re-created or re-added, which is a solid defensive practice.

abses/utils/args.py (2)

8-8: Type import added for explicit casting.

The cast import supports the explicit type casting added at line 48.


48-48: Explicit cast improves type checker confidence.

While the function signature already declares DictConfig as the return type, the explicit cast helps type checkers verify that merged is indeed a DictConfig at this point, reducing false positives in static analysis.

abses/space/patch.py (3)

372-377: LGTM! Type annotation and documentation clarified.

The return type has been simplified to np.ndarray, and the docstring now explicitly describes the return value as a 2D object-dtype numpy array containing PatchCell instances. This improves clarity.


444-444: LGTM! Return type widened to match actual behavior.

The return type now correctly reflects that the method can return either np.ndarray or xr.DataArray depending on the dtype parameter.


657-662: LGTM! Manual iteration provides explicit typing.

The implementation now manually iterates over indices, making the coordinate yielding behavior more explicit and easier to type-check.

abses/core/experiment.py (2)

45-45: Import updated for improved type precision.

The addition of HydraConf supports the more precise return type annotation at line 211.


211-212: LGTM! Return type matches Hydra's actual type.

The return type has been updated from DictConfig to HydraConf, which more accurately reflects what HydraConfig.get() returns. This improves type safety.

abses/viz/customize_marker.py (1)

27-34: LGTM! Standardized return type improves consistency.

The function now consistently returns a Path object for both built-in matplotlib markers and Font Awesome icons, rather than returning a string for built-in markers. This standardization improves type safety and API consistency.

Note: This is a breaking change if any callers expected string symbols for built-in markers.

abses/core/time_driver.py (2)

126-127: Private attribute added for normalized end time.

The _end_dt attribute stores the normalized end time value, supporting the refactored setter logic.


337-355: LGTM! Robust end-time normalization with strict typing.

The setter now explicitly normalizes inputs to DateTime | int | None:

  • None remains None
  • Positive integers are preserved as int
  • Strings/datetimes are converted to timezone-naive DateTime objects
  • Invalid types raise TypeError

This approach provides clear type guarantees and explicit error handling, improving maintainability and debuggability.

Comment thread abses/core/model.py Outdated
This commit updates the `MainModel` class to enhance type checking for the `steps` parameter. The previous check for `steps` being an integer has been replaced with a check on the `delta` value, ensuring that the logic correctly validates the number of steps before advancing time. This change improves error handling and maintains the integrity of the model's state management.
@SongshGeo SongshGeo changed the title Fix some known bugs Fixed the issue of incorrect time step advancement and enhanced error/warning messages. Nov 9, 2025
@SongshGeo SongshGeo merged commit 2418012 into master Nov 9, 2025
13 of 14 checks passed
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.

1 participant