Skip to content

Commit

Permalink
♻️ Move simulation to own module (#1041)
Browse files Browse the repository at this point in the history
* Moved simulation to glotaran.simulation module
* Change simulation imports to new simulation module.
* Updated simulation docstrings.
* Fixed mypy issues.

* 🩹🧪 Fixed deperecation test for simulation module
* 🚧📚 Added change to changelog

* 📚 Minor improvements to docstrings

Co-authored-by: s-weigand <s.weigand.phy@gmail.com>
Co-authored-by: Joris Snellenburg <jsnel@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 2, 2022
1 parent d1a9637 commit 712170f
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ repos:
args:
- "--select=D,DAR"
name: "flake8 lint docstrings"
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project|model/property.py|builtin/io/pandas)"
files: "^glotaran/(plugin_system|utils|deprecation|testing|parameter|project|simulation|model/property.py|builtin/io/pandas)"
exclude: "docs|tests?/"
additional_dependencies: [flake8-docstrings, darglint==1.8.0]

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

Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- 👌 Added IRF shift to result dataset (#994)
- 👌 Improve Result, Parameter and ParameterGroup markdown (#1012)
- 👌🧹 Add suffix to rate and lifetime and guard for missing datasets (#1022)
- ♻️ Move simulation to own module (#1041)

### 🩹 Bug fixes

Expand All @@ -29,6 +30,7 @@
### 🗑️ Deprecations (due in 0.8.0)

- `glotaran.io.save_result(result, result_path, format_name='legacy')` -> `glotaran.io.save_result(result, Path(result_path) / 'result.yml')`
- `glotaran.analysis.simulation` -> `glotaran.simulation.simulation`

### 🚧 Maintenance

Expand Down
6 changes: 6 additions & 0 deletions glotaran/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@
new_module_name="glotaran.project.scheme",
to_be_removed_in_version="0.6.0",
)

simulation = deprecate_submodule(
deprecated_module_name="glotaran.analysis.simulation",
new_module_name="glotaran.simulation.simulation",
to_be_removed_in_version="0.8.0",
)
2 changes: 1 addition & 1 deletion glotaran/analysis/test/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import pytest

from glotaran.analysis.optimization_group import OptimizationGroup
from glotaran.analysis.simulation import simulate
from glotaran.analysis.test.models import TwoCompartmentDecay as suite
from glotaran.model import ZeroConstraint
from glotaran.project import Scheme
from glotaran.simulation import simulate


@pytest.mark.parametrize("index_dependent", [True, False])
Expand Down
2 changes: 1 addition & 1 deletion glotaran/analysis/test/test_multiple_goups.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.analysis.test.models import DecayModel
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


def test_multiple_groups():
Expand Down
2 changes: 1 addition & 1 deletion glotaran/analysis/test/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import xarray as xr

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.analysis.test.models import FullModel
from glotaran.analysis.test.models import MultichannelMulticomponentDecay
from glotaran.analysis.test.models import OneCompartmentDecay
from glotaran.analysis.test.models import ThreeDatasetDecay
from glotaran.analysis.test.models import TwoCompartmentDecay
from glotaran.project import Scheme
from glotaran.simulation import simulate


@pytest.mark.parametrize("is_index_dependent", [True, False])
Expand Down
2 changes: 1 addition & 1 deletion glotaran/analysis/test/test_optimization_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from glotaran.analysis.optimization_group_calculator_linked import (
OptimizationGroupCalculatorLinked,
)
from glotaran.analysis.simulation import simulate
from glotaran.analysis.test.models import FullModel
from glotaran.analysis.test.models import MultichannelMulticomponentDecay as suite
from glotaran.analysis.test.models import SimpleTestModel
from glotaran.analysis.util import CalculatedMatrix
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


@pytest.fixture(
Expand Down
2 changes: 1 addition & 1 deletion glotaran/analysis/test/test_penalties.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest

from glotaran.analysis.optimization_group import OptimizationGroup
from glotaran.analysis.simulation import simulate
from glotaran.analysis.test.models import TwoCompartmentDecay as suite
from glotaran.model import EqualAreaPenalty
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


@pytest.mark.parametrize("index_dependent", [True, False])
Expand Down
2 changes: 1 addition & 1 deletion glotaran/analysis/test/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import pytest

from glotaran.analysis.optimization_group import OptimizationGroup
from glotaran.analysis.simulation import simulate
from glotaran.analysis.test.models import TwoCompartmentDecay as suite
from glotaran.model import Relation
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


@pytest.mark.parametrize("index_dependent", [True, False])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import xarray as xr

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.analysis.util import calculate_matrix
from glotaran.builtin.megacomplexes.coherent_artifact import CoherentArtifactMegacomplex
from glotaran.builtin.megacomplexes.decay import DecayMegacomplex
from glotaran.model import Model
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


@pytest.mark.parametrize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import pytest

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.builtin.megacomplexes.damped_oscillation import DampedOscillationMegacomplex
from glotaran.builtin.megacomplexes.decay import DecayMegacomplex
from glotaran.builtin.megacomplexes.spectral import SpectralMegacomplex
from glotaran.model import Megacomplex
from glotaran.model import Model
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


class DampedOscillationsModel(Model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import xarray as xr

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.model import Model
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


def create_gaussian_clp(labels, amplitudes, centers, widths, axis):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import pytest

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.io import load_model
from glotaran.io import load_parameters
from glotaran.project import Scheme
from glotaran.simulation import simulate

MODEL_BASE = """\
default_megacomplex: decay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import xarray as xr

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.analysis.util import calculate_matrix
from glotaran.builtin.megacomplexes.decay.test.test_decay_megacomplex import DecayModel
from glotaran.builtin.megacomplexes.spectral import SpectralMegacomplex
from glotaran.model import Megacomplex
from glotaran.model import Model
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate


class SpectralModel(Model):
Expand Down
2 changes: 1 addition & 1 deletion glotaran/builtin/megacomplexes/test/test_spectral_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import pytest

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.io import load_model
from glotaran.io import load_parameters
from glotaran.project import Scheme
from glotaran.simulation import simulate

MODEL_3C_NO_IRF = """\
dataset:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import pytest

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.io import load_model
from glotaran.io import load_parameters
from glotaran.project import Scheme
from glotaran.simulation import simulate

MODEL_3C_BASE = """\
dataset:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import numpy as np

from glotaran.analysis.optimize import optimize
from glotaran.analysis.simulation import simulate
from glotaran.builtin.megacomplexes.decay import DecayMegacomplex
from glotaran.builtin.megacomplexes.spectral import SpectralMegacomplex
from glotaran.io import prepare_time_trace_dataset
from glotaran.model import Megacomplex
from glotaran.model import Model
from glotaran.parameter import ParameterGroup
from glotaran.project import Scheme
from glotaran.simulation import simulate

ParameterSpec = namedtuple("ParameterSpec", "base equal_area shapes")
NoiseSpec = namedtuple("NoiseSpec", "active seed std_dev")
Expand Down
18 changes: 18 additions & 0 deletions glotaran/deprecation/modules/test/test_changed_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from glotaran.project import Scheme
from glotaran.project import result as project_result
from glotaran.project import scheme as project_scheme
from glotaran.simulation import simulation as simulation_module

if TYPE_CHECKING:
from _pytest.recwarn import WarningsRecorder
Expand Down Expand Up @@ -104,6 +105,23 @@ def test_analysis_result_from_import(recwarn: WarningsRecorder):
assert analysis_result == Result


def test_analysis_simulation(recwarn: WarningsRecorder):
"""Usage of glotaran.analysis.simulation"""
warnings.simplefilter("always")

from glotaran.analysis import simulation as analysis_simulation

assert len(recwarn) == 0
assert analysis_simulation.simulate == simulation_module.simulate # type: ignore[attr-defined]

check_recwarn(recwarn)


def test_analysis_simulation_from_import(recwarn: WarningsRecorder):
"""Same as 'from glotaran.analysis.simulation import simulate as analysis_scheme'"""
changed_import_test_warn(recwarn, "glotaran.analysis.simulation", attribute_name="simulate")


def test_analysis_scheme(recwarn: WarningsRecorder):
"""Usage of glotaran.analysis.scheme"""
warnings.simplefilter("always")
Expand Down
4 changes: 4 additions & 0 deletions glotaran/simulation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Package containing code for simulation of dataset models."""
from glotaran.simulation.simulation import simulate

__all__ = ["simulate"]
Loading

0 comments on commit 712170f

Please sign in to comment.