Skip to content

Commit 078c43a

Browse files
authored
Merge pull request #723 from stan-dev/fix/unit-e-extra-line
Stan 2.34: Fix parsing of unit_e output files
2 parents 734fb98 + 144d641 commit 078c43a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cmdstanpy/stanfit/mcmc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ def _assemble_draws(self) -> None:
441441
self._metric[chain, i, :] = [
442442
float(x) for x in xs
443443
]
444+
else: # unit_e changed in 2.34 to have an extra line
445+
pos = fd.tell()
446+
line = fd.readline().strip()
447+
if not line.startswith('#'):
448+
fd.seek(pos)
449+
444450
# process draws
445451
for i in range(sampling_iter_start, num_draws):
446452
line = fd.readline().strip()

cmdstanpy/utils/stancsv.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,16 @@ def scan_hmc_params(
289289
raise ValueError(
290290
'line {}: invalid step size: {}'.format(lineno, step_size)
291291
) from e
292-
if metric == 'unit_e':
293-
return lineno
292+
before_metric = fd.tell()
294293
line = fd.readline().strip()
295294
lineno += 1
295+
if metric == 'unit_e':
296+
if line.startswith("# No free parameters"):
297+
return lineno
298+
else:
299+
fd.seek(before_metric)
300+
return lineno - 1
301+
296302
if not (
297303
(
298304
metric == 'diag_e'

0 commit comments

Comments
 (0)