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

Allowing complete math overrides #609

Closed
wants to merge 4 commits into from

Conversation

irm-codebase
Copy link
Contributor

@irm-codebase irm-codebase commented Jun 19, 2024

Fixes #606

Summary of changes in this pull request

  • Introduces a new parameter (config.init.base_math) that will tell the model to skip base math if set to False.
  • Run mode math updates have been moved from the backend to the main model file.
  • Math is now always validated when modified (either in init or build). This is to prevent unexpected surprises if users save an initialized model without building it.

Reviewer checklist

  • Test(s) added to cover contribution
  • Documentation updated
  • Changelog updated
  • Coverage maintained or improved

@irm-codebase irm-codebase marked this pull request as draft June 19, 2024 09:30
@irm-codebase irm-codebase self-assigned this Jun 19, 2024
Copy link

codecov bot commented Jun 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.94%. Comparing base (8c92ba5) to head (e47e12f).

Current head e47e12f differs from pull request most recent head 280da69

Please upload reports for the commit 280da69 to get more accurate results.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           fix-config-desync     #609      +/-   ##
=====================================================
+ Coverage              95.93%   95.94%   +0.01%     
=====================================================
  Files                     24       24              
  Lines                   3638     3651      +13     
  Branches                 736      735       -1     
=====================================================
+ Hits                    3490     3503      +13     
  Misses                    84       84              
  Partials                  64       64              

see 1 file with indirect coverage changes

@irm-codebase irm-codebase changed the title add new values to config_schema Allowing complete math /schema overrides Jun 19, 2024
@irm-codebase irm-codebase force-pushed the feature-base-math-override branch 2 times, most recently from e47e12f to e6e3d44 Compare June 21, 2024 10:13
@irm-codebase irm-codebase changed the base branch from main to fix-config-desync June 21, 2024 21:23
Copy link
Contributor Author

@irm-codebase irm-codebase left a comment

Choose a reason for hiding this comment

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

@brynpickering following your comments on #606, I decided to only skip the base math, for now.
The schema approach remains the same for now, since modifying this is likely to be quite a lengthy update since MODEL_SCHEMA is a global and not a Model attribute.

Here are a few comments to aid with the review. Let me know what you think!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this functionality to model.py because it does not really interact with the backend in any way.
Keeps the code a bit leaner.

pyproject.toml Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enabled some extra linting help for pytest.
It already helped in removing some small issues in some files for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

New boolean to specify if the base math is enabled in the model. The core of this PR.

@@ -188,9 +188,6 @@ def _init_from_model_def_dict(
model_config.union(model_definition.pop("config"), allow_override=True)

init_config = update_then_validate_config("init", model_config)
# We won't store `init` in `self.config`, so we pop it out now.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am now allowing config.init to remain in model._model_data.attrs.
I think it makes the model creation more transparent, particularly because the added math files specified are kept.


log_time(
LOGGER,
self._timings,
"model_data_creation",
comment="Model: preprocessing stage 2 (model_data)",
)

math, applied_math = self._math_init_from_yaml(init_config)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new _math functions follow a functional programming approach for two reasons:

  • easier to write tests for this style
  • is explicit

I can change this to an implicit OOP approach if need-be.

return base_math
return (math, applied_math)

def _math_update_with_mode(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the function I removed from the backend. Works in the same way, except that it returns the updated math instead of directly modifying it.

Also, I made sure to avoid the use of .copy() unless absolutely needed. Should be more efficient in cases were no modification is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this file is linter updates. Run mode tests were moved to a different test file for consistency.

tests/test_core_model.py Show resolved Hide resolved
@irm-codebase irm-codebase marked this pull request as ready for review June 21, 2024 21:36
@irm-codebase irm-codebase changed the title Allowing complete math /schema overrides Allowing complete math overrides Jun 21, 2024
@irm-codebase
Copy link
Contributor Author

irm-codebase commented Jun 22, 2024

Turns out our data saving steps have some unexpected bugs. Opened #614 to deal with them.

@irm-codebase irm-codebase marked this pull request as draft June 24, 2024 17:44
@irm-codebase
Copy link
Contributor Author

Converting to draft because #614 is a blocker to this PR.

@irm-codebase irm-codebase deleted the branch fix-config-desync July 8, 2024 08:32
@irm-codebase irm-codebase deleted the feature-base-math-override branch July 19, 2024 09:38
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.

Feature: allow for complete math overrides
1 participant