Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPA gaiting failure #1098

Closed
teslar opened this issue Jun 16, 2016 · 4 comments · Fixed by #1099
Closed

SPA gaiting failure #1098

teslar opened this issue Jun 16, 2016 · 4 comments · Fixed by #1099
Labels
Milestone

Comments

@teslar
Copy link

teslar commented Jun 16, 2016

Hey,

this causes a funky compile error (Terry is informed :) ):

Traceback (most recent call last):
  File "/Users/teslar/git/nengo/nengo_gui/nengo_gui/page.py", line 438, in build
    self.sim = backend.Simulator(self.model)
  File "/Users/teslar/git/nengo/nengo/nengo/simulator.py", line 137, in __init__
    self.model.build(network)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/builder.py", line 119, in build
    return Builder.build(self, obj, *args, **kwargs)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/builder.py", line 211, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/network.py", line 72, in build_network
    model.build(subnetwork)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/builder.py", line 119, in build
    return Builder.build(self, obj, *args, **kwargs)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/builder.py", line 211, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/network.py", line 84, in build_network
    model.build(conn)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/builder.py", line 119, in build
    return Builder.build(self, obj, *args, **kwargs)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/builder.py", line 211, in build
    return cls.builders[obj_cls](model, obj, *args, **kwargs)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/connection.py", line 213, in build_connection
    model.sig[conn]['in'] = get_prepost_signal(is_pre=True)
  File "/Users/teslar/git/nengo/nengo/nengo/builder/connection.py", line 205, in get_prepost_signal
    % (conn, 'pre' if is_pre else 'post', target))
BuildError: Building <Connection from <Ensemble "gate[6]"> to <Neurons of <Ensemble "channel_6_memory_0">>>: the 'pre' object <Ensemble "gate[6]"> is not in the model, or has a size of zero.
import nengo
import nengo.spa as spa
import numpy as np

D = 32  # the dimensionality of the vectors

model = spa.SPA()

vocab = spa.Vocabulary(D)
vocab2 = spa.Vocabulary(D)

with model:

    vocab.parse("ON")
    vocab2.parse("A+B+C+D+E")

    """    
    def signal(t):
        if t < 0.25:
            return "ON"
        else:
            return "OFF"
    """

    inp = nengo.Node([0])
    deriv = nengo.Ensemble(n_neurons= 200, dimensions = 1)
    deriv2 = nengo.Ensemble(n_neurons= 200, dimensions = 1)

    model.vision = spa.State(D)
    model.switch = spa.State(D, vocab=vocab)
    model.memory = spa.State(D, feedback=1, feedback_synapse=0.05)
    model.cleanup = spa.AssociativeMemory(input_vocab=vocab2)


    nengo.Connection(inp, deriv)
    nengo.Connection(inp, deriv, transform=-1, synapse=0.05)

    nengo.Connection(deriv, deriv2, function= lambda x: np.square(x))
    nengo.Connection(deriv2, model.switch.input, transform=10*vocab["ON"].v.reshape(D, 1))


    actions = spa.Actions(
        'dot(memory, A)+dot(switch, ON)-1 --> memory=B-A, switch=3*OFF',
        'dot(memory, B)+dot(switch, ON)-1 --> memory=C-B, switch=3*OFF',
        'dot(memory, C)+dot(switch, ON)-1 --> memory=D-C, switch=3*OFF',
        'dot(memory, D)+dot(switch, ON)-1 --> memory=E-D, switch=3*OFF',
        'dot(memory, E)+dot(switch, ON)-1 --> memory=A-E, switch=3*OFF',
        'dot(vision, A) --> memory=vision',
        '0.5 --> cleanup=memory, memory=cleanup'
        )

    model.bg = spa.BasalGanglia(actions)
    model.thalamus = spa.Thalamus(model.bg)
#    model.inp = spa.Input(switch=signal)
@jgosmann jgosmann added the bug label Jun 16, 2016
@jgosmann
Copy link
Collaborator

Not sure if it is worth the effort to fix this. With PR #1014 this bug might be solved already or will at least require a separate fix.

@jgosmann jgosmann self-assigned this Jun 16, 2016
@jgosmann jgosmann added this to the 2.1.1 release milestone Jun 16, 2016
@jgosmann
Copy link
Collaborator

The problem here seems to be the recurrency from cleanup to memory and memory to cleanup.

@jgosmann
Copy link
Collaborator

It seems that the cause is the following:

  • The thalamus gating ensemble will be created within either the cleanup or the memory network (but not both).
  • A connection to the gate will be added with in both networks
  • The two networks are on the same level of the hierarchy which makes the build order undefined. Nengo might build the network without the gate ensemble first which involves building the connection to the gate ensemble. That fails in this case because the gate ensemble has not been built yet.

jgosmann added a commit that referenced this issue Jun 16, 2016
Otherwise it is build as part of a network which might build before the
required gate exists.

Fixes #1098.
@jgosmann jgosmann removed their assignment Jun 16, 2016
@jgosmann
Copy link
Collaborator

@teslar, you can try the fix-1098 branch. It should solve the problem.

tbekolay pushed a commit that referenced this issue Jun 23, 2016
Otherwise it is built as part of a network which might build before the
required gate exists.

Also add a test that fails without these changes.

Fixes #1098.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants