Example #1
0
 def check_spike_monitor(self, res, monitor):
     self.assertTrue(comp.nested_equal(monitor.num_spikes, res.num_spikes))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
     self.assertEqual(monitor.name,res.name)
     self.assertTrue(comp.nested_equal(monitor.t[:], res.t))
     self.assertTrue(comp.nested_equal(monitor.i[:], res.i))
     for idx, varname in enumerate(monitor.record_variables):
         self.assertTrue(comp.nested_equal(getattr(monitor, varname)[:], res.f_get(varname)))
Example #2
0
 def check_spike_monitor(self, res, monitor):
     self.assertTrue(comp.nested_equal(monitor.num_spikes, res.num_spikes))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
     self.assertEqual(monitor.name, res.name)
     self.assertTrue(comp.nested_equal(monitor.t[:], res.t))
     self.assertTrue(comp.nested_equal(monitor.i[:], res.i))
     for idx, varname in enumerate(monitor.record_variables):
         self.assertTrue(
             comp.nested_equal(
                 getattr(monitor, varname)[:], res.f_get(varname)))
Example #3
0
    def test_get_annotations(self):
        key_list = sorted(self.annotations.keys())
        for node in self.traj.f_iter_nodes(recursive=True):
            for name in self.annotations:
                self.assertTrue(comp.nested_equal(self.annotations[name],
                                                  node.f_get_annotations(name)))

            val_list = node.f_get_annotations(*key_list)

            for idx, val in enumerate(val_list):
                self.assertTrue(comp.nested_equal(self.annotations[key_list[idx]], val))
Example #4
0
    def test_get_annotations(self):
        key_list = list(self.annotations.keys())
        for node in self.traj.f_iter_nodes(recursive=True):
            for name in self.annotations:
                self.assertTrue(
                    comp.nested_equal(self.annotations[name],
                                      node.f_get_annotations(name)))

            val_list = node.f_get_annotations(*key_list)

            for idx, val in enumerate(val_list):
                self.assertTrue(
                    comp.nested_equal(self.annotations[key_list[idx]], val))
Example #5
0
    def check_multi_state_monitor(self, res, monitor):
        self.assertEqual(monitor.vars, res.vars)

        if len(monitor.times)>0:
            self.assertEqual('second', res.times_unit)
            self.assertTrue(comp.nested_equal(monitor.times, res.times))




        for idx, varname in enumerate(monitor.vars):
            mon = monitor.monitors[varname]
            self.assertTrue(comp.nested_equal(mon.record, res.record))

            self.assertTrue(comp.nested_equal(mon.when, res.when))

            self.assertEqual(mon.timestep, res.timestep)
            self.assertTrue(comp.nested_equal(str(mon.P), res.source))

            if hasattr(res, varname+'_mean'):
                self.assertTrue(comp.nested_equal(mon.mean, res.f_get(varname+'_mean')))
                self.assertTrue(comp.nested_equal(mon.var, res.f_get(varname+'_var')))
            if len(monitor.times)>0:
                self.assertTrue(comp.nested_equal(mon.values, res.f_get(varname+'_values')))

            self.assertTrue(comp.nested_equal(repr(mon.unit), res.f_get(varname+'_unit')))
Example #6
0
    def check_multi_state_monitor(self, res, monitor):
        self.assertEqual(monitor.vars, res.vars_)

        if len(monitor.times) > 0:
            self.assertEqual('second', res.times_unit)
            self.assertTrue(comp.nested_equal(monitor.times, res.times))

        for idx, varname in enumerate(monitor.vars):
            mon = monitor.monitors[varname]
            self.assertTrue(comp.nested_equal(mon.record, res.record))

            self.assertTrue(comp.nested_equal(mon.when, res.when))

            self.assertEqual(mon.timestep, res.timestep)
            self.assertTrue(comp.nested_equal(str(mon.P), res.source))

            if hasattr(res, varname + '_mean'):
                self.assertTrue(
                    comp.nested_equal(mon.mean, res.f_get(varname + '_mean')))
                self.assertTrue(
                    comp.nested_equal(mon.var, res.f_get(varname + '_var')))
            if len(monitor.times) > 0:
                self.assertTrue(
                    comp.nested_equal(mon.values,
                                      res.f_get(varname + '_values')))

            self.assertTrue(
                comp.nested_equal(repr(mon.unit),
                                  res.f_get(varname + '_unit')))
Example #7
0
 def test_get_data(self):
     for res in self.results.values():
         if len(res._data)==1:
             val1=res.data
             val2=res.f_get()
             self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
             val3=res['data']
             self.assertTrue(comp.nested_equal(val3,val2), '%s != %s' % (str(val3),str(val2)))
         else:
             with self.assertRaises(AttributeError):
                 res.data
             with self.assertRaises(AttributeError):
                 res['data']
             with self.assertRaises(ValueError):
                 res.f_get()
Example #8
0
    def check_state_monitor(self, res, monitor):
        self.assertEqual(monitor.record_variables, res.record_variables)
        self.assertEqual(monitor.name,res.name)

        times=np.array(monitor.t)
        if len(times)>0:
            self.assertTrue(comp.nested_equal(times, res.t))


        for idx, varname in enumerate(monitor.record_variables):
            self.assertTrue(comp.nested_equal(monitor.record, res.record))
            self.assertTrue(comp.nested_equal(monitor.when, res.when))
            self.assertTrue(comp.nested_equal(str(monitor.source), res.source))

            self.assertTrue(comp.nested_equal(getattr(monitor, varname), res.f_get(varname)))
 def test_get_data(self):
     for res in self.results.values():
         if len(res._data)==1:
             val1=res.data
             val2=res.f_get()
             self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
             val3=res['data']
             self.assertTrue(comp.nested_equal(val3,val2), '%s != %s' % (str(val3),str(val2)))
         else:
             with self.assertRaises(AttributeError):
                 res.data
             with self.assertRaises(AttributeError):
                 res['data']
             with self.assertRaises(ValueError):
                 res.f_get()
Example #10
0
    def check_state_monitor(self, res, monitor):
        self.assertEqual(monitor.record_variables, res.record_variables)
        self.assertEqual(monitor.name, res.name)

        times = np.array(monitor.t)
        if len(times) > 0:
            self.assertTrue(comp.nested_equal(times, res.t))

        for idx, varname in enumerate(monitor.record_variables):
            self.assertTrue(comp.nested_equal(monitor.record, res.record))
            self.assertTrue(comp.nested_equal(monitor.when, res.when))
            self.assertTrue(comp.nested_equal(str(monitor.source), res.source))

            self.assertTrue(
                comp.nested_equal(getattr(monitor, varname),
                                  res.f_get(varname)))
Example #11
0
 def test_get_item(self):
     for paramname in self.explore_dict:
         param = self.param[paramname]
         val1 = param.f_get_range()[1]
         val2 = param[1]
         self.assertTrue(comp.nested_equal(val1, val2),
                         '%s != %s' % (str(val1), str(val2)))
Example #12
0
    def test_annotations_insert(self):

        for node in self.traj.f_iter_nodes(recursive=True):
            for name in self.annotations:
                anno = self.annotations[name]
                node_anno = node.v_annotations[name]
                self.assertTrue(comp.nested_equal(anno, node_anno),
                                                  '%s != %s' % (str(anno), str(node_anno)))
Example #13
0
    def test_cartesian_product(self):

        cartesian_dict=cartesian_product({'param1':[1,2,3], 'param2':[42.0, 52.5]},
                                          ('param1','param2'))
        result_dict = {'param1':[1,1,2,2,3,3],'param2': [42.0,52.5,42.0,52.5,42.0,52.5]}

        self.assertTrue(nested_equal(cartesian_dict,result_dict), '%s != %s' %
                                                        (str(cartesian_dict),str(result_dict)))
Example #14
0
    def test_annotations_insert(self):

        for idx,node in \
                enumerate([self.traj] + [node for node in self.traj.f_iter_nodes(recursive=True)]):
            for name in self.annotations:
                anno = self.annotations[name]
                node_anno = node.v_annotations[name]
                self.assertTrue(comp.nested_equal(anno, node_anno),
                                '%s != %s' % (str(anno), str(node_anno)))
Example #15
0
    def test_cartesian_product_combined_params(self):
        cartesian_dict=cartesian_product( {'param1': [42.0, 52.5], 'param2':['a', 'b'],\
            'param3' : [1,2,3]}, (('param3',),('param1', 'param2')))

        result_dict={'param3':[1,1,2,2,3,3],'param1' : [42.0,52.5,42.0,52.5,42.0,52.5],
                      'param2':['a','b','a','b','a','b']}

        self.assertTrue(nested_equal(cartesian_dict,result_dict), '%s != %s' %
                                                    (str(cartesian_dict),str(result_dict)))
Example #16
0
    def compare_trajectories(self,traj1,traj2):

        trajlength = len(traj1)

        if 'results.runs' in traj1:
            rungroups = traj1.results.runs.f_children()
        else:
            rungroups = 1

        self.assertEqual(trajlength, rungroups, 'len of traj1 is %d, rungroups %d' % (trajlength, rungroups))

        old_items = to_dict_wo_config(traj1)
        new_items = to_dict_wo_config(traj2)

        self.assertEqual(len(traj1),len(traj2), 'Length unequal %d != %d.' % (len(traj1), len(traj2)))

        self.assertEqual(len(old_items),len(new_items))
        for key,item in new_items.items():
            old_item = old_items[key]

            if isinstance(item, BaseParameter):
                self.assertTrue(parameters_equal(item,old_item),
                                'For key %s: %s not equal to %s' %(key,str(old_item),str(item)))
            elif isinstance(item,BaseResult):
                self.assertTrue(results_equal(item, old_item),
                                'For key %s: %s not equal to %s' %(key,str(old_item),str(item)))
            else:
                raise RuntimeError('You shall not pass')

            self.assertTrue(nested_equal(item.v_annotations,old_item.v_annotations),'%s != %s' %
                        (item.v_annotations.f_ann_to_str(),old_item.v_annotations.f_ann_to_str()))

        # Check the annotations
        for node in traj1.f_iter_nodes(recursive=True):

            if (not 'run' in node.v_full_name) or 'run_00000000' in node.v_full_name:
                if node.v_comment != '' and node.v_full_name in traj2:
                    second_comment = traj2.f_get(node.v_full_name).v_comment
                    self.assertEqual(node.v_comment, second_comment, '%s != %s, for %s' %
                                                                     (node.v_comment, second_comment, node.v_full_name))

            if not node.v_annotations.f_is_empty():
                second_anns = traj2.f_get(node.v_full_name).v_annotations
                self.assertTrue(nested_equal(node.v_annotations, second_anns))
Example #17
0
    def check_spike_monitor(self, res, monitor):
        self.assertTrue(comp.nested_equal(monitor.delay, res.delay))
        self.assertTrue(comp.nested_equal(monitor.nspikes, res.nspikes))
        self.assertTrue(comp.nested_equal(str(monitor.source), res.source))

        self.assertEqual('second', res.spiketimes_unit)

        if res.v_storage_mode == BrianMonitorResult.TABLE_MODE:
            spike_frame = res.spikes
            spiked_list = sorted(
                list(set(spike_frame['neuron'].to_dict().values())))
            self.assertEqual(spiked_list, res.neurons_with_spikes)
            for idx, val_tuple in enumerate(monitor.spikes):
                neuron = val_tuple[0]
                time = val_tuple[1]
                vals = val_tuple[2:]

                self.assertEqual(neuron, spike_frame['neuron'][idx])

                self.assertEqual(float(time), spike_frame['spiketimes'][idx])

        elif res.v_storage_mode == BrianMonitorResult.ARRAY_MODE:

            self.assertTrue('%0' in res.format_string
                            and 'd' in res.format_string)

            spiked_set = set()
            for item_name in res:

                if item_name.startswith(
                        'spiketimes') and not item_name.endswith('unit'):
                    neuron_id = int(item_name.split('_')[-1])
                    spiked_set.add(neuron_id)

                    times = monitor.spiketimes[neuron_id]
                    self.assertTrue(comp.nested_equal(times, res[item_name]))

            spiked_list = sorted(list(spiked_set))
            self.assertEqual(spiked_list, res.neurons_with_spikes)
        else:
            raise RuntimeError('You shall not pass!')
Example #18
0
    def test_cartesian_product_combined_params(self):
        cartesian_dict=cartesian_product( {'param1': [42.0, 52.5], 'param2':['a', 'b'],\
            'param3' : [1,2,3]}, (('param3',),('param1', 'param2')))

        result_dict = {
            'param3': [1, 1, 2, 2, 3, 3],
            'param1': [42.0, 52.5, 42.0, 52.5, 42.0, 52.5],
            'param2': ['a', 'b', 'a', 'b', 'a', 'b']
        }

        self.assertTrue(nested_equal(cartesian_dict, result_dict),
                        '%s != %s' % (str(cartesian_dict), str(result_dict)))
Example #19
0
    def check_state_spike_monitor(self, res, monitor):
        self.assertTrue(comp.nested_equal(monitor.delay, res.delay))
        self.assertTrue(comp.nested_equal(monitor.nspikes, res.nspikes))
        self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
        self.assertTrue(comp.nested_equal(monitor._varnames, res.varnames))

        self.assertEqual('second', res.spiketimes_unit)

        if res.v_storage_mode == BrianMonitorResult.TABLE_MODE:
            spike_frame = res.spikes
            spiked_list=sorted(list(set(spike_frame['neuron'].to_dict().values())))
            self.assertEqual(spiked_list, res.neurons_with_spikes)
            for idx,val_tuple in enumerate(monitor.spikes):
                neuron = val_tuple[0]
                time = val_tuple[1]
                vals = val_tuple[2:]

                self.assertEqual(neuron, spike_frame['neuron'][idx])

                self.assertEqual(float(time), spike_frame['spiketimes'][idx])

                for idx_var, varname in enumerate(res.varnames):
                    val = vals[idx_var]
                    self.assertEqual(float(val),spike_frame[varname][idx])



        elif res.v_storage_mode == BrianMonitorResult.ARRAY_MODE:

            self.assertTrue('%0' in res.format_string and 'd' in res.format_string)

            spiked_set=set()
            for item_name in res:

                if item_name.startswith('spiketimes') and not item_name.endswith('unit'):
                    neuron_id = int(item_name.split('_')[-1])
                    spiked_set.add(neuron_id)

                    times = monitor.times(neuron_id)
                    self.assertTrue(comp.nested_equal(times,res[item_name]))

                for varname in res.varnames:
                    if item_name.startswith(varname) and not item_name.endswith('unit'):
                        neuron_id =int(item_name.split('_')[-1])
                        values = monitor.values(varname,neuron_id)


                        # Remove units:
                        self.assertTrue(comp.nested_equal(values,res[item_name]))

            spiked_list = sorted(list(spiked_set))
            self.assertEqual(spiked_list, res.neurons_with_spikes)
        else:
            raise RuntimeError('You shall not pass!')


        # Check Units
        for idx,varname in enumerate(monitor._varnames):
            unit = repr(get_unit_fast(monitor.spikes[0][idx+2]))
            self.assertTrue(unit,res[varname+'_unit'])
Example #20
0
 def check_population_rate_monitor(self, res, monitor):
     self.assertEqual(str(monitor.source), res.source)
     self.assertTrue(comp.nested_equal(monitor._bin, res.bin))
     self.assertTrue(comp.nested_equal('second', res.times_unit))
     self.assertTrue(comp.nested_equal('Hz', res.rate_unit))
     self.assertTrue(comp.nested_equal(monitor.rate, res.rate))
     self.assertTrue(comp.nested_equal(monitor.times, res.times))
     self.assertTrue(comp.nested_equal(monitor.delay, res.delay))
Example #21
0
 def check_population_rate_monitor(self, res, monitor):
     self.assertEqual(str(monitor.source),res.source)
     self.assertTrue(comp.nested_equal(monitor._bin,res.bin))
     self.assertTrue(comp.nested_equal('second',res.times_unit))
     self.assertTrue(comp.nested_equal('Hz',res.rate_unit))
     self.assertTrue(comp.nested_equal(monitor.rate,res.rate))
     self.assertTrue(comp.nested_equal(monitor.times,res.times))
     self.assertTrue(comp.nested_equal(monitor.delay,res.delay))
Example #22
0
    def test_cartesian_product(self):

        cartesian_dict = cartesian_product(
            {
                'param1': [1, 2, 3],
                'param2': [42.0, 52.5]
            }, ('param1', 'param2'))
        result_dict = {
            'param1': [1, 1, 2, 2, 3, 3],
            'param2': [42.0, 52.5, 42.0, 52.5, 42.0, 52.5]
        }

        self.assertTrue(nested_equal(cartesian_dict, result_dict),
                        '%s != %s' % (str(cartesian_dict), str(result_dict)))
Example #23
0
    def check_state_monitor(self, res, monitor):

        self.assertEqual('second', res.times_unit)
        self.assertEqual(monitor.varname, res.varname)
        self.assertEqual(repr(monitor.unit), res.unit)
        self.assertTrue(comp.nested_equal(monitor.record, res.record))

        self.assertTrue(comp.nested_equal(monitor.when, res.when))

        self.assertEqual(monitor.timestep, res.timestep)
        self.assertTrue(comp.nested_equal(str(monitor.P), res.source))

        if hasattr(res, 'mean'):
            self.assertTrue(comp.nested_equal(monitor.mean, res.mean))
            self.assertTrue(comp.nested_equal(monitor.var, res.var))

        if len(monitor.times) > 0:
            self.assertTrue(comp.nested_equal(monitor.times, res.times))
            self.assertTrue(comp.nested_equal(monitor.values, res.values))
Example #24
0
    def check_state_monitor(self, res, monitor):

        self.assertEqual('second', res.times_unit)
        self.assertEqual(monitor.varname, res.varname)
        self.assertEqual(repr(monitor.unit), res.unit)
        self.assertTrue(comp.nested_equal(monitor.record, res.record))

        self.assertTrue(comp.nested_equal(monitor.when, res.when))

        self.assertEqual(monitor.timestep, res.timestep)
        self.assertTrue(comp.nested_equal(str(monitor.P), res.source))

        if hasattr(res, 'mean'):
            self.assertTrue(comp.nested_equal(monitor.mean, res.mean))
            self.assertTrue(comp.nested_equal(monitor.var, res.var))

        if len(monitor.times) > 0:
            self.assertTrue(comp.nested_equal(monitor.times, res.times))
            self.assertTrue(comp.nested_equal(monitor.values, res.values))
Example #25
0
    def test_get_data(self):
        for paramname in self.param:
            param = self.param[paramname]
            val1=param.data
            val2=param.f_get()
            self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
            val3=param['data']
            self.assertTrue(comp.nested_equal(val3,val2), '%s != %s' % (str(val3),str(val2)))

            val1=param.default
            val2=param._default
            self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
            val3=param['default']
            self.assertTrue(comp.nested_equal(val3,val2), '%s != %s' % (str(val3),str(val2)))
            val4=param.f_get_default()
            self.assertTrue(comp.nested_equal(val4,val2), '%s != %s' % (str(val4),str(val2)))
            val5 = param[-1]
            self.assertTrue(comp.nested_equal(val5,val2), '%s != %s' % (str(val5),str(val2)))
Example #26
0
    def test_get_data(self):
        for paramname in self.param:
            param = self.param[paramname]
            val1=param.data
            val2=param.f_get()
            self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
            val3=param['data']
            self.assertTrue(comp.nested_equal(val3,val2), '%s != %s' % (str(val3),str(val2)))

            val1=param.default
            val2=param._default
            self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
            val3=param['default']
            self.assertTrue(comp.nested_equal(val3,val2), '%s != %s' % (str(val3),str(val2)))
            val4=param.f_get_default()
            self.assertTrue(comp.nested_equal(val4,val2), '%s != %s' % (str(val4),str(val2)))
            val5 = param[-1]
            self.assertTrue(comp.nested_equal(val5,val2), '%s != %s' % (str(val5),str(val2)))
Example #27
0
 def check_population_rate_monitor(self, res, monitor):
     self.assertEqual(str(monitor.source),res.source)
     self.assertEqual(monitor.name,res.name)
     #self.assertTrue(comp.nested_equal(monitor._bin,res.bin))
     self.assertTrue(comp.nested_equal(monitor.rate[:],res.rate))
     self.assertTrue(comp.nested_equal(monitor.t[:],res.t))
Example #28
0
 def test_f_to_dict_no_copy(self):
     for res_name,res in self.results.items():
         for key, val1 in res.f_to_dict(copy=False).items():
             val2 = res[key]
             self.assertTrue(comp.nested_equal(val1,val2))
Example #29
0
 def test_natural_naming(self):
     for res_name,res in self.results.items():
         for key, val1 in res.f_to_dict().items():
             val2 = getattr(res, key)
             self.assertTrue(comp.nested_equal(val1,val2))
Example #30
0
 def check_van_rossum_metric(self, res, monitor):
     self.assertTrue(comp.nested_equal(float(monitor.tau), res.tau))
     self.assertTrue(comp.nested_equal('second', res.tau_unit))
     self.assertTrue(comp.nested_equal(monitor.distance, res.distance))
     self.assertTrue(comp.nested_equal(monitor.N, res.N))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
Example #31
0
    def test_get_data_dictionaries_directly(self):

        ############## Cofig ###################
        config_dict_from_subtree = self.traj.config.f_to_dict()

        self.assertTrue(len(config_dict_from_subtree)>0)

        config_dict_directly = self.traj.f_get_config(copy=True)

        self.assertTrue(comp.nested_equal(config_dict_directly,config_dict_from_subtree),
                        '%s!=%s' % (str(config_dict_directly),str(config_dict_directly)))

        config_dict_directly = self.traj.f_get_config(copy=False)

        self.assertTrue(comp.nested_equal(config_dict_directly,config_dict_from_subtree),
                        '%s!=%s' % (str(config_dict_directly),str(config_dict_directly)))


        config_dict_from_subtree = self.traj.config.f_to_dict(fast_access=True)

        with self.assertRaises(ValueError):
            config_dict_directly = self.traj.f_get_config(copy=False, fast_access=True)

        config_dict_directly = self.traj.f_get_config(copy=True, fast_access=True)

        self.assertTrue(comp.nested_equal(config_dict_directly,config_dict_from_subtree),
                        '%s!=%s' % (str(config_dict_directly),str(config_dict_directly)))

        ############## Parameters #############################
        parameters_dict_from_subtree = self.traj.parameters.f_to_dict()

        self.assertTrue(len(parameters_dict_from_subtree)>0)

        parameters_dict_directly = self.traj.f_get_parameters(copy=True)

        self.assertTrue(comp.nested_equal(parameters_dict_directly,parameters_dict_from_subtree),
                        '%s!=%s' % (str(parameters_dict_directly),str(parameters_dict_directly)))

        parameters_dict_directly = self.traj.f_get_parameters(copy=False)

        self.assertTrue(comp.nested_equal(parameters_dict_directly,parameters_dict_from_subtree),
                        '%s!=%s' % (str(parameters_dict_directly),str(parameters_dict_directly)))


        ### Empty Parameters won't support fast access so we need to set
        self.traj.paul.peter.f_set(42)

        parameters_dict_from_subtree = self.traj.parameters.f_to_dict(fast_access=True)

        with self.assertRaises(ValueError):
            parameters_dict_directly = self.traj.f_get_parameters(copy=False, fast_access=True)

        parameters_dict_directly = self.traj.f_get_parameters(copy=True, fast_access=True)

        self.assertTrue(comp.nested_equal(parameters_dict_directly,parameters_dict_from_subtree),
                        '%s!=%s' % (str(parameters_dict_directly),str(parameters_dict_directly)))

        ################# Derived Parameters ############################
        derived_parameters_dict_from_subtree = self.traj.derived_parameters.f_to_dict()

        self.assertTrue(len(derived_parameters_dict_from_subtree)>0)

        derived_parameters_dict_directly = self.traj.f_get_derived_parameters(copy=True)

        self.assertTrue(comp.nested_equal(derived_parameters_dict_directly,derived_parameters_dict_from_subtree),
                        '%s!=%s' % (str(derived_parameters_dict_directly),str(derived_parameters_dict_directly)))

        derived_parameters_dict_directly = self.traj.f_get_derived_parameters(copy=False)

        self.assertTrue(comp.nested_equal(derived_parameters_dict_directly,derived_parameters_dict_from_subtree),
                        '%s!=%s' % (str(derived_parameters_dict_directly),str(derived_parameters_dict_directly)))


        derived_parameters_dict_from_subtree = self.traj.derived_parameters.f_to_dict(fast_access=True)

        with self.assertRaises(ValueError):
            derived_parameters_dict_directly = self.traj.f_get_derived_parameters(copy=False, fast_access=True)

        derived_parameters_dict_directly = self.traj.f_get_derived_parameters(copy=True, fast_access=True)

        self.assertTrue(comp.nested_equal(derived_parameters_dict_directly,derived_parameters_dict_from_subtree),
                        '%s!=%s' % (str(derived_parameters_dict_directly),str(derived_parameters_dict_directly)))



        ############## Results #################################
        results_dict_from_subtree = self.traj.results.f_to_dict()

        self.assertTrue(len(results_dict_from_subtree)>0)

        results_dict_directly = self.traj.f_get_results(copy=True)

        self.assertTrue(comp.nested_equal(results_dict_directly,results_dict_from_subtree),
                        '%s!=%s' % (str(results_dict_directly),str(results_dict_directly)))

        results_dict_directly = self.traj.f_get_results(copy=False)

        self.assertTrue(comp.nested_equal(results_dict_directly,results_dict_from_subtree),
                        '%s!=%s' % (str(results_dict_directly),str(results_dict_directly)))


        results_dict_from_subtree = self.traj.results.f_to_dict(fast_access=True)

        with self.assertRaises(ValueError):
            results_dict_directly = self.traj.f_get_results(copy=False, fast_access=True)

        results_dict_directly = self.traj.f_get_results(copy=True, fast_access=True)

        self.assertTrue(comp.nested_equal(results_dict_directly,results_dict_from_subtree),
                        '%s!=%s' % (str(results_dict_directly),str(results_dict_directly)))


        ################### Explored Parameters #######################


        # #We need to unlock the parameter because we have accessed it above
        # self.traj.f_get('yve').f_unlock()
        # explore_dict = {'yve':[4,5,65,66]}

        # # We can add to existing explored parameters if we match the length
        # self.traj.f_expand(explore_dict)

        explore_dict_directly = self.traj.f_get_explored_parameters(copy=False)

        for key in self.explore_dict:
            self.assertTrue(comp.nested_equal(self.traj.f_get(key),
                                              explore_dict_directly[self.traj.f_get(key).v_full_name]))

        explore_dict_directly = self.traj.f_get_explored_parameters(copy=True)

        for key in self.explore_dict:
            self.assertTrue(comp.nested_equal(self.traj.f_get(key),
                                              explore_dict_directly[self.traj.f_get(key).v_full_name]))

        with self.assertRaises(ValueError):
            explore_dict_directly = self.traj.f_get_explored_parameters(copy=False, fast_access=True)

        explore_dict_directly = self.traj.f_get_explored_parameters(copy=True, fast_access=True)

        for key in self.explore_dict:
            self.assertTrue(comp.nested_equal(self.traj.f_get(key,fast_access=True),
                                              explore_dict_directly[self.traj.f_get(key).v_full_name]))
Example #32
0
 def check_van_rossum_metric(self,res, monitor):
     self.assertTrue(comp.nested_equal(float(monitor.tau), res.tau))
     self.assertTrue(comp.nested_equal('second', res.tau_unit))
     self.assertTrue(comp.nested_equal(monitor.distance, res.distance))
     self.assertTrue(comp.nested_equal(monitor.N, res.N))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
Example #33
0
 def check_spike_counter(self, res, monitor):
     self.assertTrue(comp.nested_equal(monitor.count, res.count))
     self.assertTrue(comp.nested_equal(monitor.nspikes, res.nspikes))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
Example #34
0
 def test_get_item_no_copy(self):
     for node in self.traj.f_iter_nodes(recursive=True):
         for key, val1 in node.v_annotations.f_to_dict(copy=False).items():
             val2 = node.v_annotations[key]
             self.assertTrue(comp.nested_equal(val1, val2))
Example #35
0
 def check_population_spike_counter(self, res, monitor):
     self.assertTrue(comp.nested_equal(monitor.delay, res.delay))
     self.assertTrue(comp.nested_equal(monitor.nspikes, res.nspikes))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
Example #36
0
 def test_get_item_no_copy(self):
     for node in self.traj.f_iter_nodes(recursive=True):
         for key, val1 in node.v_annotations.f_to_dict(copy=False).items():
             val2 = node.v_annotations[key]
             self.assertTrue(comp.nested_equal(val1,val2))
Example #37
0
 def check_spike_counter(self, res, monitor):
     self.assertTrue(comp.nested_equal(monitor.count, res.count))
     self.assertTrue(comp.nested_equal(monitor.nspikes, res.nspikes))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
Example #38
0
 def test_natural_naming(self):
     for res_name, res in self.results.items():
         for key, val1 in res.f_to_dict().items():
             val2 = getattr(res, key)
             self.assertTrue(comp.nested_equal(val1, val2))
Example #39
0
 def test_get_item(self):
     for paramname in self.explore_dict:
         param = self.param[paramname]
         val1=param.f_get_range()[1]
         val2=param[1]
         self.assertTrue(comp.nested_equal(val1,val2), '%s != %s' % (str(val1),str(val2)))
Example #40
0
 def test_get_item(self):
     for res_name, res in self.results.items():
         for key, val1 in res.f_to_dict().items():
             val2 = res[key]
             self.assertTrue(comp.nested_equal(val1, val2))
Example #41
0
 def check_isi_hist_monitor(self, res, monitor):
     self.assertEqual(str(monitor.source), res.source)
     self.assertTrue(comp.nested_equal(monitor.count, res.count))
     self.assertTrue(comp.nested_equal(monitor.bins, res.bins))
     self.assertTrue(comp.nested_equal(monitor.delay, res.delay))
     self.assertEqual(monitor.nspikes, res.nspikes)
Example #42
0
 def test_f_to_dict_no_copy(self):
     for res_name, res in self.results.items():
         for key, val1 in res.f_to_dict(copy=False).items():
             val2 = res[key]
             self.assertTrue(comp.nested_equal(val1, val2))
Example #43
0
 def test_get_item(self):
     for res_name,res in self.results.items():
         for key, val1 in res.f_to_dict().items():
             val2 = res[key]
             self.assertTrue(comp.nested_equal(val1,val2))
Example #44
0
    def test_nested_equal(self):
        self.assertTrue(nested_equal(4, 4))
        self.assertFalse(nested_equal(4, 5))
        self.assertFalse(nested_equal(5, 4))

        self.assertTrue(nested_equal(4, np.int8(4)))
        self.assertTrue(nested_equal(np.int8(4), 4))

        self.assertFalse(nested_equal(4, np.int8(5)))

        self.assertFalse(nested_equal(np.int8(5), 4))

        frameA = pd.DataFrame(data={'a': [np.zeros((19, 19))]}, dtype=object)
        frameB = pd.DataFrame(data={'a': [np.zeros((19, 19))]}, dtype=object)

        self.assertTrue(nested_equal(frameA, frameB))
        self.assertTrue(nested_equal(frameB, frameA))

        frameB.loc[0, 'a'][0, 0] = 3
        self.assertFalse(nested_equal(frameA, frameB))
        self.assertFalse(nested_equal(frameB, frameA))

        seriesA = pd.Series(data=[[np.zeros((19, 19))]], dtype=object)
        seriesB = pd.Series(data=[[np.zeros((19, 19))]], dtype=object)

        self.assertTrue(nested_equal(seriesA, seriesB))

        self.assertTrue(nested_equal(seriesB, seriesA))

        seriesA.loc[0] = 777
        self.assertFalse(nested_equal(seriesA, seriesB))

        self.assertFalse(nested_equal(seriesB, seriesA))

        seriesA = pd.Series([1, 2, 3])
        seriesB = pd.Series([1, 2, 3])

        self.assertTrue(nested_equal(seriesA, seriesB))

        self.assertTrue(nested_equal(seriesB, seriesA))

        a = MyDummy()
        a.g = 4
        b = MyDummy()
        b.g = 4

        self.assertTrue(nested_equal(a, b))
        self.assertTrue(nested_equal(b, a))

        a.h = [1, 2, 42]
        b.h = [1, 2, 43]

        self.assertFalse(nested_equal(a, b))
        self.assertFalse(nested_equal(b, a))

        a = MyDummyWithSlots()
        a.a = 1
        a.b = 2
        b = MyDummyWithSlots2()
        b.a = 1
        b.b = 2

        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummySet([1, 2, 3])
        a.add(4)
        b = MyDummySet([1, 2, 3, 4])
        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummyList([1, 2, 3])
        a.append(4)
        b = MyDummyList([1, 2, 3, 4])
        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummyMapping(a='b', c=42)
        b = MyDummyMapping(a='b', c=42)
        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummySet([1, 2, 3])
        a.add(4)
        b = MyDummySet([1, 2, 3, 5])
        self.assertFalse(nested_equal(a, b))
        self.assertFalse(nested_equal(b, a))

        a = MyDummyList([1, 2, 3])
        a.append(5)
        b = MyDummyList([1, 2, 3, 4])
        self.assertFalse(nested_equal(a, b))

        self.assertFalse(nested_equal(b, a))

        a = MyDummyMapping(a='b', c=a)
        b = MyDummyMapping(a='b', c=b)
        self.assertFalse(nested_equal(a, b))

        self.assertFalse(nested_equal(b, a))

        a = MyDummyCMP(42)
        b = MyDummyCMP(42)

        self.assertTrue(nested_equal(a, b))
        self.assertTrue(nested_equal(b, a))

        b = MyDummyCMP(1)

        self.assertFalse(nested_equal(a, b))

        self.assertFalse(nested_equal(b, a))

        self.assertFalse(nested_equal(a, 22))
        self.assertFalse(nested_equal(22, a))

        self.assertFalse(nested_equal(None, a))
        self.assertFalse(nested_equal(a, None))

        self.assertTrue(nested_equal(None, None))
Example #45
0
 def check_population_spike_counter(self, res, monitor):
     self.assertTrue(comp.nested_equal(monitor.delay, res.delay))
     self.assertTrue(comp.nested_equal(monitor.nspikes, res.nspikes))
     self.assertTrue(comp.nested_equal(str(monitor.source), res.source))
Example #46
0
 def check_isi_hist_monitor(self, res, monitor):
     self.assertEqual(str(monitor.source),res.source)
     self.assertTrue(comp.nested_equal(monitor.count,res.count))
     self.assertTrue(comp.nested_equal(monitor.bins,res.bins))
     self.assertTrue(comp.nested_equal(monitor.delay,res.delay))
     self.assertEqual(monitor.nspikes, res.nspikes)
Example #47
0
 def check_population_rate_monitor(self, res, monitor):
     self.assertEqual(str(monitor.source), res.source)
     self.assertEqual(monitor.name, res.name)
     #self.assertTrue(comp.nested_equal(monitor._bin,res.bin))
     self.assertTrue(comp.nested_equal(monitor.rate[:], res.rate))
     self.assertTrue(comp.nested_equal(monitor.t[:], res.t))
Example #48
0
    def test_nested_equal(self):
        self.assertTrue(nested_equal(4, 4))
        self.assertFalse(nested_equal(4, 5))
        self.assertFalse(nested_equal(5, 4))

        self.assertTrue(nested_equal(4, np.int8(4)))
        self.assertTrue(nested_equal(np.int8(4), 4))

        self.assertFalse(nested_equal(4, np.int8(5)))

        self.assertFalse(nested_equal( np.int8(5), 4))

        frameA = pd.DataFrame(data={'a':[np.zeros((19,19))]}, dtype=object)
        frameB = pd.DataFrame(data={'a':[np.zeros((19,19))]}, dtype=object)

        self.assertTrue(nested_equal(frameA, frameB))
        self.assertTrue(nested_equal(frameB, frameA))

        frameB.loc[0,'a'][0,0] = 3
        self.assertFalse(nested_equal(frameA, frameB))
        self.assertFalse(nested_equal(frameB, frameA))

        seriesA = pd.Series(data=[[np.zeros((19,19))]], dtype=object)
        seriesB = pd.Series(data=[[np.zeros((19,19))]], dtype=object)

        self.assertTrue(nested_equal(seriesA, seriesB))

        self.assertTrue(nested_equal(seriesB, seriesA))

        seriesA.loc[0] = 777
        self.assertFalse(nested_equal(seriesA, seriesB))

        self.assertFalse(nested_equal(seriesB, seriesA))


        seriesA = pd.Series([1,2,3])
        seriesB = pd.Series([1,2,3])

        self.assertTrue(nested_equal(seriesA, seriesB))

        self.assertTrue(nested_equal(seriesB, seriesA))

        a = MyDummy()
        a.g = 4
        b = MyDummy()
        b.g = 4

        self.assertTrue(nested_equal(a, b))
        self.assertTrue(nested_equal(b, a))


        a.h = [1, 2, 42]
        b.h = [1, 2, 43]

        self.assertFalse(nested_equal(a, b))
        self.assertFalse(nested_equal(b, a))

        a = MyDummyWithSlots()
        a.a = 1
        a.b = 2
        b = MyDummyWithSlots2()
        b.a = 1
        b.b = 2

        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummySet([1,2,3])
        a.add(4)
        b = MyDummySet([1,2,3,4])
        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummyList([1,2,3])
        a.append(4)
        b = MyDummyList([1,2,3,4])
        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummyMapping(a='b', c=42)
        b = MyDummyMapping(a='b', c=42)
        self.assertTrue(nested_equal(a, b))

        self.assertTrue(nested_equal(b, a))

        a = MyDummySet([1,2,3])
        a.add(4)
        b = MyDummySet([1,2,3,5])
        self.assertFalse(nested_equal(a, b))
        self.assertFalse(nested_equal(b, a))

        a = MyDummyList([1,2,3])
        a.append(5)
        b = MyDummyList([1,2,3,4])
        self.assertFalse(nested_equal(a, b))

        self.assertFalse(nested_equal(b, a))

        a = MyDummyMapping(a='b', c=a)
        b = MyDummyMapping(a='b', c=b)
        self.assertFalse(nested_equal(a, b))

        self.assertFalse(nested_equal(b, a))

        a = MyDummyCMP(42)
        b = MyDummyCMP(42)

        self.assertTrue(nested_equal(a, b))
        self.assertTrue(nested_equal(b, a))
        if compat.python_major == 2:
            self.assertTrue(a == b)

        b = MyDummyCMP(1)

        self.assertFalse(nested_equal(a, b))

        self.assertFalse(nested_equal(b, a))
        if compat.python_major == 2:
            self.assertTrue(not (a == b))

        self.assertFalse(nested_equal(a, 22))
        self.assertFalse(nested_equal(22, a))

        self.assertFalse(nested_equal(None, a))
        self.assertFalse(nested_equal(a, None))

        self.assertTrue(nested_equal(None, None))