{"action":"created","issue":{"url":"https://api.github.com/repos/nengo/nengo/issues/790","labels_url":"https://api.github.com/repos/nengo/nengo/issues/790/labels{/name}","comments_url":"https://api.github.com/repos/nengo/nengo/issues/790/comments","events_url":"https://api.github.com/repos/nengo/nengo/issues/790/events","html_url":"https://github.com/nengo/nengo/issues/790","id":95265563,"number":790,"title":"Standardizing when, when not, and where to use the config system","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":8,"created_at":"2015-07-15T18:58:49Z","updated_at":"2015-07-15T20:44:12Z","closed_at":null,"body":"I'm trying to reorganize the associative memory network code to take full use of the config system (for an example see: [link](https://github.com/nengo/nengo/issues/780#issuecomment-120173547)). The idea being that if you don't specify a configuration, the network will build using whatever defaults the network designer (i.e. me) has put in, and if you do specify a configuration, it will use the configuration given.\r\n\r\nIn the examples below, the 'defaults' for the custom network are: max_rates=Uniform(10, 50), and encoders=Choice([[1]]). These can be overridden by the user.\r\n\r\n<hr>\r\nMethod 1 (the 'old' way of doing it) - Put in all the possible changes to the network in the function definition:\r\n```\r\ndef my_net(max_rates=Uniform(10, 50), encoders=Choice([[1]])):\r\n    ... # Make the network\r\n    with network:\r\n        ens = nengo.Ensemble(..., max_rates=max_rates, encoders=encoders)\r\n    ... # make the rest of the network\r\n```\r\n<hr>\r\nMethod 2 (using kwargs, and modifying the dictionary) - Used in the current AssociativeMemory code:\r\n```\r\ndef my_net(**ens_kwargs):\r\n    ... # Make the network\r\n    with network:\r\n        e_kwargs = dict(ens_kwargs)\r\n        e_kwargs['max_rates'] = ens_kwargs.get('max_rates', Uniform(10, 50))\r\n        e_kwargs['encoders'] = ens_kwargs.get('encoders', Choice([[1]]))\r\n        ens = nengo.Ensemble(**e_kwargs)\r\n    ... # make the rest of the network\r\n```\r\n<hr>\r\nMethod 3 (using kwargs, and updating the config) - Used in EnsembleArray:\r\n```\r\ndef my_net(**ens_kwargs):\r\n    ... # Make the network\r\n    with network:\r\n        network.config[nengo.Ensemble].update(ens_kwargs)\r\n        ens = nengo.Ensemble(...)     \r\n    ... # make the rest of the network\r\n```\r\n<hr>\r\nMethod 4 (pass in the config to use) - Used in Product:\r\n```\r\ndef my_net(config=None):\r\n    ... # Make the network\r\n\r\n    if config is None:\r\n        config = nengo.Config(nengo.Ensemble)\r\n        config[nengo.Ensemble].max_rates = Uniform(10, 50)\r\n        config[nengo.Ensemble].encoders = Choice([[1]])\r\n\r\n    with nested(config, network):\r\n        ens = nengo.Ensemble(...)     \r\n    ... # make the rest of the network\r\n```\r\nAlternatively, I think this will work?\r\n```\r\ndef my_net(config=None):\r\n    ... # Make the network\r\n\r\n    if config is None:\r\n        config = nengo.Config()\r\n\r\n    my_config = nengo.Config(nengo.Ensemble)\r\n    my_config[nengo.Ensemble].max_rates = Uniform(10, 50)\r\n    my_config[nengo.Ensemble].encoders = Choice([[1]])\r\n\r\n    with nested(my_config, config, network):\r\n        ens = nengo.Ensemble(...)     \r\n    ... # make the rest of the network\r\n```\r\n** Sneak edit: corrected ```nested(config, my_config, network)``` to ```nested(my_config, config, network)```\r\n** Sneak edit 2: Added case where config is None.\r\n<hr>\r\nMethod 5 (use the config from the parent network) - Used in BasalGanglia:\r\n```\r\ndef my_net(net=None):\r\n    ... # Make the network\r\n\r\n    config = nengo.Config(nengo.Ensemble)\r\n    config[nengo.Ensemble].max_rates = Uniform(10, 50)\r\n    config[nengo.Ensemble].encoders = Choice([[1]])\r\n    \r\n    with nested(config, net):\r\n        ens = nengo.Ensemble(...)\r\n    ... # make the rest of the network\r\n```\r\n\r\nWhat is the 'standard' way of doing something like this?"},"comment":{"url":"https://api.github.com/repos/nengo/nengo/issues/comments/121741563","html_url":"https://github.com/nengo/nengo/issues/790#issuecomment-121741563","issue_url":"https://api.github.com/repos/nengo/nengo/issues/790","id":121741563,"user":{"login":"drasmuss","id":1952220,"avatar_url":"https://avatars.githubusercontent.com/u/1952220?v=3","gravatar_id":"","url":"https://api.github.com/users/drasmuss","html_url":"https://github.com/drasmuss","followers_url":"https://api.github.com/users/drasmuss/followers","following_url":"https://api.github.com/users/drasmuss/following{/other_user}","gists_url":"https://api.github.com/users/drasmuss/gists{/gist_id}","starred_url":"https://api.github.com/users/drasmuss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drasmuss/subscriptions","organizations_url":"https://api.github.com/users/drasmuss/orgs","repos_url":"https://api.github.com/users/drasmuss/repos","events_url":"https://api.github.com/users/drasmuss/events{/privacy}","received_events_url":"https://api.github.com/users/drasmuss/received_events","type":"User","site_admin":false},"created_at":"2015-07-15T20:44:12Z","updated_at":"2015-07-15T20:44:12Z","body":"Wait nevermind I think you're right, I was just wrong about which order the `nested` parameters are evaluated in.  To be explicit, what we want is\r\n```\r\nwith my_config:\r\n    with config:\r\n        with network:\r\n            ....\r\n```\r\nI think we're on the same page.  Also i think you can just write it as `with config, my_config, network:` right?"}}