Updated simple logging tutorial

This commit is contained in:
Shital Shah 2019-05-27 04:24:26 -07:00
Родитель 3677cb4267
Коммит f6d5501656
9 изменённых файлов: 149 добавлений и 60 удалений

Двоичные данные
docs/images/simple_logging/line_cell.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 40 KiB

После

Ширина:  |  Высота:  |  Размер: 88 KiB

Двоичные данные
docs/images/simple_logging/line_cell2.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 112 KiB

Двоичные данные
docs/images/simple_logging/text_cell.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 18 KiB

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичные данные
docs/images/simple_logging/text_summary.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 39 KiB

После

Ширина:  |  Высота:  |  Размер: 48 KiB

Просмотреть файл

@ -4,7 +4,7 @@
In this tutorial, we will use a straightforward script that creates an array of random numbers. Our goal is to examine this array from the Jupyter Notebook while below script is running separately in a console.
```
# available in test/simple_log/sum_lazzy.py
# available in test/simple_log/sum_lazy.py
import time, random
import tensorwatch as tw
@ -32,7 +32,7 @@ Notice that we give `Watcher` object an opportunity to *observe* variables. Obse
TensorWatch has two core classes: `Watcher` and `WatcherClient`. The `Watcher` object will open up TCP/IP sockets by default and listens to any incoming requests. The `WatcherClient` allows you to connect to `Watcher` and have it execute any Python [lambda expression](http://book.pythontips.com/en/latest/lambdas.html) you want. The Python lambda expressions consume a stream of values as input and outputs another stream of values. The lambda expressions may typically contain [map, filter, and reduce](http://book.pythontips.com/en/latest/map_filter.html) so you can transform values in the input stream, filter them, or aggregate them. Let's see all these with a simple example.
## Create the Client
You can either create a Jupyter Notebook or get the existing one in your repo at `notebooks/lazy_logging.ipynb`.
You can either create a Jupyter Notebook or get the existing one in the repo at `notebooks/lazy_logging.ipynb`.
Let's first do imports:

Просмотреть файл

@ -1,7 +1,40 @@
# Welcome to the Simple Logging Tutorial
# Simple Logging Tutorial
We would start by running the script [sum_log.py](https://github.com/microsoft/tensorwatch/blob/master/test/simple_log/sum_log.py) available at `test/simple_log` directory. This is just simple code that just sums N numbers. We added couple of TensorWatch statements to log the values we want. Now while this script is running, you can execute this notebook ([download it here](https://github.com/microsoft/tensorwatch/blob/master/notebooks/simple_logging.ipynb)).
In this tutorial, we will use a simple script that maintains two variables. Our goal is to log the values of these variables using TensorWatch and view it in real-time in variety of ways from Jupyter Notebook demonstrating various features offered by TensorWatch. We would execute this script from a console and its code looks like this:
```
# available in test/simple_log/sum_log.py
import time, random
import tensorwatch as tw
# we will create two streams, one for
# sums of integers, other for random numbers
w = tw.Watcher()
st_isum = w.create_stream('isums')
st_rsum = w.create_stream('rsums')
isum, rsum = 0, 0
for i in range(10000):
isum += i
rsum += random.randint(i)
# write to streams
st_isum.write((i, isum))
st_rsum.write((i, rsum))
time.sleep(1)
```
## Basic Concepts
The `Watcher` object allows you to create streams. You can then write any values in to these streams. By default, the `Watcher` object opens up TCP/IP sockets so a client can request these streams. As values are being written on one end, they get serialized and sent to any client(s) on the other end. We will use Jupyter Notebook to create a client, open these streams and feed them to various visualizers.
## Create the Client
You can either create a new Jupyter Notebook or get the existing one in the repo at `notebooks/simple_logging.ipynb`.
Let's first do imports:
```python
@ -9,53 +42,61 @@ We would start by running the script [sum_log.py](https://github.com/microsoft/t
import tensorwatch as tw
```
First we create client that would connect to the Watcher running in out script. By default connection is made over TCP/IP sockets. We then specify the name of the log stream that we had created in the script.
Next, open the streams that we had created in above script:
```python
client = tw.WatcherClient()
stream = client.open_stream('my_log')
cli = tw.WatcherClient()
st_isum = cli.open_stream('isums')
st_rsum = cli.open_stream('rsums')
```
Now lets visualize this stream in text format.
Now lets visualize isum stream in textual format:
```python
text_vis = tw.Visualizer(stream, vis_type='text')
text_vis = tw.Visualizer(st_isum, vis_type='text')
text_vis.show()
```
<img src="images/simple_logging/text_cell.png" width=150/>
You should see a growing table in real-time like this, each row is tuple we wrote to the stream:
<img src="images/simple_logging/text_cell.png" width=120/>
That worked out good! How about feeding same stream to line chart visualization?
That worked out good! How about feeding the same stream simultaneously to plot a line graph?
```python
line_plot = tw.Visualizer(stream, vis_type='line')
line_plot = tw.Visualizer(st_isum, vis_type='line', xtitle='i', ytitle='isum')
line_plot.show()
```
<img src="images/simple_logging/line_cell.png" width=400/>
Ooo... Now we have two simultaneous visualizations running in Jupyter Notebook in real-time fed from same stream! How about adding one more? This time we want to see real-time statistics of the values coming in our stream. Oh, BTW, we had also like to see next to our text visualization above so we set the cell parameter like this:
Let's take step further. Say, we plot rsum as well but, just for fun, in the *same plot* as isum above. That's easy with the optional `host` parameter:
```python
summary = tw.Visualizer(stream, vis_type='summary', cell=text_vis)
line_plot = tw.Visualizer(st_rsum, vis_type='line', host=line_plot, ytitle='rsum')
```
This instantly changes our line plot and a new Y-Axis is automatically added for our second stream. TensorWatch allows you to add multiple streams in same visualizer.
Are you curious about statistics of these two streams? Let's display the live statistics of both streams side by side! To do this, we will use the `cell` parameter for the second visualization to place right next to the first one:
```python
istats = tw.Visualizer(st_isum, vis_type='summary')
istats.show()
rstats = tw.Visualizer(st_rsum, vis_type='summary', cell=istats)
```
The output looks like this (each panel showing statistics for the tuple that was logged in the stream):
<img src="images/simple_logging/text_summary.png" width=300/>
## Next Steps
TensorWatch allows many different frameworks for visualizations. You can build your custom ones also fairly easily. Here let's see our stream visualized using Plotly library:
We have just scratched the surface of what you can do with TensorWatch. You should check out [Lazy Logging Tutorial](lazy_logging.md) and other [notebooks](https://github.com/microsoft/tensorwatch/tree/master/notebooks) as well.
## Questions?
```python
plotly_line = tw.Visualizer(stream, vis_type='plotly-line')
plotly_line.show()
```
<img src="images/simple_logging/plotly_line.png" width=400/>
File a [Github issue](https://github.com/microsoft/tensorwatch/issues/new) and let us know if we can improve this tutorial.

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -1,14 +1,19 @@
import time
import time, random
import tensorwatch as tw
# create watcher and stream that we would use
# for logging
# we will create two streams, one for
# sums of integers, other for random numbers
w = tw.Watcher()
s = w.create_stream('my_log')
st_isum = w.create_stream('isums')
st_rsum = w.create_stream('rsums')
sum = 0
isum, rsum = 0, 0
for i in range(10000):
sum += i
# write tuple to our log
s.write((i, sum))
isum += i
rsum += random.randint(0,i)
# write to streams
st_isum.write((i, isum))
st_rsum.write((i, rsum))
time.sleep(1)

Просмотреть файл

@ -5,7 +5,7 @@
<ProjectGuid>9a7fe67e-93f0-42b5-b58f-77320fc639e4</ProjectGuid>
<ProjectHome>
</ProjectHome>
<StartupFile>simple_log\sum_lazy.py</StartupFile>
<StartupFile>simple_log\sum_log.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
@ -25,9 +25,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="deps\live_graph.py" />
<Compile Include="simple_log\example.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="simple_log\quick_start.py">
<SubType>Code</SubType>
</Compile>