Skip to content

Commit 545ee32

Browse files
committed
Make a subdirectory of the temporary directory per-runset
1 parent ebd02ee commit 545ee32

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

cmdstanpy/stanfit/runset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import re
88
import shutil
9+
import tempfile
910
from datetime import datetime
1011
from time import time
1112
from typing import List, Optional
@@ -50,7 +51,10 @@ def __init__(
5051
if args.output_dir is not None:
5152
self._output_dir = args.output_dir
5253
else:
53-
self._output_dir = _TMPDIR
54+
# make a per-run subdirectory of our master temp directory
55+
self._output_dir = tempfile.mkdtemp(
56+
prefix=args.model_name, dir=_TMPDIR
57+
)
5458

5559
# output files prefix: ``<model_name>-<YYYYMMDDHHMM>_<chain_id>``
5660
self._base_outfile = (

test/data/normal-rng.stan

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
transformed data{
2+
real x_;
3+
x_ = std_normal_rng();
4+
}
5+
generated quantities{
6+
real x = x_;
7+
}

test/test_sample.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,20 @@ def test_single_row_csv(self):
17691769
self.assertEqual(int(z_as_ndarray[0, i, j]), i + 1)
17701770
self.assertEqual(int(z_as_xr.z.data[0, 0, i, j]), i + 1)
17711771

1772+
def test_overlapping_names(self):
1773+
stan = os.path.join(DATAFILES_PATH, 'normal-rng.stan')
1774+
1775+
mod = CmdStanModel(stan_file=stan)
1776+
# %Y to force same names
1777+
fits = [
1778+
mod.sample(data={}, time_fmt="%Y", iter_sampling=1, iter_warmup=1)
1779+
for i in range(10)
1780+
]
1781+
1782+
self.assertEqual(
1783+
len(np.unique([fit.stan_variables()["x"][0] for fit in fits])), 10
1784+
)
1785+
17721786
def test_complex_output(self):
17731787
stan = os.path.join(DATAFILES_PATH, 'complex_var.stan')
17741788
model = CmdStanModel(stan_file=stan)

0 commit comments

Comments
 (0)