Skip to content

Commit b63d3d4

Browse files
committed
more changes per code review
1 parent 7be7dc0 commit b63d3d4

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

cmdstanpy/model.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,19 @@ def compile(
430430
else:
431431
get_logger().error('model compilation failed')
432432

433-
def exe_info(self) -> Optional[Dict[str, str]]:
433+
def exe_info(self) -> Dict[str, str]:
434434
"""
435435
Run model with option 'info'. Parse output statements, which all
436436
have form 'key = value' into a Dict.
437437
If exe file compiled with CmdStan < 2.27, calling model with
438438
option 'info' fail and method returns None.
439439
"""
440+
result: Dict[str, Any] = {}
440441
if self.exe_file is None:
441-
return None
442+
return result
442443
try:
443444
info = StringIO()
444445
do_command(cmd=[self.exe_file, 'info'], fd_out=info)
445-
result: Dict[str, Any] = {}
446446
lines = info.getvalue().split('\n')
447447
for line in lines:
448448
kv_pair = [x.strip() for x in line.split('=')]
@@ -451,7 +451,7 @@ def exe_info(self) -> Optional[Dict[str, str]]:
451451
result[kv_pair[0]] = kv_pair[1]
452452
return result
453453
except RuntimeError:
454-
return None
454+
return result
455455

456456
def optimize(
457457
self,
@@ -947,10 +947,7 @@ def sample(
947947
):
948948
assert isinstance(self.exe_file, str) # make typechecker happy
949949
info_dict = self.exe_info()
950-
if (
951-
info_dict is not None
952-
and info_dict['STAN_THREADS'] == 'true'
953-
):
950+
if info_dict.get('STAN_THREADS') == 'true':
954951
one_process_per_chain = False
955952
num_threads = parallel_chains * num_threads
956953
parallel_procs = 1

test/test_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def test_model_info(self):
160160
model = CmdStanModel(stan_file=b2_file, cpp_options=cpp_opts)
161161
if model.exe_file is not None and os.path.exists(model.exe_file):
162162
os.remove(model.exe_file)
163-
null_dict = model.exe_info()
164-
self.assertTrue(null_dict is None)
163+
empty_dict = model.exe_info()
164+
self.assertEqual(len(empty_dict), 0)
165165

166166
model.compile(force=True)
167167
info_dict = model.exe_info()

0 commit comments

Comments
 (0)