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

✨ Add simple decay megacomplexes #860

Merged
merged 9 commits into from
Jan 16, 2022

Conversation

joernweissenborn
Copy link
Member

@joernweissenborn joernweissenborn commented Oct 15, 2021

This PR adds megacomplexes for sequential and parallel decay.

Change summary

The new megacomplexes are essentially syntactic sugar to simplify standard models. They look like this

megacomplex:
  mc1: 
    type: decay-sequential/decay-parallel,
      compartments: [s1, s2, s3],
      rates: [kinetic.1, kinetic.2, kinetic.3]

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 #XXXX

@github-actions
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Oct 15, 2021

Codecov Report

Merging #860 (e9b1eb5) into main (91930ae) will increase coverage by 0.3%.
The diff coverage is 96.0%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #860     +/-   ##
=======================================
+ Coverage   85.0%   85.4%   +0.3%     
=======================================
  Files         85      87      +2     
  Lines       4802    4874     +72     
  Branches     923     921      -2     
=======================================
+ Hits        4086    4163     +77     
+ Misses       563     559      -4     
+ Partials     153     152      -1     
Impacted Files Coverage Δ
...n/builtin/megacomplexes/decay/decay_megacomplex.py 89.7% <88.2%> (+7.2%) ⬆️
glotaran/builtin/megacomplexes/decay/util.py 77.5% <91.1%> (+4.4%) ⬆️
glotaran/builtin/megacomplexes/decay/__init__.py 100.0% <100.0%> (ø)
.../megacomplexes/decay/decay_parallel_megacomplex.py 100.0% <100.0%> (ø)
...egacomplexes/decay/decay_sequential_megacomplex.py 100.0% <100.0%> (ø)
...iltin/megacomplexes/decay/initial_concentration.py 100.0% <100.0%> (ø)
glotaran/builtin/megacomplexes/decay/k_matrix.py 96.3% <100.0%> (+1.4%) ⬆️

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 91930ae...e9b1eb5. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 15, 2021

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

Benchmark diff v0.5.1 vs. main

Parametrized benchmark signatures:

BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)

All benchmarks:

       before           after         ratio
     [96b42630]       [e9b1eb5a]
     <v0.5.1>                   
       73.9±0.8ms       70.8±0.4ms     0.96  BenchmarkOptimize.time_optimize(False, False, False)
         122±20ms          162±8ms    ~1.32  BenchmarkOptimize.time_optimize(False, False, True)
         71.2±1ms       72.3±0.7ms     1.02  BenchmarkOptimize.time_optimize(False, True, False)
          154±4ms         147±20ms     0.95  BenchmarkOptimize.time_optimize(False, True, True)
       90.7±0.4ms         88.9±3ms     0.98  BenchmarkOptimize.time_optimize(True, False, False)
        99.6±40ms        97.2±30ms     0.98  BenchmarkOptimize.time_optimize(True, False, True)
         90.9±2ms         88.8±1ms     0.98  BenchmarkOptimize.time_optimize(True, True, False)
         97.5±5ms         103±30ms     1.06  BenchmarkOptimize.time_optimize(True, True, True)
             203M             205M     1.01  IntegrationTwoDatasets.peakmem_optimize
       2.27±0.05s       2.12±0.06s     0.93  IntegrationTwoDatasets.time_optimize

Benchmark diff main vs. PR

Parametrized benchmark signatures:

BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)

All benchmarks:

       before           after         ratio
     [91930ae8]       [e9b1eb5a]
         71.9±2ms       70.8±0.4ms     0.98  BenchmarkOptimize.time_optimize(False, False, False)
          159±7ms          162±8ms     1.02  BenchmarkOptimize.time_optimize(False, False, True)
         70.3±2ms       72.3±0.7ms     1.03  BenchmarkOptimize.time_optimize(False, True, False)
         154±20ms         147±20ms     0.96  BenchmarkOptimize.time_optimize(False, True, True)
         88.6±2ms         88.9±3ms     1.00  BenchmarkOptimize.time_optimize(True, False, False)
        97.6±30ms        97.2±30ms     1.00  BenchmarkOptimize.time_optimize(True, False, True)
         90.0±1ms         88.8±1ms     0.99  BenchmarkOptimize.time_optimize(True, True, False)
        97.7±30ms         103±30ms     1.05  BenchmarkOptimize.time_optimize(True, True, True)
             200M             205M     1.03  IntegrationTwoDatasets.peakmem_optimize
       2.29±0.04s       2.12±0.06s     0.92  IntegrationTwoDatasets.time_optimize

@joernweissenborn joernweissenborn force-pushed the feature/simpledecays branch 3 times, most recently from fed674d to aa23647 Compare October 16, 2021 11:57
@jsnel jsnel force-pushed the feature/simpledecays branch from aa23647 to 81e8f3d Compare October 18, 2021 20:17
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

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
3.2% 3.2% Duplication

@jsnel jsnel mentioned this pull request Oct 18, 2021
3 tasks
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.

At a first glimpse (didn't look at implementation details with the debugger, see failing comparison tests) there are mostly nitpicky things.

@s-weigand
Copy link
Member

Codacy has valid complaints or is gamma a method for API consistency reasons?

@joernweissenborn
Copy link
Member Author

Codacy has valid complaints or is gamma a method for API consistency reasons?

gamma is taken over from TIM(P). They call it like this there. Will be clarified when I refactor decay magacomplex to be in line with my thesis. For now it is just a "suck it up" function. Maybe @jsnel can give some context.

Still I should investigate if I cannot fix this complaints ;)

@s-weigand
Copy link
Member

SonarCloud Quality Gate failed. Quality Gate failed

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 25.1% 25.1% Duplication

Most duplications are in the testes which should be gone with #866 (Ref.: #860 (comment)).

But I think something like this

        decay_megacomplexes = [
            m
            for m in dataset_model.megacomplex
            if isinstance(
                m, (DecayMegacomplex, DecayParallelMegacomplex, DecaySequentialMegacomplex)
            )
        ]

can be nicely factored out in a conveniences function filter_objects_by_type (...naming things😓) which we then could reuse all over the place.

@jsnel
Copy link
Member

jsnel commented Dec 3, 2021

Codacy has valid complaints or is gamma a method for API consistency reasons?

gamma is taken over from TIM(P). They call it like this there. Will be clarified when I refactor decay magacomplex to be in line with my thesis. For now it is just a "suck it up" function. Maybe @jsnel can give some context.

This is not about the name gamma but its definition. In TIMP gamma is not even a function, let alone a method, it's just used as a vector.

Codacy correctly finds that:
"Method could be a function Used when a method doesn't use its bound instance, and so could be written as a function." (pylint no-self-use (R0201))

Just refactor it out or make it a staticmethod.

@jsnel
Copy link
Member

jsnel commented Dec 3, 2021

The result consistency check is failing, with significant differences in a_matrix and decay_associated_spectra. This needs to be explained / investigated. If there was a (long standing) bug that was fixed then that bug must first be fixed independently on main.

@joernweissenborn
Copy link
Member Author

The result consistency check is failing, with significant differences in a_matrix and decay_associated_spectra. This needs to be explained / investigated. If there was a (long standing) bug that was fixed then that bug must first be fixed independently on main.

I created a hotifx PR to backport the fix to 0.5.

jsnel added a commit to jsnel/pyglotaran that referenced this pull request Dec 11, 2021
Backport of bugfix glotaran#927 discovered in PR glotaran#860

It was [found](glotaran#860 (comment)) in glotaran#860 that the a_matrix when calculated for result saving was calculated without normalized initial_concentrations while the calculation for the optimization was (correctly) using the normalized version. Fixing this bug in glotaran#927 then breaks result consistency checking for some case studies, thus requiring backporting of this bugfix to the 0.4 maintenance branch which we continue to use for result/consistency checking.
jsnel added a commit to jsnel/pyglotaran that referenced this pull request Dec 11, 2021
- 🩹🚧 Backport of bugfix glotaran#927 discovered in PR glotaran#860 related to initial_concentration normalization when saving results (glotaran#934).
jsnel added a commit to jsnel/pyglotaran that referenced this pull request Dec 11, 2021
- 🩹🚧 Backport of bugfix glotaran#927 discovered in PR glotaran#860 related to initial_concentration normalization when saving results (glotaran#935).
jsnel added a commit that referenced this pull request Dec 12, 2021
…ncy checking purposes (#935)

* 🩹🚧 Backport of bugfix

Backport of bugfix #927 discovered in PR #860

It was [found](#860 (comment)) in #860 that the a_matrix when calculated for result saving was calculated without normalized initial_concentrations while the calculation for the optimization was (correctly) using the normalized version. Fixing this bug in #927 then breaks result consistency checking for some case studies, thus requiring backporting of this bugfix to the 0.4 maintenance branch which we continue to use for result/consistency checking.

* 🚀🚧 v0.4.2 Maintenance release

- 🩹🚧 Backport of bugfix #927 discovered in PR #860 related to initial_concentration normalization when saving results (#935).

* 🚇🚧 Updated 'gold standard' result comparison reference

Updated pyglotaran-examples result-comparison branch for pyglotaran v0.4.2

Note: comments in PR #936 provide explanation for a small test deviation in the results comparison check for this PR.
@jsnel jsnel force-pushed the feature/simpledecays branch from 40edcf0 to 189df85 Compare December 12, 2021 03:22
@jsnel jsnel mentioned this pull request Dec 31, 2021
1 task
@jsnel jsnel force-pushed the feature/simpledecays branch 2 times, most recently from fa5cdc2 to 196e5a8 Compare January 1, 2022 02:08
@jsnel jsnel force-pushed the feature/simpledecays branch from 196e5a8 to 233108e Compare January 9, 2022 04:12
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 15, 2022

Sourcery Code Quality Report

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

Quality metrics Before After Change
Complexity 2.66 ⭐ 3.08 ⭐ 0.42 👎
Method Length 72.54 🙂 61.79 🙂 -10.75 👍
Working memory 9.64 🙂 9.35 🙂 -0.29 👍
Quality 66.38% 🙂 67.90% 🙂 1.52% 👍
Other metrics Before After Change
Lines 839 851 12
Changed files Quality Before Quality After Quality Change
glotaran/builtin/megacomplexes/decay/init.py % % %
glotaran/builtin/megacomplexes/decay/decay_megacomplex.py 70.00% 🙂 91.10% ⭐ 21.10% 👍
glotaran/builtin/megacomplexes/decay/initial_concentration.py 83.93% ⭐ 88.17% ⭐ 4.24% 👍
glotaran/builtin/megacomplexes/decay/k_matrix.py 78.25% ⭐ 79.15% ⭐ 0.90% 👍
glotaran/builtin/megacomplexes/decay/util.py 53.80% 🙂 55.09% 🙂 1.29% 👍
glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py 59.54% 🙂 59.54% 🙂 0.00%
glotaran/builtin/megacomplexes/decay/test/test_k_matrix.py 65.74% 🙂 71.83% 🙂 6.09% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
glotaran/builtin/megacomplexes/decay/util.py calculate_decay_matrix_gaussian_irf 11 🙂 183 😞 18 ⛔ 38.30% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/builtin/megacomplexes/decay/util.py retrieve_decay_associated_data 1 ⭐ 254 ⛔ 17 ⛔ 44.09% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/builtin/megacomplexes/decay/util.py finalize_data 15 🙂 105 🙂 13 😞 49.06% 😞 Extract out complex expressions
glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py test_kinetic_model 3 ⭐ 238 ⛔ 9 🙂 54.99% 🙂 Try splitting into smaller methods
glotaran/builtin/megacomplexes/decay/util.py retrieve_species_associated_data 6 ⭐ 105 🙂 14 😞 55.78% 🙂 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 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
31.4% 31.4% Duplication

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.

For the sake of getting on with the "merge train" I guess this is fine from my side.
Even so, I don't agree with the removing of DecayMegacomplexBase which added useless code duplication and cyclic import workarounds, just because of a disagreement about using abstract base classes

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.

Reviewed ok. Raised issue for the concerns voiced during review.

@jsnel jsnel merged commit 86ed99f into glotaran:main Jan 16, 2022
@s-weigand s-weigand mentioned this pull request Jan 16, 2022
4 tasks
@s-weigand s-weigand changed the title Feature: Simple Decays ✨ Add simple decay megacomplexes Jan 16, 2022
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