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 clp guidance megacomplex #1029

Merged
merged 18 commits into from
Apr 2, 2022

Conversation

joernweissenborn
Copy link
Member

@joernweissenborn joernweissenborn commented Mar 26, 2022

This PR adds the clp-guide megacomplex.

A model with a clp guide looks like this:

{
"dataset_groups": {"default": {"link_clp": True}},
"megacomplex": {
    "mc1": {
        "type": "decay-sequential",
        "compartments": ["s1", "s2"],
        "rates": ["1", "2"],
    },
    "mc2": {"type": "clp-guide", "dimension": "time", "target": "s1"},
},
"dataset": {
    "dataset1": {"megacomplex": ["mc1"]},
    "dataset2": {"megacomplex": ["mc2"]},
},

Change summary

  • added the exclusive attribute to megacomplex decorator which ensures that a megacomplex is the only one in a dataset
  • added the builtin megacomplex ClpGuideMegacomplex
  • added the method Result.create_clp_guide_dataset to create clp guides from results

Checklist

  • ✔️ Passing the tests (mandatory for all PR's)
  • 🚧 Added changes to changelog (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 #1027

@joernweissenborn joernweissenborn requested a review from jsnel as a code owner March 26, 2022 14:00
@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 26, 2022

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]       [7e3f632b]
     <v0.5.1>                   
         61.9±1ms         64.4±1ms     1.04  BenchmarkOptimize.time_optimize(False, False, False)
         66.8±2ms        69.5±20ms     1.04  BenchmarkOptimize.time_optimize(False, False, True)
       62.6±0.7ms         64.6±3ms     1.03  BenchmarkOptimize.time_optimize(False, True, False)
        66.6±20ms         70.6±3ms     1.06  BenchmarkOptimize.time_optimize(False, True, True)
       74.8±0.7ms         78.2±3ms     1.04  BenchmarkOptimize.time_optimize(True, False, False)
        86.3±30ms        87.3±40ms     1.01  BenchmarkOptimize.time_optimize(True, False, True)
       73.2±0.8ms         76.4±3ms     1.04  BenchmarkOptimize.time_optimize(True, True, False)
        81.7±40ms         129±30ms    ~1.58  BenchmarkOptimize.time_optimize(True, True, True)
             202M             208M     1.03  IntegrationTwoDatasets.peakmem_optimize
       1.99±0.03s       1.95±0.03s     0.98  IntegrationTwoDatasets.time_optimize

Benchmark diff main vs. PR

Parametrized benchmark signatures:

BenchmarkOptimize.time_optimize(index_dependent, grouped, weight)

All benchmarks:

       before           after         ratio
     [500d1768]       [7e3f632b]
+        58.2±1ms         64.4±1ms     1.11  BenchmarkOptimize.time_optimize(False, False, False)
        65.2±20ms        69.5±20ms     1.07  BenchmarkOptimize.time_optimize(False, False, True)
         58.9±1ms         64.6±3ms     1.10  BenchmarkOptimize.time_optimize(False, True, False)
        97.6±50ms         70.6±3ms    ~0.72  BenchmarkOptimize.time_optimize(False, True, True)
         72.1±2ms         78.2±3ms     1.08  BenchmarkOptimize.time_optimize(True, False, False)
        79.5±30ms        87.3±40ms     1.10  BenchmarkOptimize.time_optimize(True, False, True)
         75.0±1ms         76.4±3ms     1.02  BenchmarkOptimize.time_optimize(True, True, False)
         140±30ms         129±30ms     0.92  BenchmarkOptimize.time_optimize(True, True, True)
             206M             208M     1.01  IntegrationTwoDatasets.peakmem_optimize
       1.88±0.03s       1.95±0.03s     1.04  IntegrationTwoDatasets.time_optimize

@codecov
Copy link

codecov bot commented Mar 26, 2022

Codecov Report

Attention: Patch coverage is 94.11765% with 5 lines in your changes missing coverage. Please review.

Project coverage is 87.1%. Comparing base (500d176) to head (7e3f632).
Report is 240 commits behind head on main.

Files Patch % Lines
.../builtin/io/ascii/wavelength_time_explicit_file.py 75.0% 2 Missing and 1 partial ⚠️
glotaran/model/dataset_model.py 93.5% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1029     +/-   ##
=======================================
+ Coverage   86.9%   87.1%   +0.2%     
=======================================
  Files         99     101      +2     
  Lines       5314    5377     +63     
  Branches     980     995     +15     
=======================================
+ Hits        4618    4687     +69     
+ Misses       544     536      -8     
- Partials     152     154      +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@s-weigand s-weigand force-pushed the feature/clp_guidance branch from be0a643 to b3f5d6b Compare March 26, 2022 15:26
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.

Just some minor nitpicks about error messages and backward compatibility with the ascii format.

Might also be nice to factor the creation out in a separate function so we can use it on a dataset from file basis (e.g. reading legacy project ascii files from TMP and TIMP) 🤔

glotaran/project/result.py Outdated Show resolved Hide resolved
glotaran/project/result.py Outdated Show resolved Hide resolved
glotaran/project/result.py Outdated Show resolved Hide resolved
glotaran/project/result.py Outdated Show resolved Hide resolved
glotaran/project/result.py Outdated Show resolved Hide resolved
glotaran/project/test/test_result.py Show resolved Hide resolved
@s-weigand s-weigand changed the title Feature: Add clp guidance megacomplex ✨ Add clp guidance megacomplex Mar 26, 2022
@s-weigand s-weigand force-pushed the feature/clp_guidance branch from 1301093 to 438eef2 Compare March 27, 2022 18:25
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 27, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.78%.

Quality metrics Before After Change
Complexity 3.80 ⭐ 4.01 ⭐ 0.21 👎
Method Length 50.68 ⭐ 51.19 ⭐ 0.51 👎
Working memory 6.85 🙂 7.16 🙂 0.31 👎
Quality 73.12% 🙂 72.34% 🙂 -0.78% 👎
Other metrics Before After Change
Lines 2008 2147 139
Changed files Quality Before Quality After Quality Change
glotaran/analysis/optimization_group.py 73.02% 🙂 72.70% 🙂 -0.32% 👎
glotaran/builtin/megacomplexes/decay/test/test_decay_megacomplex.py 54.89% 🙂 54.89% 🙂 0.00%
glotaran/model/dataset_model.py 80.93% ⭐ 73.28% 🙂 -7.65% 👎
glotaran/model/megacomplex.py 74.48% 🙂 73.97% 🙂 -0.51% 👎
glotaran/model/model.py 70.83% 🙂 70.74% 🙂 -0.09% 👎
glotaran/model/test/test_model.py 72.68% 🙂 72.44% 🙂 -0.24% 👎
glotaran/project/result.py 76.82% ⭐ 76.91% ⭐ 0.09% 👍
glotaran/project/test/test_result.py 82.73% ⭐ 83.23% ⭐ 0.50% 👍

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

File Function Complexity Length Working Memory Quality Recommendation
glotaran/model/dataset_model.py DatasetModel.ensure_unique_megacomplexes 14 🙂 104 🙂 15 😞 47.35% 😞 Extract out complex expressions
glotaran/project/result.py Result.markdown 7 ⭐ 186 😞 13 😞 47.42% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/analysis/optimization_group.py OptimizationGroup._add_weight 15 🙂 134 😞 11 😞 48.74% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/model/model.py Model.markdown 13 🙂 168 😞 10 😞 48.74% 😞 Try splitting into smaller methods. Extract out complex expressions
glotaran/model/model.py Model.from_dict 12 🙂 162 😞 10 😞 50.19% 🙂 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!

@s-weigand
Copy link
Member

This is what the model would look like as yaml, since no one besides our unit tests defines a model as dict 😉

dataset:
  dataset1:
    megacomplex:
    - mc1
  dataset2:
    megacomplex:
    - mc2
dataset_groups:
  default:
    link_clp: true
megacomplex:
  mc1:
    compartments:
    - s1
    - s2
    rates:
    - '1'
    - '2'
    type: decay-sequential
  mc2:
    dimension: time
    target: s1
    type: clp-guide

@s-weigand s-weigand force-pushed the feature/clp_guidance branch from 438eef2 to 9a5d038 Compare March 31, 2022 22:23
@s-weigand s-weigand force-pushed the feature/clp_guidance branch from 9a5d038 to 23d0360 Compare April 1, 2022 12:19
@joernweissenborn joernweissenborn requested a review from a team as a code owner April 1, 2022 12:19
s-weigand
s-weigand previously approved these changes Apr 1, 2022
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.

Should be ready to merge now (reviewing my own changes 😝 )

@jsnel @ism200 For the usage guide of create_clp_guide_dataset see the docs generated from the docstrings you can try it on binder (also works with ascii just change the file extension)

glotaran/utils/io.py Outdated Show resolved Hide resolved
glotaran/utils/io.py Outdated Show resolved Hide resolved
glotaran/utils/io.py Outdated Show resolved Hide resolved
jsnel
jsnel previously approved these changes Apr 1, 2022
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 as ok, code wise, found some improvements to documentation here and there.

jsnel added a commit to joernweissenborn/pyglotaran that referenced this pull request Apr 2, 2022
Minor improvements to documentation following code review on glotaran#1029.
Fixed interrogate issues with invalid exclude argument in pyproject.toml
Set ignore-semiprivate to true (for now) for interrogate (else coverage dips below 59)
Added a docstring to improve coverage (as measured by interrogate)
@jsnel jsnel dismissed stale reviews from s-weigand and themself via 5e03926 April 2, 2022 00:12
Minor improvements to documentation following code review on glotaran#1029.
Fixed interrogate issues with invalid exclude argument in pyproject.toml
Set ignore-semiprivate to true (for now) for interrogate (else coverage dips below 59)
Added a docstring to improve coverage (as measured by interrogate)
@jsnel jsnel force-pushed the feature/clp_guidance branch from 5e03926 to ff1ada9 Compare April 2, 2022 00:30
jsnel
jsnel previously approved these changes Apr 2, 2022
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.

Could do with some more documentation (doc strings), especially in the util function department, but code wise OK.

@jsnel jsnel requested a review from s-weigand April 2, 2022 00:37
click>=8 breaks usage of glob patterns with interrogate
Current docstring coverage is 65%
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 2, 2022

Kudos, SonarCloud Quality Gate passed!    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
0.0% 0.0% Duplication

@jsnel jsnel merged commit acc21fc into glotaran:main Apr 2, 2022
@s-weigand s-weigand mentioned this pull request Apr 2, 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.

✨Make guidance spectra a builtin megacomplex
3 participants