Skip to content

Commit 45a9b5e

Browse files
committed
Avoid race condition
1 parent 9594edb commit 45a9b5e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/sccala/sccala_bootstrap.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def cli():
126126
)
127127
parser.add_argument(
128128
"--output_dir",
129-
help="Directory used for storing STAN temporary files. Default: '/local'",
130-
default="/local",
129+
help="Directory used for storing STAN temporary files",
131130
)
132131

133132
args = parser.parse_args()

src/sccala/sccala_scm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ def cli():
150150
)
151151
parser.add_argument(
152152
"--output_dir",
153-
help="Directory used for storing STAN temporary files. Default: '/local'",
154-
default="/local",
153+
help="Directory used for storing STAN temporary files.",
155154
)
156155

157156
args = parser.parse_args()

src/sccala/scmlib/sccala.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def sample(
250250
quiet=False,
251251
init=None,
252252
classic=False,
253-
output_dir="/local",
253+
output_dir=None,
254254
):
255255
"""
256256
Samples the posterior for the given data and model using
@@ -282,7 +282,7 @@ def sample(
282282
Switches classic mode on if True. In classic mode, a/e input is
283283
ignored.
284284
output_dir : str
285-
Directory where temporary STAN files will be stored. Default: '/local'
285+
Directory where temporary STAN files will be stored. Default: None
286286
287287
Returns
288288
-------
@@ -443,7 +443,7 @@ def bootstrap(
443443
replacement=True,
444444
restart=True,
445445
walltime=24.0,
446-
output_dir="/local",
446+
output_dir=None,
447447
):
448448
"""
449449
Samples the posterior for the given data and model
@@ -483,7 +483,7 @@ def bootstrap(
483483
time is used, no new iteration will be started and job will exit
484484
cleanly. Should be used with restart set to True. Default 24.0
485485
output_dir : str
486-
Directory where temporary STAN files will be stored. Default: '/local'
486+
Directory where temporary STAN files will be stored. Default: None
487487
488488
Returns
489489
-------
@@ -657,6 +657,13 @@ def bootstrap(
657657
# and the path is 'hardcoded' anyway
658658
stan_file = os.path.join(log_dir, "model.stan")
659659

660+
if output_dir is not None:
661+
output_dir_rank = os.path.join(output_dir, "rank_%03d" % rank)
662+
if not os.path.exists(output_dir_rank):
663+
os.makedirs(output_dir_rank)
664+
else:
665+
output_dir_rank = None
666+
660667
comm.Barrier()
661668

662669
for k in tr:
@@ -714,7 +721,7 @@ def bootstrap(
714721
iter_sampling=iters,
715722
save_warmup=save_warmup,
716723
inits=[model.init] * chains,
717-
output_dir=output_dir,
724+
output_dir=output_dir_rank,
718725
)
719726

720727
self.posterior = fit.draws_pd()

0 commit comments

Comments
 (0)