def test_sameness(self): exp = TestExperiment() printer_partial = Print(name="Partial") printer_final = Print(name="Final") avgr = Averager(name="TestAverager", axis='freq_1') edges = [(exp.chan1, avgr.sink), (avgr.partial_average, printer_partial.sink), (avgr.source, printer_final.sink)] exp.set_graph(edges) exp.add_sweep(exp.freq_1, np.linspace(0, 9, 10)) exp.run_sweeps()
def test_final_variance_runs(self): exp = VarianceExperiment() printer_final = Print(name="Final") avgr = Averager('repeats', name="TestAverager") var_buff = DataBuffer(name='Variance Buffer') mean_buff = DataBuffer(name='Mean Buffer') edges = [(exp.chan1, avgr.sink), (avgr.final_variance, printer_final.sink), (avgr.final_variance, var_buff.sink), (avgr.source, mean_buff.sink)] exp.set_graph(edges) exp.run_sweeps() # var_data = var_buff.get_data()['Variance'].reshape(var_buff.descriptor.data_dims()) # mean_data = mean_buff.get_data()['chan1'].reshape(mean_buff.descriptor.data_dims()) var_data = var_buff.output_data.reshape( var_buff.descriptor.data_dims()) mean_data = mean_buff.output_data.reshape( mean_buff.descriptor.data_dims()) orig_data = exp.vals.reshape(exp.chan1.descriptor.data_dims()) self.assertTrue( np.abs(np.sum(mean_data - np.mean(orig_data, axis=0))) <= 1e-3) self.assertTrue( np.abs(np.sum(var_data - np.var(orig_data, axis=0, ddof=1))) <= 1e-3)
def test_final_average_runs(self): exp = TestExperiment() printer_final = Print(name="Final") avgr = Averager('trials', name="TestAverager") edges = [(exp.chan1, avgr.sink), (avgr.source, printer_final.sink)] exp.set_graph(edges) exp.run_sweeps()
def test_run_sweep(self): exp = SweptTestExperiment() pri = Print(name="Printer") edges = [(exp.voltage, pri.sink)] exp.set_graph(edges) exp.add_sweep(exp.field, np.linspace(0,100.0,11)) exp.add_sweep(exp.freq, np.linspace(0,10.0,3)) exp.run_sweeps()
def test_unstructured_sweep(self): exp = SweptTestExperiment() pri = Print() edges = [(exp.voltage, pri.sink)] exp.set_graph(edges) coords = [[0, 0.1], [10, 4.0], [15, 2.5], [40, 4.4], [50, 2.5], [60, 1.4], [65, 3.6], [66, 3.5], [67, 3.6], [68, 1.2]] exp.add_sweep([exp.field, exp.freq], coords) exp.run_sweeps() self.assertTrue(pri.sink.input_streams[0].points_taken.value == exp.voltage.num_points())
def test_run(self): exp = SweptTestExperiment() pri = Print() edges = [(exp.voltage, pri.sink)] exp.set_graph(edges) exp.add_sweep(exp.field, np.linspace(0,100.0,11)) exp.add_sweep(exp.freq, np.linspace(0,10.0,3)) exp.run_sweeps() logger.debug("Run test: logger.debuger ended up with %d points.", pri.sink.input_streams[0].points_taken) logger.debug("Run test: voltage ended up with %d points.", exp.voltage.output_streams[0].points_taken) self.assertTrue(pri.sink.input_streams[0].points_taken == exp.voltage.num_points())
def test_run_adaptive_sweep(self): exp = SweptTestExperiment() pri = Print(name="Printer") edges = [(exp.voltage, pri.sink)] exp.set_graph(edges) def rf(sweep_axis, exp): logger.debug("Running refinement function.") if sweep_axis.num_points() >= 5: return False sweep_axis.add_points(sweep_axis.points[-1] * 2) return True exp.add_sweep(exp.field, np.linspace(0, 100.0, 11)) exp.add_sweep(exp.freq, [1.0, 2.0], refine_func=rf) exp.run_sweeps()