Skip to content

Commit

Permalink
feat: Moved some core modules to top level (where they were imported …
Browse files Browse the repository at this point in the history
…anyway)
  • Loading branch information
wpk committed May 3, 2023
1 parent 1ca7cbc commit beac8d0
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 63 deletions.
46 changes: 46 additions & 0 deletions changelog.d/20230503_133701_william.krekelberg_module_utilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- markdownlint-disable MD041 -->
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->

### Changed

- Moved `modesl, data, idealgas` from `thermoextrap.core` to `thermoextrap`.
These were imported at top level anyway. This fixes issues with doing things
like `from thermoextrap.data import ...`, etc.
- Moved `core._docstrings_` to `docstrings`.
- Now using `cmomy.docstrings` instead of repeating them here.

<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
<!--
### Fixed
- A bullet item for the Fixed category.
-->
<!--
### Security
- A bullet item for the Security category.
-->
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
"Symbol": "~sympy.core.symbol.Symbol",
"symFunction": "~sympy.core.function.Function",
"ExtrapModel": "~thermoextrap.models.ExtrapModel",
# "DataCentralMoments": "~cmomy.core.data.DataCentralMoments"
# "DataCentralMoments": "~cmomy.DataCentralMoments"
}


Expand Down
12 changes: 6 additions & 6 deletions docs/reference/api-baseclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,37 @@ Base classes
:inherited-members:
:members:

.. autoclass:: thermoextrap.core.models.PiecewiseMixin
.. autoclass:: thermoextrap.models.PiecewiseMixin
:autosummary:
:show-inheritance:
:inherited-members:
:members:

.. autoclass:: thermoextrap.core.models.SymDerivBase
.. autoclass:: thermoextrap.models.SymDerivBase
:autosummary:
:show-inheritance:
:inherited-members:
:members:

.. autoclass:: thermoextrap.core.models.SymFuncBase
.. autoclass:: thermoextrap.models.SymFuncBase
:autosummary:
:show-inheritance:
:members:


.. autoclass:: thermoextrap.core.data.AbstractData
.. autoclass:: thermoextrap.data.AbstractData
:autosummary:
:show-inheritance:
:inherited-members:
:members:

.. autoclass:: thermoextrap.core.data.DataCentralMomentsBase
.. autoclass:: thermoextrap.data.DataCentralMomentsBase
:autosummary:
:show-inheritance:
:inherited-members:
:members:

.. autoclass:: thermoextrap.core.data.DataValuesBase
.. autoclass:: thermoextrap.data.DataValuesBase
:autosummary:
:show-inheritance:
:inherited-members:
Expand Down
10 changes: 4 additions & 6 deletions src/thermoextrap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""Classes/routines to deal with thermodynamic extrapolation."""

from . import beta, lnpi, volume, volume_idealgas

# TODO: move data, idealgas, models to top level.
from .core import data, idealgas, models
from .core.data import (
from . import beta, data, idealgas, lnpi, models, volume, volume_idealgas
from .core.xrutils import xrwrap_alpha, xrwrap_uv, xrwrap_xv
from .data import (
DataCentralMoments,
DataCentralMomentsVals,
DataValues,
Expand All @@ -14,7 +13,7 @@
)

# expose some data/models
from .core.models import (
from .models import (
Derivatives,
ExtrapModel,
ExtrapWeightedModel,
Expand All @@ -24,7 +23,6 @@
PerturbModel,
StateCollection,
)
from .core.xrutils import xrwrap_alpha, xrwrap_uv, xrwrap_xv

# updated versioning scheme
try:
Expand Down
6 changes: 3 additions & 3 deletions src/thermoextrap/adaptive_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ def factory_state_idealgas(
"""

from . import beta as xpan_beta
from .core import idealgas
from .core.data import DataCentralMomentsVals
from . import idealgas
from .data import DataCentralMomentsVals

# NOTE: this is for reproducible results.
if seed_from_beta:
Expand Down Expand Up @@ -574,7 +574,7 @@ def callback_plot_progress( # noqa: D417

import matplotlib.pyplot as plt

from .core import idealgas
from . import idealgas

if verbose:
print("depth:", info_dict["depth"])
Expand Down
6 changes: 3 additions & 3 deletions src/thermoextrap/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from functools import lru_cache
from typing import Literal

from .core._docstrings import DOCFILLER_SHARED
from .core.models import (
from .docstrings import DOCFILLER_SHARED
from .models import (
Derivatives,
ExtrapModel,
PerturbModel,
Expand Down Expand Up @@ -692,7 +692,7 @@ def factory_perturbmodel(beta, uv, xv, alpha_name="beta", **kws):
--------
~thermoextrap.models.PerturbModel
"""
from .core.data import factory_data_values
from .data import factory_data_values

data = factory_data_values(uv=uv, xv=xv, order=0, central=False, **kws)
return PerturbModel(alpha0=beta, data=data, alpha_name=alpha_name)
8 changes: 0 additions & 8 deletions src/thermoextrap/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
"""Core modules."""
from . import data, idealgas, models, stack

__all__ = [
"data",
"models",
"idealgas",
"stack",
]
7 changes: 3 additions & 4 deletions src/thermoextrap/core/data.py → src/thermoextrap/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
from custom_inherit import DocInheritMeta
from module_utilities import cached

from ._attrs_utils import (
from .core._attrs_utils import (
MyAttrsMixin,
_cache_field,
convert_dims_to_tuple,
kw_only_field,
)
from ._docstrings import DOCFILLER_SHARED
from .xrutils import xrwrap_uv, xrwrap_xv
from .core.xrutils import xrwrap_uv, xrwrap_xv
from .docstrings import DOCFILLER_SHARED

try:
from cmomy import xCentralMoments
Expand All @@ -51,7 +51,6 @@
"DataValues",
"DataValuesCentral",
"DataCallbackABC",
"AbstractData",
"factory_data_values",
"resample_indices",
]
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion src/thermoextrap/gpr_active/active_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from pymbar import timeseries
from scipy import integrate, linalg, special

from .. import DataCentralMomentsVals, ExtrapModel
from .. import beta as xpan_beta
from ..data import DataCentralMomentsVals
from ..models import ExtrapModel
from .gp_models import (
ConstantMeanWithDerivs,
DerivativeKernel,
Expand Down
4 changes: 2 additions & 2 deletions src/thermoextrap/gpr_active/ig_active.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import xarray as xr

from .. import beta as xpan_beta
from ..core import idealgas
from ..core.data import DataCentralMomentsVals
from .. import idealgas
from ..data import DataCentralMomentsVals
from .active_utils import DataWrapper


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy as np
import sympy as sp

from ._docstrings import DocFiller
from .docstrings import DocFiller

__all__ = [
"x_ave",
Expand Down
2 changes: 1 addition & 1 deletion src/thermoextrap/legacy/gpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import xarray as xr
from gpflow.ci_utils import ci_niter

from .core.models import StateCollection
from .models import StateCollection


# First define classes needed for a GPR model
Expand Down
3 changes: 2 additions & 1 deletion src/thermoextrap/legacy/gpr_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from gpflow.ci_utils import ci_niter
from module_utilities import cached

from .core.stack import GPRData, StackedDerivatives, multiindex_to_array

from ..stack import GPRData, StackedDerivatives, multiindex_to_array

__all__ = ("GPRData", "GPRModel", "StackedDerivatives", "factory_gprmodel")

Expand Down
6 changes: 3 additions & 3 deletions src/thermoextrap/lnpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@

from . import beta as beta_xpan
from .core._attrs_utils import _cache_field, convert_dims_to_tuple
from .core._docstrings import DOCFILLER_SHARED
from .core.data import DataCallbackABC
from .core.models import Derivatives, ExtrapModel, SymFuncBase, SymSubs
from .core.sputils import get_default_indexed, get_default_symbol
from .data import DataCallbackABC
from .docstrings import DOCFILLER_SHARED
from .models import Derivatives, ExtrapModel, SymFuncBase, SymSubs

docfiller_shared = DOCFILLER_SHARED.levels_to_top("cmomy", "xtrap", "beta").decorate

Expand Down
19 changes: 9 additions & 10 deletions src/thermoextrap/core/models.py → src/thermoextrap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
from module_utilities import cached
from scipy.special import factorial as sp_factorial

from thermoextrap.core.data import AbstractData, kw_only_field

from ._attrs_utils import MyAttrsMixin, _cache_field
from ._docstrings import DOCFILLER_SHARED
from .sputils import get_default_indexed, get_default_symbol
from .xrutils import xrwrap_alpha
from .core._attrs_utils import MyAttrsMixin, _cache_field
from .core.sputils import get_default_indexed, get_default_symbol
from .core.xrutils import xrwrap_alpha
from .data import AbstractData, kw_only_field
from .docstrings import DOCFILLER_SHARED

try:
from pymbar import mbar
Expand Down Expand Up @@ -59,7 +58,7 @@ class SymFuncBase(sp.Function):
See Also
--------
:class:`thermoextrap.core.models.SymDerivBase`
:class:`thermoextrap.models.SymDerivBase`
"""

Expand All @@ -77,7 +76,7 @@ def deriv_args(cls):
raise NotImplementedError("must specify in sublcass")

def fdiff(self, argindex=1):
"""Derivative of function. This will be used by :class:`thermoextrap.core.models.SymDerivBase`."""
"""Derivative of function. This will be used by :class:`thermoextrap.models.SymDerivBase`."""
raise NotImplementedError("must specify in subclass")

@classmethod
Expand All @@ -100,7 +99,7 @@ class SymDerivBase(metaclass=DocInheritMeta(style="numpy_with_merge")):
----------
func : symFunction
Function to differentiate. This should (most likely) be an instance
of :class:`thermoextrap.core.models.SymFuncBase`
of :class:`thermoextrap.models.SymFuncBase`
args : sequence of Symbol
Arguments to func
{expand}
Expand Down Expand Up @@ -145,7 +144,7 @@ def __getitem__(self, order):
@attrs.define
class SymSubs:
"""
Class to handle substitution on :class:`thermoextrap.core.models.SymDerivBase`.
Class to handle substitution on :class:`thermoextrap.models.SymDerivBase`.
Parameters
----------
Expand Down
6 changes: 3 additions & 3 deletions src/thermoextrap/recursive_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
# TODO: Change this to point to the "new" ideagas.py
# TODO: rework this code to be cleaner
# from ..legacy.ig import IGmodel
from .core import idealgas
from . import idealgas
from .core._deprecate import deprecate, deprecate_kwarg
from .core.data import factory_data_values
from .core.models import ExtrapModel, InterpModel
from .data import factory_data_values
from .models import ExtrapModel, InterpModel

try:
import matplotlib.pyplot as plt
Expand Down
2 changes: 0 additions & 2 deletions src/thermoextrap/core/stack.py → src/thermoextrap/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,6 @@ def from_states(
`StackedDerivatives.from_derivs`
"""

from .models import StateCollection

if not isinstance(states, StateCollection):
states = StateCollection(states)

Expand Down
6 changes: 3 additions & 3 deletions src/thermoextrap/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from module_utilities import cached

from .core._attrs_utils import _cache_field
from .core._docstrings import DOCFILLER_SHARED
from .core.data import DataCallbackABC, DataValues
from .core.models import Derivatives, ExtrapModel
from .core.xrutils import xrwrap_xv
from .data import DataCallbackABC, DataValues
from .docstrings import DOCFILLER_SHARED
from .models import Derivatives, ExtrapModel

docfiller_shared = DOCFILLER_SHARED.levels_to_top(
"cmomy", "xtrap", "beta", "volume"
Expand Down
6 changes: 3 additions & 3 deletions src/thermoextrap/volume_idealgas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from functools import lru_cache

from .core._docstrings import DOCFILLER_SHARED
from .core.models import Derivatives, ExtrapModel
from .docstrings import DOCFILLER_SHARED
from .models import Derivatives, ExtrapModel

docfiller_shared = DOCFILLER_SHARED.levels_to_top(
"cmomy", "xtrap", "beta", "volume"
Expand Down Expand Up @@ -104,7 +104,7 @@ def factory_extrapmodel(volume, uv, xv, order=1, alpha_name="volume", **kws):
if order != 1:
raise ValueError("only first order supported")

from .core.data import factory_data_values
from .data import factory_data_values

data = factory_data_values(
uv=uv, xv=xv, order=order, central=False, xalpha=False, **kws
Expand Down
2 changes: 1 addition & 1 deletion tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import xarray as xr

import thermoextrap as xtrap
from thermoextrap.core import stack
from thermoextrap import stack


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_u_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def data(request):

n = request.param
data.n = n
data.u, data.x1 = xtrap.core.models.get_default_symbol("u", "x1")
data.u, data.x1 = xtrap.models.get_default_symbol("u", "x1")
data.du, data.dxdu = get_default_indexed("du", "dxdu")
data.xu, data.ui = get_default_indexed("xu", "u")

Expand Down

0 comments on commit beac8d0

Please sign in to comment.