Skip to content

Commit 7c8b0b5

Browse files
committed
Merge branch 'develop' of https://github.com/stan-dev/cmdstanpy into develop
2 parents fdcf1d3 + 39ee446 commit 7c8b0b5

16 files changed

Lines changed: 308 additions & 63 deletions

.pylintrc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ confidence=
6060
# --enable=similarities". If you want to run only the classes checker, but have
6161
# no Warning level messages displayed, use "--disable=all --enable=classes
6262
# --disable=W".
63-
disable=bad-continuation,
64-
consider-using-in,
63+
disable=consider-using-in,
6564
cyclic-import,
6665
fixme,
6766
import-outside-toplevel,
@@ -267,13 +266,6 @@ max-line-length=100
267266
# Maximum number of lines in a module.
268267
max-module-lines=5000
269268

270-
# List of optional constructs for which whitespace checking is disabled. `dict-
271-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
272-
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
273-
# `empty-line` allows space-only lines.
274-
no-space-check=trailing-comma,
275-
dict-separator
276-
277269
# Allow the body of a class to be on the same line as the declaration if body
278270
# contains single statement.
279271
single-line-class-stmt=no

cmdstanpy/model.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def sample(
11501150
sys.stdout.write('\n')
11511151
get_logger().info('CmdStan done processing.')
11521152

1153-
get_logger().debug('runset\n%s', runset.__repr__())
1153+
get_logger().debug('runset\n%s', repr(runset))
11541154

11551155
# hack needed to parse CSV files if model has no params
11561156
# needed if exe is supplied without stan file
@@ -1176,14 +1176,21 @@ def sample(
11761176
)
11771177

11781178
errors = runset.get_err_msgs()
1179-
if errors or not runset._check_retcodes():
1179+
if not runset._check_retcodes():
11801180
msg = (
11811181
f'Error during sampling:\n{errors}\n'
11821182
+ f'Command and output files:\n{repr(runset)}\n'
11831183
+ 'Consider re-running with show_console=True if the above'
11841184
+ ' output is unclear!'
11851185
)
11861186
raise RuntimeError(msg)
1187+
if errors:
1188+
msg = (
1189+
f'Non-fatal error during sampling:\n{errors}\n'
1190+
+ 'Consider re-running with show_console=True if the above'
1191+
+ ' output is unclear!'
1192+
)
1193+
get_logger().warning(msg)
11871194

11881195
mcmc = CmdStanMCMC(runset)
11891196
return mcmc
@@ -1525,7 +1532,6 @@ def variational(
15251532
vb = CmdStanVB(runset)
15261533
return vb
15271534

1528-
# pylint: disable=no-self-use
15291535
def _run_cmdstan(
15301536
self,
15311537
runset: RunSet,

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 = (

cmdstanpy/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ def get_latest_cmdstan(cmdstan_dir: str) -> Optional[str]:
132132
# unmunge as needed
133133
mmp = latest.split('.')
134134
if int(mmp[2]) < 0:
135-
print("here")
136135
rc_num = str(int(mmp[2]) + 100)
137136
mmp[2] = "0-rc" + rc_num
138137
latest = '.'.join(mmp)

docsrc/installation.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ The CmdStanPy commands ``cmdstan_path`` and ``set_cmdstan_path``
173173
get and set this environment variable:
174174

175175
.. code-block:: python
176-
176+
177+
import os
177178
from cmdstanpy import cmdstan_path, set_cmdstan_path
178179
179180
oldpath = cmdstan_path()

test/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def assertRaisesRegexNested(self, exc, msg):
2424
exn_string += "\n" + str(exception)
2525
self.assertRegex(exn_string, msg)
2626

27-
# pylint: disable=no-self-use
2827
@contextlib.contextmanager
2928
def without_import(self, library, module):
3029
with unittest.mock.patch.dict('sys.modules', {library: None}):
@@ -33,7 +32,6 @@ def without_import(self, library, module):
3332
reload(module)
3433

3534
# recipe from https://stackoverflow.com/a/34333710
36-
# pylint: disable=no-self-use
3735
@contextlib.contextmanager
3836
def modified_environ(self, *remove, **update):
3937
"""
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"x": [
3+
-0.7138385321976433,
4+
0.4935568322412949,
5+
-1.3814289386914758,
6+
-1.3083830490780055,
7+
0.8594237856855641,
8+
-0.5828201693491124,
9+
0.41472726513726604,
10+
-1.3096088915626156,
11+
1.7488214394544888,
12+
-0.05582078688738188,
13+
-1.3353224485998705,
14+
-1.7564315946342453,
15+
0.48308013370199504,
16+
0.5172253170304838,
17+
-0.6719992453398311,
18+
1.2602689891739454,
19+
1.412043997788473,
20+
0.20641523053812474,
21+
0.5201078975322044,
22+
1.5723251985671267,
23+
1.3189655696099178,
24+
-0.9111971580521261,
25+
0.6393467227482712,
26+
0.4650415534005901,
27+
-0.5452984948053263,
28+
-1.5130216352610142,
29+
-0.22862960142670605,
30+
0.6160324741955371,
31+
-0.6031016074719313,
32+
0.40594275421437453,
33+
0.38508886717718016,
34+
-1.0837724674547375,
35+
2.3915682063493477,
36+
-0.07839179990381143,
37+
0.35656973307438666,
38+
-0.2766314484210899,
39+
0.7302456204684461,
40+
0.08565219038050095,
41+
1.445060390202212,
42+
-0.21089429382395108,
43+
-0.004354007671109179,
44+
1.4964952578881543,
45+
-1.2377789502217904,
46+
1.1630189497108676,
47+
0.1868059860973441,
48+
1.0013767320556666,
49+
0.17712191472558358,
50+
2.2449838737047405,
51+
0.5723783157495013,
52+
-0.5866656693806949,
53+
0.5553141820829578,
54+
-1.0832025825922065,
55+
0.021397186668024173,
56+
1.0990490407588707,
57+
-0.47857707758054946,
58+
-1.0028128626128172,
59+
-0.6541883777415636,
60+
-2.157420733621822,
61+
1.6494513567711457,
62+
0.5326574665837476,
63+
-1.2488626570176349,
64+
1.8640634506194615,
65+
-2.0015397292660646,
66+
-1.165907209784441,
67+
1.243275871223251,
68+
1.2777634989564302,
69+
-0.2540735659288359,
70+
-0.7115336394378458,
71+
2.5123445378647937,
72+
-2.3620686383068192,
73+
0.704711924978527,
74+
0.20486730052438465,
75+
-1.1481828167175874,
76+
-0.5024671222986463,
77+
1.1909459096186445,
78+
-1.807532371463237,
79+
1.5452345378964871,
80+
0.9386793566797123,
81+
0.06108017364184471,
82+
0.44078590430668,
83+
1.5390990507903806,
84+
-0.14982494315528966,
85+
0.008041862641953225,
86+
-1.059362371600711,
87+
-0.6458557072831949,
88+
0.12174558659406327,
89+
1.6343750745549894,
90+
-0.006893657965902042,
91+
-1.980063711207591,
92+
-0.17769336879869058,
93+
-0.04671777679973899,
94+
1.4532456591905836,
95+
-1.4029866194860872,
96+
-1.5024900502317675,
97+
1.4402148888890611,
98+
-1.0727333689589642,
99+
-0.6228552056768534,
100+
0.3715735241216498,
101+
-0.0371718458010515,
102+
0.5704601721659295
103+
],
104+
"y": [
105+
0.6272150230712336,
106+
0.9805824577664779,
107+
0.3422690552470167,
108+
-0.05146489851488395,
109+
0.9046913839133488,
110+
0.6925433494574392,
111+
0.8699413738367437,
112+
0.640327008582535,
113+
0.39187605728779296,
114+
0.21904955777565455,
115+
0.3614380235604899,
116+
-0.25588465129027244,
117+
0.291608586376539,
118+
-0.12437104481728656,
119+
0.39699986298775203,
120+
1.091844069641923,
121+
1.0625362033977446,
122+
1.1487142324952053,
123+
0.6499370411907814,
124+
0.7847133816156049,
125+
0.949209681430482,
126+
0.15135972083512655,
127+
0.6742472860252764,
128+
0.5405321316929282,
129+
0.7549499219120746,
130+
0.16511085413710583,
131+
-0.02498036164663142,
132+
0.6153043951506284,
133+
0.6000720457920419,
134+
1.3480303063520085,
135+
0.3158006969256599,
136+
0.3637296025891455,
137+
1.1594053723296478,
138+
0.5970385913046845,
139+
0.5946450550774676,
140+
0.8203529738679207,
141+
1.3062075618596822,
142+
0.9328024321713398,
143+
0.7743457946449005,
144+
0.3251962426760894,
145+
0.6054087282349804,
146+
0.7934998350966271,
147+
0.8831208411206976,
148+
0.7894760893728714,
149+
0.8976865289354727,
150+
0.44217549478023965,
151+
0.38284855187218103,
152+
1.095780907185152,
153+
0.6549679342197391,
154+
0.23387184425362467,
155+
0.6049693148613544,
156+
0.4028784177001803,
157+
0.6250343428214425,
158+
0.567319927379435,
159+
0.5189952397494277,
160+
0.4671091755131367,
161+
0.748868640987746,
162+
0.29251932173366013,
163+
0.8245978901245103,
164+
0.673071240496385,
165+
0.775559253840947,
166+
0.9595878211742477,
167+
0.05153108078358959,
168+
0.6958343543502022,
169+
1.2920074084872448,
170+
0.936543215882786,
171+
-0.17826337795252567,
172+
0.7061739968427398,
173+
1.4127238083350044,
174+
0.4014500370341516,
175+
0.792652667869967,
176+
0.3352243339909373,
177+
0.4509809274388745,
178+
0.6568885296125428,
179+
0.6184394273698025,
180+
0.18864416763201924,
181+
1.0875801300709682,
182+
0.9177333084623992,
183+
0.5919873026862967,
184+
0.9297749171130603,
185+
0.814520099852734,
186+
0.8465674480525497,
187+
0.028620564426356743,
188+
0.2639034807770741,
189+
0.9495620232603935,
190+
0.4000550997372736,
191+
0.7506260736682799,
192+
0.8257633294514362,
193+
0.1294350823440999,
194+
0.9276942903866539,
195+
0.8068646299718158,
196+
0.7626459434600884,
197+
0.4057250786938288,
198+
0.6216165062482524,
199+
0.9989570513537478,
200+
0.12153467332478934,
201+
0.9175681261236525,
202+
0.5831590468381432,
203+
0.6800265152948471,
204+
1.0027971008115968
205+
],
206+
"N": 100
207+
}

test/data/linear_regression.stan

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
data {
2+
int<lower=0> N;
3+
vector[N] x;
4+
vector[N] y;
5+
}
6+
parameters {
7+
real alpha;
8+
real beta;
9+
real<lower=0> sigma;
10+
}
11+
model {
12+
y ~ normal(alpha + beta * x, sigma);
13+
}

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_compiler_opts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Compiler options tests"""
22

3+
import logging
34
import os
45
import unittest
5-
import logging
66

77
from testfixtures import LogCapture
88

@@ -33,7 +33,7 @@ def test_opts_empty(self):
3333
opts = CompilerOptions()
3434
opts.validate()
3535
self.assertEqual(opts.compose(), [])
36-
self.assertEqual(opts.__repr__(), 'stanc_options={}, cpp_options={}')
36+
self.assertEqual(repr(opts), 'stanc_options={}, cpp_options={}')
3737

3838
stanc_opts = {}
3939
opts = CompilerOptions(stanc_options=stanc_opts)
@@ -48,7 +48,7 @@ def test_opts_empty(self):
4848
opts = CompilerOptions(stanc_options=stanc_opts, cpp_options=cpp_opts)
4949
opts.validate()
5050
self.assertEqual(opts.compose(), [])
51-
self.assertEqual(opts.__repr__(), 'stanc_options={}, cpp_options={}')
51+
self.assertEqual(repr(opts), 'stanc_options={}, cpp_options={}')
5252

5353
def test_opts_stanc(self):
5454
stanc_opts = {}

0 commit comments

Comments
 (0)