Skip to content

Commit

Permalink
feat: support "func_monitors" in DSRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 committed May 1, 2022
1 parent 1604fde commit e8394df
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions brainpy/dyn/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def func(_t, _dt):
for k, v in return_without_idx.items()}
res.update({k: (v.flatten()[idx] if bm.ndim(v) > 1 else v[idx])
for k, (v, idx) in return_with_idx.items()})
res.update({k: f(_t, _dt) for k, f in self.fun_monitors.items()})
return res

return func
Expand Down
3 changes: 3 additions & 0 deletions brainpy/running/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def __init__(self, target, monitors=None, fun_monitors=None,
fun_monitors = dict()
check_dict_data(fun_monitors, key_type=str, val_type=types.FunctionType)
self.fun_monitors = fun_monitors
for key in self.fun_monitors.keys():
self.mon.item_names.append(key)
self.mon.item_contents[key] = []

# progress bar
assert isinstance(progress_bar, bool), 'Must be a boolean variable.'
Expand Down

0 comments on commit e8394df

Please sign in to comment.