Skip to content

UI: Updated sampling progress overwhelms Jupyter interface #293

@amas0

Description

@amas0

Describe the bug

The improved UI messages (I believe implemented in 163af4f, I first noticed it when I went from 3.0 -> 3.1) have an odd interaction with the Jupyter interface. Effectively, multiple status lines are printed to the interface every second and model fits that only run for a few minutes will fill up the browser interface with thousands of
Sampling : X% (Y/Z) lines.

I glanced through the source and I think it's attempting to write a line to the browser every time the event loop polls for completion as in:

pystan/stan/model.py

Lines 211 to 214 in 163af4f

sampling_output.clear()
sampling_output.write_line(
f"<comment>Sampling:</comment> {round(percent_complete):3.0f}% ({iterations_count}/{total_iterations})"
)

The sampling_output.clear() doesn't clear anything in Jupyter and you just end up with a ton of lines. Another effect is your browser essentially will max out a CPU core trying to write as lines to your screen as fast as possible.

I was going to look to see if I could find some workaround to ease the issue in Jupyter while not changing the behavior in terminals, but I wanted to throw this issue up first just to have a record of it. I know it's kind of clunky because this was all clearly written to function best from a terminal interface and Jupyter hijacking that process just causes some oddities, but it would be nice to smooth out the experience.

If you have any ideas, I'd be happy to try to explore them. Otherwise, I might do some exploration and try to cook up a PR if I find something that seems to work.

Steps/Code to Reproduce

Sample from any model in a Jupyter interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions