Skip to content

Commit 3cbfae4

Browse files
authored
Merge pull request #492 from stan-dev/feature/436-num-chains
Feature/436 num chains
2 parents 3e483cd + 6eade46 commit 3cbfae4

16 files changed

+671
-403
lines changed

cmdstanpy/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""CmdStanPy Module"""
33

44
import atexit
5+
import logging
56
import shutil
67
import tempfile
78

@@ -27,9 +28,9 @@
2728

2829
def _cleanup_tmpdir() -> None:
2930
"""Force deletion of _TMPDIR."""
30-
print('deleting tmpfiles dir: {}'.format(_TMPDIR))
31+
logging.getLogger('cmdstanpy').info('deleting tmpfiles dir: %s', _TMPDIR)
3132
shutil.rmtree(_TMPDIR, ignore_errors=True)
32-
print('done')
33+
logging.getLogger('cmdstanpy').info('done')
3334

3435

3536
atexit.register(_cleanup_tmpdir)

cmdstanpy/cmdstan_args.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from enum import Enum, auto
66
from time import time
7-
from typing import Any, Dict, List, Optional, Union
7+
from typing import Any, Dict, List, Mapping, Optional, Union
88

99
import numpy as np
1010
from numpy.random import RandomState
@@ -712,7 +712,7 @@ def __init__(
712712
method_args: Union[
713713
SamplerArgs, OptimizeArgs, GenerateQuantitiesArgs, VariationalArgs
714714
],
715-
data: Union[str, Dict[str, Any], None] = None,
715+
data: Union[Mapping[str, Any], str, None] = None,
716716
seed: Union[int, List[int], None] = None,
717717
inits: Union[int, float, str, List[str], None] = None,
718718
output_dir: Optional[str] = None,
@@ -811,6 +811,7 @@ def validate(self) -> None:
811811
'Argument "sig_figs" must be an integer between 1 and 18,'
812812
' found {}'.format(self.sig_figs)
813813
)
814+
# TODO: remove at some future release
814815
if cmdstan_version_before(2, 25):
815816
self.sig_figs = None
816817
get_logger().warning(
@@ -897,7 +898,8 @@ def compose_command(
897898
csv_file: str,
898899
*,
899900
diagnostic_file: Optional[str] = None,
900-
profile_file: Optional[str] = None
901+
profile_file: Optional[str] = None,
902+
num_chains: Optional[int] = None
901903
) -> List[str]:
902904
"""
903905
Compose CmdStan command for non-default arguments.
@@ -932,13 +934,15 @@ def compose_command(
932934
cmd.append('init={}'.format(self.inits[idx]))
933935
cmd.append('output')
934936
cmd.append('file={}'.format(csv_file))
935-
if diagnostic_file is not None:
937+
if diagnostic_file:
936938
cmd.append('diagnostic_file={}'.format(diagnostic_file))
937-
if profile_file is not None:
939+
if profile_file:
938940
cmd.append('profile_file={}'.format(profile_file))
939941
if self.refresh is not None:
940942
cmd.append('refresh={}'.format(self.refresh))
941943
if self.sig_figs is not None:
942944
cmd.append('sig_figs={}'.format(self.sig_figs))
943945
cmd = self.method_args.compose(idx, cmd)
946+
if num_chains:
947+
cmd.append('num_chains={}'.format(num_chains))
944948
return cmd

0 commit comments

Comments
 (0)