{"action":"created","issue":{"url":"https://api.github.com/repos/nengo/nengo/issues/784","labels_url":"https://api.github.com/repos/nengo/nengo/issues/784/labels{/name}","comments_url":"https://api.github.com/repos/nengo/nengo/issues/784/comments","events_url":"https://api.github.com/repos/nengo/nengo/issues/784/events","html_url":"https://github.com/nengo/nengo/issues/784","id":94416669,"number":784,"title":"Working with read-only vocabularies have unintended side effects","user":{"login":"xchoo","id":1971583,"avatar_url":"https://avatars.githubusercontent.com/u/1971583?v=3","gravatar_id":"","url":"https://api.github.com/users/xchoo","html_url":"https://github.com/xchoo","followers_url":"https://api.github.com/users/xchoo/followers","following_url":"https://api.github.com/users/xchoo/following{/other_user}","gists_url":"https://api.github.com/users/xchoo/gists{/gist_id}","starred_url":"https://api.github.com/users/xchoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xchoo/subscriptions","organizations_url":"https://api.github.com/users/xchoo/orgs","repos_url":"https://api.github.com/users/xchoo/repos","events_url":"https://api.github.com/users/xchoo/events{/privacy}","received_events_url":"https://api.github.com/users/xchoo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":24,"created_at":"2015-07-11T00:08:30Z","updated_at":"2015-07-13T03:28:28Z","closed_at":null,"body":"As a workaround to #699 and #731, PR #699 implements subvocabularies as read-only vocabularies. However, this poses a problem when trying to use spa modules that use these subvocabularies (the associative memory module, for example).\r\n\r\n```\r\n# Using the spa_subvocab branch\r\nvocab = spa.Vocabulary(32)\r\nvocab.parse('A+B+C')\r\nsubvocab = vocab.create_subset(['A'])\r\n\r\nwith spa.SPA() as model:\r\n    model.buff = spa.Buffer(32)\r\n    model.am = spa.AssociativeMemory(subvocab)\r\n\r\n    ctx_actions = spa.Actions('buff=am * C')\r\n    model.cortical = spa.Cortical(ctx_actions)\r\n```\r\n\r\nThe above code throws the following error: ```ValueError: Cannot add semantic pointer 'C' to read-only vocabulary.```. This is because (as intended), the spa code is looking for ```C``` in ```model.am```'s vocabulary, and since that vocabulary is a subset vocabulary, it: 1) can't find ```C```, 2) can't add ```C``` because it is read only.\r\n\r\nOne solution is to apply the vocabulary operations (looking for a semantic pointer, adding a semantic pointer) to a vocabulary's parent vocab if it is read only.\r\n\r\nThe current solution to the above problem is to insert a buffer after the associative memory:\r\n```\r\nwith spa.SPA() as model:\r\n    model.buff = spa.Buffer(32)\r\n    model.am = spa.AssociativeMemory(subvocab)\r\n    model.am_out = spa.Buffer(32)\r\n\r\n    ctx_actions = spa.Actions('am_out=am', 'buff=am_out * C')\r\n    model.cortical = spa.Cortical(ctx_actions)\r\n```"},"comment":{"url":"https://api.github.com/repos/nengo/nengo/issues/comments/120797783","html_url":"https://github.com/nengo/nengo/issues/784#issuecomment-120797783","issue_url":"https://api.github.com/repos/nengo/nengo/issues/784","id":120797783,"user":{"login":"xchoo","id":1971583,"avatar_url":"https://avatars.githubusercontent.com/u/1971583?v=3","gravatar_id":"","url":"https://api.github.com/users/xchoo","html_url":"https://github.com/xchoo","followers_url":"https://api.github.com/users/xchoo/followers","following_url":"https://api.github.com/users/xchoo/following{/other_user}","gists_url":"https://api.github.com/users/xchoo/gists{/gist_id}","starred_url":"https://api.github.com/users/xchoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xchoo/subscriptions","organizations_url":"https://api.github.com/users/xchoo/orgs","repos_url":"https://api.github.com/users/xchoo/repos","events_url":"https://api.github.com/users/xchoo/events{/privacy}","received_events_url":"https://api.github.com/users/xchoo/received_events","type":"User","site_admin":false},"created_at":"2015-07-13T03:28:28Z","updated_at":"2015-07-13T03:28:28Z","body":"Oh. I didn't mean to actually strip them out. I meant that the processing of the constants will have to be handled differently.\r\n\r\nE.g. for ```buff1 * C * buff2``` the code would have to build the network for ```buff1 * buff2``` first (i.e. stripping out the constant), and then on the transform to ```buff3``` to the ```transform_to``` thing.\r\n"}}