cmdstanpy 1.3.0__tar.gz → 1.3.1__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 (59) hide show
  1. {cmdstanpy-1.3.0/cmdstanpy.egg-info → cmdstanpy-1.3.1}/PKG-INFO +3 -3
  2. cmdstanpy-1.3.1/cmdstanpy/_version.py +3 -0
  3. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/cmdstan_args.py +3 -7
  4. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/compilation.py +19 -82
  5. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/install_cxx_toolchain.py +5 -7
  6. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/model.py +76 -219
  7. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/progress.py +1 -2
  8. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/gq.py +1 -1
  9. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/laplace.py +2 -1
  10. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/mcmc.py +2 -1
  11. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/runset.py +18 -12
  12. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/__init__.py +3 -5
  13. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/cmdstan.py +4 -3
  14. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/data_munging.py +2 -1
  15. cmdstanpy-1.3.1/cmdstanpy/utils/deprecation.py +58 -0
  16. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1/cmdstanpy.egg-info}/PKG-INFO +3 -3
  17. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy.egg-info/SOURCES.txt +2 -0
  18. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy.egg-info/requires.txt +2 -2
  19. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/pyproject.toml +2 -2
  20. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_compiler_opts.py +0 -106
  21. cmdstanpy-1.3.1/test/test_deprecations.py +140 -0
  22. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_generate_quantities.py +4 -4
  23. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_logging.py +1 -0
  24. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_model.py +69 -144
  25. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_optimize.py +13 -13
  26. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_sample.py +3 -5
  27. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_utils.py +0 -1
  28. cmdstanpy-1.3.0/cmdstanpy/_version.py +0 -3
  29. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/LICENSE.md +0 -0
  30. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/MANIFEST.in +0 -0
  31. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/README.md +0 -0
  32. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/__init__.py +0 -0
  33. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/install_cmdstan.py +0 -0
  34. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/py.typed +0 -0
  35. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/__init__.py +0 -0
  36. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/metadata.py +0 -0
  37. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/mle.py +0 -0
  38. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/pathfinder.py +0 -0
  39. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/stanfit/vb.py +0 -0
  40. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/command.py +0 -0
  41. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/filesystem.py +0 -0
  42. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/json.py +0 -0
  43. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/logging.py +0 -0
  44. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy/utils/stancsv.py +0 -0
  45. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy.egg-info/dependency_links.txt +0 -0
  46. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy.egg-info/entry_points.txt +0 -0
  47. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/cmdstanpy.egg-info/top_level.txt +0 -0
  48. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/setup.cfg +0 -0
  49. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_cmdstan_args.py +0 -0
  50. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_compliance.py +0 -0
  51. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_cxx_installation.py +0 -0
  52. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_install_cmdstan.py +0 -0
  53. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_laplace.py +0 -0
  54. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_log_prob.py +0 -0
  55. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_metadata.py +0 -0
  56. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_pathfinder.py +0 -0
  57. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_runset.py +0 -0
  58. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_stancsv.py +0 -0
  59. {cmdstanpy-1.3.0 → cmdstanpy-1.3.1}/test/test_variational.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cmdstanpy
3
- Version: 1.3.0
3
+ Version: 1.3.1
4
4
  Summary: Python interface to CmdStan
5
5
  Author: Stan Dev Team
6
6
  License: BSD-3-Clause
@@ -34,8 +34,8 @@ Requires-Dist: mypy; extra == "test"
34
34
  Requires-Dist: xarray; extra == "test"
35
35
  Requires-Dist: polars>=1.8.2; extra == "test"
36
36
  Provides-Extra: docs
37
- Requires-Dist: sphinx<6,>5; extra == "docs"
38
- Requires-Dist: pydata-sphinx-theme<0.9; extra == "docs"
37
+ Requires-Dist: sphinx<9; extra == "docs"
38
+ Requires-Dist: pydata-sphinx-theme<0.17; extra == "docs"
39
39
  Requires-Dist: nbsphinx; extra == "docs"
40
40
  Requires-Dist: ipython; extra == "docs"
41
41
  Requires-Dist: ipykernel<7; extra == "docs"
@@ -0,0 +1,3 @@
1
+ """PyPi Version"""
2
+
3
+ __version__ = '1.3.1'
@@ -632,7 +632,7 @@ class CmdStanArgs:
632
632
  def __init__(
633
633
  self,
634
634
  model_name: str,
635
- model_exe: OptionalPath,
635
+ model_exe: str,
636
636
  chain_ids: Optional[list[int]],
637
637
  method_args: Union[
638
638
  SamplerArgs,
@@ -692,10 +692,6 @@ class CmdStanArgs:
692
692
  * if no seed specified, set random seed.
693
693
  * length of per-chain lists equals specified # of chains
694
694
  """
695
- if self.model_name is None:
696
- raise ValueError('no stan model specified')
697
- if self.model_exe is None:
698
- raise ValueError('model not compiled')
699
695
 
700
696
  if self.chain_ids is not None:
701
697
  for chain_id in self.chain_ids:
@@ -857,10 +853,10 @@ class CmdStanArgs:
857
853
  idx, len(self.chain_ids)
858
854
  )
859
855
  )
860
- cmd.append(self.model_exe) # type: ignore # guaranteed by validate
856
+ cmd.append(self.model_exe)
861
857
  cmd.append(f'id={self.chain_ids[idx]}')
862
858
  else:
863
- cmd.append(self.model_exe) # type: ignore # guaranteed by validate
859
+ cmd.append(self.model_exe)
864
860
 
865
861
  if self.seed is not None:
866
862
  if not isinstance(self.seed, list):
@@ -8,7 +8,6 @@ import os
8
8
  import platform
9
9
  import shutil
10
10
  import subprocess
11
- from copy import copy
12
11
  from datetime import datetime
13
12
  from pathlib import Path
14
13
  from typing import Any, Iterable, Optional, Union
@@ -37,12 +36,6 @@ STANC_OPTS = [
37
36
  'warn-pedantic',
38
37
  ]
39
38
 
40
- # TODO(2.0): remove
41
- STANC_DEPRECATED_OPTS = {
42
- 'allow_undefined': 'allow-undefined',
43
- 'include_paths': 'include-paths',
44
- }
45
-
46
39
  STANC_IGNORE_OPTS = [
47
40
  'debug-lex',
48
41
  'debug-parse',
@@ -67,7 +60,6 @@ STANC_IGNORE_OPTS = [
67
60
  OptionalPath = Union[str, os.PathLike, None]
68
61
 
69
62
 
70
- # TODO(2.0): can remove add function and other logic
71
63
  class CompilerOptions:
72
64
  """
73
65
  User-specified flags for stanc and C++ compiler.
@@ -95,26 +87,6 @@ class CompilerOptions:
95
87
  self._stanc_options, self._cpp_options
96
88
  )
97
89
 
98
- def __eq__(self, other: Any) -> bool:
99
- """Overrides the default implementation"""
100
- if self.is_empty() and other is None: # equiv w/r/t compiler
101
- return True
102
- if not isinstance(other, CompilerOptions):
103
- return False
104
- return (
105
- self._stanc_options == other.stanc_options
106
- and self._cpp_options == other.cpp_options
107
- and self._user_header == other.user_header
108
- )
109
-
110
- def is_empty(self) -> bool:
111
- """True if no options specified."""
112
- return (
113
- self._stanc_options == {}
114
- and self._cpp_options == {}
115
- and self._user_header == ''
116
- )
117
-
118
90
  @property
119
91
  def stanc_options(self) -> dict[str, Union[bool, int, str, Iterable[str]]]:
120
92
  """Stanc compiler options."""
@@ -144,31 +116,12 @@ class CompilerOptions:
144
116
  Check stanc compiler args and consistency between stanc and C++ options.
145
117
  Raise ValueError if bad config is found.
146
118
  """
147
- # pylint: disable=no-member
148
119
  if self._stanc_options is None:
149
120
  return
150
121
  ignore = []
151
122
  paths = None
152
123
  has_o_flag = False
153
124
 
154
- for deprecated, replacement in STANC_DEPRECATED_OPTS.items():
155
- if deprecated in self._stanc_options:
156
- if replacement:
157
- get_logger().warning(
158
- 'compiler option "%s" is deprecated, use "%s" instead',
159
- deprecated,
160
- replacement,
161
- )
162
- self._stanc_options[replacement] = copy(
163
- self._stanc_options[deprecated]
164
- )
165
- del self._stanc_options[deprecated]
166
- else:
167
- get_logger().warning(
168
- 'compiler option "%s" is deprecated and should '
169
- 'not be used',
170
- deprecated,
171
- )
172
125
  for key, val in self._stanc_options.items():
173
126
  if key in STANC_IGNORE_OPTS:
174
127
  get_logger().info('ignoring compiler option: %s', key)
@@ -267,37 +220,6 @@ class CompilerOptions:
267
220
 
268
221
  self._cpp_options['USER_HEADER'] = self._user_header
269
222
 
270
- def add(self, new_opts: "CompilerOptions") -> None: # noqa: disable=Q000
271
- """Adds options to existing set of compiler options."""
272
- if new_opts.stanc_options is not None:
273
- if self._stanc_options is None:
274
- self._stanc_options = new_opts.stanc_options
275
- else:
276
- for key, val in new_opts.stanc_options.items():
277
- if key == 'include-paths':
278
- if isinstance(val, Iterable) and not isinstance(
279
- val, str
280
- ):
281
- for path in val:
282
- self.add_include_path(str(path))
283
- else:
284
- self.add_include_path(str(val))
285
- else:
286
- self._stanc_options[key] = val
287
- if new_opts.cpp_options is not None:
288
- for key, val in new_opts.cpp_options.items():
289
- self._cpp_options[key] = val
290
- if new_opts._user_header != '' and self._user_header == '':
291
- self._user_header = new_opts._user_header
292
-
293
- def add_include_path(self, path: str) -> None:
294
- """Adds include path to existing set of compiler options."""
295
- path = os.path.abspath(os.path.expanduser(path))
296
- if 'include-paths' not in self._stanc_options:
297
- self._stanc_options['include-paths'] = [path]
298
- elif path not in self._stanc_options['include-paths']:
299
- self._stanc_options['include-paths'].append(path)
300
-
301
223
  def compose_stanc(self, filename_in_msg: Optional[str]) -> list[str]:
302
224
  opts = []
303
225
 
@@ -343,7 +265,8 @@ class CompilerOptions:
343
265
 
344
266
 
345
267
  def src_info(
346
- stan_file: str, compiler_options: CompilerOptions
268
+ stan_file: str,
269
+ stanc_options: Optional[dict[str, Any]] = None,
347
270
  ) -> dict[str, Any]:
348
271
  """
349
272
  Get source info for Stan program file.
@@ -354,7 +277,7 @@ def src_info(
354
277
  cmd = (
355
278
  [stanc_path()]
356
279
  # handle include-paths, allow-undefined etc
357
- + compiler_options.compose_stanc(None)
280
+ + CompilerOptions(stanc_options=stanc_options).compose_stanc(None)
358
281
  + ['--info', str(stan_file)]
359
282
  )
360
283
  proc = subprocess.run(cmd, capture_output=True, text=True, check=False)
@@ -407,12 +330,26 @@ def compile_stan_file(
407
330
  )
408
331
  compiler_options.validate()
409
332
 
333
+ # if program has include directives, record path
334
+ if '#include' in src.read_text():
335
+ path = os.fspath(src.parent.resolve())
336
+ if 'include-paths' not in compiler_options.stanc_options:
337
+ compiler_options.stanc_options['include-paths'] = [path]
338
+ else:
339
+ paths: list[str] = compiler_options.stanc_options[
340
+ 'include-paths'
341
+ ] # type: ignore
342
+ if path not in paths:
343
+ paths.append(path)
344
+
410
345
  exe_target = src.with_suffix(EXTENSION)
411
346
  if exe_target.exists():
412
347
  exe_time = os.path.getmtime(exe_target)
413
348
  included_files = [src]
414
349
  included_files.extend(
415
- src_info(str(src), compiler_options).get('included_files', [])
350
+ src_info(str(src), compiler_options.stanc_options).get(
351
+ 'included_files', []
352
+ )
416
353
  )
417
354
  out_of_date = any(
418
355
  os.path.getmtime(included_file) > exe_time
@@ -482,7 +419,7 @@ def compile_stan_file(
482
419
  raise ValueError(
483
420
  f"Failed to compile Stan model '{src}'. Console:\n{console}"
484
421
  )
485
- return str(exe_target)
422
+ return os.fspath(exe_target)
486
423
 
487
424
 
488
425
  def format_stan_file(
@@ -33,16 +33,14 @@ IS_64BITS = sys.maxsize > 2**32
33
33
 
34
34
  def usage() -> None:
35
35
  """Print usage."""
36
- print(
37
- """Arguments:
36
+ print("""Arguments:
38
37
  -v (--version) :CmdStan version
39
38
  -d (--dir) : install directory
40
39
  -s (--silent) : install with /VERYSILENT instead of /SILENT for RTools
41
40
  -m (--no-make) : don't install mingw32-make (Windows RTools 4.0 only)
42
41
  --progress : flag, when specified show progress bar for RTools download
43
42
  -h (--help) : this message
44
- """
45
- )
43
+ """)
46
44
 
47
45
 
48
46
  def get_config(dir: str, silent: bool) -> list[str]:
@@ -244,11 +242,11 @@ def get_url(version: str) -> str:
244
242
  if version == '4.0':
245
243
  # pylint: disable=line-too-long
246
244
  if IS_64BITS:
247
- url = 'https://cran.r-project.org/bin/windows/Rtools/rtools40-x86_64.exe' # noqa: disable=E501
245
+ url = 'https://cran-archive.r-project.org/bin/windows/Rtools/rtools40-x86_64.exe' # noqa: disable=E501
248
246
  else:
249
- url = 'https://cran.r-project.org/bin/windows/Rtools/rtools40-i686.exe' # noqa: disable=E501
247
+ url = 'https://cran-archive.r-project.org/bin/windows/Rtools/rtools40-i686.exe' # noqa: disable=E501
250
248
  elif version == '3.5':
251
- url = 'https://cran.r-project.org/bin/windows/Rtools/Rtools35.exe'
249
+ url = 'https://cran-archive.r-project.org/bin/windows/Rtools/Rtools35.exe' # noqa: disable=E501
252
250
  return url
253
251
 
254
252