nengo / nengo-gui

Nengo interactive visualizer
Other
97 stars 38 forks source link

Trying to expand network gives error #893

Closed jgosmann closed 7 years ago

jgosmann commented 7 years ago
Traceback (most recent call last):
  File "/home/jgosmann/.pyenv/versions/3.5.3/lib/python3.5/site-packages/nengo_gui/guibackend.py", line 230, in ws_default
    component.update_client(self.ws)
  File "/home/jgosmann/.pyenv/versions/3.5.3/lib/python3.5/site-packages/nengo_gui/components/netgraph.py", line 399, in update_client
    self.expand_network(network, client)
  File "/home/jgosmann/.pyenv/versions/3.5.3/lib/python3.5/site-packages/nengo_gui/components/netgraph.py", line 492, in expand_network
    pos = self.layout.make_layout(network)
  File "/home/jgosmann/.pyenv/versions/3.5.3/lib/python3.5/site-packages/nengo_gui/layout.py", line 112, in make_layout
    post = post.object
AttributeError: 'ObjView' object has no attribute 'object'

The network causing this error:

class AssocMatLearning2(spa.Network):
    input_vocab = VocabularyOrDimParam(
        'input_vocab', optional=False, readonly=True)
    output_vocab = VocabularyOrDimParam(
        'output_vocab', optional=False, readonly=True)

    def __init__(
            self, input_vocab=Default, output_vocab=Default, fn=None,
            **kwargs):
        super(AssocMatLearning2, self).__init__(**kwargs)

        self.input_vocab = input_vocab
        self.output_vocab = output_vocab

        with self:
            d = self.input_vocab.dimensions
            self.state = spa.State(self.input_vocab, subdimensions=64)
            self.target = spa.State(self.output_vocab)
            self.input_cue = self.state.input
            self.input_target = self.target.input
            self.output = nengo.Node(size_in=self.output_vocab.dimensions)

            for i, e in enumerate(self.state.all_ensembles):
                sd = e.dimensions
                start = i * sd
                end = (i + 1) * sd
                conn = nengo.Connection(
                    e, self.output[start:end],
                    learning_rule_type=AML(10.),
                    function=lambda x, sd=sd: np.zeros(sd),
                    solver=nengo.solvers.LstsqL2(solver=RandomizedSVD()))
                nengo.Connection(
                    self.target.output[start:end], conn.learning_rule)

            self.compare = spa.Compare(d)
            nengo.Connection(self.output, self.compare.input_a, transform=1.)
            nengo.Connection(self.input_target, self.compare.input_b)
            inhibit_net(self.compare.output, self.target, strength=1.)

            # FIXME seed/generation of this
            if fn is not None:
                v = spa.Vocabulary(
                    self.input_vocab.dimensions, rng=np.random.RandomState(42))
                for i in range(self.output_vocab.dimensions):
                    v.populate('CTX' + str(i))
                nengo.Connection(
                    self.state.output, self.output, transform=v.vectors)

            self.no_learn = nengo.Node(size_in=1)
            inhibit_net(self.no_learn, self.target)

        self.inputs = {
            'default': (self.input_cue, self.input_vocab),
            'target': (self.input_target, self.output_vocab),
            'no_learn': (self.no_learn, None)}
        self.outputs = {'default': (self.output, self.output_vocab)}
tcstewar commented 7 years ago

Thank you! I'm pretty sure I know how to fix this (it's a dumb bug on my part where I didn't check if something is an ObjView), but in order to test it, I need to be able to run your model. Could you add in the needed import statements? I'm having trouble finding where some of those things are....

jgosmann commented 7 years ago

It's the tcm branch of this repository. Run pytry imem/models.py --gui. The problematic network is net_m_tf (and probably net_m_ft too) in the tcm network. You will need nengo_spa to run it (and you might have to pip install the repository).

tcstewar commented 7 years ago

It's the tcm branch of [this repository].

Hmm, there doesn't seem to be a tcm branch in this repository.......

jgosmann commented 7 years ago

Sorry, I forgot to insert the actual link.

tcstewar commented 7 years ago

Sorry, I forgot to insert the actual link.

Hmm, that doesn't seem to run for me... Do I need a particular nengo version?

running NeuralTCM#20170518-122541-ed06ce50
Traceback (most recent call last):
  File "C:\Python27\Scripts\pytry-script.py", line 9, in <module>
    load_entry_point('pytry', 'console_scripts', 'pytry')()
  File "c:\users\terry\documents\github\pytry\pytry\cmdline.py", line 44, in run
    t.run(**args)
  File "c:\users\terry\documents\github\pytry\pytry\trial.py", line 88, in run
    result = self.execute_trial(p)
  File "c:\users\terry\documents\github\pytry\pytry\nengo.py", line 48, in execute_trial
    model = self.model(p)
  File ".\imem\models.py", line 38, in model
    model.tcm = tcm.TCM(p.beta, self.control, p.item_d, p.context_d)
  File "c:\users\terry\documents\github\imem\imem\tcm.py", line 285, in __init__
    self.context_vocab, self.item_vocab)
  File "c:\users\terry\documents\github\imem\imem\tcm.py", line 148, in __init__
    self.target.output[start:end], conn.learning_rule)
  File "c:\users\terry\documents\github\nengo\nengo\base.py", line 35, in __call__
    inst.__init__(*args, **kwargs)
  File "c:\users\terry\documents\github\nengo\nengo\connection.py", line 424, in __init__
    self.post = post
  File "c:\users\terry\documents\github\nengo\nengo\base.py", line 106, in __setattr__
    super(NengoObject, self).__setattr__(name, val)
  File "c:\users\terry\documents\github\nengo\nengo\config.py", line 454, in __setattr__
    super(SupportDefaultsMixin, self).__setattr__(name, val)
  File "c:\users\terry\documents\github\nengo\nengo\params.py", line 112, in __set__
    new_value = self.validate(instance, value)
  File "c:\users\terry\documents\github\nengo\nengo\connection.py", line 31, in validate
    return super(PrePostParam, self).validate(conn, nengo_obj)
  File "c:\users\terry\documents\github\nengo\nengo\base.py", line 220, in validate
    if self.nonzero_size_in and nengo_obj.size_in < 1:
  File "c:\users\terry\documents\github\nengo\nengo\connection.py", line 624, in size_in
    return getattr(self, self.default_error_signal).size_in
  File "c:\users\terry\documents\github\nengo\nengo\connection.py", line 617, in default_error_signal
    "Directly connecting to the learning rule is only allowed if"
ValueError: Directly connecting to the learning rule is only allowed ifit uses exactly one error signal.

And actually, since this is such a small fix, could you check if this commit fixes it for you?

https://github.com/nengo/nengo_gui/commit/393e8bb16f13a5a25a56e93fad10ab3a157e0003

jgosmann commented 7 years ago

One of nengo master or most recent release should work. I can test it myself once I got my computer working again

On May 18, 2017 12:32:11 PM EDT, tcstewar notifications@github.com wrote:

Sorry, I forgot to insert the actual link.

Hmm, that doesn't seem to run for me... Do I need a particular nengo version?

running NeuralTCM#20170518-122541-ed06ce50
Traceback (most recent call last):
 File "C:\Python27\Scripts\pytry-script.py", line 9, in <module>
   load_entry_point('pytry', 'console_scripts', 'pytry')()
File "c:\users\terry\documents\github\pytry\pytry\cmdline.py", line 44,
in run
   t.run(**args)
File "c:\users\terry\documents\github\pytry\pytry\trial.py", line 88,
in run
   result = self.execute_trial(p)
File "c:\users\terry\documents\github\pytry\pytry\nengo.py", line 48,
in execute_trial
   model = self.model(p)
 File ".\imem\models.py", line 38, in model
   model.tcm = tcm.TCM(p.beta, self.control, p.item_d, p.context_d)
File "c:\users\terry\documents\github\imem\imem\tcm.py", line 285, in
__init__
   self.context_vocab, self.item_vocab)
File "c:\users\terry\documents\github\imem\imem\tcm.py", line 148, in
__init__
   self.target.output[start:end], conn.learning_rule)
File "c:\users\terry\documents\github\nengo\nengo\base.py", line 35, in
__call__
   inst.__init__(*args, **kwargs)
File "c:\users\terry\documents\github\nengo\nengo\connection.py", line
424, in __init__
   self.post = post
File "c:\users\terry\documents\github\nengo\nengo\base.py", line 106,
in __setattr__
   super(NengoObject, self).__setattr__(name, val)
File "c:\users\terry\documents\github\nengo\nengo\config.py", line 454,
in __setattr__
   super(SupportDefaultsMixin, self).__setattr__(name, val)
File "c:\users\terry\documents\github\nengo\nengo\params.py", line 112,
in __set__
   new_value = self.validate(instance, value)
File "c:\users\terry\documents\github\nengo\nengo\connection.py", line
31, in validate
   return super(PrePostParam, self).validate(conn, nengo_obj)
File "c:\users\terry\documents\github\nengo\nengo\base.py", line 220,
in validate
   if self.nonzero_size_in and nengo_obj.size_in < 1:
File "c:\users\terry\documents\github\nengo\nengo\connection.py", line
624, in size_in
   return getattr(self, self.default_error_signal).size_in
File "c:\users\terry\documents\github\nengo\nengo\connection.py", line
617, in default_error_signal
   "Directly connecting to the learning rule is only allowed if"
ValueError: Directly connecting to the learning rule is only allowed
ifit uses exactly one error signal.

And actually, since this is such a small fix, could you check if this commit fixes it for you?

https://github.com/nengo/nengo_gui/commit/393e8bb16f13a5a25a56e93fad10ab3a157e0003

-- 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/893#issuecomment-302463842

-- Sent from my Android device with K-9 Mail. Please excuse my brevity.

tcstewar commented 7 years ago

One of nengo master or most recent release should work. I can test it myself once I got my computer working again

Looks like there's a bunch of Python3 vs Python2 issues causing the problem, which means I can't test it from home. But I'm 99% sure that fix above will do it for you.

jgosmann commented 7 years ago

I can verify the fix works.