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

✨ Use xarray internally and move relations/constraints/penaltys to glotaran.model #734

Conversation

s-weigand
Copy link
Member

@s-weigand s-weigand commented Jul 3, 2021

Same as #715 but with the targe branch being staging.
Author @joernweissenborn

Change summary

  • moved relations, contraints and penalties to glotaran.model
  • megacomplex.calculate_matrix now returns xarray.DataArray

DEPRECATION FOR MODELDICTS STILL NEEDED

Checklist

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

closes #715

@s-weigand s-weigand requested review from joernweissenborn, jsnel and a team as code owners July 3, 2021 23:18
@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2021

Binder 👈 Launch a binder notebook on branch joernweissenborn/pyglotaran/feature/moverelationsandconstraints

@s-weigand s-weigand changed the title Feature/moverelationsandconstraints ✨ Use xarray internally and move relations/constraints/penaltys to glotaran.model Jul 3, 2021
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 3, 2021

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 5.71 ⭐ 5.34 ⭐ -0.37 👍
Method Length 80.98 🙂 77.81 🙂 -3.17 👍
Working memory 10.05 😞 10.02 😞 -0.03 👍
Quality 60.42% 🙂 61.39% 🙂 0.97% 👍
Other metrics Before After Change
Lines 3707 3394 -313
Changed files Quality Before Quality After Quality Change
glotaran/analysis/problem.py 82.00% ⭐ 82.09% ⭐ 0.09% 👍
glotaran/analysis/problem_grouped.py 53.35% 🙂 54.85% 🙂 1.50% 👍
glotaran/analysis/problem_ungrouped.py 68.72% 🙂 62.99% 🙂 -5.73% 👎
glotaran/analysis/simulation.py 17.43% ⛔ 21.92% ⛔ 4.49% 👍
glotaran/analysis/util.py 57.57% 🙂 64.34% 🙂 6.77% 👍
glotaran/analysis/test/models.py 66.85% 🙂 66.48% 🙂 -0.37% 👎
glotaran/analysis/test/test_optimization.py 24.77% ⛔ 26.31% 😞 1.54% 👍
glotaran/analysis/test/test_problem.py 59.95% 🙂 61.49% 🙂 1.54% 👍
glotaran/builtin/models/kinetic_image/kinetic_baseline_megacomplex.py 90.73% ⭐ 86.85% ⭐ -3.88% 👎
glotaran/builtin/models/kinetic_image/kinetic_decay_megacomplex.py 65.10% 🙂 64.36% 🙂 -0.74% 👎
glotaran/builtin/models/kinetic_image/test/test_baseline.py 70.07% 🙂 65.39% 🙂 -4.68% 👎
glotaran/builtin/models/kinetic_spectrum/coherent_artifact_megacomplex.py 69.27% 🙂 68.38% 🙂 -0.89% 👎
glotaran/builtin/models/kinetic_spectrum/test/test_coherent_artifact.py 52.26% 🙂 51.69% 🙂 -0.57% 👎
glotaran/builtin/models/kinetic_spectrum/test/test_spectral_penalties.py 45.86% 😞 43.41% 😞 -2.45% 👎
glotaran/builtin/models/spectral/spectral_megacomplex.py 73.47% 🙂 71.44% 🙂 -2.03% 👎
glotaran/builtin/models/spectral/test/test_spectral_model.py 56.65% 🙂 56.65% 🙂 0.00%
glotaran/model/init.py % % %
glotaran/model/dataset_descriptor.py 83.20% ⭐ 86.28% ⭐ 3.08% 👍
glotaran/model/decorator.py 63.07% 🙂 62.16% 🙂 -0.91% 👎
glotaran/model/megacomplex.py 93.31% ⭐ 94.50% ⭐ 1.19% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
glotaran/analysis/simulation.py simulate 24 😞 318 ⛔ 20 ⛔ 19.82% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
glotaran/analysis/test/test_optimization.py test_optimization 19 😞 529 ⛔ 14 😞 26.31% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
glotaran/analysis/problem_ungrouped.py UngroupedProblem._calculate_residual_for_problem 16 🙂 355 ⛔ 16 ⛔ 27.91% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/model/decorator.py model 14 🙂 282 ⛔ 19 ⛔ 29.01% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/analysis/problem_grouped.py GroupedProblem._append_to_grouped_bag 8 ⭐ 286 ⛔ 22 ⛔ 32.50% 😞 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!

@sonarcloud
Copy link

sonarcloud bot commented Jul 3, 2021

Kudos, SonarCloud Quality Gate passed!

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

No Coverage information No Coverage information
No Duplication information No Duplication information

@codecov
Copy link

codecov bot commented Jul 3, 2021

Codecov Report

Merging #734 (0d301cd) into staging (2e7421b) will decrease coverage by 2.4%.
The diff coverage is 85.0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           staging    #734     +/-   ##
=========================================
- Coverage     81.7%   79.3%   -2.5%     
=========================================
  Files           79      83      +4     
  Lines         4024    4127    +103     
  Branches       706     720     +14     
=========================================
- Hits          3291    3274     -17     
- Misses         606     728    +122     
+ Partials       127     125      -2     
Impacted Files Coverage Δ
glotaran/model/clp_penalties.py 31.9% <31.9%> (ø)
glotaran/model/interval_property.py 60.0% <60.0%> (ø)
glotaran/analysis/util.py 89.1% <88.1%> (-7.2%) ⬇️
glotaran/model/constraint.py 92.3% <92.3%> (ø)
glotaran/analysis/problem_grouped.py 96.2% <97.7%> (-0.2%) ⬇️
glotaran/analysis/problem.py 93.2% <100.0%> (+2.3%) ⬆️
glotaran/analysis/problem_ungrouped.py 98.3% <100.0%> (+0.2%) ⬆️
glotaran/analysis/simulation.py 61.9% <100.0%> (-7.9%) ⬇️
...dels/kinetic_image/kinetic_baseline_megacomplex.py 93.7% <100.0%> (+0.8%) ⬆️
.../models/kinetic_image/kinetic_decay_megacomplex.py 62.9% <100.0%> (+0.4%) ⬆️
... and 21 more

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 2e7421b...0d301cd. Read the comment docs.

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.

Extensively reviewed in PR #715 but agreed to re-create against a staging branch instead of main to address performance regressions before merging the feature(s) into main.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2021

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

Benchmark diff

All benchmarks:

       before           after         ratio
     [dc00e6da]       [0d301cd4]
     <v0.4.0>                   
             178M             183M     1.02  IntegrationTwoDatasets.peakmem_create_result
             199M             204M     1.02  IntegrationTwoDatasets.peakmem_optimize
+         293±5ms       1.01±0.02s     3.44  IntegrationTwoDatasets.time_create_result
+      6.19±0.03s          1.15±0m    11.16  IntegrationTwoDatasets.time_optimize

@s-weigand s-weigand merged commit eb2204e into glotaran:staging Jul 4, 2021
s-weigand added a commit that referenced this pull request Jul 4, 2021
…otaran.model (#734)

* Changed calculate_matrix function to return xarrays

* Added relation and constraint to basemodel

* Added functions to apply relations and constraints

* Removed LabelAndMatrix class

* Added relations and constraints tests to base model

* Added penalties to base model

* Adapted models to changes

* Address xarray deprecation warnings

Fixed DeprecationWarning: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property. This will raise a TypeError in 0.19.0.

Co-authored-by: Jörn Weißenborn <[email protected]>
Co-authored-by: Joris Snellenburg <[email protected]>
s-weigand added a commit that referenced this pull request Jul 9, 2021
…otaran.model (#734)

* Changed calculate_matrix function to return xarrays

* Added relation and constraint to basemodel

* Added functions to apply relations and constraints

* Removed LabelAndMatrix class

* Added relations and constraints tests to base model

* Added penalties to base model

* Adapted models to changes

* Address xarray deprecation warnings

Fixed DeprecationWarning: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property. This will raise a TypeError in 0.19.0.

Co-authored-by: Jörn Weißenborn <[email protected]>
Co-authored-by: Joris Snellenburg <[email protected]>
jsnel added a commit that referenced this pull request Aug 14, 2021
…otaran.model (#734)

* Changed calculate_matrix function to return xarrays

* Added relation and constraint to basemodel

* Added functions to apply relations and constraints

* Removed LabelAndMatrix class

* Added relations and constraints tests to base model

* Added penalties to base model

* Adapted models to changes

* Address xarray deprecation warnings

Fixed DeprecationWarning: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property. This will raise a TypeError in 0.19.0.

Co-authored-by: Jörn Weißenborn <[email protected]>
Co-authored-by: Joris Snellenburg <[email protected]>
jsnel added a commit to jsnel/pyglotaran that referenced this pull request Aug 14, 2021
…otaran.model (glotaran#734)

* Changed calculate_matrix function to return xarrays

* Added relation and constraint to basemodel

* Added functions to apply relations and constraints

* Removed LabelAndMatrix class

* Added relations and constraints tests to base model

* Added penalties to base model

* Adapted models to changes

* Address xarray deprecation warnings

Fixed DeprecationWarning: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property. This will raise a TypeError in 0.19.0.

Co-authored-by: Jörn Weißenborn <[email protected]>
Co-authored-by: Joris Snellenburg <[email protected]>
jsnel added a commit that referenced this pull request Sep 16, 2021
…otaran.model (#734)

* Changed calculate_matrix function to return xarrays

* Added relation and constraint to basemodel

* Added functions to apply relations and constraints

* Removed LabelAndMatrix class

* Added relations and constraints tests to base model

* Added penalties to base model

* Adapted models to changes

* Address xarray deprecation warnings

Fixed DeprecationWarning: Using a DataArray object to construct a variable is ambiguous, please extract the data using the .data property. This will raise a TypeError in 0.19.0.

Co-authored-by: Jörn Weißenborn <[email protected]>
Co-authored-by: Joris Snellenburg <[email protected]>
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.

3 participants