cmdstanpy 1.2.2__tar.gz → 1.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. {cmdstanpy-1.2.2/cmdstanpy.egg-info → cmdstanpy-1.2.4}/PKG-INFO +1 -1
  2. cmdstanpy-1.2.4/cmdstanpy/_version.py +3 -0
  3. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/install_cmdstan.py +2 -0
  4. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/install_cxx_toolchain.py +4 -0
  5. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/pathfinder.py +4 -2
  6. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/runset.py +10 -10
  7. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/stancsv.py +8 -2
  8. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4/cmdstanpy.egg-info}/PKG-INFO +1 -1
  9. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_optimize.py +5 -4
  10. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_sample.py +31 -8
  11. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_variational.py +9 -4
  12. cmdstanpy-1.2.2/cmdstanpy/_version.py +0 -3
  13. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/LICENSE.md +0 -0
  14. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/MANIFEST.in +0 -0
  15. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/README.md +0 -0
  16. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/__init__.py +0 -0
  17. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/cmdstan_args.py +0 -0
  18. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/compilation.py +0 -0
  19. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/model.py +0 -0
  20. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/progress.py +0 -0
  21. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/py.typed +0 -0
  22. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/__init__.py +0 -0
  23. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/gq.py +0 -0
  24. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/laplace.py +0 -0
  25. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/mcmc.py +0 -0
  26. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/metadata.py +0 -0
  27. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/mle.py +0 -0
  28. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/stanfit/vb.py +0 -0
  29. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/__init__.py +0 -0
  30. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/cmdstan.py +0 -0
  31. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/command.py +0 -0
  32. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/data_munging.py +0 -0
  33. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/filesystem.py +0 -0
  34. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/json.py +0 -0
  35. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy/utils/logging.py +0 -0
  36. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy.egg-info/SOURCES.txt +0 -0
  37. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy.egg-info/dependency_links.txt +0 -0
  38. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy.egg-info/entry_points.txt +0 -0
  39. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy.egg-info/requires.txt +0 -0
  40. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/cmdstanpy.egg-info/top_level.txt +0 -0
  41. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/pyproject.toml +0 -0
  42. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/setup.cfg +0 -0
  43. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_cmdstan_args.py +0 -0
  44. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_compiler_opts.py +0 -0
  45. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_compliance.py +0 -0
  46. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_cxx_installation.py +0 -0
  47. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_generate_quantities.py +0 -0
  48. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_install_cmdstan.py +0 -0
  49. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_laplace.py +0 -0
  50. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_log_prob.py +0 -0
  51. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_metadata.py +0 -0
  52. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_model.py +0 -0
  53. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_pathfinder.py +0 -0
  54. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_runset.py +0 -0
  55. {cmdstanpy-1.2.2 → cmdstanpy-1.2.4}/test/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cmdstanpy
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Python interface to CmdStan
5
5
  Author: Stan Dev Team
6
6
  License: BSD-3-Clause
@@ -0,0 +1,3 @@
1
+ """PyPi Version"""
2
+
3
+ __version__ = '1.2.4'
@@ -523,6 +523,8 @@ def retrieve_version(version: str, progress: bool = True) -> None:
523
523
  first = tar.next()
524
524
  if first is not None:
525
525
  top_dir = first.name
526
+ else:
527
+ top_dir = ''
526
528
  cmdstan_dir = f'cmdstan-{version}'
527
529
  if top_dir != cmdstan_dir:
528
530
  raise CmdStanInstallError(
@@ -235,8 +235,10 @@ def get_toolchain_name() -> str:
235
235
  return ''
236
236
 
237
237
 
238
+ # TODO(2.0): drop 3.5 support
238
239
  def get_url(version: str) -> str:
239
240
  """Return URL for toolchain."""
241
+ url = ''
240
242
  if platform.system() == 'Windows':
241
243
  if version == '4.0':
242
244
  # pylint: disable=line-too-long
@@ -277,6 +279,8 @@ def run_rtools_install(args: Dict[str, Any]) -> None:
277
279
 
278
280
  if 'verbose' in args:
279
281
  verbose = args['verbose']
282
+ else:
283
+ verbose = False
280
284
 
281
285
  install_dir = args['dir']
282
286
  if install_dir is None:
@@ -214,8 +214,10 @@ class CmdStanPathfinder:
214
214
  """
215
215
  return ( # type: ignore
216
216
  self._metadata.cmdstan_config.get("num_paths", 4) > 1
217
- and self._metadata.cmdstan_config.get('psis_resample', 1) == 1
218
- and self._metadata.cmdstan_config.get('calculate_lp', 1) == 1
217
+ and self._metadata.cmdstan_config.get('psis_resample', 1)
218
+ in (1, 'true')
219
+ and self._metadata.cmdstan_config.get('calculate_lp', 1)
220
+ in (1, 'true')
219
221
  )
220
222
 
221
223
  def save_csvfiles(self, dir: Optional[str] = None) -> None:
@@ -61,18 +61,26 @@ class RunSet:
61
61
  self._base_outfile = (
62
62
  f'{args.model_name}-{datetime.now().strftime(time_fmt)}'
63
63
  )
64
- # per-process console messages
64
+ # per-process outputs
65
65
  self._stdout_files = [''] * self._num_procs
66
+ self._profile_files = [''] * self._num_procs # optional
66
67
  if one_process_per_chain:
67
68
  for i in range(chains):
68
69
  self._stdout_files[i] = self.file_path("-stdout.txt", id=i)
70
+ if args.save_profile:
71
+ self._profile_files[i] = self.file_path(
72
+ ".csv", extra="-profile", id=chain_ids[i]
73
+ )
69
74
  else:
70
75
  self._stdout_files[0] = self.file_path("-stdout.txt")
76
+ if args.save_profile:
77
+ self._profile_files[0] = self.file_path(
78
+ ".csv", extra="-profile"
79
+ )
71
80
 
72
81
  # per-chain output files
73
82
  self._csv_files: List[str] = [''] * chains
74
83
  self._diagnostic_files = [''] * chains # optional
75
- self._profile_files = [''] * chains # optional
76
84
 
77
85
  if chains == 1:
78
86
  self._csv_files[0] = self.file_path(".csv")
@@ -80,10 +88,6 @@ class RunSet:
80
88
  self._diagnostic_files[0] = self.file_path(
81
89
  ".csv", extra="-diagnostic"
82
90
  )
83
- if args.save_profile:
84
- self._profile_files[0] = self.file_path(
85
- ".csv", extra="-profile"
86
- )
87
91
  else:
88
92
  for i in range(chains):
89
93
  self._csv_files[i] = self.file_path(".csv", id=chain_ids[i])
@@ -91,10 +95,6 @@ class RunSet:
91
95
  self._diagnostic_files[i] = self.file_path(
92
96
  ".csv", extra="-diagnostic", id=chain_ids[i]
93
97
  )
94
- if args.save_profile:
95
- self._profile_files[i] = self.file_path(
96
- ".csv", extra="-profile", id=chain_ids[i]
97
- )
98
98
 
99
99
  def __repr__(self) -> str:
100
100
  repr = 'RunSet: chains={}, chain_ids={}, num_processes={}'.format(
@@ -52,7 +52,7 @@ def check_sampler_csv(
52
52
  )
53
53
  )
54
54
  if save_warmup:
55
- if not ('save_warmup' in meta and meta['save_warmup'] == 1):
55
+ if not ('save_warmup' in meta and meta['save_warmup'] in (1, 'true')):
56
56
  raise ValueError(
57
57
  'bad Stan CSV file {}, '
58
58
  'config error, expected save_warmup = 1'.format(path)
@@ -116,6 +116,7 @@ def scan_optimize_csv(path: str, save_iters: bool = False) -> Dict[str, Any]:
116
116
  all_iters[i, :] = [float(x) for x in xs]
117
117
  if i == iters - 1:
118
118
  mle: np.ndarray = np.array(xs, dtype=float)
119
+ # pylint: disable=possibly-used-before-assignment
119
120
  dict['mle'] = mle
120
121
  if save_iters:
121
122
  dict['all_iters'] = all_iters
@@ -192,7 +193,12 @@ def scan_config(fd: TextIO, config_dict: Dict[str, Any], lineno: int) -> int:
192
193
  try:
193
194
  val = float(raw_val)
194
195
  except ValueError:
195
- val = raw_val
196
+ if raw_val == "true":
197
+ val = 1
198
+ elif raw_val == "false":
199
+ val = 0
200
+ else:
201
+ val = raw_val
196
202
  config_dict[key_val[0].strip()] = val
197
203
  cur_pos = fd.tell()
198
204
  line = fd.readline().strip()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cmdstanpy
3
- Version: 1.2.2
3
+ Version: 1.2.4
4
4
  Summary: Python interface to CmdStan
5
5
  Author: Stan Dev Team
6
6
  License: BSD-3-Clause
@@ -262,12 +262,13 @@ def test_variables_3d() -> None:
262
262
  )
263
263
  vars_iters = multidim_mle_iters.stan_variables(inc_iterations=True)
264
264
  assert len(vars_iters) == len(multidim_mle_iters.metadata.stan_vars)
265
+ assert 'frac_60' in vars_iters
266
+ n_iter = vars_iters['frac_60'].shape[0]
267
+ assert n_iter > 1
265
268
  assert 'y_rep' in vars_iters
266
- assert vars_iters['y_rep'].shape == (8, 5, 4, 3)
269
+ assert vars_iters['y_rep'].shape == (n_iter, 5, 4, 3)
267
270
  assert 'beta' in vars_iters
268
- assert vars_iters['beta'].shape == (8, 2)
269
- assert 'frac_60' in vars_iters
270
- assert vars_iters['frac_60'].shape == (8,)
271
+ assert vars_iters['beta'].shape == (n_iter, 2)
271
272
 
272
273
 
273
274
  def test_optimize_good() -> None:
@@ -1748,33 +1748,36 @@ def test_save_latent_dynamics() -> None:
1748
1748
 
1749
1749
  def test_save_profile() -> None:
1750
1750
  stan = os.path.join(DATAFILES_PATH, 'profile_likelihood.stan')
1751
- profile_model = CmdStanModel(stan_file=stan)
1751
+ profile_model = CmdStanModel(
1752
+ stan_file=stan, cpp_options={"STAN_THREADS": '1'}, force_compile=True
1753
+ )
1754
+
1752
1755
  profile_fit = profile_model.sample(
1753
1756
  chains=2,
1754
1757
  parallel_chains=2,
1758
+ force_one_process_per_chain=True,
1755
1759
  seed=12345,
1756
1760
  iter_warmup=100,
1757
1761
  iter_sampling=200,
1758
1762
  save_profile=True,
1759
1763
  )
1760
- for i in range(profile_fit.runset.chains):
1761
- profile_file = profile_fit.runset.profile_files[i]
1764
+ assert len(profile_fit.runset.profile_files) == 2
1765
+ for profile_file in profile_fit.runset.profile_files:
1762
1766
  assert os.path.exists(profile_file)
1763
1767
 
1764
1768
  profile_fit = profile_model.sample(
1765
1769
  chains=2,
1766
1770
  parallel_chains=2,
1771
+ force_one_process_per_chain=False,
1767
1772
  seed=12345,
1773
+ iter_warmup=100,
1768
1774
  iter_sampling=200,
1769
- save_latent_dynamics=True,
1770
1775
  save_profile=True,
1771
1776
  )
1772
1777
 
1773
- for i in range(profile_fit.runset.chains):
1774
- profile_file = profile_fit.runset.profile_files[i]
1778
+ assert len(profile_fit.runset.profile_files) == 1
1779
+ for profile_file in profile_fit.runset.profile_files:
1775
1780
  assert os.path.exists(profile_file)
1776
- diagnostics_file = profile_fit.runset.diagnostic_files[i]
1777
- assert os.path.exists(diagnostics_file)
1778
1781
 
1779
1782
 
1780
1783
  def test_xarray_draws() -> None:
@@ -2027,6 +2030,26 @@ def test_tuple_data_in() -> None:
2027
2030
  data_model.sample(data, chains=1, iter_warmup=1, iter_sampling=1)
2028
2031
 
2029
2032
 
2033
+ def test_csv_roundtrip():
2034
+ stan = os.path.join(DATAFILES_PATH, 'matrix_var.stan')
2035
+ model = CmdStanModel(stan_file=stan)
2036
+ fit = model.sample(
2037
+ iter_sampling=10, iter_warmup=9, chains=2, save_warmup=True
2038
+ )
2039
+ z = fit.stan_variable(var="z")
2040
+ assert z.shape == (20, 4, 3)
2041
+ z_with_warmup = fit.stan_variable(var="z", inc_warmup=True)
2042
+ assert z_with_warmup.shape == (38, 4, 3)
2043
+
2044
+ # mostly just asserting that from_csv always succeeds
2045
+ # in parsing latest cmdstan headers
2046
+ fit_from_csv = from_csv(fit.runset.csv_files)
2047
+ z_from_csv = fit_from_csv.stan_variable(var="z")
2048
+ assert z_from_csv.shape == (20, 4, 3)
2049
+ z_with_warmup_from_csv = fit.stan_variable(var="z", inc_warmup=True)
2050
+ assert z_with_warmup_from_csv.shape == (38, 4, 3)
2051
+
2052
+
2030
2053
  @pytest.mark.order(before="test_no_xarray")
2031
2054
  def test_serialization(stanfile='bernoulli.stan'):
2032
2055
  # This test must before any test that uses the `without_import` context
@@ -15,6 +15,7 @@ import pytest
15
15
  from cmdstanpy.cmdstan_args import CmdStanArgs, VariationalArgs
16
16
  from cmdstanpy.model import CmdStanModel
17
17
  from cmdstanpy.stanfit import CmdStanVB, RunSet, from_csv
18
+ from cmdstanpy.utils.cmdstan import cmdstan_version_before
18
19
 
19
20
  HERE = os.path.dirname(os.path.abspath(__file__))
20
21
  DATAFILES_PATH = os.path.join(HERE, 'data')
@@ -150,12 +151,12 @@ def test_variational_good() -> None:
150
151
  'mu[2]',
151
152
  )
152
153
  # fixed seed, id=1 by default will give known output values
153
- assert variational.eta == 100
154
+ assert variational.eta == 10
154
155
  np.testing.assert_almost_equal(
155
- variational.variational_params_dict['mu[1]'], 311.545, decimal=2
156
+ variational.variational_params_dict['mu[1]'], 302.142, decimal=2
156
157
  )
157
158
  np.testing.assert_almost_equal(
158
- variational.variational_params_dict['mu[2]'], 532.801, decimal=2
159
+ variational.variational_params_dict['mu[2]'], 361.005, decimal=2
159
160
  )
160
161
  np.testing.assert_almost_equal(
161
162
  variational.variational_params_np[0],
@@ -177,7 +178,11 @@ def test_variational_eta_small() -> None:
177
178
  DATAFILES_PATH, 'variational', 'eta_should_be_small.stan'
178
179
  )
179
180
  model = CmdStanModel(stan_file=stan)
180
- variational = model.variational(algorithm='meanfield', seed=12345)
181
+ if cmdstan_version_before(2, 35):
182
+ seed = 12345
183
+ else:
184
+ seed = 1234
185
+ variational = model.variational(algorithm='meanfield', seed=seed)
181
186
  assert variational.column_names == (
182
187
  'lp__',
183
188
  'log_p__',
@@ -1,3 +0,0 @@
1
- """PyPi Version"""
2
-
3
- __version__ = '1.2.2'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes