def test(): # Hypersurface shape and pygor box_dim = 2 box_a = np.array([-1300., -1000.]) box_b = 500. * np.ones(box_dim) shape = pygor_dummy.Box(ndim=box_dim, a=box_a, b=box_b) th_leak = -500. * np.ones(2) shape = pygor_dummy.Leakage(shape, th_leak) origin = 0. * np.ones(box_dim) # Dummy function for extra measurement box_peaks = ([-1400., -1100], [-750, -900]) box_goodscore = ([-1400., -1100], [-1100, -900]) do_extra_meas = DummyExtMeas(box_peaks, box_goodscore) pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor_dummy( shape) # Poff detector step_back = 100 # important param for measuring d len_after_pinchoff = 100 threshold_high = 0.8 threshold_low = 0.2 d_r = 10 detector_pinchoff = util.PinchoffDetectorThreshold( threshold_low) # pichoff detector detector_conducting = util.ConductingDetectorThreshold( threshold_high) # reverse direction tester = Tester(pg, lb_short, ub_short, detector_pinchoff, d_r=d_r, len_after_pinchoff=len_after_pinchoff, logging=True, detector_conducting=detector_conducting, set_big_jump=set_big_jump, set_small_jump=set_small_jump) # Initial observations num_init = 10 u_all = random_hypersphere(box_dim, num_init) u_all, r_all, d_all, poff_all, detected_all, time_all, extra_meas_all = rw.get_full_data( u_all, tester, step_back, origin=origin) # GP hypersurface model ### # Gaussian process for r ### num_active_gates = box_dim l_prior_mean = 0.2 * np.ones(num_active_gates) l_prior_var = 0.1 * 0.1 * np.ones(num_active_gates) r_min, r_max = 0.0, np.sqrt(num_active_gates) * 2000. v_prior_mean = ((r_max - r_min) / 4.0)**2 v_prior_var = v_prior_mean**2 noise_var_r = np.square(d_r / 2.0) gp_r = GP_util.create_GP(num_active_gates, 'Matern52', v_prior_mean, l_prior_mean, (r_max - r_min) / 2.0) GP_util.set_GP_prior(gp_r, l_prior_mean, l_prior_var, None, None) # do not set prior for kernel var GP_util.fix_hyperparams(gp_r, False, True) # GP with initial observations #gp_r.create_model(u_all, r_all[:,np.newaxis], noise_var_r, noise_prior='fixed') #gp_r.optimize(num_restarts=20, opt_messages=False, print_result=True) #plot_example(lb_short, ub_short, shape, gp_r, u_all, r_all, origin, 'initial') #print(np.array(sampler.history_all).shape) # (num_samples, num_iter, ndim) #plot_example(lb_short, ub_short, shape, gp_r, u_all, r_all, origin, 'after') num_samples = 100 do_random_meas(box_dim, num_samples, tester, step_back, origin, lb_short, ub_short, gp_r, do_extra_meas=do_extra_meas, save_dir=None)
def main(): conf_name = 'dummy' if conf_name == 'config1': conf_func = config.config1 ip = "http://129.67.86.107:8000/RPC2" save_dir = Path('./save_Dominic_ABL_group_optparam_run2') settletime, settletime_big = 0.01, 0.03 # settletime_big is for shuttling, 'None' disables shuttling # ['c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] origin = -100. threshold_low = 0.0 # for pinchoff detector d_r = 10 # length of one step elif conf_name == 'config2': # ['c3', 'c4', 'c8', 'c10', 'c11', 'c12', 'c16'] conf_func = config.config2 ip = 'http://129.67.85.38:8000/RPC2' save_dir = Path('./save_Basel2_group') settletime, settletime_big = 0.02, 0.02 # settletime_big is for shuttling, 'None' disables shuttling origin = -100. threshold_low = 2.e-11 d_r = 10 # length of one step elif conf_name == 'dummy': import pygor_dummy box_dim = 5 box_a = -1000. * np.ones(box_dim) box_b = 1000. * np.ones(box_dim) shape = pygor_dummy.Box(ndim=box_dim, a=box_a, b=box_b) th_leak = np.array([-500., -400., -300., 0., 0.]) shape = pygor_dummy.Leakage(shape, th_leak) save_dir = Path('./save_dummy') origin = -100. threshold_low = 0.2 d_r = 10 # length of one step else: raise ValueError('Unsupported setup') save_dir.mkdir(exist_ok=True) if conf_name != 'dummy': pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor(conf_func, ip, settletime, settletime_big) else: pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor_dummy(shape) threshold_high = 0.8 * max_current num_active_gates = len(active_gate_idxs) # gate names are for nothing active_gate_names = ["c{}".format(i+1) for i in active_gate_idxs] print(active_gate_names) ''' Disable grouped gates new_wires = [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 0]] pg = PygorRewire(pg, new_wires) lb_short = lb_short[:4] ub_short = ub_short[:4] num_active_gates = len(new_wires) ''' # choose the origin if np.isscalar(origin): origin = origin*np.ones(num_active_gates) else: if len(origin) != num_active_gates: raise ValueError('Wrong array shape of the origin.') origin.dump(str(save_dir / 'origin.npy')) # important algorithm parameters #threshold_low = 0.2 * (max_current - min_current) + min_current step_back = 100 # important param for measuring d len_after_pinchoff=50 num_samples = 100 # number of initial samples (by Latin hypercube design) detector_pinchoff = util.PinchoffDetectorThreshold(threshold_low) # pichoff detector detector_conducting = util.ConductingDetectorThreshold(threshold_high) # reverse direction # create a Callable object, input: unit_vector, output: distance between the boundary and the origin tester = Tester(pg, lb_short, ub_short, detector_pinchoff, d_r=d_r, len_after_pinchoff=len_after_pinchoff, logging=True, detector_conducting=detector_conducting, set_big_jump = set_big_jump, set_small_jump = set_small_jump) ### # Set a problem and a model ### #do_extra_meas = lambda vols, th: config_model.do_extra_meas(pg, vols, th) do_extra_meas = None ### # Gaussian process for r ### l_prior_mean = 0.4 * np.ones(num_active_gates) l_prior_var = 0.1*0.1 * np.ones(num_active_gates) r_min, r_max = 0.0, np.sqrt(num_active_gates)* 2000. v_prior_mean = ((r_max-r_min)/4.0)**2 #v_prior_var = v_prior_mean**2 #noise_var_r = np.square(d_r/2.0) gp_r = GP_util.create_GP(num_active_gates, 'Matern52', v_prior_mean, l_prior_mean, (r_max-r_min)/2.0) GP_util.set_GP_prior(gp_r, l_prior_mean, l_prior_var, None, None) # do not set prior for kernel var GP_util.fix_hyperparams(gp_r, False, True) ### # Gaussian process classifiers for predicting each probability component ### l_prior_mean = 500. * np.ones(num_active_gates) l_prior_var = 100.**2 * np.ones(num_active_gates) v_prior_mean = 50. v_prior_var = 20.**2 gpc_dict = dict() gpc_dict['valid'] = GP_util.create_GP(num_active_gates, 'Matern52', lengthscale=l_prior_mean, const_kernel=True, GP=GPC) gpc_dict['peak'] = GP_util.create_GP(num_active_gates, 'Matern52', lengthscale=l_prior_mean, const_kernel=True, GP=GPC) # when a point is valid gpc_dict['goodscore'] = GP_util.create_GP(num_active_gates, 'Matern52', lengthscale=l_prior_mean, const_kernel=True, GP=GPC) # when a point is valid and has peaks GP_util.set_GP_prior(gpc_dict['valid'], l_prior_mean, l_prior_var, v_prior_mean, v_prior_var) # do not set prior for kernel var GP_util.set_GP_prior(gpc_dict['peak'], l_prior_mean, l_prior_var, v_prior_mean, v_prior_var) # do not set prior for kernel var GP_util.set_GP_prior(gpc_dict['goodscore'], l_prior_mean, l_prior_var, v_prior_mean, v_prior_var) # do not set prior for kernel var do_random_meas(num_active_gates, num_samples, tester, step_back, origin, lb_short, ub_short, gp_r, gpc_dict, do_extra_meas=do_extra_meas, save_dir=save_dir) print('Time for random sampling: ', time.time()-tic)
def main(): # make a dummy pygor num_active_gates = 2 lb = np.array([-1000., -1000.]) ub = np.array([0., 0.]) # cube box = pygor_dummy.Box(ndim=num_active_gates, a=[-500., -500], b=[500., 500.]) pg = pygor_dummy.PygorDummyBinary(lb, ub, box) # circle #circle = pygor_dummy.Circle(r=500.,ndim=num_active_gates) #pg = pygor_dummy.PygorDummyBinary(lb,ub, circle) # convexhull conv_points = np.array([[-500., -100.], [-700., 200.], [1000., 200.], [1000., -200.]]) convexhull = pygor_dummy.Convexhull(conv_points) pg = pygor_dummy.PygorDummyBinary(lb, ub, convexhull) img = pg.do2d('c1', -1000., 0., 128, 'c2', -1000, 0., 128)[0] plt.figure() plt.imshow(img, cmap='RdBu_r', aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]]) plt.savefig('test_dummy') plt.close() # algorithm parameters threshold = 0.2 d_r = 10 step_back = 50. num_lhs = 5 # pichoff detector detector_pinchoff = util.PinchoffDetectorThreshold(threshold) # tester to get r and d information tester = Tester(pg, lb, ub, detector_pinchoff, d_r=d_r, logging=True) u_all, r_all, d_all, detected_all, time_all = get_u_init( num_active_gates, num_lhs, tester, step_back) # simple GP #GP_hypersurface(u_all, r_all, fname='basic', overlay=img, lb_overlay=lb, ub_overlay=ub) #u_ext_all, r_ext_all = calc_ur_from_d(u_all, r_all, d_all, step_back) # intersection model h = Hypersurface_IndependentGP(num_active_gates) # data v_ext = calc_v_from_urd(u_all, r_all, d_all, step_back) h.set_data(v_ext, noise_var=(d_r / 2.)**2) resol = 300 num_samples = 10 v1_grid = np.linspace(lb[0], ub[0], resol) v_test = np.hstack((v1_grid[:, np.newaxis], np.zeros(resol)[:, np.newaxis])) samples_v2 = -h.generate_samples_dg(v_test, 1, num_samples) v2_grid = np.linspace(lb[1], ub[1], resol) v_test = np.hstack((np.zeros(resol)[:, np.newaxis], v2_grid[:, np.newaxis])) samples_v1 = -h.generate_samples_dg(v_test, 0, num_samples) plt.figure() plt.imshow(img, cmap='RdBu_r', aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]], alpha=0.3) for i in range(num_samples): line, = plt.plot(samples_v2[i], v1_grid, alpha=0.5) plt.plot(v2_grid, samples_v1[i], color=line.get_color(), alpha=0.5) # obsevations plt.scatter(v_ext[0, :, 1], v_ext[0, :, 0], marker='x', color='black') plt.scatter(v_ext[1, :, 1], v_ext[1, :, 0], marker='x', color='black') plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_intersection') plt.close() # intersection likelihood V2, V1 = np.meshgrid(v2_grid, v1_grid) v_test = np.array([V1.ravel(), V2.ravel()]).transpose() L = h.boundary_likelihood(v_test) L = L.reshape(V1.shape) fig = plt.figure() ax = plt.gca() cs = ax.imshow(L, aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]]) fig.colorbar(cs) plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_intersection_L') plt.close() # expected distance to the hypersurface d_all, _ = h.posterior_d(v_test, full_cov=False) ss_d = np.sqrt(np.sum(np.square(d_all), axis=0)) ss_d = ss_d.reshape(V1.shape) fig = plt.figure() plt.imshow(img, cmap='RdBu_r', aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]], alpha=0.5) ax = plt.gca() cs = ax.imshow(ss_d, aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]], alpha=0.5) fig.colorbar(cs) plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_sum_sq_d') plt.close() # probability that v is inside of a hypersurface P = h.prob_inside_each(v_test) P = P.reshape(V1.shape) fig = plt.figure() ax = plt.gca() cs = ax.imshow(P, aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]]) fig.colorbar(cs) plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_prob_inside') plt.close() # Expected improvement v = np.zeros(num_active_gates) d_best = tester.measure_dist_all_axis(v) print(d_best) EI = h.EI2(v_test, d_best) EI = EI.reshape(V1.shape) fig = plt.figure() ax = plt.gca() cs = ax.imshow(EI, aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]]) fig.colorbar(cs) plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_EI') plt.close() # Expected improvement with stepback v = np.zeros(num_active_gates) d_best = tester.measure_dist_all_axis(v) print(d_best) EI = h.EI2(v_test, d_best, stepback=100.) EI = EI.reshape(V1.shape) fig = plt.figure() ax = plt.gca() cs = ax.imshow(EI, aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]]) fig.colorbar(cs) plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_EI_stepback') plt.close() #algorithm stepback = 50. num_iter = 5 v_init = -stepback * np.ones(num_active_gates) # initial point # measurement d = tester.measure_dist_all_axis(v_init + stepback) v_all = np.array([v_init]) d_all = np.array([d]) v_ext = calc_v_from_vd(v_all, d_all, step_back) # update the hypersurface model h = Hypersurface_IndependentGP(num_active_gates) h.set_data(v_ext, noise_var=(d_r / 2.)**2) v_bestL_all = list() v_bestEI_all = list() for i in range(num_iter): # draw corner likelihood L = h.boundary_likelihood(v_test) draw_map(L.reshape((V1.shape)), lb, ub, 'Corner_{}'.format(i)) best_L_idx = np.argmax(L) v_bestL_all.append(v_test[best_L_idx]) # d at best v d_sum = np.sum(d_all, axis=1) d_best_idx = np.argmin(d_sum) d_best = d_all[d_best_idx] print('d_best:', d_best) # next point EI = h.EI2(v_test, d_best, stepback=stepback) draw_map(EI.reshape((V1.shape)), lb, ub, 'EI_{}'.format(i)) best_idx = np.argmax(EI) v_bestEI = v_test[best_idx] v_bestEI_all.append(v_bestEI) # go the the next point d_step = 5. dist = L2_norm(v_all[-1] - v_bestEI) unit_vector = (v_bestEI - v_all[-1]) / dist vol_line, val_line, pinchoff_idx = tester.measure_dist_unit_vector( v_all[-1], unit_vector, d_r=d_step, max_r=dist) if pinchoff_idx != -1: # pinchoff detected v_next = vol_line[ pinchoff_idx] - unit_vector * d_step # right before pinchoff else: # pinchoff not detected from the current v to v_bestEI v_next = vol_line[-1] # measurement v_all = np.concatenate((v_all, v_next[np.newaxis, :]), axis=0) d = tester.measure_dist_all_axis(v_all[-1] + stepback) d_all = np.concatenate((d_all, d[np.newaxis, :]), axis=0) # update the hypersurface model v_ext = calc_v_from_vd(v_all, d_all, step_back) h.set_data(v_ext, noise_var=(d_r / 2.)**2) np.set_printoptions(precision=0) np.set_printoptions(suppress=True) print(v_all) v_bestL_all = np.array(v_bestL_all) print(v_bestL_all) v_bestEI_all = np.array(v_bestEI_all) print(v_bestEI_all) fig = plt.figure(dpi=300) ax = plt.gca() cs = ax.imshow(img, aspect='equal', origin='lower', extent=[lb[1], ub[1], lb[0], ub[0]]) fig.colorbar(cs) plt.scatter(v_all[:, 1], v_all[:, 0], marker='.', color='black') plt.xlim(lb[1], ub[1]) plt.ylim(lb[0], ub[0]) plt.savefig('temp_history') plt.close()
def main(): conf_name = 'config1' if conf_name == 'config1': conf_func = config.config1 ip = "http://129.67.86.107:8000/RPC2" save_dir = Path('./save_Dominic_redo_Basel2_correct') settletime, settletime_big = 0.01, 0.03 # settletime_big is for shuttling, 'None' disables shuttling # ['c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] #origin = -100. origin = 0. threshold_low = 0.0 # for pinchoff detector d_r = 10 # length of one step elif conf_name == 'config2': # ['c3', 'c4', 'c8', 'c10', 'c11', 'c12', 'c16'] conf_func = config.config2 ip = "http://129.67.85.235:8000/RPC2" save_dir = Path('./save_Florian_redo') settletime, settletime_big = 0.01, 0.03 # settletime_big is for shuttling, 'None' disables shuttling #origin = -100. origin = 0. settletime = 0.01 threshold_low = 2.e-11 d_r = 10 # length of one step elif conf_name == 'dummy': import pygor_dummy box_dim = 5 box_a = -1000. * np.ones(box_dim) box_b = 1000. * np.ones(box_dim) shape = pygor_dummy.Box(ndim=box_dim, a=box_a, b=box_b) th_leak = np.array([-500., -400., -300., 0., 0.]) shape = pygor_dummy.Leakage(shape, th_leak) save_dir = Path('./save_dummy') origin = -100. threshold_low = 0.2 d_r = 10 # length of one step else: raise ValueError('Unsupported setup') save_dir.mkdir(exist_ok=True) if conf_name != 'dummy': pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor(conf_func, ip, settletime, settletime_big) else: pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor_dummy(shape) threshold_high = 0.8 * max_current active_gate_names = ["c{}".format(i+1) for i in active_gate_idxs] num_active_gates = len(active_gate_names) print(active_gate_names) # choose the origin if np.isscalar(origin): origin = origin*np.ones(num_active_gates) else: if len(origin) != num_active_gates: raise ValueError('Wrong array shape of origin.') # important algorithm parameters len_after_pinchoff=100 detector_pinchoff = util.PinchoffDetectorThreshold(threshold_low) # pichoff detector detector_conducting = util.ConductingDetectorThreshold(threshold_high) # reverse direction # create a Callable object, input: unit_vector, output: distance between the boundary and the origin tester = Tester(pg, lb_short, ub_short, detector_pinchoff, d_r=d_r, len_after_pinchoff=len_after_pinchoff, logging=True, detector_conducting=detector_conducting, set_big_jump = set_big_jump, set_small_jump = set_small_jump) #do_extra_meas = lambda vols: config_model.do_extra_meas(pg, vols) do_extra_meas = None # load voltages of a previous experiment load_dir = Path('./save_Florian_randompoints') #load_dir = Path('./save_Dominic_hs') #load_dir = Path('./save_Dominic_randomHS_origin0_fixed') vols_prev = np.load(load_dir/'vols_poff.npy', allow_pickle=True) num_points = len(vols_prev) vols_poff_all = list() detected_all = list() for i, v in enumerate(vols_prev): v = convert_Basel2_to_Basel1(v) v_origin = v - origin u = v_origin / np.sqrt(np.sum(np.square(v_origin))) # voltage -> unit vector # Get measurements r, vols_pinchoff, found, t_firstjump = tester.get_r(u, origin=origin) # Measure the distance vols_poff_all.append(vols_pinchoff) detected_all.append(found) print(i) print(v) print(vols_pinchoff) np.array(vols_poff_all).dump(str(save_dir / 'vols_poff_after.npy')) np.array(vols_prev).dump(str(save_dir / 'vols_poff_prev.npy')) np.array(detected_all).dump(str(save_dir / 'detected_after.npy'))
d_r = 10 # length of one step elif conf_name == 'config2': conf_func = config.config2 ip = "http://129.67.85.235:8000/RPC2" save_dir = Path('./save_YutianFlorian8') settletime, settletime_big = 0.01, None # settletime_big is for shuttling, 'None' disables shuttling origin = -100. settletime = 0.01 threshold_low = 5.e-11 d_r = 10 # length of one step elif conf_name == 'dummy': import pygor_dummy box_dim = 5 box_a = -500. * np.ones(box_dim) box_b = 500. * np.ones(box_dim) shape = pygor_dummy.Box(ndim=box_dim, a=box_a, b=box_b) save_dir = Path('./save_dummy') origin = -100. threshold_low = 0.2 d_r = 10 # length of one step else: raise ValueError('Unsupported setup') save_dir.mkdir(exist_ok=True) origin = np.load(save_dir / 'origin.npy') #origin = np.zeros(8) vols_all = np.load(save_dir / 'vols.npy') d_all = np.load(save_dir / 'dist_surface.npy') pinchoff_idx = np.load(save_dir / 'pinchoff_idx.npy') d_tot = np.array(np.load(save_dir / 'obj_val.npy'))
def main(): conf_name = 'config2' if conf_name == 'config1': conf_func = config.config1 ip = "http://129.67.86.107:8000/RPC2" save_dir = Path('./save_Dominic_ABL_group_optparam_run2/135_2') settletime, settletime_big = 0.01, 0.03 # settletime_big is for shuttling, 'None' disables shuttling # ['c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] threshold_low = 0.0 # for pinchoff detector d_r = 10 # length of one step elif conf_name == 'config2': # ['c3', 'c4', 'c8', 'c10', 'c11', 'c12', 'c16'] conf_func = config.config2 #ip = "http://129.67.85.235:8000/RPC2" ip = 'http://129.67.85.38:8000/RPC2' save_dir = Path('./save_Basel2_group/105') settletime, settletime_big = 0.02, 0.02 # settletime_big is for shuttling, 'None' disables shuttling threshold_low = 2.e-11 d_r = 10 # length of one step elif conf_name == 'dummy': import pygor_dummy box_dim = 5 box_a = -1000. * np.ones(box_dim) box_b = 1000. * np.ones(box_dim) shape = pygor_dummy.Box(ndim=box_dim, a=box_a, b=box_b) th_leak = np.array([-500., -400., -300., 0., 0.]) shape = pygor_dummy.Leakage(shape, th_leak) save_dir = Path('./save_dummy') threshold_low = 0.2 d_r = 10 # length of one step else: raise ValueError('Unsupported setup') save_dir.mkdir(exist_ok=True) if conf_name != 'dummy': pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor( conf_func, ip, settletime, settletime_big) else: pg, active_gate_idxs, lb_short, ub_short, max_current, min_current, set_big_jump, set_small_jump = config.setup_pygor_dummy( shape) threshold_high = 0.8 * max_current active_gate_names = ["c{}".format(i + 1) for i in active_gate_idxs] num_active_gates = len(active_gate_names) print(active_gate_names) # important algorithm parameters len_after_pinchoff = 100 detector_pinchoff = util.PinchoffDetectorThreshold( threshold_low) # pichoff detector detector_conducting = util.ConductingDetectorThreshold( threshold_high) # reverse direction # create a Callable object, input: unit_vector, output: distance between the boundary and the origin tester = Tester(pg, lb_short, ub_short, detector_pinchoff, d_r=d_r, len_after_pinchoff=len_after_pinchoff, logging=True, detector_conducting=detector_conducting, set_big_jump=set_big_jump, set_small_jump=set_small_jump) #do_extra_meas = lambda vols, th: config_model.do_extra_meas(pg, vols, th) do_extra_meas = None #v_target = np.array([-1877.11448379, -315.09271412, -588.03713859, -1743.6191362 , -587.8001855 , -693.38667762, -832.91995001, -186.99101894]) #new_wires = [[1, 0, 0, 0, 0, 0, 0, 0], #[0, 1, 0, 0, 0, 0, 0, 1], #[0, 0, 1, 0, 0, 0, 1, 0], #[0, 0, 0, 1, 1, 1, 0, 0]] new_wires = [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 1], [0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 0]] new_wires = np.array(new_wires) v_target = np.array( [-1290.10731323, -1521.90819125, -813.40589252, -1069.5955569]) v_target = np.matmul(new_wires.T, v_target) origin = np.minimum(v_target + 200., 0.) print('Origin: ', origin) np.array(v_target).dump(str(save_dir / 'v_local.npy')) np.array(origin).dump(str(save_dir / 'origin_local.npy')) num_trials = 500 sigma = 100. #name_g1, name_g2 = 'c5', 'c9' name_g1, name_g2 = 'c8', 'c12' resol = 64 w1 = w2 = 75 idx_g1, idx_g2 = active_gate_names.index(name_g1), active_gate_names.index( name_g2) lb_g1, lb_g2 = lb_short[idx_g1], lb_short[idx_g2] ub_g1, ub_g2 = ub_short[idx_g1], ub_short[idx_g2] v_all = list() meas_all = list() time_all = list() for i in range(num_trials): ''' delta = np.random.normal(scale=sigma, size=num_active_gates) v_origin = v_target + delta - origin print('Random vol:', v_origin+origin) u = v_origin / np.sqrt(np.sum(np.square(v_origin))) # voltage -> unit vector ''' u = random_hypersphere(num_active_gates, 1)[0] # Get measurements t = time.time() r, vols_pinchoff, found, t_firstjump = tester.get_r( u, origin=origin) # Measure the distance t1 = time.time() - t print('Poff at ', vols_pinchoff) if found: # measurement print('Found') meas = measure_2d.scan2d(pg, name_g1, name_g2, resol, vols_pinchoff, w1, w2, lb_g1, lb_g2, ub_g1, ub_g2, str(i), pic_dpi=None, mult1=1., mult2=1., save_dir=save_dir) ''' meas = do_extra_meas(vols_pinchoff, 0.0) # highres = meas[-6] if len(meas) > 10 else None # lowres = meas[4] if len(meas) > 4 else None if lowres: plt.imsave(str(save_dir/(str(i)+'lowres.png')), lowres, origin='lower', cmap='viridis') if highres: plt.imsave(str(save_dir/(str(i)+'highres.png')), highres, origin='lower', cmap='viridis') ''' else: print('Not found') meas = [] t2 = time.time() - t time_all.append((t1, t2)) v_all.append(vols_pinchoff) meas_all.append(meas) np.array(v_all).dump(str(save_dir / 'vols_poff.npy')) #np.array(meas_all).dump(str(save_dir/'meas.npy')) np.save(str(save_dir / 'meas'), meas_all) np.array(time_all).dump(str(save_dir / 'time.npy'))