Skip to content

Commit 810b32a

Browse files
committed
Add exception handling to stancsv parsing in assemble_draws
1 parent 29ee368 commit 810b32a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

cmdstanpy/stanfit/mcmc.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,25 @@ def _assemble_draws(self) -> None:
444444

445445
mass_matrix_per_chain: List[Optional[npt.NDArray[np.float64]]] = []
446446
for chain in range(self.chains):
447-
comments, draws = stancsv.parse_stan_csv_comments_and_draws(
448-
self.runset.csv_files[chain]
449-
)
447+
try:
448+
comments, draws = stancsv.parse_stan_csv_comments_and_draws(
449+
self.runset.csv_files[chain]
450+
)
450451

451-
self._draws[:, chain, :] = stancsv.csv_bytes_list_to_numpy(draws)
452+
self._draws[:, chain, :] = stancsv.csv_bytes_list_to_numpy(
453+
draws
454+
)
452455

453-
if not self._is_fixed_param:
454-
(
455-
self._step_size[chain],
456-
mass_matrix,
457-
) = stancsv.parse_hmc_adaptation_lines(comments)
458-
mass_matrix_per_chain.append(mass_matrix)
456+
if not self._is_fixed_param:
457+
(
458+
self._step_size[chain],
459+
mass_matrix,
460+
) = stancsv.parse_hmc_adaptation_lines(comments)
461+
mass_matrix_per_chain.append(mass_matrix)
462+
except Exception as exc:
463+
raise ValueError(
464+
f"Parsing output from {self.runset.csv_files[chain]} failed"
465+
) from exc
459466

460467
if all(mm is not None for mm in mass_matrix_per_chain):
461468
if self.metric_type == "diag_e":

0 commit comments

Comments
 (0)