Skip to content

Commit b91d54e

Browse files
committed
trying out with mo.output
1 parent 53be4e0 commit b91d54e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

python/nutpie/sample.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ def _trace_to_arviz(traces, n_tune, shapes, **kwargs):
267267
"""
268268

269269

270+
def in_marimo_notebook() -> bool:
271+
try:
272+
import marimo as mo
273+
274+
return mo.running_in_notebook()
275+
except ImportError:
276+
return False
277+
278+
270279
# Adapted from fastprogress
271280
def in_notebook():
272281
def in_colab():
@@ -362,6 +371,27 @@ def callback(formatted):
362371
self._html = formatted
363372
self.display_id.update(self)
364373

374+
progress_type = _lib.ProgressType.template_callback(
375+
progress_rate, progress_template, cores, callback
376+
)
377+
elif in_marimo_notebook():
378+
import marimo as mo
379+
380+
if progress_template is None:
381+
progress_template = _progress_template
382+
383+
if progress_style is None:
384+
progress_style = _progress_style
385+
386+
self._html = ""
387+
388+
mo.output.replace(mo.Html("Sampling is about to start..."))
389+
390+
def callback(formatted):
391+
self._html = formatted
392+
html = mo.Html(f"{progress_style}\n{formatted}")
393+
mo.output.replace(html)
394+
365395
progress_type = _lib.ProgressType.template_callback(
366396
progress_rate, progress_template, cores, callback
367397
)

0 commit comments

Comments
 (0)