How to reset channels in the notebook?

Problem

I am running experiments in the cloud notebook but I keep overwriting existing channels and causing errors. For example I run my training script:

1
2
3
4
5
import numpy as np

for epoch in range(100):
    loss = np.random.random()
    ctx.channel_send('epoch_loss', epoch, loss)

and everything is fine:

image

but when I run it again it crashes:

image

How can I fix that?

Solution

You need to reset channels. There are two options to do so.

Reset named channel

Run ctx.channel_reset('YOUR_CHANNEL_NAME') before sending values to channel:

1
2
3
ctx.channel_reset('epoch_loss')
for epoch in range(100):
    ...

Reset all channels

Run ctx.reset_all_channels() before sending values to channel:

1
2
3
ctx.reset_all_channels()
for epoch in range(100):
    ...

Either way your channel will be reset and you could go on sending values and displaying charts with no problems:

image

See also