{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "0",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:29.567962Z",
"iopub.status.busy": "2026-06-30T22:37:29.567767Z",
"iopub.status.idle": "2026-06-30T22:37:29.572345Z",
"shell.execute_reply": "2026-06-30T22:37:29.571654Z"
},
"tags": [
"hide-in-docs"
]
},
"outputs": [],
"source": [
"# Check whether easydiffraction is installed; install it if needed.\n",
"# Required for remote environments such as Google Colab.\n",
"import importlib.util\n",
"\n",
"if importlib.util.find_spec('easydiffraction') is None:\n",
" %pip install easydiffraction==0.19.1"
]
},
{
"cell_type": "markdown",
"id": "1",
"metadata": {},
"source": [
"# Bayesian Analysis Resume (`bumps-dream`): LBCO, HRPT\n",
"\n",
"This tutorial shows how to reopen the Bayesian project created previously,\n",
"inspect the saved fit results and then run more sampling steps to\n",
"extend the existing chain. Both BUMPS-DREAM and emcee support saving\n",
"and resuming their sampler state, so the same workflow applies to\n",
"either engine.\n",
"\n",
"This workflow is useful when:\n",
"- the initial sampling run has not yet converged and more steps are needed,\n",
"- the initial sampling run has converged but more steps are desired\n",
" for better posterior resolution,\n",
"- the initial sampling run has converged but the posterior plots have\n",
" not yet been inspected and the user wants to see the plots before\n",
" deciding whether to run more steps.\n",
"\n",
"The workflow uses the same La0.5Ba0.5CoO3 powder diffraction example\n",
"as the DREAM Bayesian tutorial:\n",
"\n",
"- run a short local refinement,\n",
"- derive finite fit bounds for the sampled parameters,\n",
"- switch to DREAM and sample the posterior,\n",
"- save the project with the DREAM sampler state,\n",
"- resume the chain with additional steps,\n",
"- inspect posterior plots after each sampling stage."
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## π οΈ Import Library"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:29.574040Z",
"iopub.status.busy": "2026-06-30T22:37:29.573906Z",
"iopub.status.idle": "2026-06-30T22:37:32.412996Z",
"shell.execute_reply": "2026-06-30T22:37:32.412124Z"
}
},
"outputs": [],
"source": [
"import easydiffraction as edi"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## π Load Project"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"### Locate Project\n",
"\n",
"Download and extract the saved DREAM project, with the persisted\n",
"sampler state and posterior caches, from the EasyDiffraction data\n",
"repository."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:32.414789Z",
"iopub.status.busy": "2026-06-30T22:37:32.414506Z",
"iopub.status.idle": "2026-06-30T22:37:32.783252Z",
"shell.execute_reply": "2026-06-30T22:37:32.782372Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mGetting data\u001b[0m\u001b[1;36m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Data \u001b[32m'proj-lbco-hrpt-dream'\u001b[0m: Bayesian Analysis \u001b[1m(\u001b[0mbumps-dream\u001b[1m)\u001b[0m: LBCO, HRPT\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Data \u001b[32m'proj-lbco-hrpt-dream'\u001b[0m downloaded and extracted to \u001b[32m'../../../projects/proj-lbco-hrpt-dream-bcff2d3b8ff0'\u001b[0m\n"
]
}
],
"source": [
"project_dir = edi.download_data('proj-lbco-hrpt-dream', destination='projects')"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"### Load Project\n",
"\n",
"Loading restores the persisted fit state, posterior samples, and plot\n",
"caches. No new fit is launched in this tutorial."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "8",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:32.784757Z",
"iopub.status.busy": "2026-06-30T22:37:32.784600Z",
"iopub.status.idle": "2026-06-30T22:37:34.521803Z",
"shell.execute_reply": "2026-06-30T22:37:34.521129Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Switching minimizer type removes these settings: \n",
" β’ max_iterations \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β οΈ Switching minimizer type adds these settings with defaults: \n",
" β’ burn_in_steps=600 \n",
" β’ initialization_method='latin_hypercube' \n",
" β’ parallel_workers=0 \n",
" β’ population_size=4 \n",
" β’ random_seed=None \n",
" β’ sampling_steps=3000 \n",
" β’ thinning_interval=1 \n"
]
}
],
"source": [
"project = edi.Project.load(project_dir)"
]
},
{
"cell_type": "markdown",
"id": "9",
"metadata": {},
"source": [
"Re-save the project to a fresh working directory so resuming the\n",
"chain below writes there instead of the bundled read-only copy."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "10",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:34.524035Z",
"iopub.status.busy": "2026-06-30T22:37:34.523849Z",
"iopub.status.idle": "2026-06-30T22:37:34.926564Z",
"shell.execute_reply": "2026-06-30T22:37:34.925786Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project π¦ \u001b[0m\u001b[32m'lbco_hrpt_dream'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/bayesian-dream-resume-lbco-hrpt'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π project.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π lbco.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π hrpt.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π analysis/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π analysis.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π mcmc.h5\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π reports/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" βββ π lbco_hrpt_dream.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/bayesian-dream-resume-lbco-hrpt')"
]
},
{
"cell_type": "markdown",
"id": "11",
"metadata": {},
"source": [
"## π Inspect Results"
]
},
{
"cell_type": "markdown",
"id": "12",
"metadata": {},
"source": [
"### Display Structure\n",
"\n",
"Render the La0.5Ba0.5CoO3 structure restored from the saved project."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "13",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:34.928267Z",
"iopub.status.busy": "2026-06-30T22:37:34.928070Z",
"iopub.status.idle": "2026-06-30T22:37:34.956050Z",
"shell.execute_reply": "2026-06-30T22:37:34.955397Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStructure π§© \u001b[0m\u001b[32m'lbco'\u001b[0m\u001b[1;36m \u001b[0m\u001b[1;36m(\u001b[0m\u001b[1;36mAtom view type: \u001b[0m\u001b[32m'covalent'\u001b[0m\u001b[1;36m)\u001b[0m\n"
]
},
{
"data": {
"text/html": [
"
\n",
"
\n",
"
Loading plotβ¦
\n",
"
\n",
"
\n",
"
\n",
"
drag = rotate
wheel = zoom
right-drag = pan
\n",
"
\n",
"
\n",
"\n",
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.structure(struct_name='lbco')"
]
},
{
"cell_type": "markdown",
"id": "14",
"metadata": {},
"source": [
"### Display Fit Results\n",
"\n",
"The fit summary reports the committed point estimate, sampler\n",
"settings, convergence diagnostics, and posterior parameter summaries\n",
"from the saved Bayesian run."
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "15",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:34.957711Z",
"iopub.status.busy": "2026-06-30T22:37:34.957535Z",
"iopub.status.idle": "2026-06-30T22:37:35.211972Z",
"shell.execute_reply": "2026-06-30T22:37:35.211123Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"βοΈ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | sampling_steps | 10000 | Total sampler iterations per chain. |
|---|
| 2 | burn_in_steps | 2000 | Sampler iterations discarded as warm-up. |
|---|
| 3 | thinning_interval | 1 | Sampler thinning interval. |
|---|
| 4 | population_size | 4 | Number of chains or walkers. |
|---|
| 5 | parallel_workers | 0 | Worker count; 0 uses all available CPUs. |
|---|
| 6 | initialization_method | latin_hypercube | Sampler initialization method. |
|---|
| 7 | random_seed | 42 | Random seed; None uses a system-derived seed. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Bayesian fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | π§ͺ Sampler | dream |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | π¬ Engine message | DREAM sampling completed |
|---|
| 4 | β±οΈ Fitting time (seconds) | 1979.34 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.29 |
|---|
| 6 | π R-factor (Rf, %) | 5.65 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 4.91 |
|---|
| 8 | π Weighted R-factor (wR, %) | 4.08 |
|---|
| 9 | π Best log-posterior | -1157.01 |
|---|
| 10 | π Convergence status | passed |
|---|
| 11 | π Max r-hat | 1.003 |
|---|
| 12 | π Min ess bulk | 6949.232 |
|---|
| 13 | π Draws per chain | 10000 |
|---|
| 14 | π Chains | 20 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Committed parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | lbco | cell | | length_a | Γ
| 3.8913 | 3.8913 | 0.0001 | 0.00 % β |
|---|
| 2 | hrpt | linked_structure | lbco | scale | | 9.1329 | 9.1330 | 0.0292 | 0.00 % β |
|---|
| 3 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0817 | 0.0817 | 0.0067 | 0.04 % β |
|---|
| 4 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1169 | -0.1169 | 0.0048 | 0.01 % β |
|---|
| 5 | hrpt | instrument | | twotheta_offset | deg | 0.6306 | 0.6306 | 0.0017 | 0.00 % β |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ start = parameter value before sampling
β’ value = estimate written back to the project (best posterior sample)
β’ s.u. = standard uncertainty (one sigma), posterior standard deviation
β’ change = relative change from start, in %; β = increase, β = decrease
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Posterior distribution:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | median | 95% CI | r-hat | ess bulk |
|---|
| 1 | lbco | cell | | length_a | Γ
| 3.8913 | [3.8911, 3.8915] | 1.003 | 7072.4 |
|---|
| 2 | hrpt | linked_structure | lbco | scale | | 9.1328 | [9.0754, 9.1903] | 1.003 | 8504.9 |
|---|
| 3 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0814 | [0.0687, 0.0946] | 1.003 | 7256.3 |
|---|
| 4 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1167 | [-0.1262, -0.1074] | 1.003 | 7393.3 |
|---|
| 5 | hrpt | instrument | | twotheta_offset | deg | 0.6303 | [0.6270, 0.6335] | 1.003 | 6949.2 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ median = 50th percentile of the marginal posterior
β’ 95% CI = 95% credible interval (2.5%-97.5%, asymmetric)
β’ r-hat = Gelman-Rubin diagnostic (good convergence: r-hat <= 1.01)
β’ ess bulk = bulk effective sample size (typically >= 400)
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.results()"
]
},
{
"cell_type": "markdown",
"id": "16",
"metadata": {},
"source": [
"### Display Correlations\n",
"\n",
"The correlation matrix is restored from the saved project state."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "17",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:35.213559Z",
"iopub.status.busy": "2026-06-30T22:37:35.213370Z",
"iopub.status.idle": "2026-06-30T22:37:35.247809Z",
"shell.execute_reply": "2026-06-30T22:37:35.247048Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.correlations()"
]
},
{
"cell_type": "markdown",
"id": "18",
"metadata": {},
"source": [
"### Display Posterior Densities\n",
"\n",
"The pair plot and one-dimensional posterior distributions now load\n",
"from the persisted caches generated when the Bayesian fit was saved."
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "19",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:35.249769Z",
"iopub.status.busy": "2026-06-30T22:37:35.249602Z",
"iopub.status.idle": "2026-06-30T22:37:35.697700Z",
"shell.execute_reply": "2026-06-30T22:37:35.696904Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.pairs()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "20",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:35.705692Z",
"iopub.status.busy": "2026-06-30T22:37:35.705496Z",
"iopub.status.idle": "2026-06-30T22:37:35.859725Z",
"shell.execute_reply": "2026-06-30T22:37:35.859088Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.distribution()"
]
},
{
"cell_type": "markdown",
"id": "21",
"metadata": {},
"source": [
"### Display Posterior Predictive\n",
"\n",
"The posterior predictive view reuses the cached predictive summary\n",
"stored in the project rather than recalculating it on first display.\n",
"It overlays the 95% credible interval propagated from the posterior\n",
"samples."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "22",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:35.861126Z",
"iopub.status.busy": "2026-06-30T22:37:35.860954Z",
"iopub.status.idle": "2026-06-30T22:37:35.910603Z",
"shell.execute_reply": "2026-06-30T22:37:35.909922Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.predictive(expt_name='hrpt')"
]
},
{
"cell_type": "markdown",
"id": "23",
"metadata": {},
"source": [
"A zoomed view is useful for checking the propagated uncertainty in a\n",
"narrow region of the diffraction pattern."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "24",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:35.914620Z",
"iopub.status.busy": "2026-06-30T22:37:35.914445Z",
"iopub.status.idle": "2026-06-30T22:37:35.963274Z",
"shell.execute_reply": "2026-06-30T22:37:35.962237Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.predictive(expt_name='hrpt', x_min=92, x_max=93)"
]
},
{
"cell_type": "markdown",
"id": "25",
"metadata": {},
"source": [
"## π² Resume Sampling"
]
},
{
"cell_type": "markdown",
"id": "26",
"metadata": {},
"source": [
"### Run Sampling\n",
"\n",
"Resume from the saved DREAM state and append 100 more generations to\n",
"the existing chain. We use only 100 steps here to keep the tutorial\n",
"fast, but in practice you would typically run more steps to ensure\n",
"convergence and better posterior resolution.\n",
"\n",
"Each DREAM generation evaluates the whole population in parallel, so\n",
"the cost of resuming scales with `population_size`: `extra_steps=100`\n",
"with the default population is on the order of a couple of thousand\n",
"model evaluations, not 100. The progress bar counts the new\n",
"generations (`1/100`), independent of how long the saved chain\n",
"already is."
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "27",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:37:35.964718Z",
"iopub.status.busy": "2026-06-30T22:37:35.964563Z",
"iopub.status.idle": "2026-06-30T22:38:53.688437Z",
"shell.execute_reply": "2026-06-30T22:38:53.687631Z"
}
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"\n",
"(function() {\n",
" const button = document.getElementById('ed-fit-stop-27f8c7683588415fb49ce8eaacbafe30-button');\n",
" const status = document.getElementById('ed-fit-stop-27f8c7683588415fb49ce8eaacbafe30-status');\n",
" const kernelId = '';\n",
" if (!button) {\n",
" return;\n",
" }\n",
"\n",
" function setStatus(text) {\n",
" if (status) {\n",
" status.textContent = text;\n",
" }\n",
" }\n",
"\n",
" function pageConfig() {\n",
" const element = document.getElementById('jupyter-config-data');\n",
" if (!element || !element.textContent) {\n",
" return {};\n",
" }\n",
" try {\n",
" return JSON.parse(element.textContent);\n",
" } catch (error) {\n",
" return {};\n",
" }\n",
" }\n",
"\n",
" function baseUrl(config) {\n",
" const configured = config.baseUrl || config.base_url ||\n",
" (window.Jupyter && Jupyter.notebook && Jupyter.notebook.base_url);\n",
" if (configured) {\n",
" return configured.endsWith('/') ? configured : configured + '/';\n",
" }\n",
" const markers = ['/lab/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = window.location.pathname.indexOf(marker);\n",
" if (index >= 0) {\n",
" return window.location.pathname.slice(0, index + 1);\n",
" }\n",
" }\n",
" return '/';\n",
" }\n",
"\n",
" function token(config) {\n",
" return config.token || new URLSearchParams(window.location.search).get('token') || '';\n",
" }\n",
"\n",
" function cookie(name) {\n",
" const prefix = name + '=';\n",
" for (const part of document.cookie.split(';')) {\n",
" const trimmed = part.trim();\n",
" if (trimmed.startsWith(prefix)) {\n",
" return decodeURIComponent(trimmed.slice(prefix.length));\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" function notebookPath() {\n",
" const decoded = decodeURIComponent(window.location.pathname);\n",
" const markers = ['/lab/tree/', '/notebooks/', '/tree/'];\n",
" for (const marker of markers) {\n",
" const index = decoded.indexOf(marker);\n",
" if (index >= 0) {\n",
" return decoded.slice(index + marker.length);\n",
" }\n",
" }\n",
" return '';\n",
" }\n",
"\n",
" async function kernelFromSessions(config) {\n",
" const url = new URL(baseUrl(config) + 'api/sessions', window.location.origin);\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const response = await fetch(url, {credentials: 'same-origin'});\n",
" if (!response.ok) {\n",
" return '';\n",
" }\n",
" const sessions = await response.json();\n",
" const path = notebookPath();\n",
" const session = sessions.find((item) => item.path === path) || sessions[0];\n",
" return session && session.kernel ? session.kernel.id : '';\n",
" }\n",
"\n",
" async function interruptKernel(config, resolvedKernelId) {\n",
" const url = new URL(\n",
" baseUrl(config) + 'api/kernels/' + resolvedKernelId + '/interrupt',\n",
" window.location.origin\n",
" );\n",
" const authToken = token(config);\n",
" if (authToken) {\n",
" url.searchParams.set('token', authToken);\n",
" }\n",
" const xsrfToken = cookie('_xsrf');\n",
" const headers = {};\n",
" if (xsrfToken) {\n",
" headers['X-XSRFToken'] = xsrfToken;\n",
" }\n",
" const response = await fetch(url, {\n",
" method: 'POST',\n",
" credentials: 'same-origin',\n",
" headers: headers\n",
" });\n",
" return response.ok;\n",
" }\n",
"\n",
" button.addEventListener('click', async function() {\n",
" button.disabled = true;\n",
" setStatus('Stopping...');\n",
" const config = pageConfig();\n",
" try {\n",
" const resolvedKernelId = kernelId || await kernelFromSessions(config);\n",
" if (!resolvedKernelId) {\n",
" throw new Error('Could not resolve the current kernel id.');\n",
" }\n",
" const interrupted = await interruptKernel(config, resolvedKernelId);\n",
" if (!interrupted) {\n",
" throw new Error('Jupyter Server rejected the interrupt request.');\n",
" }\n",
" setStatus('Interrupt sent...');\n",
" } catch (error) {\n",
" button.disabled = false;\n",
" setStatus('Use Kernel > Interrupt to stop this fit.');\n",
" }\n",
" });\n",
"})();\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mStandard fitting\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Using experiment π¬ \u001b[32m'hrpt'\u001b[0m for \u001b[32m'single'\u001b[0m fitting\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Starting fit process with \u001b[32m'bumps \u001b[0m\u001b[32m(\u001b[0m\u001b[32mdream\u001b[0m\u001b[32m)\u001b[0m\u001b[32m'\u001b[0m\u001b[33m...\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Bayesian sampling progress:\n"
]
},
{
"data": {
"text/html": [
" | step | progress | time (s) | log posterior | phase |
|---|
| 1 | | | 0.33 | -1159.79 | pre-processing |
|---|
| 2 | 5/100 | 5.0% | 1.41 | -1159.63 | sampling |
|---|
| 3 | 9/100 | 9.0% | 2.54 | -1159.34 | sampling |
|---|
| 4 | 14/100 | 14.0% | 3.82 | -1159.14 | sampling |
|---|
| 5 | 18/100 | 18.0% | 4.89 | -1159.07 | sampling |
|---|
| 6 | 22/100 | 22.0% | 6.01 | -1159.58 | sampling |
|---|
| 7 | 26/100 | 26.0% | 7.07 | -1159.60 | sampling |
|---|
| 8 | 30/100 | 30.0% | 8.18 | -1159.35 | sampling |
|---|
| 9 | 34/100 | 34.0% | 9.23 | -1159.18 | sampling |
|---|
| 10 | 38/100 | 38.0% | 10.33 | -1159.38 | sampling |
|---|
| 11 | 43/100 | 43.0% | 11.71 | -1159.60 | sampling |
|---|
| 12 | 47/100 | 47.0% | 12.72 | -1159.84 | sampling |
|---|
| 13 | 51/100 | 51.0% | 13.73 | -1159.74 | sampling |
|---|
| 14 | 55/100 | 55.0% | 14.85 | -1159.31 | sampling |
|---|
| 15 | 59/100 | 59.0% | 15.93 | -1159.31 | sampling |
|---|
| 16 | 64/100 | 64.0% | 17.36 | -1159.35 | sampling |
|---|
| 17 | 68/100 | 68.0% | 18.46 | -1159.91 | sampling |
|---|
| 18 | 72/100 | 72.0% | 19.51 | -1159.99 | sampling |
|---|
| 19 | 76/100 | 76.0% | 20.59 | -1159.63 | sampling |
|---|
| 20 | 80/100 | 80.0% | 21.60 | -1159.34 | sampling |
|---|
| 21 | 84/100 | 84.0% | 22.63 | -1159.28 | sampling |
|---|
| 22 | 88/100 | 88.0% | 23.73 | -1159.03 | sampling |
|---|
| 23 | 93/100 | 93.0% | 25.08 | -1159.65 | sampling |
|---|
| 24 | 97/100 | 97.0% | 26.22 | -1159.57 | sampling |
|---|
| 25 | 100/100 | 100.0% | 27.08 | -1159.81 | sampling |
|---|
| 26 | | | 77.26 | | post-processing |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β
Bayesian sampling complete.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project π¦ \u001b[0m\u001b[32m'lbco_hrpt_dream'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/bayesian-dream-resume-lbco-hrpt'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π project.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π lbco.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π hrpt.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π analysis/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π analysis.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π mcmc.h5\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π reports/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" βββ π lbco_hrpt_dream.html\n"
]
}
],
"source": [
"project.analysis.minimizer.random_seed = 42 # fixed seed for reproducible output\n",
"project.analysis.fit(resume=True, extra_steps=100)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "28",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:38:53.690309Z",
"iopub.status.busy": "2026-06-30T22:38:53.690153Z",
"iopub.status.idle": "2026-06-30T22:38:53.718879Z",
"shell.execute_reply": "2026-06-30T22:38:53.718121Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"βοΈ Settings used:\n"
]
},
{
"data": {
"text/html": [
" | Name | Value | Description |
|---|
| 1 | sampling_steps | 10000 | Total sampler iterations per chain. |
|---|
| 2 | burn_in_steps | 2000 | Sampler iterations discarded as warm-up. |
|---|
| 3 | thinning_interval | 1 | Sampler thinning interval. |
|---|
| 4 | population_size | 4 | Number of chains or walkers. |
|---|
| 5 | parallel_workers | 0 | Worker count; 0 uses all available CPUs. |
|---|
| 6 | initialization_method | latin_hypercube | Sampler initialization method. |
|---|
| 7 | random_seed | 42 | Random seed; None uses a system-derived seed. |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Bayesian fit results:\n"
]
},
{
"data": {
"text/html": [
" | Metric | Value |
|---|
| 1 | π§ͺ Sampler | bumps (dream) |
|---|
| 2 | β
Overall status | success |
|---|
| 3 | π¬ Engine message | DREAM sampling completed |
|---|
| 4 | β±οΈ Fitting time (seconds) | 77.26 |
|---|
| 5 | π Goodness-of-fit (reduced ΟΒ²) | 1.29 |
|---|
| 6 | π R-factor (Rf, %) | 5.65 |
|---|
| 7 | π R-factor squared (RfΒ², %) | 4.92 |
|---|
| 8 | π Weighted R-factor (wR, %) | 4.08 |
|---|
| 9 | π Best log-posterior | -1157.01 |
|---|
| 10 | π Convergence status | passed |
|---|
| 11 | π Max r-hat | 1.003 |
|---|
| 12 | π Min ess bulk | 6995.224 |
|---|
| 13 | π Draws per chain | 10100 |
|---|
| 14 | π Chains | 20 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Committed parameters:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | start | value | s.u. | change |
|---|
| 1 | lbco | cell | | length_a | Γ
| 3.8913 | 3.8913 | 0.0001 | 0.00 % β |
|---|
| 2 | hrpt | linked_structure | lbco | scale | | 9.1330 | 9.1329 | 0.0292 | 0.00 % β |
|---|
| 3 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0817 | 0.0817 | 0.0067 | 0.04 % β |
|---|
| 4 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1169 | -0.1169 | 0.0048 | 0.01 % β |
|---|
| 5 | hrpt | instrument | | twotheta_offset | deg | 0.6306 | 0.6306 | 0.0017 | 0.00 % β |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ start = parameter value before sampling
β’ value = estimate written back to the project (best posterior sample)
β’ s.u. = standard uncertainty (one sigma), posterior standard deviation
β’ change = relative change from start, in %; β = increase, β = decrease
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"π Posterior distribution:\n"
]
},
{
"data": {
"text/html": [
" | datablock | category | entry | parameter | units | median | 95% CI | r-hat | ess bulk |
|---|
| 1 | lbco | cell | | length_a | Γ
| 3.8913 | [3.8911, 3.8915] | 1.003 | 7114.3 |
|---|
| 2 | hrpt | linked_structure | lbco | scale | | 9.1328 | [9.0754, 9.1903] | 1.003 | 8598.5 |
|---|
| 3 | hrpt | peak | | broad_gauss_u | degΒ² | 0.0814 | [0.0687, 0.0946] | 1.003 | 7353.6 |
|---|
| 4 | hrpt | peak | | broad_gauss_v | degΒ² | -0.1167 | [-0.1262, -0.1074] | 1.003 | 7491.6 |
|---|
| 5 | hrpt | instrument | | twotheta_offset | deg | 0.6303 | [0.6270, 0.6336] | 1.003 | 6995.2 |
|---|
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" β’ median = 50th percentile of the marginal posterior
β’ 95% CI = 95% credible interval (2.5%-97.5%, asymmetric)
β’ r-hat = Gelman-Rubin diagnostic (good convergence: r-hat <= 1.01)
β’ ess bulk = bulk effective sample size (typically >= 400)
"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.fit.results()"
]
},
{
"cell_type": "markdown",
"id": "29",
"metadata": {},
"source": [
"### Display Resumed Posterior\n",
"\n",
"After resume, the posterior plots use the extended chain."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "30",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:38:53.720521Z",
"iopub.status.busy": "2026-06-30T22:38:53.720354Z",
"iopub.status.idle": "2026-06-30T22:38:54.230314Z",
"shell.execute_reply": "2026-06-30T22:38:54.229477Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.pairs()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "31",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:38:54.238329Z",
"iopub.status.busy": "2026-06-30T22:38:54.238044Z",
"iopub.status.idle": "2026-06-30T22:38:54.406483Z",
"shell.execute_reply": "2026-06-30T22:38:54.405621Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.distribution()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "32",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:38:54.408020Z",
"iopub.status.busy": "2026-06-30T22:38:54.407862Z",
"iopub.status.idle": "2026-06-30T22:38:54.455434Z",
"shell.execute_reply": "2026-06-30T22:38:54.454229Z"
}
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"project.display.posterior.predictive(expt_name='hrpt', x_min=92, x_max=93)"
]
},
{
"cell_type": "markdown",
"id": "33",
"metadata": {},
"source": [
"## πΎ Save Project"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "34",
"metadata": {
"execution": {
"iopub.execute_input": "2026-06-30T22:38:54.456919Z",
"iopub.status.busy": "2026-06-30T22:38:54.456751Z",
"iopub.status.idle": "2026-06-30T22:38:54.856343Z",
"shell.execute_reply": "2026-06-30T22:38:54.855546Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[1;36mSaving project π¦ \u001b[0m\u001b[32m'lbco_hrpt_dream'\u001b[0m\u001b[1;36m to \u001b[0m\u001b[32m'../../../projects/bayesian-dream-resume-lbco-hrpt'\u001b[0m\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π project.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π structures/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π lbco.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π experiments/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π hrpt.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π analysis/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π analysis.edi\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"β βββ π mcmc.h5\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"βββ π reports/\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" βββ π lbco_hrpt_dream.html\n"
]
}
],
"source": [
"project.save_as(dir_path='projects/bayesian-dream-resume-lbco-hrpt')"
]
}
],
"metadata": {
"jupytext": {
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}