Changeset 450

Show
Ignore:
Timestamp:
08/20/10 18:14:40 (18 months ago)
Author:
emuller
Message:

First prototype of architecture for ParameterSet validation against a schema ... no validation yet, and still some bugs ...

Location:
branches/parameter_set_schema_validation
Files:
3 added
1 modified
1 moved

Legend:

Unmodified
Added
Removed
  • branches/parameter_set_schema_validation/setup.py

    r400 r450  
    1414                'NeuroTools.spike2.sonpy', 
    1515                'NeuroTools.datastore', 
     16                'NeuroTools.parameters', 
    1617                'NeuroTools.datastore.django_orm', 
    1718               ], 
  • branches/parameter_set_schema_validation/src/parameters/__init__.py

    r439 r450  
    99 
    1010Parameter 
    11 ParameterRange - for specifying a list of possible values for a given parameter. 
    12 ParameterSet   - for representing/managing hierarchical parameter sets. 
    13 ParameterTable - a sub-class of ParameterSet that can represent a table of parameters. 
    14 ParameterSpace - a collection of ParameterSets, representing multiple points in 
    15                  parameter space. 
     11ParameterRange  - for specifying a list of possible values for a given parameter. 
     12ParameterSet    - for representing/managing hierarchical parameter sets. 
     13ParameterTable  - a sub-class of ParameterSet that can represent a table of parameters. 
     14ParameterSpace  - a collection of ParameterSets, representing multiple points in 
     15                  parameter space. 
     16ParameterSchema - a sub-class of ParameterSet, which may also contain  
     17 
     18 
    1619 
    1720Functions 
     
    2831from NeuroTools import check_dependency 
    2932from NeuroTools.random import ParameterDist, GammaDist, UniformDist, NormalDist 
    30  
     33#from NeuroTools.parameters.validators import schema_checkers_namespace 
     34#from NeuroTools.parameters.validators import Subclass 
    3135 
    3236def isiterable(x): 
     
    159163     
    160164    @staticmethod 
    161     def read_from_str(s): 
     165    def read_from_str(s,update_namespace=None): 
    162166        """ 
    163167        ParameterSet definition s should be a Python dict definition 
     
    185189                                UniformDist=UniformDist, 
    186190                                NormalDist=NormalDist, 
    187                                 pi=numpy.pi))             
     191                                pi=numpy.pi)) 
     192        if update_namespace: 
     193            global_dict.update(update_namespace) 
     194 
    188195        try: 
    189196            D = eval(s, global_dict) 
     
    197204            raise Exception("'%s' is not allowed as a parameter name." % k) 
    198205     
    199     def __init__(self, initialiser, label=None): 
    200          
     206    def __init__(self, initialiser, label=None, update_namespace=None): 
     207 
    201208        def walk(d, label): 
    202209            # Iterate through the dictionary `d`, replacing `dict`s by 
     
    228235                f.close() 
    229236 
    230             initialiser = ParameterSet.read_from_str(pstr) 
     237            initialiser = ParameterSet.read_from_str(pstr,update_namespace) 
    231238         
    232239        # By this stage, `initialiser` should be a dict. Iterate through it, 
     
    243250                    self[k] = v 
    244251        else: 
    245             raise TypeError("`initialiser` must be a `dict`, a `ParameterSet` object or a valid URL") 
    246                      
     252            raise TypeError("`initialiser` must be a `dict`, a `ParameterSet` object, a string, or a valid URL") 
     253 
    247254        # Set the label 
    248255        if hasattr(initialiser, 'label'): 
     
    256263        self.names = self.keys 
    257264        self.parameters = self.items 
     265 
    258266         
    259267    def flat(self): 
     
    298306        else: 
    299307            # nested set 
    300             dict.__getitem__(self,split[0])[split[1]]=value 
     308            try: 
     309                dict.__getitem__(self,split[0])[split[1]]=value 
     310            except KeyError: 
     311                # setting nested name without parent existing 
     312                # create parent 
     313                dict.__setitem__(self,split[0],{}) 
     314                # and try again 
     315                dict.__getitem__(self,split[0])[split[1]]=value 
    301316    
    302317    # should __len__() be the usual dict length, or the flattened length? Probably the former for consistency with dicts