Skip to content

Commit e58942e

Browse files
committed
Propagate progress, add core argument
1 parent 92c7bb6 commit e58942e

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

cmdstanpy/install_cmdstan.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def clean_all(verbose: bool = False) -> None:
9393
raise CmdStanInstallError(f'Command "make clean-all" failed\n{str(e)}')
9494

9595

96-
def build(verbose: bool = False, progress: bool = True) -> None:
96+
def build(verbose: bool = False, progress: bool = True, cores: int = 1) -> None:
9797
"""
9898
Run command ``make build`` in the current directory, which must be
9999
the home directory of a CmdStan version (or GitHub repo).
@@ -106,8 +106,10 @@ def build(verbose: bool = False, progress: bool = True) -> None:
106106
Default is ``False``.
107107
:param progress: Boolean value; when ``True`` display progress progress bar.
108108
Default is ``True``.
109+
:param cores: Integer, number of cores to use in the ``make`` command.
110+
Default is 1 core.
109111
"""
110-
cmd = [MAKE, 'build']
112+
cmd = [MAKE, 'build', f'-j{cores}']
111113
try:
112114
if verbose:
113115
do_command(cmd)
@@ -200,19 +202,26 @@ def compile_example(verbose: bool = False) -> None:
200202
raise CmdStanInstallError(f'Command "make clean-all" failed\n{e}')
201203

202204

203-
def rebuild_cmdstan(verbose: bool = False, progress: bool = True) -> None:
205+
def rebuild_cmdstan(
206+
verbose: bool = False, progress: bool = True, cores: int = 1
207+
) -> None:
204208
"""
205209
Rebuilds the existing CmdStan installation.
206210
This assumes CmdStan has already been installed,
207211
though it need not be installed via CmdStanPy for
208212
this function to work.
209213
210214
:param verbose: Boolean value; when ``True``, show output from make command.
215+
Default is ``False``.
216+
:param progress: Boolean value; when ``True`` display progress progress bar.
217+
Default is ``True``.
218+
:param cores: Integer, number of cores to use in the ``make`` command.
219+
Default is 1 core.
211220
"""
212221
try:
213222
with pushd(cmdstan_path()):
214223
clean_all(verbose)
215-
build(verbose, progress)
224+
build(verbose, progress, cores)
216225
compile_example(verbose)
217226
except ValueError as e:
218227
raise CmdStanInstallError(
@@ -221,7 +230,11 @@ def rebuild_cmdstan(verbose: bool = False, progress: bool = True) -> None:
221230

222231

223232
def install_version(
224-
cmdstan_version: str, overwrite: bool = False, verbose: bool = False
233+
cmdstan_version: str,
234+
overwrite: bool = False,
235+
verbose: bool = False,
236+
progress: bool = True,
237+
cores: int = 1,
225238
) -> None:
226239
"""
227240
Build specified CmdStan version by spawning subprocesses to
@@ -244,7 +257,7 @@ def install_version(
244257
)
245258
clean_all(verbose)
246259
print('Rebuilding version {}'.format(cmdstan_version))
247-
build(verbose)
260+
build(verbose, progress=progress, cores=cores)
248261
print('Test model compilation')
249262
compile_example(verbose)
250263
print('Installed {}'.format(cmdstan_version))
@@ -417,6 +430,12 @@ def parse_cmdline_args() -> Dict[str, Any]:
417430
action='store_true',
418431
help="flag, when specified show progress bar for CmdStan download",
419432
)
433+
parser.add_argument(
434+
"--cores",
435+
default=1,
436+
type=int,
437+
help="number of cores to use while building",
438+
)
420439
if platform.system() == 'Windows':
421440
# use compiler installed with install_cxx_toolchain
422441
# Install a new compiler if compiler not found
@@ -519,6 +538,8 @@ def main(args: Dict[str, Any]) -> None:
519538
cmdstan_version=cmdstan_version,
520539
overwrite=args['overwrite'],
521540
verbose=args['verbose'],
541+
progress=progress,
542+
cores=args['cores'],
522543
)
523544
except RuntimeError as e:
524545
print(e)

cmdstanpy/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ def install_cmdstan(
11481148
compiler: bool = False,
11491149
progress: bool = False,
11501150
verbose: bool = False,
1151+
cores: int = 1,
11511152
) -> bool:
11521153
"""
11531154
Download and install a CmdStan release from GitHub. Downloads the release
@@ -1187,6 +1188,7 @@ def install_cmdstan(
11871188
"compiler": compiler,
11881189
"progress": progress,
11891190
"dir": dir,
1191+
"cores": cores,
11901192
}
11911193

11921194
try:

0 commit comments

Comments
 (0)