From 767cec6d8677217ec2177c91fc10a475d9f98e05 Mon Sep 17 00:00:00 2001 From: Karthik Chandrashekara Date: Tue, 1 Apr 2025 20:09:56 +0200 Subject: [PATCH] Minor modification to gradient descent script. --- Dipolar-Gas-Simulator/+Scripts/run_locally.m | 34 +++++------ .../@DipolarGas/runGradientDescent.m | 60 ++++++++++--------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Dipolar-Gas-Simulator/+Scripts/run_locally.m b/Dipolar-Gas-Simulator/+Scripts/run_locally.m index 1a07fe0..8dc0c14 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_locally.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_locally.m @@ -6,36 +6,33 @@ OptionsStruct = struct; -OptionsStruct.NumberOfAtoms = 5E5; +OptionsStruct.NumberOfAtoms = 8E4; OptionsStruct.DipolarPolarAngle = deg2rad(0); OptionsStruct.DipolarAzimuthAngle = 0; -OptionsStruct.ScatteringLength = 88.5; +OptionsStruct.ScatteringLength = 95; -AspectRatio = 2.0; -HorizontalTrapFrequency = 125; -VerticalTrapFrequency = AspectRatio * HorizontalTrapFrequency; -OptionsStruct.TrapFrequencies = [HorizontalTrapFrequency, HorizontalTrapFrequency, VerticalTrapFrequency]; +OptionsStruct.TrapFrequencies = [30, 60, 90]; OptionsStruct.TrapPotentialType = 'Harmonic'; -OptionsStruct.NumberOfGridPoints = [64, 64, 32]; -OptionsStruct.Dimensions = [18, 18, 18]; +OptionsStruct.NumberOfGridPoints = [256, 128, 128]; +OptionsStruct.Dimensions = [30, 20, 20]; OptionsStruct.UseApproximationForLHY = true; OptionsStruct.IncludeDDICutOff = true; OptionsStruct.CutoffType = 'Cylindrical'; OptionsStruct.SimulationMode = 'EnergyMinimization'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution' | 'EnergyMinimization' -OptionsStruct.MaxIterationsForGD = 1E5; -OptionsStruct.TimeStepSize = 1E-4; % in s -OptionsStruct.MinimumTimeStepSize = 2E-10; % in s -OptionsStruct.TimeCutOff = 2E6; % in s -OptionsStruct.EnergyTolerance = 5E-10; -OptionsStruct.ResidualTolerance = 1E-08; +OptionsStruct.MaxIterationsForGD = 2E4; +% OptionsStruct.TimeStepSize = 1E-4; % in s +% OptionsStruct.MinimumTimeStepSize = 2E-10; % in s +% OptionsStruct.TimeCutOff = 2E6; % in s +% OptionsStruct.EnergyTolerance = 5E-10; +% OptionsStruct.ResidualTolerance = 1E-08; OptionsStruct.NoiseScaleFactor = 0.01; OptionsStruct.PlotLive = true; OptionsStruct.JobNumber = 0; OptionsStruct.RunOnGPU = false; OptionsStruct.SaveData = true; -OptionsStruct.SaveDirectory = sprintf('./Results/Data_3D/AspectRatio%s', strrep(num2str(AspectRatio), '.', '_')); +OptionsStruct.SaveDirectory = './Results/Data_3D/GradientDescent'; options = Helper.convertstruct2cell(OptionsStruct); clear OptionsStruct @@ -65,10 +62,11 @@ SaveDirectory = './Results/Data_3D/CompleteLHY/BeyondSSD_Honeycomb'; JobNumber = 0; Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) %% - Plot GS wavefunction -% SaveDirectory = './Results/Data_3D/ApproximateLHY/AspectRatio2_8'; +SaveDirectory = './Results/Data_3D/ApproximateLHY/AspectRatio2_8'; % SaveDirectory = './Results/Data_3D/ApproximateLHY/AspectRatio3_7'; -SaveDirectory = './Results/Data_3D/ApproximateLHY/AspectRatio3_8'; -JobNumber = 0; +% SaveDirectory = './Results/Data_3D/ApproximateLHY/AspectRatio3_8'; +% SaveDirectory = './Results/Data_3D/ApproximateLHY/AspectRatio3_9'; +JobNumber = 2; Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) %% % SaveDirectory = './Results/Data_3D/ApproximateLHY/BeyondSSD_SSD'; diff --git a/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/runGradientDescent.m b/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/runGradientDescent.m index 69e36f5..b9a5301 100644 --- a/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/runGradientDescent.m +++ b/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/runGradientDescent.m @@ -3,8 +3,8 @@ function [psi] = runGradientDescent(this,psi,Params,Transf,VDk,V,Observ) format long; % Convergence Criteria: - epsilon = 1E-8; - alpha = 1E-4; + epsilon = 1E-6; + alpha = 1E-3; beta = 0.9; Observ.residual = 1; @@ -30,36 +30,38 @@ function [psi] = runGradientDescent(this,psi,Params,Transf,VDk,V,Observ) if residual < epsilon fprintf('Convergence reached at iteration %d\n', idx); break; - end + else - % Update psi using heavy-ball method - psi_new = (1 + beta) * psi - alpha * J - beta * psi_old; - psi_old = psi; - - % Normalize psi - Norm = sum(abs(psi_new(:)).^2) * Transf.dx * Transf.dy * Transf.dz; - psi = sqrt(Params.N) * psi_new / sqrt(Norm); - - if mod(idx,100) == 0 - - % Collect change in energy - E = this.Calculator.calculateTotalEnergy(psi,Params,Transf,VDk,V); - E = E/Norm; - Observ.EVec = [Observ.EVec E]; - - % Collect chemical potentials - Observ.mucVec = [Observ.mucVec muchem]; - - % Collect residuals - Observ.residual = [Observ.residual residual]; - Observ.res_idx = Observ.res_idx + 1; + % Update psi using heavy-ball method + psi_new = (1 + beta) * psi - alpha * J - beta * psi_old; + psi_old = psi; - if this.PlotLive - Plotter.plotLive(psi,Params,Transf,Observ) - drawnow + % Normalize psi + Norm = sum(abs(psi_new(:)).^2) * Transf.dx * Transf.dy * Transf.dz; + psi = sqrt(Params.N) * psi_new / sqrt(Norm); + + % Write output at specified intervals + if mod(idx,100) == 0 + + % Collect change in energy + E = this.Calculator.calculateTotalEnergy(psi,Params,Transf,VDk,V); + E = E/Norm; + Observ.EVec = [Observ.EVec E]; + + % Collect chemical potentials + Observ.mucVec = [Observ.mucVec muchem]; + + % Collect residuals + Observ.residual = [Observ.residual residual]; + Observ.res_idx = Observ.res_idx + 1; + + if this.PlotLive + Plotter.plotLive(psi,Params,Transf,Observ) + drawnow + end + + save(sprintf(strcat(this.SaveDirectory, '/Run_%03i/psi_gs.mat'),Params.njob),'psi','muchem','Observ','Transf','Params','VDk','V'); end - - save(sprintf(strcat(this.SaveDirectory, '/Run_%03i/psi_gs.mat'),Params.njob),'psi','muchem','Observ','Transf','Params','VDk','V'); end end