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

♻️ Refactor: Model and Parameters #1135

Merged
merged 45 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e5ebe97
Added basic model.
joernweissenborn Sep 18, 2022
c08ce71
Added megacomplexes model.
joernweissenborn Sep 18, 2022
f64705c
New Model can load from dict.
joernweissenborn Sep 20, 2022
e9e45bb
Basic idea for item fill.
joernweissenborn Sep 20, 2022
2a3c8e7
Added get issues.
joernweissenborn Sep 21, 2022
7a0ad27
Added item fill.
joernweissenborn Sep 22, 2022
2a4dee3
Added model as_dict.
joernweissenborn Sep 22, 2022
b31b492
Added model markdown.
joernweissenborn Sep 22, 2022
eab88d2
Added get parameter labels.
joernweissenborn Sep 22, 2022
c0ba88a
Added validate dataset datasetmodel megacomplexes.
joernweissenborn Sep 23, 2022
cc1a92b
Added global items.
joernweissenborn Sep 23, 2022
36a8427
Replaced old model with new.
joernweissenborn Sep 23, 2022
1033264
Adapted optimization.
joernweissenborn Sep 23, 2022
4cc7425
Adapted builtin megacomplexes.
joernweissenborn Sep 30, 2022
c5c288a
Reimplemented ParameterGroup as Parameters.
joernweissenborn Oct 1, 2022
b79c460
Adapted yml load parameters.
joernweissenborn Oct 2, 2022
d0499ec
All test are working again.
joernweissenborn Oct 2, 2022
85add4e
Fixed mypy issues and added docstrings for model package.
joernweissenborn Oct 3, 2022
405a85a
Fixed small bugs.
joernweissenborn Oct 3, 2022
1870cb0
🩹 Fixed benchmarks
s-weigand Oct 3, 2022
3f8949f
♻️ Refactored by Sourcery
Oct 3, 2022
2f6fbcf
Fixed project parameter generation.
joernweissenborn Oct 8, 2022
e43b38d
💥 Raised min python version to 3.10
s-weigand Oct 8, 2022
5a6fe74
Refactored clp penalties to have types.
joernweissenborn Oct 9, 2022
b59eca9
Deprecated parameter group.
joernweissenborn Oct 9, 2022
bfb38e9
Fixed model as_dict aand validate.
joernweissenborn Oct 9, 2022
cbf68fd
Fixed unique megacomplex check.
joernweissenborn Oct 9, 2022
ae0521d
Fixed damped oscillation megacomplex type.
joernweissenborn Oct 9, 2022
071aa98
Small fixes.
joernweissenborn Oct 14, 2022
9d54e16
🩹🗑️ Raised deprecation version for new deprecations to 0.9.0
s-weigand Oct 15, 2022
6fc6a69
🧹 Renamed fuctions not conforming to snake case
s-weigand Oct 15, 2022
38c9add
✨ Added equality check for Parameters
s-weigand Oct 15, 2022
90ef396
♻️ Made nan_or_equal work with general values not only numeric
s-weigand Oct 15, 2022
1843ed2
👌 Added helper decorator to omit default values from repr in attrs class
s-weigand Oct 15, 2022
c3695b3
👌 Added proper repr to Parameters
s-weigand Oct 15, 2022
d718352
🧪🩹 Fixed and reactivated pandas tests
s-weigand Oct 15, 2022
9d8f6c9
🩹📚 Changed read the docs config to work with python 3.10
s-weigand Oct 15, 2022
6d7597a
Fixed bug in interval item.
joernweissenborn Oct 16, 2022
611f084
Fixed Parameters.copy.
joernweissenborn Oct 16, 2022
90ac37a
Added test to check that initial parameters don't get overwritten.
joernweissenborn Oct 16, 2022
0245e19
Included review comments.
joernweissenborn Nov 4, 2022
a23d15e
Updated changelog.
joernweissenborn Nov 4, 2022
c5996bf
🩹 Fixed integration benchmark
s-weigand Nov 4, 2022
f96340f
👌Avoid redefining built-in type
jsnel Nov 4, 2022
3c2006e
📚 Added change to changelog
jsnel Nov 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/CI_CD_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Run pre-commit
uses: pre-commit/[email protected]

Expand All @@ -29,10 +29,10 @@ jobs:
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install check manifest
run: python -m pip install check-manifest 'setuptools>=62.4.0'
- name: Run check manifest
Expand All @@ -47,10 +47,10 @@ jobs:
with:
conda-channels: conda-forge
activate-conda: false
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install dependencies
run: |
conda install -y pandoc
Expand All @@ -72,10 +72,10 @@ jobs:
with:
conda-channels: conda-forge
activate-conda: false
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install dependencies
run: |
conda install -y pandoc
Expand All @@ -96,10 +96,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install -U pip wheel
Expand All @@ -117,7 +117,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: [3.8, 3.9, "3.10"]
python-version: ["3.10"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -147,10 +147,10 @@ jobs:
needs: [test, docs, docs-notebooks]
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install -U pip wheel 'setuptools>=62.4.0'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
name: Doxygen callgraph
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install dependencies
run: pip install requests
- name: Get ref to check out
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/full_benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
with:
fetch-depth: 0
ref: main
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install ASV
run: |
pip install asv virtualenv
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
example_name: ${{fromJson(needs.create-example-list.outputs.example-list)}}
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install pyglotaran
run: |
pip install wheel
Expand Down Expand Up @@ -93,10 +93,10 @@ jobs:
echo "♻️ pyglotaran-examples commit: $(< comparison-results-current/example_commit_sha.txt)"
echo "::endgroup::"

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr_benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.10"
- name: Install ASV
run: |
pip install 'asv!=0.5' virtualenv
Expand Down
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ repos:
types: [file]
types_or: [python, pyi]
args: [--py38-plus]
exclude: "glotaran.model.item"

- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
Expand Down Expand Up @@ -105,17 +106,17 @@ repos:
args:
- "--select=D,DAR"
name: "flake8 lint docstrings"
files: "^glotaran/(plugin_system|utils|deprecation|testing|optimization|parameter|project|simulation|model/property.py|builtin/io/pandas)"
files: "^glotaran/(plugin_system|utils|deprecation|testing|optimization|parameter|project|simulation|model|builtin/io/pandas)"
exclude: "docs|tests?/"
additional_dependencies: [flake8-docstrings, darglint==1.8.0]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
hooks:
- id: mypy
files: "^glotaran/(plugin_system|utils|deprecation|testing|optimization|parameter|project|simulation|model/property.py|builtin/io/pandas)"
files: "^glotaran/(plugin_system|utils|deprecation|testing|optimization|parameter|project|simulation|model|builtin/io/pandas)"
exclude: "docs"
additional_dependencies: [types-all]
additional_dependencies: [types-all, types-attrs]

- repo: https://github.com/econchick/interrogate
rev: 1.5.0
Expand Down
2 changes: 1 addition & 1 deletion .sourcery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ refactor:
- simplify-boolean-comparison
- simplify-len-comparison
- remove-unnecessary-cast
python_version: "3.8"
python_version: "3.10"

metrics:
quality_threshold: 25.0
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Before you submit a pull request, check that it meets these guidelines:
1. The pull request should include tests.
2. If the pull request adds functionality, the docs should be updated. Put
your new functionality into a function with a `docstring`_.
3. The pull request should work for Python 3.8 and 3.9
3. The pull request should work for Python 3.10
Check your Github Actions ``https://github.com/<your_name_here>/pyglotaran/actions``
and make sure that the tests pass for all supported Python versions.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A common use case for the library is the analysis of time-resolved spectroscopy

Prerequisites:

- Python 3.8, 3.9 or 3.10
- Python 3.10
- On Windows only 64bit is supported

Note for Windows Users: The easiest way to get python for Windows is via [Anaconda](https://www.anaconda.com/)
Expand Down
11 changes: 9 additions & 2 deletions benchmark/benchmarks/integration/ex_two_datasets/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pathlib import Path

from glotaran import __version__

try:
# 0.4.0 -0.5.1
from glotaran.analysis.optimize import optimize
Expand Down Expand Up @@ -28,15 +30,20 @@ class IntegrationTwoDatasets:
def setup(self):
dataset1 = load_dataset(SCRIPT_DIR / "data/data1.ascii")
dataset2 = load_dataset(SCRIPT_DIR / "data/data2.ascii")
model = load_model(str(SCRIPT_DIR / "models/model.yml"))
parameters = load_parameters(str(SCRIPT_DIR / "models/parameters.yml"))
addition_kwargs = {}
if int(__version__.split(".")[1]) < 7:
model = load_model(str(SCRIPT_DIR / "models/model_lt_0.7.0.yml"))
addition_kwargs["non_negative_least_squares"] = True
else:
model = load_model(str(SCRIPT_DIR / "models/model.yml"))
self.scheme = Scheme(
model,
parameters,
{"dataset1": dataset1, "dataset2": dataset2},
maximum_number_function_evaluations=11,
non_negative_least_squares=True,
optimization_method="TrustRegionReflection",
**addition_kwargs,
)

def time_optimize(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type: kinetic-spectrum
default_megacomplex: decay

dataset:
dataset1:
Expand Down Expand Up @@ -33,16 +33,16 @@ initial_concentration:

irf:
irf1:
type: spectral-multi-gaussian
center: [irf.center]
width: [irf.width]
type: gaussian
center: irf.center
width: irf.width
irf1_no_dispersion:
type: spectral-multi-gaussian
center: [irf.center]
width: [irf.width]
type: gaussian
center: irf.center
width: irf.width

# It works without equal_area_penalties but then the inputs cannot be estimated
equal_area_penalties:
clp_penalties:
- type: equal_area
source: s1
source_intervals: [[300, 3000]]
Expand All @@ -57,7 +57,6 @@ equal_area_penalties:
target_intervals: [[300, 3000]]
parameter: area.1
weight: 0.1

# Example of weight application:
# weights:
# - datasets: [dataset1, dataset2]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
type: kinetic-spectrum

dataset:
dataset1:
megacomplex: [complex1]
initial_concentration: input1
irf: irf1
scale: scale.1
dataset2:
megacomplex: [complex1]
initial_concentration: input2
irf: irf1
scale: scale.2

megacomplex:
complex1:
k_matrix: [km1]

k_matrix:
km1:
matrix:
(s1, s1): "rates.k1"
(s2, s2): "rates.k2"
(s3, s3): "rates.k3"

initial_concentration:
input1:
compartments: [s1, s2, s3]
parameters: [inputs.1, inputs.2, inputs.3]
input2:
compartments: [s1, s2, s3]
parameters: [inputs.1, inputs.7, inputs.8]

irf:
irf1:
type: spectral-multi-gaussian
center: [irf.center]
width: [irf.width]
irf1_no_dispersion:
type: spectral-multi-gaussian
center: [irf.center]
width: [irf.width]

# It works without equal_area_penalties but then the inputs cannot be estimated
equal_area_penalties:
- type: equal_area
source: s1
source_intervals: [[300, 3000]]
target: s2
target_intervals: [[300, 3000]]
parameter: area.1
weight: 0.1
- type: equal_area
source: s1
source_intervals: [[300, 3000]]
target: s3
target_intervals: [[300, 3000]]
parameter: area.1
weight: 0.1
# Example of weight application:
# weights:
# - datasets: [dataset1, dataset2]
# global_interval: [100, 102]
# model_interval: [301, 502]
# value: 0.95
21 changes: 12 additions & 9 deletions benchmark/pytest/analysis/test_optimization_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from glotaran.model import Model
from glotaran.model import megacomplex
from glotaran.optimization.optimization_group import OptimizationGroup
from glotaran.parameter import ParameterGroup
from glotaran.parameter import Parameters
from glotaran.project import Scheme
from glotaran.testing.plugin_system import monkeypatch_plugin_registry

Expand All @@ -32,11 +32,15 @@
np.ones((TEST_AXIS_GLOBAL_SIZE, TEST_AXIS_MODEL_SIZE)),
coords=(("global", TEST_AXIS_GLOBAL.data), ("test", TEST_AXIS_MODEL.data)),
)
TEST_PARAMETERS = ParameterGroup.from_list([])
TEST_PARAMETERS = Parameters.from_list([])


@megacomplex(dimension="test", properties={"is_index_dependent": bool})
@megacomplex()
class BenchmarkMegacomplex(Megacomplex):
dimension: str = "test"
type: str = "benchmark"
is_index_dependent: bool

def calculate_matrix(
self,
dataset_model,
Expand All @@ -60,22 +64,21 @@ def finalize_data(
pass


BenchmarkModel = Model.create_class_from_megacomplexes([BenchmarkMegacomplex])


@monkeypatch_plugin_registry(test_megacomplex={"benchmark": BenchmarkMegacomplex})
def setup_model(index_dependent, link_clp):
model_dict = {
"megacomplex": {"m1": {"is_index_dependent": index_dependent}},
"megacomplex": {"m1": {"type": "benchmark", "is_index_dependent": index_dependent}},
"dataset_groups": {"default": {"link_clp": link_clp}},
"dataset": {
"dataset1": {"megacomplex": ["m1"]},
"dataset2": {"megacomplex": ["m1"]},
"dataset3": {"megacomplex": ["m1"]},
},
}
return Model.from_dict(
model_dict,
megacomplex_types={"benchmark": BenchmarkMegacomplex},
default_megacomplex_type="benchmark",
)
return BenchmarkModel(**model_dict)


def setup_scheme(model):
Expand Down
Loading