Skip to content

Commit

Permalink
Merge pull request #192 from intel-innersource/doc/walk-through-tut
Browse files Browse the repository at this point in the history
Added walk through tutorial
  • Loading branch information
weidel-p committed Jul 4, 2022
2 parents 087e6c1 + 01bd9e1 commit 4ba2ad7
Show file tree
Hide file tree
Showing 3 changed files with 963 additions and 4 deletions.
33 changes: 32 additions & 1 deletion src/lava/proc/monitor/process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (C) 2021-22 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
# See: https://spdx.org/licenses/

import matplotlib.pyplot as plt
from lava.magma.core.process.process import AbstractProcess
from lava.magma.core.process.variable import Var
from lava.magma.core.process.ports.ports import InPort, OutPort, RefPort
Expand Down Expand Up @@ -255,3 +255,34 @@ def get_data(self):
self.data[target_name[0]][target_name[1]] = data_var.get()

return self.data

def plot(self, ax, target, *args, **kwargs):
"""
Plot the recorded data into subplots.
Can handle recordings of multiple processes and multiple variables
per process.
Each process will create a separate column in the subplots, each
variable will be plotted in a separate row.
Parameters
----------
ax : matplotlib.Axes
Axes to plot the data into
target: Var or OutPort
The target which should be plotted
*args
Passed to the matplotlib.plot function to customize the plot.
**kwargs
Passed to the matplotlib.plot function to customize the plot.
"""

# fetch data
data = self.get_data()
# set plot attributes
ax.set_title(target.process.name)
ax.set_xlabel("Time step")
ax.set_ylabel(target.name)

# plot data
ax.plot(data[target.process.name][target.name], *args, **kwargs)
12 changes: 9 additions & 3 deletions tests/lava/tutorials/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ def _run_notebook(self, notebook: str, e2e_tutorial: bool = False):
finally:
os.chdir(cwd)

@unittest.skipIf(system_name != "linux", "Tests work on linux")
def test_end_to_end_00_tour_through_lava(self):
"""Test tutorial end to end 00 tour through lava."""
self._run_notebook(
"tutorial00_tour_through_lava.ipynb",
e2e_tutorial=True
)

@unittest.skipIf(system_name != "linux", "Tests work on linux")
def test_end_to_end_01_mnist(self):
"""Test tutorial end to end 01 mnist."""
Expand Down Expand Up @@ -224,9 +232,7 @@ def test_in_depth_05__connect_processes(self):
"tutorial05_connect_processes.ipynb"
)

@unittest.skip("Skip until \
https://github.com/lava-nc/lava/issues/242 is fixed")
# @unittest.skipIf(system_name != "linux", "Tests work on linux")
@unittest.skipIf(system_name != "linux", "Tests work on linux")
def test_in_depth_06_hierarchical_processes(self):
"""Test tutorial in depth hierarchical processes."""
self._run_notebook(
Expand Down
Loading

0 comments on commit 4ba2ad7

Please sign in to comment.