AssertionError when using nengo_ocl

Hi. I want to run the following program. This program is to implement binding and unbinding of symbols about a little lot of sentences.

# coding: utf-8

import nengo
import nengo.spa as spa
import matplotlib
import matplotlib.pyplot as plt
import time
import numpy as np
import xlwt
import nengo_ocl
import os
os.environ['PYOPENCL_CTX']='0'
D=2400
st=0.2
SD=100
npd=200
start = time.time()


vocab = spa.Vocabulary(dimensions=D)

vocab.add('ZERO', [0]*D)

s = []
a = []
#s[0]
s.append("STATEMENT1 + OldMan_and_OldWoman*Agt_Lived + Lived*Verb + Village*Where_Lived_in")

#a[0]
a.append("OldMan*Agt_Gathered + Gathered*Verb + Woods*What_Gathered")
#s[1]
s.append("STATEMENT2 + OldMan*Agt_Went + Went*Verb + Mountain*Where_Went_to + (OldMan*Agt_Gathered + Gathered*Verb + Woods*What_Gathered)*Why_Went")

#a[1]
a.append("OldWoman*Agt_Washed + Washed*Verb + Clothes*What_Washed")
#s[2]
s.append("STATEMENT3 + OldWoman*Agt_Went_to + Went_to*Verb + River*Obj_Went_to + (OldWoman*Agt_Washed + Washed*Verb + Clothes*What_Washed)*Why_Went")

#s[3]
s.append("STATEMENT4 + OldWoman*Agt_Found + Found*Verb + (BigPeach*Agt_Came_floating_down + Came_floating_down*Verb + River*What_Came_floating_down)*What_Found")

#a[2]
a.append("OldWoman*Agt_Took + Took*Verb + BigPeach*What_Took + Home*Where_Took_To")
#s[4]
s.append("STATEMENT5 + OldWoman*Agt_Came + Came*Verb + Home*Where_Came + (OldWoman*Agt_Took + Took*Verb + BigPeach*What_Took + Home*Where_Took_To)*Why_Came")

#a[3],a[4]
a.append("OldWoman*Agt_Cut + Cut*Verb + BigPeach*What_Cut")
a.append("OldWoman*Agt_Began + Began*Verb + (OldWoman*Agt_Cut + Cut*Verb + BigPeach*What_Cut)*What_Began")
#s[5]
s.append("STATEMENT6 + BigBaby*Agt_Came_out + Came_out*Verb + BigPeach*What_Came_out_from + (OldWoman*Agt_Began + Began*Verb + (OldWoman*Agt_Cut + Cut*Verb + BigPeach*What_Cut)*What_Began)*When_Came_out")

#a[5]
a.append("OldMan_and_OldWoman*Agt_Saw + Saw*Verb + (BigBaby*Agt_Came_out + Came_out*Verb + BigPeach*What_Came_out_from + (OldWoman*Agt_Began + Began*Verb + (OldWoman*Agt_Cut + Cut*Verb + BigPeach*What_Cut)*What_Began)*When_Came_out)*What_Saw")
#s[6]
s.append("STATEMENT7 + OldMan_and_OldWoman*Agt + Be_surprised*Verb + (OldMan_and_OldWoman*Agt_Saw + Saw*Verb + (BigBaby*Agt_Came_out + Came_out*Verb + BigPeach*What_Came_out_from + (OldWoman*Agt_Began + Began*Verb + (OldWoman*Agt_Cut +Cut*Verb + BigPeach*What_Cut)*What_Began)*When_Came_out)*What_Saw)*Why_Be_surprised")

#a[6]
a.append("BigBaby*Agt_Was_Born + Was_Born*Verb + Peach*What_Was_Born_from")
#s[7]
s.append("STATEMENT8 + OldMan_and_OldWoman*Agt_Named + Named*Verb + BigBaby*What_Named_to + Momotaro*What_Named + (BigBaby*Agt_Was_Born + Was_Born*Verb + Peach*What_Was_Born_from)*Why_Named")

#s[8]
s.append("STATEMENT9 + Momotaro*Agt_Grew_up + Grew_up*Verb + Strong_and_Kind_boy*What_Grow_up_to")

#a[7]
a.append("A_few_bad_Ogre*Agt_Lived + Lived*Verb + Ogre_Island*Where_Lived_in")
#s[9]
s.append("STATEMENT10 + Momotaro*Agt_Heard + Heard*Verb + (A_few_bad_Ogre*Agt_Lived + Lived*Verb + Ogre_Island*Obj_Lived_in)*What_Heard")

#a[8]
a.append("Momotaro*Agt_Went + Went*Verb + Ogre_Island*Where_Went_to + (Momotaro*Agt_Defeated + Defeated*Verb + Ogres*What_Defeated)*Why_Went")
#s[10]
s.append("STATEMENT11 + Momotaro*Agt_Decided + Decided*Verb + (Momotaro*Agt_Went + Went*Verb + Ogre_Island*Where_Went_to + (Momotaro*Agt_Defeated + Defeated*Verb + Ogres*What_Defeated)*Why_Went)*What_Decided")

#s[11]
s.append("STATEMENT12 + OldMan_and_OldWoman*Agt_Made + Made*Verb + Kibidango*What_Made")

#s[12]
s.append("STATEMENT13 + Momotaro*Agt_Carried + Carried*Verb + Kibidango*What_Carried + Bag*What_Carried_in")

#s[13]
s.append("STATEMENT14 + Momotaro*Agt_Left + Left*Verb + Home*Where_Left")

#s[14]
s.append("STATEMENT15 + Momotaro*Agt_Met + Met*Verb + Dog*What_Met")
#a[9]
a.append("Momotaro*Agt_Gave + Gave*Verb + Kibidango*What_Gave + Dog*Gave_to")
#s[15]
s.append("STATEMENT16 + Dog*Agt_Followed + Followed*Verb + Momotaro*What_Followed + (Momotaro*Agt_Gave + Gave*Verb + Kibidango*What_Gave + Dog*Gave_to)*Why_Followed")

#s[16]
s.append("STATEMENT17 + Momotaro*Agt_Met + Met*Verb + Monkey*What_Met")
#a[10]
a.append("Momotaro*Agt_Gave + Gave*Verb + Kibidango*What_Gave + Monkey*Gave_to")
#s[17]
s.append("STATEMENT18 + Monkey*Agt_Followed + Followed*Verb + Momotaro*What_Followed + (Momotaro*Agt_Gave + Gave*Verb + Kibidango*What_Gave + Monkey*Gave_to)*Why_Followed")

#s[18]
s.append("STATEMENT19 + Momotaro*Agt_Met + Met*Verb + Pheasant*What_Met")
#a[11]
a.append("Momotaro*Agt_Gave + Gave*Verb + Kibidango*What_Gave + Pheasant*Gave_to")
#s[19]
s.append("STATEMENT20 + Pheasant*Agt_Followed + Followed*Verb + Momotaro*What_Followed + (Momotaro*Agt_Gave + Gave*Verb + Kibidango*What_Gave + Pheasant*Gave_to)*Why_Followed")

#s[20]
s.append("STATEMENT21 + Momotaro_and_Dog_and_Monkey_and_Pheasant*Agt_Reached + Reached*Verb + Ogres_Island*Where_Reached")

#s[21]
s.append("STATEMENT22 + BigOgres*Agt_Were + Were*Verb + Ogres_Island*Where_Were_in")

#s[22]
s.append("STATEMENT23 + Momotaro*Agt_Picked_up + Picked_up*Verb + Stone*What_Picked_up")

#s[23]
s.append("STATEMENT24 + Momotaro*Agt_Threw + Threw*Verb + Stone*What_Threw + Ogre*Threw_to")

#s[24]
s.append("STATEMENT25 + Ogres*Agt_Ran_away + Ran_away*Verb")

#s[25]
s.append("STATEMENT26 + Momotaro*Agt_Got + Got*Verb + Many_treasures*What_Got + Ogres_Island*Where_Got")

#s[26]
s.append("STATEMENT27 + Momotaro_and_Dog_and_Monkey_and_Pheasant*Agt_Came + Came*Verb + Home*Where_Came")

#s[27]
s.append("STATEMENT28 + Momotaro_and_OldMan_and_OldWoman*Agt_Lived + Lived*Verb + Happily*Adj_Lived")


for num in range(1,len(s)+1):
    vocab.add('S'+str(num),vocab.parse(s[num-1]).v/np.linalg.norm(vocab.parse(s[num-1]).v))

for num in range(1,len(a)+1):
    vocab.add('A'+str(num),vocab.parse(a[num-1]).v/np.linalg.norm(vocab.parse(a[num-1]).v))


model = spa.SPA(label="Simple question answering",vocabs=[vocab])


with model:
    model.text_in = spa.State(dimensions=D)
    model.question_cue = spa.State(dimensions=D)


    model.memory1 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory2 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory3 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory4 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory5 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory6 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory7 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory8 = spa.State(D, subdimensions=SD,feedback=1, feedback_synapse=0.1)
    model.memory9 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory10 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory11 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory12 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory13 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory14 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory15 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory16 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory17 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory18 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory19 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory20 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory21 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory22 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory23 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory24 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory25 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory26 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory27 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)
    model.memory28 = spa.State(D, subdimensions=SD, feedback=1, feedback_synapse=0.1)

    model.question=spa.State(D,subdimensions=SD)
    model.out = spa.State(dimensions=D,subdimensions=2*SD)

    # Connect the state populations
    cortical_actions1 = spa.Actions(
        'dot(text_in, STATEMENT1) --> memory1=text_in-STATEMENT1',
        'dot(text_in, STATEMENT2) --> memory2=text_in-STATEMENT2',
        'dot(text_in, STATEMENT3) --> memory3=text_in-STATEMENT3',
        'dot(text_in, STATEMENT4) --> memory4=text_in-STATEMENT4',
        'dot(text_in, STATEMENT5) --> memory5=text_in-STATEMENT5',
        'dot(text_in, STATEMENT6) --> memory6=text_in-STATEMENT6',
        'dot(text_in, STATEMENT7) --> memory7=text_in-STATEMENT7',
        'dot(text_in, STATEMENT8) --> memory8=text_in-STATEMENT8',
        'dot(text_in, STATEMENT9) --> memory9=text_in-STATEMENT9',
        'dot(text_in, STATEMENT10) --> memory10=text_in-STATEMENT10',
        'dot(text_in, STATEMENT11) --> memory11=text_in-STATEMENT11',
        'dot(text_in, STATEMENT12) --> memory12=text_in-STATEMENT12',
        'dot(text_in, STATEMENT13) --> memory13=text_in-STATEMENT13',
        'dot(text_in, STATEMENT14) --> memory14=text_in-STATEMENT14',
        'dot(text_in, STATEMENT15) --> memory15=text_in-STATEMENT15',
        'dot(text_in, STATEMENT16) --> memory16=text_in-STATEMENT16',
        'dot(text_in, STATEMENT17) --> memory17=text_in-STATEMENT17',
        'dot(text_in, STATEMENT18) --> memory18=text_in-STATEMENT18',
        'dot(text_in, STATEMENT19) --> memory19=text_in-STATEMENT19',
        'dot(text_in, STATEMENT20) --> memory20=text_in-STATEMENT20',
        'dot(text_in, STATEMENT21) --> memory21=text_in-STATEMENT21',
        'dot(text_in, STATEMENT22) --> memory22=text_in-STATEMENT22',
        'dot(text_in, STATEMENT23) --> memory23=text_in-STATEMENT23',
        'dot(text_in, STATEMENT24) --> memory24=text_in-STATEMENT24',
        'dot(text_in, STATEMENT25) --> memory25=text_in-STATEMENT25',
        'dot(text_in, STATEMENT26) --> memory26=text_in-STATEMENT26',
        'dot(text_in, STATEMENT27) --> memory27=text_in-STATEMENT27',
        'dot(text_in, STATEMENT28) --> memory28=text_in-STATEMENT28',
        'dot(text_in,QUESTION) --> question=text_in-QUESTION'
        )
    model.bg1 = spa.BasalGanglia(cortical_actions1)
    model.thalamus1 = spa.Thalamus(model.bg1)

    cortical_actions2=spa.Actions(
        'dot(question_cue, S1) --> out = memory1*~question',
        'dot(question_cue, S2) --> out = memory2*~question',
        'dot(question_cue, S3) --> out = memory3*~question',
        'dot(question_cue, S4) --> out = memory4*~question',
        'dot(question_cue, S5) --> out = memory5*~question',
        'dot(question_cue, S6) --> out = memory6*~question',
        'dot(question_cue, S7) --> out = memory7*~question',
        'dot(question_cue, S8) --> out = memory8*~question',
        'dot(question_cue, S9) --> out = memory9*~question',
        'dot(question_cue,S10) --> out = memory10*~question',
        'dot(question_cue,S11) --> out = memory11*~question',
        'dot(question_cue,S12) --> out = memory12*~question',
        'dot(question_cue,S13) --> out = memory13*~question',
        'dot(question_cue,S14) --> out = memory14*~question',
        'dot(question_cue,S15) --> out = memory15*~question',
        'dot(question_cue,S16) --> out = memory16*~question',
        'dot(question_cue,S17) --> out = memory17*~question',
        'dot(question_cue,S18) --> out = memory18*~question',
        'dot(question_cue,S19) --> out = memory19*~question',
        'dot(question_cue,S20) --> out = memory20*~question',
        'dot(question_cue,S21) --> out = memory21*~question',
        'dot(question_cue,S22) --> out = memory22*~question',
        'dot(question_cue,S23) --> out = memory23*~question',
        'dot(question_cue,S24) --> out = memory24*~question',
        'dot(question_cue,S25) --> out = memory25*~question',
        'dot(question_cue,S26) --> out = memory26*~question',
        'dot(question_cue,S27) --> out = memory27*~question',
        'dot(question_cue,S28) --> out = memory28*~question'
    )
    model.bg2 = spa.BasalGanglia(cortical_actions2)
    model.thalamus2 = spa.Thalamus(model.bg2)


def text_input(t):
    if t < st:
        return s[0]
    elif t < 2*st:
        return s[1]
    elif t < 3*st:
        return s[2]
    elif t < 4*st:
        return s[3]
    elif t < 5*st:
        return s[4]
    elif t < 6*st:
        return s[5]
    elif t < 7*st:
        return s[6]
    elif t < 8*st:
        return s[7]
    elif t < 9*st:
        return s[8]
    elif t < 10*st:
        return s[9]
    elif t < 11*st:
        return s[10]
    elif t < 12*st:
        return s[11]
    elif t < 13*st:
        return s[12]
    elif t < 14*st:
        return s[13]
    elif t < 15*st:
        return s[14]
    elif t < 16*st:
        return s[15]
    elif t < 17*st:
        return s[16]
    elif t < 18*st:
        return s[17]
    elif t < 19*st:
        return s[18]
    elif t < 20*st:
        return s[19]
    elif t < 21*st:
        return s[20]
    elif t < 22*st:
        return s[21]
    elif t < 23*st:
        return s[22]
    elif t < 24*st:
        return s[23]
    elif t < 25*st:
        return s[24]
    elif t < 26*st:
        return s[25]
    elif t < 27*st:
        return s[26]
    elif t < 28*st:
        return s[27]
    elif t < 29*st:
        return 'QUESTION+Where_Lived_in'
    elif t < 30*st:
        return 'QUESTION+Why_Named'
    elif t < 31*st:
        return 'QUESTION+Why_Followed*What_Gave'
    else:
        return 'ZERO'


def question_cue_input(t):
    if t < 28*st:
        return 'ZERO'
    elif t < 29*st:
        return 'OldMan_and_OldWoman*Agt_Lived+Lived*Verb'
    elif t < 30*st:
        return 'OldMan_and_OldWoman*Agt_Named+Named*Verb+BigBaby*What_Named_to +Momotaro*What_Named'
    elif t < 31*st:
        return "Monkey*Agt_Followed+Followed*Verb+Momotaro*What_Followed"
    else:
        return 'ZERO'


with model:
    model.inp = spa.Input(text_in=text_input, question_cue=question_cue_input)


with model:
    model.config[nengo.Probe].synapse = nengo.Lowpass(0.03)
    text_in = nengo.Probe(model.text_in.output)
    question = nengo.Probe(model.question.output)
    question_cue = nengo.Probe(model.question_cue.output)
    memory1 = nengo.Probe(model.memory1.output)
    memory2 = nengo.Probe(model.memory2.output)
    memory3 = nengo.Probe(model.memory3.output)
    memory4 = nengo.Probe(model.memory4.output)
    memory5 = nengo.Probe(model.memory5.output)
    memory6 = nengo.Probe(model.memory6.output)
    memory7 = nengo.Probe(model.memory7.output)
    memory8 = nengo.Probe(model.memory8.output)
    memory9 = nengo.Probe(model.memory9.output)
    memory10 = nengo.Probe(model.memory10.output)
    memory11 = nengo.Probe(model.memory11.output)
    memory12 = nengo.Probe(model.memory12.output)
    memory13 = nengo.Probe(model.memory13.output)
    memory14 = nengo.Probe(model.memory14.output)
    memory15 = nengo.Probe(model.memory15.output)
    memory16 = nengo.Probe(model.memory16.output)
    memory17 = nengo.Probe(model.memory17.output)
    memory18 = nengo.Probe(model.memory18.output)
    memory19 = nengo.Probe(model.memory19.output)
    memory20 = nengo.Probe(model.memory20.output)
    memory21 = nengo.Probe(model.memory21.output)
    memory22 = nengo.Probe(model.memory22.output)
    memory23 = nengo.Probe(model.memory23.output)
    memory24 = nengo.Probe(model.memory24.output)
    memory25 = nengo.Probe(model.memory25.output)
    memory26 = nengo.Probe(model.memory26.output)
    memory27 = nengo.Probe(model.memory27.output)
    memory28 = nengo.Probe(model.memory28.output)
    out = nengo.Probe(model.out.output)

print('Probes are done at ')
probe_time=time.time()-start
print(probe_time)

with nengo_ocl.Simulator(model) as sim:
    sim.run(6.2)

sim_time=time.time()-probe_time
print(sim_time)

I used AWS EC2 (and nengo.Simulator) before, but I use nengo_ocl.Simulator. When I run this code, AssertionError was appeared.

Traceback (most recent call last):
  File "spa_q_and_a.py", line 368, in <module>
    with nengo_ocl.Simulator(model) as sim:
  File "/home/iwao/anaconda3/lib/python3.6/site-packages/nengo_ocl/simulator.py", line 275, in __init__
    dtype=np.float32)
  File "/home/iwao/anaconda3/lib/python3.6/site-packages/nengo_ocl/raggedarray.py", line 55, in __init__
    self.starts = starts
  File "/home/iwao/anaconda3/lib/python3.6/site-packages/nengo_ocl/raggedarray.py", line 113, in starts
    assert np.all(self.starts >= 0)
AssertionError

I examined this error.I found the difference between nengo.Simulator and nengo_ocl.Simulator is that the later has raggedarray.py but the former doesn’t.

As the error shows, I printed “self.starts” of “assert np.all(self.starts >= 0)” in raggedarray.py.

[ 0 1 2 ... -256094452 -250334452 -244574452]

I confirmed “np.all(self.starts >= 0) is False”, but I couldn’t understand what this means.
Does anyone know? Thanks.

I think the problem is that you’re running out of memory. The dimensionality of your pointers is very high (2400). We typically don’t go above 512 in our models.

The starts attribute tracks the memory offset for each element of the array. It looks like you’re getting an overflow there, i.e. the sizes of the individual arrays are so large that the offset grows larger than the max value for an int32 (2**31), so you end up with negative values.

Right now, I’m only using int32s to store these values, which could theoretically be limiting (I think it should allow 8 GB of memory, and some cards are larger than that these days). However, there are a few other problems that I’d also have to solve to allow models that large, which are a bit more involved than just changing the datatype.

So I think for now, you’ll just have to make your model a bit smaller. I would guess that you don’t actually need D=2400 for your model to work, I think D=512 should be fine.

I set my pointer to 512 and I could run my model successfully even though noise increased. As you said, high dimensionality caused the error.
Thanks.