def _set_sheet_views(instance, state): if state['simulation'] is None: return None name = state['_name_param_value'] if not hasattr(state['simulation'], 'views'): state['simulation'].views = AttrDict() if name not in state['simulation'].views: if hasattr(instance, 'views'): state['views'] = instance.views else: state['views'] = AttrDict() state['simulation'].views[name] = state['views'] views = state['views'] views['maps'] = AttrDict() views['cfs'] = AttrDict() views['rfs'] = AttrDict() views['curves'] = AttrDict() if 'sheet_views' in state: svs = state['sheet_views'] for key, sv in svs.items(): data, bounds = sv.view() new_sv = Matrix(data, bounds) metadata = dict(dimension_labels=['Time']) metadata_names = ['cyclic_range', 'precedence', 'row_precedence', 'src_name'] for p in metadata_names: if hasattr(sv, p): metadata[p] = getattr(sv, p) state['views'].maps[key] = NdMapping((sv.timestamp, new_sv), **metadata) if 'curve_dict' in state: old_curves = state['curve_dict'] curves = views['curves'] for key, value in old_curves.items(): key = key.capitalize() for label, item in value.items(): labels = unit_value(label) label_name = labels[0].split(' ')[0] l_val = labels[-1] if key not in views['curves']: curves[key] = NdMapping(dimension_labels=['Time']) for f_val, old_sv in item.items(): timestamp = old_sv.timestamp curves[key][timestamp] = NdMapping(dimension_labels=[label_name]) if l_val not in curves[key][timestamp].keys(): curves[key][timestamp] [l_val] = NdMapping(dimension_labels=[key], label=label, timestamp=old_sv.timestamp) data, bounds = old_sv.view() sv = Matrix(data, bounds) curves[key][timestamp][l_val][f_val] = sv state.pop('curve_dict', None) state.pop('sheet_views', None)
def test(plotgroup_names): import topo assert topo.sim.name==sim_name assert topo.sim['V1'].nominal_density==8 assert topo.sim.time()==100 failing_tests=[] for name in plotgroup_names: print "\n* Testing plotgroups['%s']:"%name sheet = topo.sim['V1'] _reset_views(sheet) plotgroups[name]._exec_pre_plot_hooks() filename = resolve_path('tests/data_maptests/%s_t%s_%s.data'%(sim_name,topo.sim.timestr(), name.replace(' ','_'))) print "Reading previous results from %s" % (filename) f = open(filename,'r') try: topo_version,previous_views = pickle.load(f) ######################################## except AttributeError: # PRALERT: Code to allow loading of old data files after # boundingregion was moved to holoviews. import sys from holoviews.core import boundingregion sys.modules['imagen.boundingregion'] = boundingregion # CEBALERT: code here just to support old data file. Should # generate a new one so it's no longer necessary. from topo.misc.legacy import preprocess_state import topo.base.boundingregion def _boundingregion_not_parameterized(instance,state): for a in ['initialized', '_name_param_value', 'nopickle']: if a in state: del state[a] preprocess_state(topo.base.boundingregion.BoundingRegion, _boundingregion_not_parameterized) f.seek(0) topo_version,previous_views = pickle.load(f) ######################################## f.close() if 'sheet_views' in previous_views[sheet.name]: previous_sheet_views = previous_views[sheet.name]['sheet_views'] for view_name in previous_sheet_views: failing_tests += checkclose(sheet.name + " " + view_name,topo_version, sheet.views.Maps[view_name].last.data, previous_sheet_views[view_name].view()[0]) if 'curve_dict' in previous_views[sheet.name]: previous_curve_dicts = previous_views[sheet.name]['curve_dict'] # CB: need to cleanup var names e.g. val time, duration = (topo.sim.time(), 1.0) for curve_name in previous_curve_dicts: for other_param in previous_curve_dicts[curve_name]: other_param_val = unit_value(other_param)[-1] for val in previous_curve_dicts[curve_name][other_param]: new_curves = sheet.views.Curves[curve_name.capitalize()+"Tuning"] new_curves = new_curves.clone(key_dimensions=[d(values=[]) for d in new_curves.key_dimensions]) new = new_curves[time, duration, other_param_val-0.01:other_param_val+0.01, val].values()[0].data old = previous_curve_dicts[curve_name][other_param][val].view()[0] failing_tests += checkclose("%s %s %s %s" %(sheet.name,curve_name,other_param,val), topo_version, new, old) if failing_tests != []: raise AssertionError, "Failed map tests: %s" % (failing_tests)
def test(plotgroup_names): import topo assert topo.sim.name == sim_name assert topo.sim['V1'].nominal_density == 8 assert topo.sim.time() == 100 failing_tests = [] for name in plotgroup_names: print "\n* Testing plotgroups['%s']:" % name sheet = topo.sim['V1'] _reset_views(sheet) plotgroups[name]._exec_pre_plot_hooks() filename = resolve_path( 'tests/data_maptests/%s_t%s_%s.data' % (sim_name, topo.sim.timestr(), name.replace(' ', '_'))) print "Reading previous results from %s" % (filename) f = open(filename, 'r') try: topo_version, previous_views = pickle.load(f) ######################################## except AttributeError: # PRALERT: Code to allow loading of old data files after # boundingregion was moved to holoviews. import sys from holoviews.core import boundingregion sys.modules['imagen.boundingregion'] = boundingregion # CEBALERT: code here just to support old data file. Should # generate a new one so it's no longer necessary. from topo.misc.legacy import preprocess_state import topo.base.boundingregion def _boundingregion_not_parameterized(instance, state): for a in ['initialized', '_name_param_value', 'nopickle']: if a in state: del state[a] preprocess_state(topo.base.boundingregion.BoundingRegion, _boundingregion_not_parameterized) f.seek(0) topo_version, previous_views = pickle.load(f) ######################################## f.close() if 'sheet_views' in previous_views[sheet.name]: previous_sheet_views = previous_views[sheet.name]['sheet_views'] for view_name in previous_sheet_views: failing_tests += checkclose( sheet.name + " " + view_name, topo_version, sheet.views.Maps[view_name].last.data, previous_sheet_views[view_name].view()[0]) if 'curve_dict' in previous_views[sheet.name]: previous_curve_dicts = previous_views[sheet.name]['curve_dict'] # CB: need to cleanup var names e.g. val time, duration = (topo.sim.time(), 1.0) for curve_name in previous_curve_dicts: for other_param in previous_curve_dicts[curve_name]: other_param_val = unit_value(other_param)[-1] for val in previous_curve_dicts[curve_name][other_param]: new_curves = sheet.views.Curves[ curve_name.capitalize() + "Tuning"] new = new_curves[time, duration, other_param_val - 0.01:other_param_val + 0.01, val].values()[0].data old = previous_curve_dicts[curve_name][other_param][ val].view()[0] failing_tests += checkclose( "%s %s %s %s" % (sheet.name, curve_name, other_param, val), topo_version, new, old) if failing_tests != []: raise AssertionError, "Failed map tests: %s" % (failing_tests)