def refine_func(sweep_axis, experiment): data, desc = load_from_HDF5(writer.filename.value, reshape=False) groupname = writer.groupname.value zs = data[groupname][z_name] ys = data[groupname][y_name] xs = data[groupname][x_name] points = np.array([xs, ys]).transpose() new_points = refine.refine_scalar_field(points, zs, all_points=False, criterion=criterion, threshold=threshold) if len(points) + len(new_points) > max_points: print("Reached maximum points ({}).".format(max_points)) return False print("Reached {} points.".format(len(points) + len(new_points))) sweep_axis.add_points(new_points) if plotter: data = np.array([xs, ys, zs]).transpose() experiment.push_to_plot(plotter, data) # time.sleep(0.02) return True
def refine_func(sweep_axis): points, mean = sw.load_switching_data(wr.filename) new_points = refine.refine_scalar_field(points, mean, all_points=False, criterion="integral", threshold="one_sigma") if len(points) + len(new_points) > max_points: print("Reached maximum points ({}).".format(max_points)) return False print("Reached {} points.".format(len(points) + len(new_points))) sweep_axis.add_points(new_points) # Plot previous mesh x = [list(el) for el in points[mesh.simplices, 0]] y = [list(el) for el in points[mesh.simplices, 1]] val = [np.mean(vals) for vals in mean[mesh.simplices]] desc = DataStreamDescriptor() desc.add_axis(sweep_axis) exp.push_to_plot(fig1, desc, points) time.sleep(1) return True
interpolation='none') ax2.imshow(values_orig, origin='lower', extent=extent, aspect=aspect, interpolation='none') # Evaluate values at original mesh points values = np.apply_along_axis(ff, 1, points) # Find new points and update values for i in range(ITERATION): new_points = refine_scalar_field(points, values, all_points=False, criterion="difference", threshold="one_sigma", resolution=ACCEPT_RESOLUTION, noise_level=ACCEPT_NOISE) if new_points is None: print("No more points can be added.") break # Update points and values points = np.append(points, new_points, axis=0) new_values = np.apply_along_axis(ff, 1, new_points) values = np.append(values, new_values, axis=0) if len(points) > MAX_POINTS: print("Reach maximum number of points! Stop.") break
exp.set_graph(edges) main_sweep = exp.add_unstructured_sweep( [exp.pulse_duration, exp.pulse_voltage], points) figs = [] t1 = time.time() for i in range(exp.iteration): exp.reset() exp.run_sweeps() points, mean = sw.load_switching_data(wr.filename) figs.append( sw.phase_diagram_mesh(points, mean, title="Iteration={}".format(i))) new_points = refine.refine_scalar_field(points, mean, all_points=False, criterion="integral", threshold="one_sigma") if new_points is None: print("No more points can be added.") break # print("Added {} new points.".format(len(new_points))) print("Elapsed time: {}".format((time.time() - t1) / 60)) main_sweep.update_values(new_points) exp.pulse_durations = new_points[:, 0] exp.pulse_voltages = new_points[:, 1] exp.setup_arb() time.sleep(3) t2 = time.time()