{ "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": [ "
NameValueDescription
1sampling_steps10000Total sampler iterations per chain.
2burn_in_steps2000Sampler iterations discarded as warm-up.
3thinning_interval1Sampler thinning interval.
4population_size4Number of chains or walkers.
5parallel_workers0Worker count; 0 uses all available CPUs.
6initialization_methodlatin_hypercubeSampler initialization method.
7random_seed42Random 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": [ "
MetricValue
1πŸ§ͺ Samplerdream
2βœ… Overall statussuccess
3πŸ’¬ Engine messageDREAM 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 statuspassed
11πŸ“Š Max r-hat1.003
12πŸ“Š Min ess bulk6949.232
13πŸ“Š Draws per chain10000
14πŸ“Š Chains20
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Committed parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1lbcocelllength_aΓ…3.89133.89130.00010.00 % ↓
2hrptlinked_structurelbcoscale9.13299.13300.02920.00 % ↑
3hrptpeakbroad_gauss_udegΒ²0.08170.08170.00670.04 % ↑
4hrptpeakbroad_gauss_vdegΒ²-0.1169-0.11690.00480.01 % ↓
5hrptinstrumenttwotheta_offsetdeg0.63060.63060.00170.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": [ "
datablockcategoryentryparameterunitsmedian95% CIr-hatess bulk
1lbcocelllength_aΓ…3.8913[3.8911, 3.8915]1.0037072.4
2hrptlinked_structurelbcoscale9.1328[9.0754, 9.1903]1.0038504.9
3hrptpeakbroad_gauss_udegΒ²0.0814[0.0687, 0.0946]1.0037256.3
4hrptpeakbroad_gauss_vdegΒ²-0.1167[-0.1262, -0.1074]1.0037393.3
5hrptinstrumenttwotheta_offsetdeg0.6303[0.6270, 0.6335]1.0036949.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", "
\n", "
Loading plot…
\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", "
\n", "
Loading plot…
\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": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "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": [ "
Loading plot…
" ], "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": [ "
Loading plot…
" ], "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": [ "
stepprogresstime (s)log posteriorphase
10.33-1159.79pre-processing
25/1005.0%1.41-1159.63sampling
39/1009.0%2.54-1159.34sampling
414/10014.0%3.82-1159.14sampling
518/10018.0%4.89-1159.07sampling
622/10022.0%6.01-1159.58sampling
726/10026.0%7.07-1159.60sampling
830/10030.0%8.18-1159.35sampling
934/10034.0%9.23-1159.18sampling
1038/10038.0%10.33-1159.38sampling
1143/10043.0%11.71-1159.60sampling
1247/10047.0%12.72-1159.84sampling
1351/10051.0%13.73-1159.74sampling
1455/10055.0%14.85-1159.31sampling
1559/10059.0%15.93-1159.31sampling
1664/10064.0%17.36-1159.35sampling
1768/10068.0%18.46-1159.91sampling
1872/10072.0%19.51-1159.99sampling
1976/10076.0%20.59-1159.63sampling
2080/10080.0%21.60-1159.34sampling
2184/10084.0%22.63-1159.28sampling
2288/10088.0%23.73-1159.03sampling
2393/10093.0%25.08-1159.65sampling
2497/10097.0%26.22-1159.57sampling
25100/100100.0%27.08-1159.81sampling
2677.26post-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": [ "
NameValueDescription
1sampling_steps10000Total sampler iterations per chain.
2burn_in_steps2000Sampler iterations discarded as warm-up.
3thinning_interval1Sampler thinning interval.
4population_size4Number of chains or walkers.
5parallel_workers0Worker count; 0 uses all available CPUs.
6initialization_methodlatin_hypercubeSampler initialization method.
7random_seed42Random 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": [ "
MetricValue
1πŸ§ͺ Samplerbumps (dream)
2βœ… Overall statussuccess
3πŸ’¬ Engine messageDREAM 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 statuspassed
11πŸ“Š Max r-hat1.003
12πŸ“Š Min ess bulk6995.224
13πŸ“Š Draws per chain10100
14πŸ“Š Chains20
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "πŸ“ˆ Committed parameters:\n" ] }, { "data": { "text/html": [ "
datablockcategoryentryparameterunitsstartvalues.u.change
1lbcocelllength_aΓ…3.89133.89130.00010.00 % ↑
2hrptlinked_structurelbcoscale9.13309.13290.02920.00 % ↓
3hrptpeakbroad_gauss_udegΒ²0.08170.08170.00670.04 % ↓
4hrptpeakbroad_gauss_vdegΒ²-0.1169-0.11690.00480.01 % ↑
5hrptinstrumenttwotheta_offsetdeg0.63060.63060.00170.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": [ "
datablockcategoryentryparameterunitsmedian95% CIr-hatess bulk
1lbcocelllength_aΓ…3.8913[3.8911, 3.8915]1.0037114.3
2hrptlinked_structurelbcoscale9.1328[9.0754, 9.1903]1.0038598.5
3hrptpeakbroad_gauss_udegΒ²0.0814[0.0687, 0.0946]1.0037353.6
4hrptpeakbroad_gauss_vdegΒ²-0.1167[-0.1262, -0.1074]1.0037491.6
5hrptinstrumenttwotheta_offsetdeg0.6303[0.6270, 0.6336]1.0036995.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", "
\n", "
Loading plot…
\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": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Loading plot…
" ], "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": [ "
Loading plot…
" ], "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 }