-
Notifications
You must be signed in to change notification settings - Fork 18
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
Refactor model.from_dict to parse megacomplex_type from dict and add simple_generator for testing #807
Conversation
Codecov Report
@@ Coverage Diff @@
## staging #807 +/- ##
=========================================
+ Coverage 84.5% 84.7% +0.2%
=========================================
Files 75 77 +2
Lines 4201 4343 +142
Branches 757 785 +28
=========================================
+ Hits 3553 3682 +129
- Misses 515 521 +6
- Partials 133 140 +7
Continue to review full report at Codecov.
|
5fa810f
to
34bec3b
Compare
a25db46
to
92ea07f
Compare
The keyword arguments megacomplex_types and default_megacomplex_type are only used for overwrites in testing Co-authored-by: Sebastian Weigand <[email protected]>
Those context managers allow easy updating or recreating or the plugin registry for test where you don't want to add plugings to the global registry.
for more information, see https://pre-commit.ci
Allows the definition of basic models and parameters without all the boilerplate Note: first draft version, many improvements still possible
Amazing for debugging and printing complex objects
A parallel model only has rates on the diagonal
When rates is set with just a list of floats (without the additional dict element specifying defaults)
model and parameters generated using the simple_generator are shown to be equivalent to the hard coded dicts
92ea07f
to
c4fd7c4
Compare
This PR opens up the possibility for further refactoring the tests, for instance the other tests in
This could be an easy issue for a new contributor (@s-weigand could you create a new issue for this with some details). This could then be picked up after merging this PR into staging (@joernweissenborn). |
Fix in handling irf when not specified Add basic sanity checking for .rates Added tests for SimpleGenerator Added error handling class SimpleGeneratorError Removed explicit dependency on rich Clean up mains
Accidentally the pre-commit check for |
to monkeypatch_plugin_registry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor nitpicky things. 😅
Also, could we rename simple_generator.py
into something like model_generators.py
, if we have the need to create more we can make it a sub_package?
SimpleGenerator sounds like we will need more complex ones.
Co-authored-by: Sebastian Weigand <[email protected]>
and added docstrings - Change SimpleGeneratorError to ValueError - Eliminate SimpleGeneratorError - Merge _validate_rates and _rates into one
♻️ Rename simple_generator to model_generators; its purpose is to generate models (together with the parameters specification) based on parameter input values the user assigns to the instance of the model generator 📚 Added darglint compatible docstrings everywhere
862fad3
to
c18f791
Compare
🩹Use the new monkeypatch_plugin_registry contextmanager in the pytest benchamrks to setup_model 🐛 Make removal of (optional) key fault tolerant
Adding `pylint: disable=W0622` to allow for redefining built-in print
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Benchmark is done. Checkout the benchmark result page. Benchmark diffParametrized benchmark signatures: BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)
|
Implemented requested changes: add docstrings to semi-private methods, rename simple_generator to model_generators
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.28%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
…dd simple_generator for testing (#807) * 👌 Refactor model.from_dict to use kwargs only for override; The keyword arguments megacomplex_types and default_megacomplex_type are only used for overwrites in testing * ♻️ Refactor a simple DecayModel used in testing * ✨🧪 Added plugin registry monkeypatch context managers for testing * 🔧Add rich dependency (Amazing for debugging and printing complex objects) * 🐛 Fix ThreeComponentParallel to be actually parallel * 🔧🩹 Fixed pydocstyle and darglint not picking up the testing module * 🩹Adapted pytest benchmarks to new monkeypatch_plugin_registry * 🩹 Ignore Codacy issue W0622 redefining built-in `print` when using `from rich import print` Co-authored-by: Sebastian Weigand <[email protected]> Co-authored-by: Sourcery AI <> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
One of the issues with current tests is that they are hard to read because of large in-line dicts with minimal differences between them, occasionally resulting in the introduction of errors (such as defining a parallel model as a sequential model, illustrated by this commit fixing that error: dce7f0b)
To fix this we need:
This PR introduces those changes, and then illustrates the use of the simple generator by using it to refactor a single class (
ThreeComponentParallel
) used in tests.This PR opens up the possibility for further refactoring tests for improved readability, to come in a future PR (see #815).
Co-authored-by: Sebastian Weigand [email protected]
Change summary
test_decay_megacomplex.py
as an example of the new featuresChecklist
Closes issues
closes #816