Skip to content

Mobility fitting#19

Merged
nury12n merged 57 commits into
materialsgenomefoundation:mainfrom
nury12n:mobility_fitting
Jun 5, 2026
Merged

Mobility fitting#19
nury12n merged 57 commits into
materialsgenomefoundation:mainfrom
nury12n:mobility_fitting

Conversation

@nury12n

@nury12n nury12n commented Feb 5, 2025

Copy link
Copy Markdown
Collaborator

This adds a number of features to generate and assess mobility models

Main changes

  • ESPEI residual functions for tracer and interdiffusivity. These include both equilibrium and non-equilibrium configurations. For tracer diffusivity: activation energy, pre-factor/frequency, and diffusivity can all be used in datasets
    • NOTE: this currently requires the development version of espei
  • ESPEI fitting steps to generate models from tracer diffusivity data
    • There's some wrapper functions so automatically generate the FittingStep and ModelFittingDescription for each element, so the user doesn't have to create the fitting steps themselves
    • Two options exists for paramter generation: from activation energy and pre-factor (recommended), or from diffusivities (not recommended since this can lead to overfitting, but is implemented for completion-sake)
  • Manual fitting module which allows users to generate models where data does not exist on endmembers (ex. carbides with a phase model of $(A)_1 (C,VA)_1$, where $A:VA$ is unstable and diffusivity cannot be experimentally obtained
  • Liquid mobility module implementing:
  • MobilityTemplate object where user can create a custom mobility model, add parameters and insert model into an existing TDB
    • This is used by the manual fitting and liquid mobility modules
  • Example for the Cu-Ni system, going through espei parameter generation, liquid mobility model generation, manual fitting, MCMC optimization and UQ on interdiffusivity

Other changes

  • Diffusion model with recording enabled will pre-pad the recorded time and concentration profile arrays in batches of 10000 iterations rather than on every step. This improves the performance of long running models by preventing these arrays from being copied every iteration
  • Some plotting changes in the diffusion model to allow for custom labeling and offsets in z axis

TODO

  • Unit tests for parameter generation, manual fitting and liquid mobility modules
  • Examples for generating and optimizing a mobility model (should include both ESPEI parameter generation and manual fitting)

@nury12n nury12n requested a review from bocklund April 18, 2025 21:06
bocklund added a commit to PhasesResearchLab/ESPEI that referenced this pull request Jun 3, 2026
When installing ESPEI from a git source using package managers, e.g.

```shell
pip install git+https://github.com/phasesresearchlab/espei.git@master
```

or entirely from a fresh env using `uv`:
```shell
uv init --bare
uv add "espei @ git+https://github.com/phasesresearchlab/espei.git@master"
```

the code can successfully install, but give errors like this when you try to use it:

```python
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import espei
  File "/Users/bocklund1/src/test/.venv/lib/python3.13/site-packages/espei/__init__.py", line 10, in <module>
    __version__ = get_version(root='..', relative_to=__file__)
  File "/Users/bocklund1/src/test/.venv/lib/python3.13/site-packages/setuptools_scm/_get_version.py", line 56, in get_version
    return _get_version_public(
        root=root,
    ...<17 lines>...
        scm=scm,
    )
  File "/Users/bocklund1/src/test/.venv/lib/python3.13/site-packages/vcs_versioning/_get_version_impl.py", line 257, in get_version
    _version_missing(config)
    ~~~~~~~~~~~~~~~~^^^^^^^^
  File "/Users/bocklund1/src/test/.venv/lib/python3.13/site-packages/vcs_versioning/_get_version_impl.py", line 207, in _version_missing
    raise LookupError(error_msg)
LookupError: setuptools-scm was unable to detect version for /Users/bocklund1/src/test/.venv/lib/python3.13/site-packages.

Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj

Alternatively, set the version with the environment variable SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${NORMALIZED_DIST_NAME} as described in https://setuptools-scm.readthedocs.io/en/latest/config/
```

Looking at 
```python
# espei/__init__.py
try:
    from ._dev import get_version
    # We have a local (editable) installation and can get the version based on the
    # source control management system at the project root.
    __version__ = get_version(root='..', relative_to=__file__)
    del get_version
except ImportError:
    # Fall back on the metadata of the installed package
    from importlib.metadata import version
    __version__ = version("espei")
    del version
```

There current behavior of `__init__.py` expects one of the following cases:
1. Installing from a release version that has a sdist/bdist where `MANIFEST.in` does `prune espei/_dev` and therefore `._dev` doesn't exist and we hit the `ImportError` fallback to `importlib.metadata`
2. For working from the git source checkout, you have full git history and `get_version` from `setuptools_scm` detects the git tag and can set the versions correctly. 

However, when installing on one of the failure modes above, you get an in between case where
a) you get all the files, which includes `_dev/__init__.py`, and
b) you don't get the full git repo with the full git version history

and thus you don't get the `ImportError`, but you have `setuptools_scm.get_version` raise a `LookupError` when it fails. 

This PR catches that `LookupError` and falls back onto the `importlib.metadata` version which does work on installs using the `git+` mechanism above on `pip` and `uv`. It also adds a new GitHub Action file for doing smoke tests, where in this case we add a single test that installing ESPEI to a bare repo and then importing works.


This should fix issues in getting CI working in downstream packages like here: materialsgenomefoundation/kawin#19
@nury12n nury12n merged commit f0c3479 into materialsgenomefoundation:main Jun 5, 2026
4 of 7 checks passed
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.

1 participant