From d16271aed144a4798945ee678166e5b5275ff6cc Mon Sep 17 00:00:00 2001 From: Mitzi Morris Date: Wed, 6 Oct 2021 20:25:32 -0400 Subject: [PATCH] more cleanup --- cmdstanpy/model.py | 15 +++++++-------- cmdstanpy/utils.py | 11 +++++------ cmdstanpy_tutorial.ipynb | 8 +------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/cmdstanpy/model.py b/cmdstanpy/model.py index df04ba2e..cbc284f9 100644 --- a/cmdstanpy/model.py +++ b/cmdstanpy/model.py @@ -1303,14 +1303,13 @@ def _run_cmdstan( ) while proc.poll() is None: if proc.stdout is not None: - lines = proc.stdout.readlines() - for line in lines: - fd_out.write(line) - line = line.strip() - if show_console and len(line) > 1: - print('chain {}: {}'.format(idx + 1, line)) - if show_progress and progress_hook is not None: - progress_hook(line) + line = proc.stdout.readline() + fd_out.write(line) + line = line.strip() + if show_console and len(line) > 1: + print('chain {}: {}'.format(idx + 1, line)) + if show_progress and progress_hook is not None: + progress_hook(line) if show_progress and progress_hook is not None: progress_hook("Done") diff --git a/cmdstanpy/utils.py b/cmdstanpy/utils.py index b98391ab..a8b08c78 100644 --- a/cmdstanpy/utils.py +++ b/cmdstanpy/utils.py @@ -961,12 +961,11 @@ def do_command( ) while proc.poll() is None: if proc.stdout is not None: - lines = proc.stdout.readlines() - for line in lines: - if fd_out is not None: - fd_out.write(line) - if pbar is not None: - pbar(line.strip()) + line = proc.stdout.readline() + if fd_out is not None: + fd_out.write(line) + if pbar is not None: + pbar(line.strip()) stdout, _ = proc.communicate() if stdout: diff --git a/cmdstanpy_tutorial.ipynb b/cmdstanpy_tutorial.ipynb index 8d7a3e57..b88bb633 100644 --- a/cmdstanpy_tutorial.ipynb +++ b/cmdstanpy_tutorial.ipynb @@ -308,15 +308,9 @@ "metadata": {}, "outputs": [], "source": [ - "%matplotlib inline\n", - "import pandas as pd\n", - "\n", "vars = fit.stan_variables()\n", "for (k,v) in vars.items():\n", - " print(k, v.shape)\n", - "\n", - "thetas = fit.stan_variable(var='theta')\n", - "pd.DataFrame(data=thetas).plot.density()" + " print(k, v.shape)" ] }, {