Skip to content

Add Hall-Ross, circle jump and 3D Gaussian diffusion models - #279

Open
markbujehein wants to merge 11 commits into
easyscience:developfrom
markbujehein:more-diffusion-models
Open

markbujehein wants to merge 11 commits into
easyscience:developfrom
markbujehein:more-diffusion-models

Conversation

@markbujehein

@markbujehein markbujehein commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds four diffusion models, with tests and tutorials:

  • HallRossJumpDiffusion: jump diffusion with a Gaussian distribution of jump lengths.
  • EquivalentSitesCircle: jumps between N equivalent sites on a circle.
  • JumpSitesLogNormalDistribution: the circle model with a log-normal distribution of jump rates.
  • GaussianModel3D: diffusion in an isotropic 3D harmonic well. The sum over Lorentzians is truncated, with a warning when more than 1e-3 of the weight is lost.

Shared base class

The circle, log-normal and Gaussian models all describe the same kind of spectrum: an elastic line plus a set of Lorentzians at each Q. Only the physics differs, meaning how wide each Lorentzian is and how much intensity it carries. The work of turning that physics into fit components is the same every time, so it now lives in one place, DeltaLorentzianDiffusionModelBase. It creates the delta function and the Lorentzians for each Q, gives them predictable names, links their areas and widths to the model parameters, and provides the fit targets (elastic_area, area_<j>, width_<j>). A fix or improvement to that machinery reaches all three models at once.

Each model file keeps its own physics and its own parameters, including some code that is repeated between files, so that you can read one model from top to bottom without jumping between classes. The one repeated piece of physics is the circle weight formula, which appears in both circle models.

For future models, adding another "elastic line plus Lorentzians" model means writing only its physics: the widths, the EISF and the weight of each Lorentzian. The components, naming and fit targets come for free and behave the same as in the existing models. This makes sense because several models (Mantid, QENSlibrary) are are very identical and share what's now being defined in DeltaLorentzianDiffusionModelBase.

ABCMeta

The base class uses metaclass=ABCMeta, the same pattern EasyScience Core's release-3.0
uses for its own abstract classes (JobBase, AnalysisBase). Without it, Python does not
enforce @abstractmethod here, because the parent classes use the plain type metaclass.

  • With ABCMeta: a new model that defines calculate_EISF but forgets calculate_QISF_order
    raises a TypeError naming the missing method as soon as it is created.
  • Without it, as in ModelComponent today: a component that forgets _evaluate_values is
    created without complaint and returns None when evaluated.

If Core 3.0 moves ABCMeta onto its base classes, this declaration becomes redundant and keeps
working.


Related:

markbujehein and others added 10 commits October 26, 2026 11:13
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clarify equations, parameters, and references across multiple classes.
- Introduced a new tutorial notebook for the equivalent sites on a circle model, detailing the mathematical framework and providing visualizations.
- Added a tutorial for the 3D Gaussian model, explaining diffusion in a harmonic potential and including relevant plots.
- Created a tutorial for jump sites with a log-normal distribution, extending the equivalent sites model to disordered environments with log-normal jump rates.
- Updated mkdocs.yml to include links to the new tutorials.
- Enhanced documentation in the equivalent sites circle model and jump sites log-normal distribution code to clarify model parameters and references.
Clarify diffusion model details more clearly and explicitly
Solves Ruff throwing 'useless-expression' during notebook-lint-check
@easyscience

easyscience Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Label error. Requires at least 1 of: [bot] release, [scope] bug, [scope] documentation, [scope] enhancement, [scope] maintenance, [scope] significant. Found:

@markbujehein
markbujehein marked this pull request as ready for review October 26, 2026 13:38
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (b1d6773) to head (c4d536c).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #279      +/-   ##
===========================================
+ Coverage    98.23%   98.38%   +0.14%     
===========================================
  Files           61       66       +5     
  Lines         6227     6803     +576     
  Branches      1039     1092      +53     
===========================================
+ Hits          6117     6693     +576     
  Misses          57       57              
  Partials        53       53              
Flag Coverage Δ
unittests 98.38% <100.00%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/easydynamics/__init__.py 100.00% <100.00%> (ø)
src/easydynamics/sample_model/__init__.py 100.00% <100.00%> (ø)
...ydynamics/sample_model/diffusion_model/__init__.py 100.00% <100.00%> (ø)
...ion_model/delta_lorentzian_diffusion_model_base.py 100.00% <100.00%> (ø)
...e_model/diffusion_model/equivalent_sites_circle.py 100.00% <100.00%> (ø)
.../sample_model/diffusion_model/gaussian_model_3d.py 100.00% <100.00%> (ø)
..._model/diffusion_model/hall_ross_jump_diffusion.py 100.00% <100.00%> (ø)
...fusion_model/jump_sites_log_normal_distribution.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@markbujehein
markbujehein marked this pull request as draft October 26, 2026 13:51
Test that the circle, log-normal and 3D Gaussian models reject a non-float Q,
and test the delta_name and delta_display_name setters of the base class.
Rename the base-class test model from Toy to DummyDiffusionModel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@markbujehein
markbujehein marked this pull request as ready for review October 26, 2026 14:26

This branch has not been deployed

No deployments
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