if isinstance(Vpoint, np.ndarray): sweep_points = Vpoint break if not(isinstance(sweep_points, np.ndarray)): sweep_points = [Vres] SweepIdx = 0 cprint("Sweeping %s from %.2f V to %.2f V" % (electrode_names[SweepIdx], sweep_points[0], sweep_points[-1]), "green") simulation_name += "_%s_sweep" % (electrode_names[SweepIdx]) electron_initial_positions = anneal.get_rectangular_initial_condition(N_electrons, N_rows=N_rows, N_cols=N_cols, x0=(inserted_res_length*1E-6 + box_length)/2., y0=0.0E-6, dx=0.40E-6) x_trap_init, y_trap_init = anneal.r2xy(electron_initial_positions) if platform.system() == 'Windows': save_path = r"S:\Gerwin\Electron on helium\Electron optimization\Realistic potential\Single electron loading" elif platform.system() == 'Linux': save_path = r"/mnt/slab/Gerwin/Electron on helium/Electron optimization/Realistic potential/Single electron loading" else: save_path = r"/Users/gkoolstra/Desktop/Single electron loading/Data" sub_dir = time.strftime("%y%m%d_%H%M%S_{}".format(simulation_name)) save = True # Evaluate all files in the following range. xeval = np.linspace(-4.0, box_length*1E6, 751) yeval = anneal.construct_symmetric_y(-4.0, 201)
X_eval, Y_eval = np.meshgrid(x_eval * 1E-6, y_eval * 1E-6) VBG_mat = np.zeros((len(y_eval), len(x_eval))) for j, X in enumerate(x_eval * 1E-6): VBG_mat[:, j] = CMS.Vbg(X * np.ones(len(y_eval)), y_eval * 1E-6) # Solve for the electron positions in the trap area! ConvMon = anneal.ConvergenceMonitor(Uopt=CMS.Vtotal, grad_Uopt=CMS.grad_total, N=10, Uext=CMS.V, xext=xeval * 1E-6, yext=yeval * 1E-6, verbose=False, eps=epsilon, save_path=conv_mon_save_path) ConvMon.figsize = (8., 2.) x_trap_init, y_trap_init = anneal.r2xy(trap_initial_condition) trap_minimizer_options = {'jac': CMS.grad_total, 'options': {'disp': False, 'gtol': gradient_tolerance, 'eps': epsilon}, 'callback': ConvMon.monitor_convergence} trap = minimize(CMS.Vtotal, trap_initial_condition, method='CG', **trap_minimizer_options) if trap['status'] > 0: cprint("WARNING: Initial minimization for Trap did not converge!", "red") print("Final L-inf norm of gradient = %.2f eV/m" % (np.amax(trap['jac']))) best_trap = trap else: cprint("SUCCESS: Initial minimization for Trap converged!", "green") # This maps the electron positions within the simulation domain cprint("Perturbing solution %d times at %.2f K" \
def coordinate_transformation(r): x, y = anneal.r2xy(r) y_new = EP.map_y_into_domain(y) r_new = anneal.xy2r(x, y_new) return r_new
if N_cols * col_spacing > box_length: raise ValueError( "Placing electrons outside of the box length as initial condition is not allowed! Increase N_rows!" ) electron_initial_positions = anneal.get_rectangular_initial_condition( N_electrons, N_rows=N_rows, N_cols=N_cols, x0=0.0E-6, y0=0.0E-6, dx=col_spacing, dy=row_spacing) xinit, yinit = anneal.r2xy(electron_initial_positions) def coordinate_transformation(r): x, y = anneal.r2xy(r) y_new = EP.map_y_into_domain(y) r_new = anneal.xy2r(x, y_new) return r_new # This is where the actual solving starts... os.mkdir(os.path.join(save_path, sub_dir)) time.sleep(1) os.mkdir(os.path.join(save_path, sub_dir, "Figures")) if save:
f.close() # Create a movie ConvMon.create_movie(fps=10, filenames_in=time.strftime("%Y%m%d") + "_figure_%05d.png", filename_out="resonator_%d_electrons.mp4" % (N_electrons)) # Move the file from the Figures folder to the sub folder os.rename( os.path.join(save_path, sub_dir, "Figures/resonator_%d_electrons.mp4" % (N_electrons)), os.path.join(save_path, sub_dir, "resonator_%d_electrons.mp4" % (N_electrons))) x, y = anneal.r2xy(res['x']) final_func_val = res['fun'] n_iterations = res['nit'] if 0: if len(np.shape(ConvMon.jac)) > 1: figgy = plt.figure(figsize=(6, 4)) common.configure_axes(12) # LInf-norm plt.plot(ConvMon.iter, np.amax(np.abs(ConvMon.jac[:, ::2]), axis=1), '.-r', label=r'$L^\infty$-norm $\nabla_x U_\mathrm{opt}$') plt.plot(ConvMon.iter, np.amax(np.abs(ConvMon.jac[:, 1::2]), axis=1), '.-b',
Voi_idx = common.find_nearest(np.array(Vres), Voi) modes = ten_strongest_mode_numbers[Voi_idx, :9] fig3 = plt.figure(figsize=(6., 4.)) plt.plot( np.sqrt(Eigenvalues[Voi_idx, :]) / (2 * np.pi * 1E9), 'o', **common.plot_opt('red', msize=4)) plt.xlabel("Mode number") plt.ylabel("$\omega_e/2\pi$ (GHz)") plt.title("Frequency of all modes at Vres = %.2f V" % Voi) if save: common.save_figure(fig3, save_path=os.path.join(save_path, sub_dir)) # Look at the electron position of the last voltage step and single out the electrons in the left and right row # Note: this only makes sense if you have two rows! xi, yi = anneal.r2xy(electron_positions[Voi_idx, :]) right_idxs = np.where(xi > 0)[0] sorted_right_idxs = np.argsort(right_idxs) left_idxs = np.where(xi < 0)[0] sorted_left_idxs = np.argsort(left_idxs) sorted_idxs = np.argsort(yi) if len(right_idxs) == 0 or len(left_idxs) == 0: print("2 row configuration not detected, assuming 1 row") two_rows = False else: two_rows = True # Here we create a plot with the amplitude of the electrons in the chain (from bottom to top) for the first # 9 strongest eigenmodes. The last subplot shows the mode that couples strongest. fig4 = plt.figure(figsize=(12., 10.))