Skip to content

Commit 3514acf

Browse files
committed
More input validation
1 parent 2a382aa commit 3514acf

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

cmdstanpy/model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,10 @@ def laplace_sample(
17141714
"Method 'laplace_sample' not available for CmdStan versions "
17151715
"before 2.32"
17161716
)
1717+
if opt_args is not None and mode is not None:
1718+
raise ValueError(
1719+
"Cannot specify both 'opt_args' and 'mode' arguments"
1720+
)
17171721
if mode is None:
17181722
optimize_args = {
17191723
"seed": seed,

cmdstanpy/stanfit/laplace.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from .runset import RunSet
3333

3434
# TODO list:
35-
# - tests
3635
# - docs and example notebook
3736
# - make sure features like standalone GQ are updated/working
3837

@@ -57,7 +56,6 @@ def _assemble_draws(self) -> None:
5756
if self._draws.shape != (0,):
5857
return
5958

60-
# TODO: should we fake a chain dimension?
6159
with open(self._runset.csv_files[0], 'r') as fd:
6260
lines = (line for line in fd if not line.startswith('#'))
6361
self._draws = np.loadtxt(

test/test_laplace.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ def test_laplace_bad_jacobian_mismatch():
4646
)
4747

4848

49+
def test_laplace_bad_two_modes():
50+
model_file = os.path.join(DATAFILES_PATH, 'optimize', 'rosenbrock.stan')
51+
model = cmdstanpy.CmdStanModel(stan_file=model_file)
52+
with pytest.raises(ValueError):
53+
model.laplace_sample(
54+
data={},
55+
mode=os.path.join(DATAFILES_PATH, 'optimize', 'rosenbrock_mle.csv'),
56+
opt_args={'iter': 1003},
57+
jacobian=False,
58+
)
59+
60+
4961
def test_laplace_outputs():
5062
model_file = os.path.join(DATAFILES_PATH, 'optimize', 'rosenbrock.stan')
5163
model = cmdstanpy.CmdStanModel(stan_file=model_file)

0 commit comments

Comments
 (0)