nengo-gui icon indicating copy to clipboard operation
nengo-gui copied to clipboard

can't do html vis on node when size_out != 0?

Open studywolf opened this issue 8 years ago • 8 comments

I've been playing around trying to nail this down exactly, but it's kind of strange.

import nengo
import numpy as np

model = nengo.Network()
with model:

    def display(t, x):
        output = x**2

        # visualization code -----------------------------------------------------
        display._nengo_html_ = '''
        <svg width="100%" height="100%" viewbox="0 0 100 100">
            <circle cx="{x}" cy="{x}" r="1.5" stroke="black" stroke-width="1" fill="black" />
        </svg>
        '''.format(**locals())
        # end of visualization code ---------------------------------------------
        return output

    node_input = nengo.Node(output=[1])
    node_display_output = nengo.Node(output=display, size_in=1, size_out=1)
    # node_display_no_output = nengo.Node(output=display, size_in=1)
    nengo.Connection(node_input, node_display_output)
    # nengo.Connection(node_input, node_display_no_output)

if you run this it will not let you create an HTML plot in nengo gui, if you switch the commented lines around for no_output then it will, and also if you uncomment both of the it will. So not sure what could cause this but it's strange!

studywolf avatar May 08 '16 15:05 studywolf

The problem is that the function isn't called before the Simulation starts to run, so _nengo_html_ isn't set before the simulation starts, so the GUI doesn't know to give you the HTML View option.

There's two ways around this. Either do:

node_display_output = nengo.Node(output=display, size_in=1, size_out=1)
display._nengo_html_ = ''   # makes sure the attribute exists

or do this:

node_display_output = nengo.Node(output=display, size_in=1)

I prefer the last case, but it does rely on the fact that nengo calls the function once in order to determine size_out for itself, which is a bit magical.

tcstewar avatar May 08 '16 19:05 tcstewar

Hm! OK interesting, thanks!

Hummm...why does it work for both nodes though if you uncomment both lines?

studywolf avatar May 09 '16 16:05 studywolf

Hummm...why does it work for both nodes though if you uncomment both lines?

Because you're not specifying size_out, so it has to call the function right away to figure out size_out, and so _nengo_html_ gets set.

tcstewar avatar May 09 '16 18:05 tcstewar

Ah so since I've only specified size out for one node, if it had to check size out for one node it checks for all?

studywolf avatar May 09 '16 18:05 studywolf

Ah so since I've only specified size out for one node, if it had to check size out for one node it checks for all?

Hmm... no, that shouldn't be happening... can you post the full example? I'm having trouble sorting out what the other Nodes are you're referring to.

tcstewar avatar May 09 '16 18:05 tcstewar

Will do! Just in transit now, I'll post when i get to wireless! On May 9, 2016 2:51 PM, "tcstewar" [email protected] wrote:

Ah so since I've only specified size out for one node, if it had to check size out for one node it checks for all?

Hmm... no, that shouldn't be happening... can you post the full example? I'm having trouble sorting out what the other Nodes are you're referring to.

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/nengo/nengo_gui/issues/733#issuecomment-217954568

studywolf avatar May 09 '16 18:05 studywolf

Hey Travis, are you still experiencing this issue? (:

Seanny123 avatar Jun 06 '16 18:06 Seanny123

Ah, so yeah still getting this, I had named the nodes wrong before, though.

So here with both uncommented they can both use the html display, and with the _display one commented you can't get an html from the _no_display. The weird thing was that both nodes let you do the html display when only one doesn't specify size_out.

import nengo
import numpy as np

model = nengo.Network()
with model:

    def display(t, x):
        output = x**2

        # visualization code -----------------------------------------------------
        display._nengo_html_ = '''
        <svg width="100%" height="100%" viewbox="0 0 100 100">
            <circle cx="{x}" cy="{x}" r="1.5" stroke="black" stroke-width="1" fill="black" />
        </svg>
        '''.format(**locals())
        # end of visualization code ---------------------------------------------
        return output

    node_input = nengo.Node(output=[1])
    node_display_no_output = nengo.Node(output=display, size_in=1, size_out=1)
    nengo.Connection(node_input, node_display_no_output)

    node_display_output = nengo.Node(output=display, size_in=1)
    nengo.Connection(node_input, node_display_output)

studywolf avatar Jun 09 '16 18:06 studywolf