Skip to content

Commit 2ed87fe

Browse files
committed
Merge branch 'develop'
2 parents 95a816a + acab458 commit 2ed87fe

8 files changed

Lines changed: 39 additions & 29 deletions

File tree

cmdstanpy/install_cmdstan.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
from time import sleep
2929
from typing import Any, Callable, Dict, Optional
3030

31-
from tqdm.auto import tqdm # type: ignore
31+
from tqdm.auto import tqdm
3232

3333
from cmdstanpy import _DOT_CMDSTAN, _DOT_CMDSTANPY
34-
3534
from cmdstanpy.utils import (
3635
cmdstan_path,
3736
do_command,
@@ -94,7 +93,7 @@ def clean_all(verbose: bool = False) -> None:
9493
raise CmdStanInstallError(f'Command "make clean-all" failed\n{str(e)}')
9594

9695

97-
def build(verbose: bool = False, progress: bool = True) -> None:
96+
def build(verbose: bool = False, progress: bool = True, cores: int = 1) -> None:
9897
"""
9998
Run command ``make build`` in the current directory, which must be
10099
the home directory of a CmdStan version (or GitHub repo).
@@ -107,8 +106,10 @@ def build(verbose: bool = False, progress: bool = True) -> None:
107106
Default is ``False``.
108107
:param progress: Boolean value; when ``True`` display progress progress bar.
109108
Default is ``True``.
109+
:param cores: Integer, number of cores to use in the ``make`` command.
110+
Default is 1 core.
110111
"""
111-
cmd = [MAKE, 'build']
112+
cmd = [MAKE, 'build', f'-j{cores}']
112113
try:
113114
if verbose:
114115
do_command(cmd)
@@ -201,19 +202,26 @@ def compile_example(verbose: bool = False) -> None:
201202
raise CmdStanInstallError(f'Command "make clean-all" failed\n{e}')
202203

203204

204-
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:
205208
"""
206209
Rebuilds the existing CmdStan installation.
207210
This assumes CmdStan has already been installed,
208211
though it need not be installed via CmdStanPy for
209212
this function to work.
210213
211214
: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.
212220
"""
213221
try:
214222
with pushd(cmdstan_path()):
215223
clean_all(verbose)
216-
build(verbose, progress)
224+
build(verbose, progress, cores)
217225
compile_example(verbose)
218226
except ValueError as e:
219227
raise CmdStanInstallError(
@@ -222,7 +230,11 @@ def rebuild_cmdstan(verbose: bool = False, progress: bool = True) -> None:
222230

223231

224232
def install_version(
225-
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,
226238
) -> None:
227239
"""
228240
Build specified CmdStan version by spawning subprocesses to
@@ -245,7 +257,7 @@ def install_version(
245257
)
246258
clean_all(verbose)
247259
print('Rebuilding version {}'.format(cmdstan_version))
248-
build(verbose)
260+
build(verbose, progress=progress, cores=cores)
249261
print('Test model compilation')
250262
compile_example(verbose)
251263
print('Installed {}'.format(cmdstan_version))
@@ -418,6 +430,12 @@ def parse_cmdline_args() -> Dict[str, Any]:
418430
action='store_true',
419431
help="flag, when specified show progress bar for CmdStan download",
420432
)
433+
parser.add_argument(
434+
"--cores",
435+
default=1,
436+
type=int,
437+
help="number of cores to use while building",
438+
)
421439
if platform.system() == 'Windows':
422440
# use compiler installed with install_cxx_toolchain
423441
# Install a new compiler if compiler not found
@@ -520,6 +538,8 @@ def main(args: Dict[str, Any]) -> None:
520538
cmdstan_version=cmdstan_version,
521539
overwrite=args['overwrite'],
522540
verbose=args['verbose'],
541+
progress=progress,
542+
cores=args['cores'],
523543
)
524544
except RuntimeError as e:
525545
print(e)

cmdstanpy/install_cxx_toolchain.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,6 @@ def main(args: Dict[str, Any]) -> None:
303303

304304
if 'progress' in args:
305305
progress = args['progress']
306-
try:
307-
# pylint: disable=unused-import
308-
from tqdm import tqdm # noqa: F401
309-
except (ImportError, ModuleNotFoundError):
310-
progress = False
311306
else:
312307
progress = False
313308

cmdstanpy/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pathlib import Path
1515
from typing import Any, Callable, Dict, List, Mapping, Optional, Union
1616

17-
from tqdm.auto import tqdm # type: ignore
17+
from tqdm.auto import tqdm
1818

1919
from cmdstanpy import _CMDSTAN_REFRESH, _CMDSTAN_SAMPLING, _CMDSTAN_WARMUP
2020
from cmdstanpy.cmdstan_args import (
@@ -1368,10 +1368,10 @@ def _run_cmdstan(
13681368
) # make the typechecker happy
13691369
sampler_args.fixed_param = True
13701370

1371-
# pylint: disable=no-self-use
1371+
@staticmethod
13721372
@progbar.wrap_callback
13731373
def _wrap_sampler_progress_hook(
1374-
self, chain_id: int, total: int
1374+
chain_id: int, total: int
13751375
) -> Optional[Callable[[str], None]]:
13761376
"""Sets up tqdm callback for CmdStan sampler console msgs."""
13771377
pbar: tqdm = tqdm(

cmdstanpy/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import numpy as np
3232
import pandas as pd
3333
import ujson as json
34-
from tqdm.auto import tqdm # type: ignore
34+
from tqdm.auto import tqdm
3535

3636
from cmdstanpy import (
3737
_CMDSTAN_SAMPLING,
@@ -990,7 +990,7 @@ def do_command(
990990

991991

992992
def returncode_msg(retcode: int) -> str:
993-
""" interpret retcode"""
993+
"""interpret retcode"""
994994
if retcode < 0:
995995
sig = -1 * retcode
996996
return f'terminated by signal {sig}'
@@ -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
@@ -1176,6 +1177,8 @@ def install_cmdstan(
11761177
:param verbose: Boolean value; when ``True``, show console output from all
11771178
intallation steps, i.e., download, build, and test CmdStan release.
11781179
Default is ``False``.
1180+
:param cores: Integer, number of cores to use in the ``make`` command.
1181+
Default is 1 core.
11791182
11801183
:return: Boolean value; ``True`` for success.
11811184
"""
@@ -1187,6 +1190,7 @@ def install_cmdstan(
11871190
"compiler": compiler,
11881191
"progress": progress,
11891192
"dir": dir,
1193+
"cores": cores,
11901194
}
11911195

11921196
try:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ warn_return_any = true
2020

2121
[[tool.mypy.overrides]]
2222
module = [
23-
'tqdm',
23+
'tqdm.auto',
2424
'pandas',
2525
'ujson',
2626
'numpy', # these two are required for py36, which numpy 1.21 doesn't support

test/test_cmdstan_args.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ def test_args_fitted_params(self):
645645
class VariationalTest(unittest.TestCase):
646646
def test_args_variational(self):
647647
args = VariationalArgs()
648-
self.assertTrue(True)
649648

650649
args = VariationalArgs(output_samples=1)
651650
args.validate(chains=1)

test/test_model.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from testfixtures import LogCapture, StringComparison
1010

1111
from cmdstanpy.model import CmdStanModel
12-
from cmdstanpy.utils import EXTENSION, cmdstan_path
12+
from cmdstanpy.utils import EXTENSION
1313

1414
HERE = os.path.dirname(os.path.abspath(__file__))
1515
DATAFILES_PATH = os.path.join(HERE, 'data')
@@ -34,10 +34,6 @@
3434

3535

3636
class CmdStanModelTest(unittest.TestCase):
37-
def show_cmdstan_version(self):
38-
print('\n\nCmdStan version: {}\n\n'.format(cmdstan_path()))
39-
self.assertTrue(True)
40-
4137
def test_model_good(self):
4238
# compile on instantiation, override model name
4339
model = CmdStanModel(model_name='bern', stan_file=BERN_STAN)

test/test_variational.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ def test_variational_good(self):
167167

168168
self.assertEqual(variational.variational_sample.shape, (1000, 5))
169169

170-
def test_variational_missing_args(self):
171-
self.assertTrue(True)
172-
173170
def test_variational_eta_small(self):
174171
stan = os.path.join(
175172
DATAFILES_PATH, 'variational', 'eta_should_be_small.stan'
@@ -186,7 +183,6 @@ def test_variational_eta_small(self):
186183
self.assertAlmostEqual(
187184
fabs(variational.variational_params_dict['mu[2]']), 0.09, places=1
188185
)
189-
self.assertTrue(True)
190186

191187
def test_variational_eta_fail(self):
192188
stan = os.path.join(

0 commit comments

Comments
 (0)