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

♻️ Move simulation to own module #1041

Merged
merged 7 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
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