Skip to content

Commit c98944b

Browse files
committed
Update model to always be compiled, remove deprecated compilation features
1 parent 956f237 commit c98944b

File tree

8 files changed

+129
-490
lines changed

8 files changed

+129
-490
lines changed

cmdstanpy/cmdstan_args.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ class CmdStanArgs:
632632
def __init__(
633633
self,
634634
model_name: str,
635-
model_exe: OptionalPath,
635+
model_exe: Union[os.PathLike, str],
636636
chain_ids: Optional[list[int]],
637637
method_args: Union[
638638
SamplerArgs,
@@ -692,10 +692,6 @@ def validate(self) -> None:
692692
* if no seed specified, set random seed.
693693
* length of per-chain lists equals specified # of chains
694694
"""
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')
699695

700696
if self.chain_ids is not None:
701697
for chain_id in self.chain_ids:

cmdstanpy/compilation.py

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import platform
99
import shutil
1010
import subprocess
11-
from copy import copy
1211
from datetime import datetime
1312
from pathlib import Path
1413
from typing import Any, Iterable, Optional, Union
@@ -37,11 +36,6 @@
3736
'warn-pedantic',
3837
]
3938

40-
# TODO(2.0): remove
41-
STANC_DEPRECATED_OPTS = {
42-
'allow_undefined': 'allow-undefined',
43-
'include_paths': 'include-paths',
44-
}
4539

4640
STANC_IGNORE_OPTS = [
4741
'debug-lex',
@@ -67,7 +61,6 @@
6761
OptionalPath = Union[str, os.PathLike, None]
6862

6963

70-
# TODO(2.0): can remove add function and other logic
7164
class CompilerOptions:
7265
"""
7366
User-specified flags for stanc and C++ compiler.
@@ -151,24 +144,6 @@ def validate_stanc_opts(self) -> None:
151144
paths = None
152145
has_o_flag = False
153146

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-
)
172147
for key, val in self._stanc_options.items():
173148
if key in STANC_IGNORE_OPTS:
174149
get_logger().info('ignoring compiler option: %s', key)
@@ -267,37 +242,6 @@ def validate_user_header(self) -> None:
267242

268243
self._cpp_options['USER_HEADER'] = self._user_header
269244

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-
301245
def compose_stanc(self, filename_in_msg: Optional[str]) -> list[str]:
302246
opts = []
303247

@@ -343,7 +287,8 @@ def compose(self, filename_in_msg: Optional[str] = None) -> list[str]:
343287

344288

345289
def src_info(
346-
stan_file: str, compiler_options: CompilerOptions
290+
stan_file: str,
291+
stanc_options: Optional[dict[str, Any]] = None,
347292
) -> dict[str, Any]:
348293
"""
349294
Get source info for Stan program file.
@@ -354,7 +299,7 @@ def src_info(
354299
cmd = (
355300
[stanc_path()]
356301
# handle include-paths, allow-undefined etc
357-
+ compiler_options.compose_stanc(None)
302+
+ CompilerOptions(stanc_options=stanc_options).compose_stanc(None)
358303
+ ['--info', str(stan_file)]
359304
)
360305
proc = subprocess.run(cmd, capture_output=True, text=True, check=False)
@@ -412,7 +357,9 @@ def compile_stan_file(
412357
exe_time = os.path.getmtime(exe_target)
413358
included_files = [src]
414359
included_files.extend(
415-
src_info(str(src), compiler_options).get('included_files', [])
360+
src_info(str(src), compiler_options.stanc_options).get(
361+
'included_files', []
362+
)
416363
)
417364
out_of_date = any(
418365
os.path.getmtime(included_file) > exe_time

0 commit comments

Comments
 (0)