Skip to content

Commit b5a11fd

Browse files
committed
Merge branch 'develop' of https://github.com/stan-dev/cmdstanpy into develop
2 parents 5952f2b + 9029dab commit b5a11fd

75 files changed

Lines changed: 7878 additions & 3795 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ disable=bad-continuation,
7676
consider-using-with,
7777
consider-using-dict-items,
7878
unspecified-encoding,
79-
consider-using-f-string
79+
consider-using-f-string,
8080

8181
# Enable the message, report, category or checker with the given id(s). You can
8282
# either give multiple identifier separated by comma (,) or put this option

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CmdStanPy is a lightweight pure-Python interface to CmdStan which provides acces
77

88
CmdStanPy is distributed via PyPi: https://pypi.org/project/cmdstanpy/
99

10+
or Conda Forge: https://anaconda.org/conda-forge/cmdstanpy
11+
1012
### Goals
1113

1214
- Clean interface to Stan services so that CmdStanPy can keep up with Stan releases.

cmdstanpy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
_CMDSTAN_SAMPLING = 1000
2323
_CMDSTAN_THIN = 1
2424
_CMDSTAN_REFRESH = 100
25-
_DOT_CMDSTANPY = '.cmdstanpy'
2625
_DOT_CMDSTAN = '.cmdstan'
2726

2827

cmdstanpy/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""PyPi Version"""
22

3-
__version__ = '0.9.77'
3+
__version__ = '1.0.0rc1'

cmdstanpy/cmdstan_args.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
CmdStan arguments
33
"""
4-
import logging
54
import os
65
from enum import Enum, auto
76
from time import time
@@ -721,7 +720,6 @@ def __init__(
721720
save_latent_dynamics: bool = False,
722721
save_profile: bool = False,
723722
refresh: Optional[int] = None,
724-
logger: Optional[logging.Logger] = None,
725723
) -> None:
726724
"""Initialize object."""
727725
self.model_name = model_name
@@ -745,11 +743,6 @@ def __init__(
745743
elif isinstance(method_args, VariationalArgs):
746744
self.method = Method.VARIATIONAL
747745
self.method_args.validate(len(chain_ids) if chain_ids else None)
748-
if logger is not None:
749-
get_logger().warning(
750-
"Parameter 'logger' is deprecated."
751-
" Control logging behavior via logging.getLogger('cmdstanpy')"
752-
)
753746
self.validate()
754747

755748
def validate(self) -> None:

cmdstanpy/compiler_opts.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Makefile options for stanc and C++ compilers
33
"""
44

5-
import logging
65
import os
76
from pathlib import Path
87
from typing import Any, Dict, List, Optional, Union
@@ -57,17 +56,11 @@ def __init__(
5756
stanc_options: Optional[Dict[str, Any]] = None,
5857
cpp_options: Optional[Dict[str, Any]] = None,
5958
user_header: Optional[str] = None,
60-
logger: Optional[logging.Logger] = None,
6159
) -> None:
6260
"""Initialize object."""
6361
self._stanc_options = stanc_options if stanc_options is not None else {}
6462
self._cpp_options = cpp_options if cpp_options is not None else {}
6563
self._user_header = user_header if user_header is not None else ''
66-
if logger is not None:
67-
get_logger().warning(
68-
"Parameter 'logger' is deprecated."
69-
" Control logging behavior via logging.getLogger('cmdstanpy')"
70-
)
7164

7265
def __repr__(self) -> str:
7366
return 'stanc_options={}, cpp_options={}'.format(

cmdstanpy/install_cmdstan.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030

3131
from tqdm.auto import tqdm
3232

33-
from cmdstanpy import _DOT_CMDSTAN, _DOT_CMDSTANPY
33+
from cmdstanpy import _DOT_CMDSTAN
3434
from cmdstanpy.utils import (
3535
cmdstan_path,
3636
do_command,
37-
get_logger,
3837
pushd,
3938
validate_dir,
4039
wrap_url_progress_hook,
@@ -465,15 +464,6 @@ def main(args: Dict[str, Any]) -> None:
465464
)
466465

467466
cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN))
468-
if not os.path.exists(cmdstan_dir):
469-
cmdstanpy_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTANPY))
470-
if os.path.exists(cmdstanpy_dir):
471-
cmdstan_dir = cmdstanpy_dir
472-
get_logger().warning(
473-
"Using ~/.cmdstanpy is deprecated and"
474-
" will not be automatically detected in version 1.0!\n"
475-
" Please rename to ~/.cmdstan"
476-
)
477467

478468
install_dir = cmdstan_dir
479469
if args['dir']:

cmdstanpy/install_cxx_toolchain.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
from time import sleep
2424
from typing import Any, Dict, List
2525

26-
from cmdstanpy import _DOT_CMDSTAN, _DOT_CMDSTANPY
26+
from cmdstanpy import _DOT_CMDSTAN
2727
from cmdstanpy.utils import (
28-
get_logger,
2928
pushd,
3029
validate_dir,
3130
wrap_url_progress_hook,
@@ -285,19 +284,7 @@ def main(args: Dict[str, Any]) -> None:
285284

286285
install_dir = args['dir']
287286
if install_dir is None:
288-
cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN))
289-
if not os.path.exists(cmdstan_dir):
290-
cmdstanpy_dir = os.path.expanduser(
291-
os.path.join('~', _DOT_CMDSTANPY)
292-
)
293-
if os.path.exists(cmdstanpy_dir):
294-
cmdstan_dir = cmdstanpy_dir
295-
get_logger().warning(
296-
"Using ~/.cmdstanpy is deprecated and"
297-
" will not be automatically detected in version 1.0!\n"
298-
" Please rename to ~/.cmdstan"
299-
)
300-
install_dir = cmdstan_dir
287+
install_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN))
301288
validate_dir(install_dir)
302289
print('Install directory: {}'.format(install_dir))
303290

cmdstanpy/model.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""CmdStanModel"""
22

33
import io
4-
import logging
54
import os
65
import platform
76
import re
@@ -91,7 +90,6 @@ def __init__(
9190
stanc_options: Optional[Dict[str, Any]] = None,
9291
cpp_options: Optional[Dict[str, Any]] = None,
9392
user_header: Optional[str] = None,
94-
logger: Optional[logging.Logger] = None,
9593
) -> None:
9694
"""
9795
Initialize object given constructor args.
@@ -113,11 +111,6 @@ def __init__(
113111
cpp_options=cpp_options,
114112
user_header=user_header,
115113
)
116-
if logger is not None:
117-
get_logger().warning(
118-
"Parameter 'logger' is deprecated."
119-
" Control logging behavior via logging.getLogger('cmdstanpy')"
120-
)
121114

122115
if model_name is not None:
123116
if not model_name.strip():
@@ -1181,6 +1174,7 @@ def variational(
11811174
:param iter: Maximum number of ADVI iterations.
11821175
11831176
:param grad_samples: Number of MC draws for computing the gradient.
1177+
Default is 10. If problems arise, try doubling current value.
11841178
11851179
:param elbo_samples: Number of MC draws for estimate of ELBO.
11861180
@@ -1247,14 +1241,10 @@ def variational(
12471241

12481242
# treat failure to converge as failure
12491243
transcript_file = runset.stdout_files[dummy_chain_id]
1250-
valid = True
12511244
pat = re.compile(r'The algorithm may not have converged.', re.M)
12521245
with open(transcript_file, 'r') as transcript:
12531246
contents = transcript.read()
1254-
errors = re.findall(pat, contents)
1255-
if len(errors) > 0:
1256-
valid = False
1257-
if not valid:
1247+
if len(re.findall(pat, contents)) > 0:
12581248
if require_converged:
12591249
raise RuntimeError(
12601250
'The algorithm may not have converged.\n'
@@ -1268,12 +1258,25 @@ def variational(
12681258
'Proceeding because require_converged is set to False',
12691259
)
12701260
if not runset._check_retcodes():
1271-
msg = 'Error during variational inference:\n{}'.format(
1272-
runset.get_err_msgs()
1273-
)
1274-
msg = '{}Command and output files:\n{}'.format(
1275-
msg, runset.__repr__()
1261+
transcript_file = runset.stdout_files[dummy_chain_id]
1262+
with open(transcript_file, 'r') as transcript:
1263+
contents = transcript.read()
1264+
pat = re.compile(
1265+
r'stan::variational::normal_meanfield::calc_grad:', re.M
12761266
)
1267+
if len(re.findall(pat, contents)) > 0:
1268+
if grad_samples is None:
1269+
grad_samples = 10
1270+
msg = (
1271+
'Variational algorithm gradient calculation failed. '
1272+
'Double the value of argument "grad_samples", '
1273+
'current value is {}.'.format(grad_samples)
1274+
)
1275+
else:
1276+
msg = (
1277+
'Variational algorithm failed.\n '
1278+
'Console output:\n{}'.format(contents)
1279+
)
12771280
raise RuntimeError(msg)
12781281
# pylint: disable=invalid-name
12791282
vb = CmdStanVB(runset)

0 commit comments

Comments
 (0)