Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
a8946ce
Add Bayesian posterior sampling to Analysis1d
henrikjacobsenfys Aug 13, 2026
7db52f9
Add Bayesian posterior sampling to Analysis and ParameterAnalysis
henrikjacobsenfys Aug 13, 2026
7ad2900
Label the posterior plot axes with units and quantities
henrikjacobsenfys Aug 13, 2026
0c3c689
Qualify parameter labels by model name, and cover the remaining branches
henrikjacobsenfys Aug 13, 2026
46d745a
Warm the tutorial data cache before running notebooks in parallel
henrikjacobsenfys Aug 13, 2026
ff50a2c
Rebuild the fitter when a binding changes shape, and stabilise the in…
henrikjacobsenfys Aug 13, 2026
b28b9e4
Address the review findings on the sampling API
henrikjacobsenfys Aug 13, 2026
439135a
Cover the review fixes, and drop a redundant guard
henrikjacobsenfys Aug 13, 2026
e6bd67c
Gather the per-Q chains on Analysis after independent sampling
henrikjacobsenfys Aug 13, 2026
6170a43
Step through the per-Q corner plots with a slider
henrikjacobsenfys Aug 13, 2026
1292f44
Show the per-Q corner slider in the Bayesian tutorial
henrikjacobsenfys Aug 13, 2026
442a5bd
Put the corner slider under the figure
henrikjacobsenfys Aug 13, 2026
619c46a
Reach the whole library through one namespace
henrikjacobsenfys Aug 13, 2026
bb10623
Compose the posterior sampler instead of mixing it in
henrikjacobsenfys Aug 14, 2026
ca72513
Compose the sampler into Analysis and ParameterAnalysis
henrikjacobsenfys Aug 14, 2026
11a5e14
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 14, 2026
8297346
Export the multi-Q sampler and drop the mixin's name
henrikjacobsenfys Aug 14, 2026
4441138
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 14, 2026
29f27ff
Point the front door at the composed sampler
henrikjacobsenfys Aug 14, 2026
c8cf9e0
Unwrap the security-issue line again
henrikjacobsenfys Aug 14, 2026
85f8a71
Warm the tutorial data cache before running notebooks in parallel
henrikjacobsenfys Aug 13, 2026
7b11a44
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 14, 2026
f1218ec
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 14, 2026
7e53eb7
Mark setup, action and expectation apart in the new tests
henrikjacobsenfys Aug 16, 2026
cecb994
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 16, 2026
2ecc29f
Mark setup, action and expectation apart in the multi-Q tests
henrikjacobsenfys Aug 16, 2026
d711bf2
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 16, 2026
522a6e9
Mark setup, action and expectation apart in the namespace tests
henrikjacobsenfys Aug 16, 2026
fbfedd6
Give the sampler its own test file
henrikjacobsenfys Aug 16, 2026
1814139
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 16, 2026
c6d3e1b
Put each test in the file of the class it exercises
henrikjacobsenfys Aug 16, 2026
017e4c0
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 16, 2026
f6756c7
Refuse silent chain corruption and harden the posterior sampler
henrikjacobsenfys Aug 17, 2026
46b45b4
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 17, 2026
2839da4
Keep the multi-Q sampler pointed at the chain the user actually ran
henrikjacobsenfys Aug 17, 2026
edf2904
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 17, 2026
6ccc0ba
Add marginal posteriors, correlation heatmaps and sampling progress
henrikjacobsenfys Aug 17, 2026
26a0836
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 17, 2026
74fa676
Give every posterior plot a Q slider over independent chains
henrikjacobsenfys Aug 17, 2026
866e1b2
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 17, 2026
26c168b
Write the progress line through sys.stdout
henrikjacobsenfys Aug 17, 2026
fa94bb2
Show the new posterior plots in the Bayesian tutorial
henrikjacobsenfys Aug 17, 2026
7a7dfe3
Apply the formatting fixes
henrikjacobsenfys Aug 17, 2026
132fc59
Satisfy the docstring and formatting checks
henrikjacobsenfys Aug 17, 2026
75a0e45
Merge branch 'bayesian' into bayesian-analysis
henrikjacobsenfys Aug 17, 2026
fbe8dd4
Document propagated exceptions the way the docstring linter expects
henrikjacobsenfys Aug 17, 2026
5074a8f
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 17, 2026
2b218d5
Merge remote-tracking branch 'origin/develop' into bayesian-analysis
henrikjacobsenfys Aug 17, 2026
6310e72
Give the Bayesian tutorial the widget backend its sliders need
henrikjacobsenfys Aug 17, 2026
2de049f
Merge branch 'bayesian-analysis' into import-style
henrikjacobsenfys Aug 17, 2026
0f57860
Merge remote-tracking branch 'origin/develop' into import-style
henrikjacobsenfys Aug 17, 2026
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
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ git add .
git commit -m "Improve performance of time integrator for large systems"
```

### Imports in Tutorials and Examples

Anything user-facing — the tutorial notebooks and the `python` examples
in docstrings — reaches EasyDynamics through a single namespace:

```python
import easydynamics as edyn

experiment = edyn.Experiment('Vanadium')
model = edyn.SampleModel(components=edyn.Gaussian(width=0.1))
```

Every public name is re-exported from `easydynamics`, so this always
works. Please do not mix in `import easydynamics.sample_model as sm`, or
reach into a module with
`from easydynamics.analysis.analysis1d import Analysis1d`: a reader then
has to scroll back to the imports to find out where a name came from.

If something you need is missing from `edyn.`, add it to `__all__` in
`src/easydynamics/__init__.py` rather than importing around it.

Inside the library itself, keep importing from the specific module that
defines a name. Only the public front door is flat.

---

## 6. Code Quality Checks
Expand Down
39 changes: 19 additions & 20 deletions docs/docs/tutorials/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"import pooch\n",
"\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"\n",
"%matplotlib widget"
]
Expand Down Expand Up @@ -56,28 +55,28 @@
"# Example of Analysis with a simple sample model and instrument model\n",
"# The scattering from vanadium is purely elastic, so we model it with a\n",
"# delta function\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = sm.SampleModel(\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = edyn.SampleModel(\n",
" components=delta_function,\n",
")\n",
"\n",
"# The resolution is in this case modeled as a Gaussian. However, we can\n",
"# add as many components as we like to the resolution model\n",
"res_gauss = sm.Gaussian(width=0.1)\n",
"res_gauss = edyn.Gaussian(width=0.1)\n",
"res_gauss.area.fixed = True\n",
"resolution_components = sm.ComponentCollection()\n",
"resolution_components = edyn.ComponentCollection()\n",
"resolution_components.append_component(res_gauss)\n",
"resolution_model = sm.ResolutionModel(components=resolution_components)\n",
"resolution_model = edyn.ResolutionModel(components=resolution_components)\n",
"\n",
"# The background model is created in the same way. In this case, we use\n",
"# a flat background\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"# We combine the resolution abd background model into an instrument\n",
"# model. This model also contains a small energy offset to account for\n",
"# instrument misalignment.\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")\n",
Expand Down Expand Up @@ -190,19 +189,19 @@
"# Now we set up the model, similarly to how we set up the model for the\n",
"# vanadium data.\n",
"\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"lorentzian = sm.Lorentzian(display_name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = sm.ComponentCollection(\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"lorentzian = edyn.Lorentzian(display_name='Lorentzian', area=0.5, width=0.3)\n",
"component_collection = edyn.ComponentCollection(\n",
" components=[delta_function, lorentzian],\n",
")\n",
"\n",
"sample_model = sm.SampleModel(\n",
"sample_model = edyn.SampleModel(\n",
" components=component_collection,\n",
")\n",
"\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" background_model=background_model,\n",
")\n",
"\n",
Expand Down Expand Up @@ -265,22 +264,22 @@
"# Let us now fit directly to a diffusion model. We replace the\n",
"# Lorentzian with a Brownian translational diffusion model and keep the\n",
"# other parameters the same.\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"component_collection = sm.ComponentCollection(\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=0.2)\n",
"component_collection = edyn.ComponentCollection(\n",
" components=[delta_function],\n",
")\n",
"diffusion_model = sm.BrownianTranslationalDiffusion(\n",
"diffusion_model = edyn.BrownianTranslationalDiffusion(\n",
" display_name='Brownian Translational Diffusion', diffusion_coefficient=2.4e-9, scale=0.5\n",
")\n",
"\n",
"sample_model = sm.SampleModel(\n",
"sample_model = edyn.SampleModel(\n",
" components=component_collection,\n",
" diffusion_models=diffusion_model,\n",
")\n",
"\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" background_model=background_model,\n",
")\n",
"\n",
Expand Down
18 changes: 8 additions & 10 deletions docs/docs/tutorials/analysis1d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"import pooch\n",
"\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"from easydynamics.analysis.analysis1d import Analysis1d\n",
"\n",
"%matplotlib widget"
]
Expand Down Expand Up @@ -49,24 +47,24 @@
"metadata": {},
"outputs": [],
"source": [
"# Example of Analysis1d with a simple sample model and instrument model\n",
"delta_function = sm.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = sm.SampleModel(\n",
"# Example of edyn.Analysis1d with a simple sample model and instrument model\n",
"delta_function = edyn.DeltaFunction(display_name='DeltaFunction', area=1)\n",
"sample_model = edyn.SampleModel(\n",
" components=delta_function,\n",
")\n",
"\n",
"res_gauss = sm.Gaussian(width=0.1)\n",
"resolution_model = sm.ResolutionModel(components=res_gauss)\n",
"res_gauss = edyn.Gaussian(width=0.1)\n",
"resolution_model = edyn.ResolutionModel(components=res_gauss)\n",
"\n",
"\n",
"background_model = sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001]))\n",
"background_model = edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001]))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
"instrument_model = edyn.InstrumentModel(\n",
" resolution_model=resolution_model,\n",
" background_model=background_model,\n",
")\n",
"\n",
"my_analysis = Analysis1d(\n",
"my_analysis = edyn.Analysis1d(\n",
" display_name='Vanadium Analysis',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sample_model,\n",
Expand Down
24 changes: 11 additions & 13 deletions docs/docs/tutorials/bayesian.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
"import pooch\n",
"\n",
"import easydynamics as edyn\n",
"import easydynamics.sample_model as sm\n",
"from easydynamics.analysis.analysis1d import Analysis1d\n",
"\n",
"# Make the plots interactive; the Q sliders need the widget backend\n",
"%matplotlib widget"
Expand Down Expand Up @@ -77,17 +75,17 @@
"metadata": {},
"outputs": [],
"source": [
"vanadium_components = sm.ComponentCollection()\n",
"vanadium_components.append_component(sm.Gaussian(width=0.1, area=1, name='Res. Gauss'))\n",
"vanadium_components = edyn.ComponentCollection()\n",
"vanadium_components.append_component(edyn.Gaussian(width=0.1, area=1, name='Res. Gauss'))\n",
"\n",
"instrument_model = sm.InstrumentModel(\n",
" background_model=sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001])),\n",
"instrument_model = edyn.InstrumentModel(\n",
" background_model=edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001])),\n",
")\n",
"\n",
"analysis = Analysis1d(\n",
"analysis = edyn.Analysis1d(\n",
" display_name='Vanadium Analysis',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sm.SampleModel(components=vanadium_components),\n",
" sample_model=edyn.SampleModel(components=vanadium_components),\n",
" instrument_model=instrument_model,\n",
" Q_index=5,\n",
")\n",
Expand Down Expand Up @@ -345,15 +343,15 @@
"source": [
"# Fresh models, so this analysis is independent of the single-Q one above rather than\n",
"# sharing its already-sampled components.\n",
"all_q_components = sm.ComponentCollection()\n",
"all_q_components.append_component(sm.Gaussian(width=0.1, area=1, name='Res. Gauss'))\n",
"all_q_components = edyn.ComponentCollection()\n",
"all_q_components.append_component(edyn.Gaussian(width=0.1, area=1, name='Res. Gauss'))\n",
"\n",
"full_analysis = edyn.Analysis(\n",
" display_name='Vanadium, all Q',\n",
" experiment=vanadium_experiment,\n",
" sample_model=sm.SampleModel(components=all_q_components),\n",
" instrument_model=sm.InstrumentModel(\n",
" background_model=sm.BackgroundModel(components=sm.Polynomial(coefficients=[0.001])),\n",
" sample_model=edyn.SampleModel(components=all_q_components),\n",
" instrument_model=edyn.InstrumentModel(\n",
" background_model=edyn.BackgroundModel(components=edyn.Polynomial(coefficients=[0.001])),\n",
" ),\n",
")\n",
"full_analysis.fit(fit_method='independent')\n",
Expand Down
14 changes: 8 additions & 6 deletions docs/docs/tutorials/component_collection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import easydynamics.sample_model as sm\n",
"import easydynamics as edyn\n",
"\n",
"%matplotlib widget"
]
Expand All @@ -32,13 +32,15 @@
"metadata": {},
"outputs": [],
"source": [
"component_collection = sm.ComponentCollection()\n",
"component_collection = edyn.ComponentCollection()\n",
"\n",
"# Creating components\n",
"gaussian = sm.Gaussian(display_name='Gaussian', width=0.5, area=1)\n",
"dho = sm.DampedHarmonicOscillator(display_name='DHO', center=1.0, width=0.3, area=2.0)\n",
"lorentzian = sm.Lorentzian(display_name='Lorentzian', center=-1.0, width=0.2, area=1.0)\n",
"polynomial = sm.Polynomial(display_name='Polynomial', coefficients=[0.1, 0, 0.5]) # y=0.1+0.5*x^2\n",
"gaussian = edyn.Gaussian(display_name='Gaussian', width=0.5, area=1)\n",
"dho = edyn.DampedHarmonicOscillator(display_name='DHO', center=1.0, width=0.3, area=2.0)\n",
"lorentzian = edyn.Lorentzian(display_name='Lorentzian', center=-1.0, width=0.2, area=1.0)\n",
"polynomial = edyn.Polynomial(\n",
" display_name='Polynomial', coefficients=[0.1, 0, 0.5]\n",
") # y=0.1+0.5*x^2\n",
"\n",
"# Adding components to the component collection\n",
"component_collection.append_component(gaussian)\n",
Expand Down
22 changes: 12 additions & 10 deletions docs/docs/tutorials/components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"import numpy as np\n",
"import scipp as sc\n",
"\n",
"import easydynamics.sample_model as sm\n",
"import easydynamics as edyn\n",
"\n",
"%matplotlib widget"
]
Expand All @@ -36,13 +36,13 @@
"outputs": [],
"source": [
"# Creating a component\n",
"gaussian = sm.Gaussian(display_name='Gaussian', width=0.5, area=1)\n",
"dho = sm.DampedHarmonicOscillator(display_name='DHO', center=1.0, width=0.3, area=2.0)\n",
"lorentzian = sm.Lorentzian(display_name='Lorentzian', center=-1.0, width=0.2, area=1.0)\n",
"polynomial = sm.Polynomial(\n",
"gaussian = edyn.Gaussian(display_name='Gaussian', width=0.5, area=1)\n",
"dho = edyn.DampedHarmonicOscillator(display_name='DHO', center=1.0, width=0.3, area=2.0)\n",
"lorentzian = edyn.Lorentzian(display_name='Lorentzian', center=-1.0, width=0.2, area=1.0)\n",
"polynomial = edyn.Polynomial(\n",
" display_name='Polynomial', coefficients=[-0.2, 0, 0.5]\n",
") # y=-0.2+0.5*x^2\n",
"exponential = sm.Exponential(display_name='Exponential', amplitude=1.0, rate=-0.5)\n",
"exponential = edyn.Exponential(display_name='Exponential', amplitude=1.0, rate=-0.5)\n",
"\n",
"x = np.linspace(-2, 2, 100)\n",
"\n",
Expand Down Expand Up @@ -94,7 +94,7 @@
"metadata": {},
"outputs": [],
"source": [
"delta = sm.DeltaFunction(display_name='Delta', center=0.0, area=1.0)\n",
"delta = edyn.DeltaFunction(display_name='Delta', center=0.0, area=1.0)\n",
"x1 = np.linspace(-2, 2, 100)\n",
"y = delta.evaluate(x1)\n",
"x2 = np.linspace(-2, 2, 51)\n",
Expand Down Expand Up @@ -122,7 +122,9 @@
"x1 = sc.linspace(dim='x', start=-2.0, stop=2.0, num=100, unit='meV')\n",
"x2 = sc.linspace(dim='x', start=-2.0 * 1e3, stop=2.0 * 1e3, num=101, unit='microeV')\n",
"\n",
"polynomial = sm.Polynomial(display_name='Polynomial', coefficients=[0.1, 0, 0.5]) # y=0.1+0.5*x^2\n",
"polynomial = edyn.Polynomial(\n",
" display_name='Polynomial', coefficients=[0.1, 0, 0.5]\n",
") # y=0.1+0.5*x^2\n",
"y1 = polynomial.evaluate(x1)\n",
"y2 = polynomial.evaluate(x2)\n",
"\n",
Expand All @@ -148,7 +150,7 @@
"metadata": {},
"outputs": [],
"source": [
"expr = sm.ExpressionComponent(\n",
"expr = edyn.ExpressionComponent(\n",
" 'A * exp(-(x - x0)**2 / (2*sigma**2)) +B*sin(2*pi*x/period)',\n",
" parameters={'A': 10, 'x0': 0, 'sigma': 1},\n",
" parameter_units={\n",
Expand Down Expand Up @@ -185,7 +187,7 @@
"metadata": {},
"outputs": [],
"source": [
"expr = sm.ExpressionComponent(\n",
"expr = edyn.ExpressionComponent(\n",
" 'A*erf(B*x)',\n",
")\n",
"\n",
Expand Down
Loading
Loading