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

Refactored ModelProperty. #914

Merged
merged 14 commits into from
Nov 29, 2021

Conversation

joernweissenborn
Copy link
Member

@joernweissenborn joernweissenborn commented Nov 26, 2021

This PR refactors the ModelProperty class.

Change summary

  • Markdown printing of Model has been changed
    • Beautification is left for followup PR

Checklist

  • ✔️ Passing the tests (mandatory for all PR's)
  • 👌 Closes issue (mandatory for ✨ feature and 🩹 bug fix PR's)
  • 🧪 Adds new tests for the feature (mandatory for ✨ feature and 🩹 bug fix PR's)
  • 📚 Adds documentation of the feature

Closes issues

closes #901

@github-actions
Copy link
Contributor

Binder 👈 Launch a binder notebook on branch joernweissenborn/pyglotaran/refactor/propertymarkdown

@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2021

Benchmark is done. Checkout the benchmark result page.
Benchmark differences below 5% might be due to CI noise.

Benchmark diff v0.5.0rc1 vs. main

Parametrized benchmark signatures:

BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)

All benchmarks:

       before           after         ratio
     [d05c042a]       [210bdb80]
     <v0.5.0rc1>                 
         72.0±2ms         76.1±2ms     1.06  BenchmarkOptimize.time_optimize(False, False, False)
         175±10ms         167±20ms     0.95  BenchmarkOptimize.time_optimize(False, False, True)
         73.1±1ms         76.6±2ms     1.05  BenchmarkOptimize.time_optimize(False, True, False)
         144±30ms          156±7ms     1.08  BenchmarkOptimize.time_optimize(False, True, True)
         95.0±3ms         94.9±3ms     1.00  BenchmarkOptimize.time_optimize(True, False, False)
         108±30ms          104±3ms     0.96  BenchmarkOptimize.time_optimize(True, False, True)
         92.0±1ms         96.6±1ms     1.05  BenchmarkOptimize.time_optimize(True, True, False)
         140±40ms         107±40ms    ~0.76  BenchmarkOptimize.time_optimize(True, True, True)
             197M             199M     1.01  IntegrationTwoDatasets.peakmem_optimize
+      1.91±0.04s       2.46±0.05s     1.29  IntegrationTwoDatasets.time_optimize

Benchmark diff main vs. PR

Parametrized benchmark signatures:

BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)

All benchmarks:

       before           after         ratio
     [979643ac]       [210bdb80]
         80.9±3ms         76.1±2ms     0.94  BenchmarkOptimize.time_optimize(False, False, False)
         150±40ms         167±20ms    ~1.11  BenchmarkOptimize.time_optimize(False, False, True)
         76.1±2ms         76.6±2ms     1.01  BenchmarkOptimize.time_optimize(False, True, False)
         165±20ms          156±7ms     0.95  BenchmarkOptimize.time_optimize(False, True, True)
         95.7±2ms         94.9±3ms     0.99  BenchmarkOptimize.time_optimize(True, False, False)
         106±40ms          104±3ms     0.98  BenchmarkOptimize.time_optimize(True, False, True)
         94.6±2ms         96.6±1ms     1.02  BenchmarkOptimize.time_optimize(True, True, False)
         112±30ms         107±40ms     0.95  BenchmarkOptimize.time_optimize(True, True, True)
             196M             199M     1.01  IntegrationTwoDatasets.peakmem_optimize
       2.28±0.07s       2.46±0.05s     1.08  IntegrationTwoDatasets.time_optimize

@codecov
Copy link

codecov bot commented Nov 26, 2021

Codecov Report

Merging #914 (210bdb8) into main (979643a) will increase coverage by 0.5%.
The diff coverage is 91.9%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #914     +/-   ##
=======================================
+ Coverage   84.5%   85.1%   +0.5%     
=======================================
  Files         85      85             
  Lines       4785    4793      +8     
  Branches     891     920     +29     
=======================================
+ Hits        4047    4079     +32     
+ Misses       589     562     -27     
- Partials     149     152      +3     
Impacted Files Coverage Δ
glotaran/parameter/parameter.py 95.4% <63.6%> (+4.1%) ⬆️
glotaran/model/property.py 92.5% <91.8%> (+6.9%) ⬆️
glotaran/model/item.py 95.4% <94.7%> (+1.9%) ⬆️
glotaran/model/megacomplex.py 100.0% <100.0%> (+1.4%) ⬆️
glotaran/model/model.py 85.5% <100.0%> (ø)
glotaran/model/util.py 85.2% <100.0%> (+14.7%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 979643a...210bdb8. Read the comment docs.

@joernweissenborn joernweissenborn requested a review from a team as a code owner November 27, 2021 12:36
s-weigand
s-weigand previously approved these changes Nov 28, 2021
Copy link
Member

@s-weigand s-weigand left a comment

Choose a reason for hiding this comment

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

Functionality wise this looks good to me 👍
So thanks a lot, users will love the enhanced information they get. ❤️

But also it works quite well for 0.6.0 we should really reflect on if we really need this kind of metaprogramming or if we could maybe solve our requirements in a more maintainable fashion and pythonic way, instead of our mad scientist (e.g. utilizing attrs).

For me the most problematic point is inheriting a from the property decorator class, which leads this strange tests in test_model_property that don't reflect the actual usage.
The more tests the married, but they should reflect the usage in the code.

For now, there is no quick way around it (at least after 2h of trial and error from my side) and it would be out of scope for this PR, since this is an integral part of the code for 3 years.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Nov 28, 2021

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 3.12%.

Quality metrics Before After Change
Complexity 7.76 ⭐ 5.11 ⭐ -2.65 👍
Method Length 50.75 ⭐ 47.74 ⭐ -3.01 👍
Working memory 7.06 🙂 6.97 🙂 -0.09 👍
Quality 69.62% 🙂 72.74% 🙂 3.12% 👍
Other metrics Before After Change
Lines 2794 3029 235
Changed files Quality Before Quality After Quality Change
glotaran/builtin/io/yml/test/test_model_parser.py 82.35% ⭐ 80.11% ⭐ -2.24% 👎
glotaran/model/item.py 56.94% 🙂 64.34% 🙂 7.40% 👍
glotaran/model/megacomplex.py 72.53% 🙂 74.48% 🙂 1.95% 👍
glotaran/model/model.py 70.83% 🙂 70.83% 🙂 0.00%
glotaran/model/property.py 48.70% 😞 58.53% 🙂 9.83% 👍
glotaran/model/util.py 83.31% ⭐ 86.62% ⭐ 3.31% 👍
glotaran/model/test/test_model.py 72.58% 🙂 72.61% 🙂 0.03% 👍
glotaran/parameter/parameter.py 85.18% ⭐ 84.83% ⭐ -0.35% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
glotaran/model/property.py ModelProperty.glotaran_validate 33 ⛔ 167 😞 12 😞 32.34% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
glotaran/model/item.py model_item 18 🙂 292 ⛔ 8 🙂 41.32% 😞 Try splitting into smaller methods
glotaran/model/property.py ModelProperty.glotaran_fill 20 😞 133 😞 13 😞 41.71% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
glotaran/model/property.py _model_property_setter_factory 14 🙂 139 😞 14 😞 44.28% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/model/property.py _model_property_setter_factory.setter 11 🙂 132 😞 14 😞 47.70% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

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!

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug E 14 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@jsnel jsnel left a comment

Choose a reason for hiding this comment

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

LGTM, but I do agree and want to place emphasis on @s-weigand 's findings:

For me the most problematic point is inheriting a from the property decorator class, which leads this strange tests in test_model_property that don't reflect the actual usage.
The more tests the married, but they should reflect the usage in the code.

As (now) picked up by SonarCloud:
https://sonarcloud.io/summary/new_code?id=glotaran_pyglotaran&pullRequest=914

Let's add it to the v0.6.0 list.

@jsnel jsnel merged commit 88111bb into glotaran:main Nov 29, 2021
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.

🐛 Parameters used for expressions missing in Model markdown and report
3 participants