ctn-waterloo/nengo_spinnaker — pull request #32 by mundya (2014-05-15 13:51:11+00:00)
Title: Refactored Vertices

- [x] Refactor the Vertex code to reduce duplication of PACMAN boilerplate.
- Regions are defined at the start of a vertex.
- Region methods (`pre_sizeof`, `sizeof`, `write`, `pre_prepare` and `post_prepare` [pre- and post- refer to partitioning and mapping]) are marked with decorators. **Functions `pre_sizeof` and `write` are mandatory**.
- [x] Added a fixed point library for Python with `bitsk` taking a float and returning a fixpoint, and `kbits` taking a fixpoint and return a float. (Thanks @tcstewar!)
- [x] Filters can be attached to a Vertex with a decorator (arguments are the region IDs for filter parameters and filter routing entries).
- [ ] Refactor the filter code so that filters are generated and routed later in the build process (in a `post_prepare` function.
- [ ] Refactor the Ensemble code to move Decoder management inside

```python
from utils import filters, vertices

@filters.with_filters(3, 4)
class MyNewVertex(vertices.NengoVertex):
"""A sample NengoVertex with 4 regions:
1. System
2. ...
3. Filters
4. Filter routing

Application executable (APLX) will be expected to be found as "nengo_myvx.aplx" in the `binaries`
directory inside the nengo_spinnaker package.
"""
REGIONS = vertices.ordered_regions('SYSTEM', '...')
MODEL_NAME = "nengo_myvx"

@vertices.region_pre_sizeof('SYSTEM')
def region_pre_sizeof_system(self, n_atoms):
"""Size of the system prior to partitioning.

:param n_atoms: number of atoms in the proposed subvertex
"""
return 1 # Return the desired number of words

@vertices.region_sizeof('SYSTEM')
def region_sizeof_system(self, subvertex):
pass

@vertices.region_pre_prepare('SYSTEM')
def region_pre_prep_system(self):
pass

@vertices.region_post_prepare('SYSTEM')
def region_post_prep_system(self):
pass

@vertices.region_write('SYSTEM')pass
def region_write_system(self, subvertex, spec):
"""Write the given region for the given subvertex in the given spec file.

*The subvertex will _already_ have been switched to the appropriate
region.*
"""
spec.write(data=...)

# Functions will be required for other regions...
```