def basic_save_load_snapshot(self): """ Very basic test to check the activity matrix of a GeneratorSheet comes back ok, and that class attributes are pickled. """ assert topo.sim.name == SIM_NAME topo.sim['R'] = GeneratorSheet(input_generator=Gaussian(), nominal_density=2) topo.sim.run(1) R_act = copy.deepcopy(topo.sim['R'].activity) Line.x = 12.0 topo.sim.startup_commands.append("z=99") save_snapshot(SNAPSHOT_NAME) Line.x = 9.0 exec "z=88" in __main__.__dict__ topo.sim['R'].set_input_generator(Line()) topo.sim.run(1) load_snapshot( resolve_path(SNAPSHOT_NAME, search_paths=[normalize_path.prefix])) # CEBALERT: should also test that unpickling order is correct # (i.e. startup_commands, class attributes, simulation) assert_array_equal(R_act, topo.sim['R'].activity) self.assertEqual(Line.x, 12.0) self.assertEqual(__main__.__dict__['z'], 99)
def basic_save_load_snapshot(self): """ Very basic test to check the activity matrix of a GeneratorSheet comes back ok, and that class attributes are pickled. """ assert topo.sim.name == SIM_NAME topo.sim["R"] = GeneratorSheet(input_generator=Gaussian(), nominal_density=2) topo.sim.run(1) R_act = copy.deepcopy(topo.sim["R"].activity) Line.x = 12.0 topo.sim.startup_commands.append("z=99") save_snapshot(SNAPSHOT_NAME) Line.x = 9.0 exec "z=88" in __main__.__dict__ topo.sim["R"].set_input_generator(Line()) topo.sim.run(1) load_snapshot(resolve_path(SNAPSHOT_NAME, search_paths=[normalize_path.prefix])) # CEBALERT: should also test that unpickling order is correct # (i.e. startup_commands, class attributes, simulation) assert_array_equal(R_act, topo.sim["R"].activity) self.assertEqual(Line.x, 12.0) self.assertEqual(__main__.__dict__["z"], 99)
def plotting_and_saving_analysis_fn(prefix=""): """For use with memuse_batch() to test snapshot and plotting memory usage.""" import topo from topo.command import save_snapshot from topo.command.analysis import measure_sine_pref,save_plotgroup print "%sMemuse at time %s: %s" % (prefix,topo.sim.timestr(),allsizes_mb()) measure_sine_pref() print "%sAfter measure_sine_pref: %s" % (prefix,allsizes_mb()) save_plotgroup("Orientation Preference") print "%sAfter save_plotgroup: %s" % (prefix,allsizes_mb()) save_snapshot("/tmp/tmp.typ") print "%sAfter save_snapshot: %s" % (prefix,allsizes_mb())
def plotting_and_saving_analysis_fn(prefix=""): """For use with memuse_batch() to test snapshot and plotting memory usage.""" import topo from topo.command import save_snapshot from topo.command.analysis import measure_sine_pref, save_plotgroup print "%sMemuse at time %s: %s" % (prefix, topo.sim.timestr(), allsizes_mb()) measure_sine_pref() print "%sAfter measure_sine_pref: %s" % (prefix, allsizes_mb()) save_plotgroup("Orientation Preference") print "%sAfter save_plotgroup: %s" % (prefix, allsizes_mb()) save_snapshot("/tmp/tmp.typ") print "%sAfter save_snapshot: %s" % (prefix, allsizes_mb())
def saveSnapShot(saveSnapshotTime): if saveSnapshotTime is not None: print("Snapshot missing! Regenenerating over %d periods" % int(saveSnapshotTime)) # typName ='gcal_continuous_%d.typ' % int(saveSnapshotTime) fullTypPath = typPath+ loadSnapshot#typName scheduleInfo(saveSnapshotTime, 10) topo.sim.run(int(saveSnapshotTime)) save_snapshot(os.path.abspath(fullTypPath)) print "Snapshot generated. Rerun script." sys.exit()
def compare_with_and_without_snapshot_CreateSnapshot( script="models/lissom.ty"): data_filename = os.path.split(script)[1] + "_PICKLETEST" locn = resolve_path(os.path.join('tests', data_filename)) print "Loading pickle at %s" % locn try: data = pickle.load(open(locn, "rb")) except IOError: print "\nData file '" + data_filename + "' could not be opened; run _A() first." raise # retrieve parameters used when script was run run_for = data['run_for'] break_at = data['break_at'] look_at = data['look_at'] # CEBALERT: shouldn't need to re-list - should be able to read from data! cortex_density = data['cortex_density'] lgn_density = data['lgn_density'] retina_density = data['retina_density'] dims = data['dims'] dataset = data['dataset'] __main__.__dict__['cortex_density'] = cortex_density __main__.__dict__['lgn_density'] = lgn_density __main__.__dict__['retina_density'] = retina_density __main__.__dict__['dims'] = dims __main__.__dict__['dataset'] = dataset execfile(script, __main__.__dict__) # check we have the same before any pickling topo.sim.run(break_at) assert_array_equal(data[topo.sim.time()], topo.sim[look_at].activity, err_msg="\nAt topo.sim.time()=%d" % topo.sim.time()) from topo.command import save_snapshot locn = normalize_path(os.path.join('tests', data_filename + '.typ_')) print "Saving snapshot to %s" % locn save_snapshot(locn)
def compare_with_and_without_snapshot_CreateSnapshot(script="models/lissom.ty"): data_filename=os.path.split(script)[1]+"_PICKLETEST" locn = resolve_path(os.path.join('tests',data_filename)) print "Loading pickle at %s"%locn try: data = pickle.load(open(locn,"rb")) except IOError: print "\nData file '"+data_filename+"' could not be opened; run _A() first." raise # retrieve parameters used when script was run run_for=data['run_for'] break_at=data['break_at'] look_at=data['look_at'] # CEBALERT: shouldn't need to re-list - should be able to read from data! cortex_density=data['cortex_density'] lgn_density=data['lgn_density'] retina_density=data['retina_density'] dims=data['dims'] dataset=data['dataset'] __main__.__dict__['cortex_density']=cortex_density __main__.__dict__['lgn_density']=lgn_density __main__.__dict__['retina_density']=retina_density __main__.__dict__['dims']=dims __main__.__dict__['dataset']=dataset execfile(script,__main__.__dict__) # check we have the same before any pickling topo.sim.run(break_at) assert_array_equal(data[topo.sim.time()],topo.sim[look_at].activity, err_msg="\nAt topo.sim.time()=%d"%topo.sim.time()) from topo.command import save_snapshot locn = normalize_path(os.path.join('tests',data_filename+'.typ_')) print "Saving snapshot to %s"%locn save_snapshot(locn)
def save_snapshot(times=None, **kwargs): if topo.sim.time() != times[-1]: return None from topo.command import save_snapshot save_snapshot()
def saver_function(): from topo.command import save_snapshot save_snapshot(normalize_path('snapshot.typ'))
def complex_surround_analysis_function(): """ Basic example of an analysis command for run_batch; users are likely to need something similar but highly customized. """ import topo from topo.command.analysis import save_plotgroup from topo.analysis.featureresponses import SinusoidalMeasureResponseCommand, FeatureCurveCommand from topo.base.projection import ProjectionSheet from topo.sheet import GeneratorSheet from topo.command import save_snapshot from param import normalize_path import contrib.cc_lesi.connection_analysis import contrib.jacommands import contrib.surround_analysis_new_cleaned exec "from topo.analysis.vision import analyze_complexity" in __main__.__dict__ import matplotlib matplotlib.rc('xtick', labelsize=17) matplotlib.rc('ytick', labelsize=17) SinusoidalMeasureResponseCommand.frequencies = [2.4] SinusoidalMeasureResponseCommand.scale = __main__.__dict__.get( "analysis_scale", 2.3) from topo.analysis.featureresponses import PatternPresenter PatternPresenter.duration = 4.0 import topo.command.pylabplot reload(topo.command.pylabplot) # Build a list of all sheets worth measuring f = lambda x: hasattr(x, 'measure_maps') and x.measure_maps measured_sheets = filter(f, topo.sim.objects(ProjectionSheet).values()) input_sheets = topo.sim.objects(GeneratorSheet).values() # Set potentially reasonable defaults; not necessarily useful topo.command.analysis.coordinate = (0.0, 0.0) if input_sheets: topo.command.analysis.input_sheet_name = input_sheets[0].name if measured_sheets: topo.command.analysis.sheet_name = measured_sheets[0].name save_plotgroup("Orientation Preference and Complexity") save_plotgroup("Activity", normalize='Individually') # Plot all projections for all measured_sheets for s in measured_sheets: for p in s.projections().values(): save_plotgroup("Projection", projection=p) contrib.cc_lesi.connection_analysis.Analyse_connectivity() if (float(topo.sim.time()) > 6020.0): if __main__.__dict__.get("save", False): save_snapshot(normalize_path('snapshot.typ')) #contrib.surround_analysis.run_dynamics_analysis(0.0,0.0,0.7,__main__.__dict__.get("analysis_scale",0.3)) topo.command.pylabplot.measure_or_tuning_fullfield.instance( sheet=topo.sim["V1Complex"])() topo.command.pylabplot.cyclic_tuning_curve.instance( x_axis="orientation", filename="ORTC[0,0]", sheet=topo.sim["V1Complex"], coords=[(0, 0)])() topo.command.pylabplot.cyclic_tuning_curve.instance( x_axis="orientation", filename="ORTC[0.1,0.1]", sheet=topo.sim["V1Complex"], coords=[(0.1, 0.1)])() topo.command.pylabplot.cyclic_tuning_curve.instance( x_axis="orientation", filename="ORTC[0.1,-0.1]", sheet=topo.sim["V1Complex"], coords=[(0.1, -0.1)])() topo.command.pylabplot.cyclic_tuning_curve.instance( x_axis="orientation", filename="ORTC[-0.1,0.1]", sheet=topo.sim["V1Complex"], coords=[(-0.1, 0.1)])() topo.command.pylabplot.cyclic_tuning_curve.instance( x_axis="orientation", filename="ORTC[-0.1,-0.1]", sheet=topo.sim["V1Complex"], coords=[(-0.1, -0.1)])() topo.command.pylabplot.cyclic_tuning_curve.instance( x_axis="orientation", filename="ORTC[0.2,0.2]", sheet=topo.sim["V1Complex"], coords=[(0.2, 0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.2,-0.2]",sheet=topo.sim["V1Complex"],coords=[(0.2,-0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.2,0.2]",sheet=topo.sim["V1Complex"],coords=[(-0.2,0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.2,-0.2]",sheet=topo.sim["V1Complex"],coords=[(-0.2,-0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.1]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.1]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,0]",sheet=topo.sim["V1Complex"],coords=[(-0.1,0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,0]",sheet=topo.sim["V1Complex"],coords=[(0.1,-0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,0.3]",sheet=topo.sim["V1Complex"],coords=[(0.3,0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,-0.3]",sheet=topo.sim["V1Complex"],coords=[(0.3,-0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,0.3]",sheet=topo.sim["V1Complex"],coords=[(-0.3,0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,-0.3]",sheet=topo.sim["V1Complex"],coords=[(-0.3,-0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,0.24]",sheet=topo.sim["V1Complex"],coords=[(0.24,0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,-0.24]",sheet=topo.sim["V1Complex"],coords=[(0.24,-0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,0.24]",sheet=topo.sim["V1Complex"],coords=[(-0.24,0.42)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,-0.24]",sheet=topo.sim["V1Complex"],coords=[(-0.24,-0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.24]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.24]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.42)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,0]",sheet=topo.sim["V1Complex"],coords=[(-0.24,0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,0]",sheet=topo.sim["V1Complex"],coords=[(0.24,-0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.3]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.3]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,0]",sheet=topo.sim["V1Complex"],coords=[(-0.3,0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,0]",sheet=topo.sim["V1Complex"],coords=[(0.3,-0.0)])() #contrib.surround_analysis_new_cleaned.surround_analysis("V1Complex").run_analysis_with_step_grid(4,4,max_curves=__main__.__dict__.get("max_curves",20)) contrib.surround_analysis_new_cleaned.surround_analysis( "V1Complex").run_lhi_informed_analysis( max_curves=__main__.__dict__.get("max_curves", 26), center_size=__main__.__dict__.get("center_size", 20))
def complex_surround_analysis_function(): """ Basic example of an analysis command for run_batch; users are likely to need something similar but highly customized. """ import topo from topo.command.analysis import save_plotgroup from topo.analysis.featureresponses import SinusoidalMeasureResponseCommand,FeatureCurveCommand from topo.base.projection import ProjectionSheet from topo.sheet import GeneratorSheet from topo.command import save_snapshot from param import normalize_path import contrib.jacommands import contrib.surround_analysis_new_cleaned exec "from topo.analysis.vision import analyze_complexity" in __main__.__dict__ import matplotlib matplotlib.rc('xtick', labelsize=17) matplotlib.rc('ytick', labelsize=17) SinusoidalMeasureResponseCommand.frequencies=[2.4] SinusoidalMeasureResponseCommand.scale=__main__.__dict__.get("analysis_scale",0.3) from topo.analysis.featureresponses import PatternPresenter PatternPresenter.duration=4.0 import topo.command.pylabplot reload(topo.command.pylabplot) # Build a list of all sheets worth measuring f = lambda x: hasattr(x,'measure_maps') and x.measure_maps measured_sheets = filter(f,topo.sim.objects(ProjectionSheet).values()) input_sheets = topo.sim.objects(GeneratorSheet).values() # Set potentially reasonable defaults; not necessarily useful topo.command.analysis.coordinate=(0.0,0.0) if input_sheets: topo.command.analysis.input_sheet_name=input_sheets[0].name if measured_sheets: topo.command.analysis.sheet_name=measured_sheets[0].name save_plotgroup("Orientation Preference and Complexity") save_plotgroup("Activity",normalize='Individually') # Plot all projections for all measured_sheets for s in measured_sheets: for p in s.projections().values(): save_plotgroup("Projection",projection=p) if(float(topo.sim.time()) > 6020.0): if __main__.__dict__.get("save",False): save_snapshot(normalize_path('snapshot.typ')) #contrib.surround_analysis.run_dynamics_analysis(0.0,0.0,0.7,__main__.__dict__.get("analysis_scale",0.3)) #topo.command.pylabplot.measure_or_tuning_fullfield.instance(sheet=topo.sim["V1Complex"])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0]",sheet=topo.sim["V1Complex"],coords=[(0,0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,0.1]",sheet=topo.sim["V1Complex"],coords=[(0.1,0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,-0.1]",sheet=topo.sim["V1Complex"],coords=[(0.1,-0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,0.1]",sheet=topo.sim["V1Complex"],coords=[(-0.1,0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,-0.1]",sheet=topo.sim["V1Complex"],coords=[(-0.1,-0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.2,0.2]",sheet=topo.sim["V1Complex"],coords=[(0.2,0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.2,-0.2]",sheet=topo.sim["V1Complex"],coords=[(0.2,-0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.2,0.2]",sheet=topo.sim["V1Complex"],coords=[(-0.2,0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.2,-0.2]",sheet=topo.sim["V1Complex"],coords=[(-0.2,-0.2)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.1]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.1]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.1)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.1,0]",sheet=topo.sim["V1Complex"],coords=[(-0.1,0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.1,0]",sheet=topo.sim["V1Complex"],coords=[(0.1,-0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,0.3]",sheet=topo.sim["V1Complex"],coords=[(0.3,0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,-0.3]",sheet=topo.sim["V1Complex"],coords=[(0.3,-0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,0.3]",sheet=topo.sim["V1Complex"],coords=[(-0.3,0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,-0.3]",sheet=topo.sim["V1Complex"],coords=[(-0.3,-0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,0.24]",sheet=topo.sim["V1Complex"],coords=[(0.24,0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,-0.24]",sheet=topo.sim["V1Complex"],coords=[(0.24,-0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,0.24]",sheet=topo.sim["V1Complex"],coords=[(-0.24,0.42)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,-0.24]",sheet=topo.sim["V1Complex"],coords=[(-0.24,-0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.24]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.24)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.24]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.42)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.24,0]",sheet=topo.sim["V1Complex"],coords=[(-0.24,0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.24,0]",sheet=topo.sim["V1Complex"],coords=[(0.24,-0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,0.3]",sheet=topo.sim["V1Complex"],coords=[(0.0,0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0,-0.3]",sheet=topo.sim["V1Complex"],coords=[(0.0,-0.3)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[-0.3,0]",sheet=topo.sim["V1Complex"],coords=[(-0.3,0.0)])() #topo.command.pylabplot.cyclic_tuning_curve.instance(x_axis="orientation",filename="ORTC[0.3,0]",sheet=topo.sim["V1Complex"],coords=[(0.3,-0.0)])() #contrib.surround_analysis_new_cleaned.surround_analysis("V1Complex").run_analysis_with_step_grid(4,4,max_curves=__main__.__dict__.get("max_curves",20)) contrib.surround_analysis_new_cleaned.surround_analysis("V1Complex").run_lhi_informed_analysis(max_curves=__main__.__dict__.get("max_curves",20),center_size=__main__.__dict__.get("center_size",20))