From 044db810e20628c7a4c7423d0d43d1d8b5f1dabd Mon Sep 17 00:00:00 2001 From: Karthik Chandrashekara Date: Sat, 10 May 2025 00:36:17 +0200 Subject: [PATCH] Latest modified scripts to generate phase diagram --- .../run_hybrid_worker_for_phase_boundary.m | 16 ++-- Dipolar-Gas-Simulator/+Scripts/run_locally.m | 84 +++++++++++++++++-- .../+Scripts/run_on_cluster.m | 18 ++-- .../+Simulator/@DipolarGas/DipolarGas.m | 3 +- .../Data_3D/GradientDescent/CleanUp.ps1 | 27 ------ .../GradientDescent/IdentifyMissingFiles.ps1 | 41 --------- .../submit_jobs_for_phase_boundary.sh | 6 +- 7 files changed, 98 insertions(+), 97 deletions(-) delete mode 100644 Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/CleanUp.ps1 delete mode 100644 Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/IdentifyMissingFiles.ps1 diff --git a/Dipolar-Gas-Simulator/+Scripts/run_hybrid_worker_for_phase_boundary.m b/Dipolar-Gas-Simulator/+Scripts/run_hybrid_worker_for_phase_boundary.m index 15b7c2f..1978f54 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_hybrid_worker_for_phase_boundary.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_hybrid_worker_for_phase_boundary.m @@ -53,16 +53,16 @@ function run_hybrid_worker_for_phase_boundary(batchParams, batchIdx) OptionsStruct.TrapPotentialType = 'Harmonic'; OptionsStruct.NumberOfGridPoints = [128, 256, 128]; - OptionsStruct.Dimensions = [30, 50, 30]; + OptionsStruct.Dimensions = [40, 80, 40]; OptionsStruct.UseApproximationForLHY = true; OptionsStruct.IncludeDDICutOff = true; - OptionsStruct.CutoffType = 'CustomCylindrical'; - OptionsStruct.CustomCylindricalCutOffRadius = 12; - OptionsStruct.CustomCylindricalCutOffHeight = 10; - OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; - OptionsStruct.TimeStepSize = 5E-4; - OptionsStruct.MinimumTimeStepSize = 2E-6; - OptionsStruct.TimeCutOff = 1E5; + OptionsStruct.CutoffType = 'Cylindrical'; + OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution' | 'EnergyMinimization' + OptionsStruct.GradientDescentMethod = 'NonLinearCGD'; % 'HeavyBall' | 'NonLinearCGD' + OptionsStruct.MaxIterationsForGD = 15000; + OptionsStruct.TimeStepSize = 1E-3; % in s + OptionsStruct.MinimumTimeStepSize = 1E-6; % in s + OptionsStruct.TimeCutOff = 1E6; % in s OptionsStruct.EnergyTolerance = 5E-10; OptionsStruct.ResidualTolerance = 1E-05; OptionsStruct.NoiseScaleFactor = 0.010; diff --git a/Dipolar-Gas-Simulator/+Scripts/run_locally.m b/Dipolar-Gas-Simulator/+Scripts/run_locally.m index debd816..8dd8566 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_locally.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_locally.m @@ -549,7 +549,11 @@ SaveDirectory = './Results/Data_3D/AnisotropicTrap/TiltedDipoles45'; JobNumber = 0; Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) %% -SaveDirectory = './Results/Data_3D/GradientDescent/Phi020/aS_090_theta_020_phi_000_N_100000'; +SaveDirectory = './Results/Data_3D/GradientDescent/aS_088_theta_000_phi_000_N_750000'; +JobNumber = 0; +Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) +%% +SaveDirectory = './Results/Data_3D/PhaseDiagram/ImagTimePropagation/aS_9.458000e+01_theta_000_phi_000_N_304167'; JobNumber = 0; Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) %% @@ -588,7 +592,11 @@ end %% SaveDirectory = './Results/Data_3D/GradientDescent/'; -JobNumber = 1; +JobNumber = 0; +Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) +%% +SaveDirectory = './Results/Data_3D/ImagTimeProp/'; +JobNumber = 0; Plotter.visualizeGSWavefunction(SaveDirectory, JobNumber) %% Visualize phase diagram @@ -619,8 +627,11 @@ grid on; %% Density modulation determination -SaveDirectory = './Results/Data_3D/GradientDescent/Phi030/aS_079_theta_030_phi_000_N_100000'; -JobNumber = 0; +% SaveDirectory = './Results/Data_3D/GradientDescent/Phi020/aS_090_theta_020_phi_000_N_100000'; +% JobNumber = 0; + +SaveDirectory = './Results/Data_3D/PhaseDiagram'; +JobNumber = 1; % Load data Data = load(sprintf(horzcat(SaveDirectory, '/Run_%03i/psi_gs.mat'),JobNumber),'psi','Params','Transf','Observ'); @@ -670,7 +681,7 @@ function ModulationFlag = determineDensityModulation(psi, Params, Transf) smoothedProfile = smooth(densityProfile, 10); % Step 2: Compute the residual (original - smoothed) - residual = densityProfile - smoothedProfile; % We do this + residual = densityProfile - smoothedProfile; % Step 3: Compute the Fourier Transform of the residual N = length(residual); @@ -679,9 +690,11 @@ function ModulationFlag = determineDensityModulation(psi, Params, Transf) P1 = P2(1:N/2+1); % Single-sided spectrum P1(2:end-1) = 2*P1(2:end-1); % Correct for the energy in the negative frequencies + P1 = P1(15:end); + % Step 4: Check for significant peaks in the Fourier spectrum % We check if the peak frequency is above a certain threshold - threshold = 1E-3; % This can be adjusted based on the expected modulation strength + threshold = 500; % This can be adjusted based on the expected modulation strength peakValue = max(P1); if peakValue > threshold @@ -689,4 +702,61 @@ function ModulationFlag = determineDensityModulation(psi, Params, Transf) else ModulationFlag = false; % Indicates otherwise end -end \ No newline at end of file +end + +%% Generate lists + +% Set display format +format longG + +% Generate the lists +list1 = linspace(1E5, 5E6, 25); +list2 = linspace(80, 105, 25); + +% Convert to strings with no scientific notation +str_list1 = compose('%.0f', list1); +str_list2 = compose('%.2f', list2); + +% Join as space-separated strings +row1 = strjoin(str_list1', ' '); +row2 = strjoin(str_list2', ' '); + +% Display results +disp(row1) +disp(row2) + +%% Phase diagram for untilted case +N = [1E5, 3.04E5, 5.08E5, 7.125E5, 9.16E5, 1.12E6, 1.325E6, 1.529E6, ... + 1.733E6, 1.9375E6, 2.141E6, 2.345E6, 2.55E6, 2.75E6, 2.95E6, ... + 3.1625E6, 3.367E6, 3.57E6, 3.775E6, 3.979E6, 4.183E6, 4.3875E6, ... + 4.591E6, 4.795E6, 5E6]; + +as_LB = [87.29, 93.54, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, ... + NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]; + +as_UB = [88.33, 94.58, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, ... + NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]; + +% Filter only rows with non-NaN data +valid_idx = ~isnan(as_LB) & ~isnan(as_UB); +N_valid = N(valid_idx); +LB_valid = as_LB(valid_idx); +UB_valid = as_UB(valid_idx); + +% Create shaded area between LB and UB +x_fill = [N_valid, fliplr(N_valid)]; +y_fill = [LB_valid, fliplr(UB_valid)]; + +% Plot settings +figure(1); +set(gcf,'Position',[100 100 950 750]) +fill(x_fill, y_fill, [0.8 0.8 1], 'EdgeColor', 'none'); % Light blue shade +% Axes settings +set(gca, 'XScale', 'log'); +xlim([1E4, 1E7]); +ylim([79, 106]); +xlabel('Atom number', 'Interpreter', 'latex', 'FontSize', 16); +ylabel('Scattering length $a_s$ ($a_0$)', 'Interpreter', 'latex', 'FontSize', 16); +grid on; +set(gca,'FontSize',16,'Box','On','Linewidth',2); + diff --git a/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m b/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m index dc4a3de..0eeee9a 100644 --- a/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m +++ b/Dipolar-Gas-Simulator/+Scripts/run_on_cluster.m @@ -1,33 +1,33 @@ OptionsStruct = struct; -OptionsStruct.NumberOfAtoms = 90000; +OptionsStruct.NumberOfAtoms = 5E7; OptionsStruct.DipolarPolarAngle = deg2rad(0); OptionsStruct.DipolarAzimuthAngle = 0; -OptionsStruct.ScatteringLength = 85; +OptionsStruct.ScatteringLength = 102; OptionsStruct.TrapFrequencies = [50, 20, 150]; OptionsStruct.TrapPotentialType = 'Harmonic'; OptionsStruct.NumberOfGridPoints = [128, 256, 128]; -OptionsStruct.Dimensions = [30, 50, 30]; +OptionsStruct.Dimensions = [40, 80, 40]; OptionsStruct.UseApproximationForLHY = true; OptionsStruct.IncludeDDICutOff = true; OptionsStruct.CutoffType = 'Cylindrical'; OptionsStruct.SimulationMode = 'ImaginaryTimeEvolution'; % 'ImaginaryTimeEvolution' | 'RealTimeEvolution' | 'EnergyMinimization' OptionsStruct.GradientDescentMethod = 'NonLinearCGD'; % 'HeavyBall' | 'NonLinearCGD' OptionsStruct.MaxIterationsForGD = 15000; -OptionsStruct.TimeStepSize = 5E-4; % in s -OptionsStruct.MinimumTimeStepSize = 2E-6; % in s -OptionsStruct.TimeCutOff = 1E6; % in s +OptionsStruct.TimeStepSize = 1E-3; % in s +OptionsStruct.MinimumTimeStepSize = 1E-6; % in s +OptionsStruct.TimeCutOff = 1E4; % in s OptionsStruct.EnergyTolerance = 5E-10; OptionsStruct.ResidualTolerance = 1E-05; OptionsStruct.NoiseScaleFactor = 0.010; -OptionsStruct.PlotLive = false; +OptionsStruct.PlotLive = true; OptionsStruct.JobNumber = 0; -OptionsStruct.RunOnGPU = true; +OptionsStruct.RunOnGPU = false; OptionsStruct.SaveData = true; -OptionsStruct.SaveDirectory = './Results/Data_3D/GradientDescent'; +OptionsStruct.SaveDirectory = './Results/Data_3D/ImagTimeProp'; options = Helper.convertstruct2cell(OptionsStruct); sim = Simulator.DipolarGas(options{:}); diff --git a/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/DipolarGas.m b/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/DipolarGas.m index 0f78ade..cca3847 100644 --- a/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/DipolarGas.m +++ b/Dipolar-Gas-Simulator/+Simulator/@DipolarGas/DipolarGas.m @@ -162,7 +162,7 @@ classdef DipolarGas < handle & matlab.mixin.Copyable methods function set.TimeStepSize(this, val) - assert(val > 1e-06, 'Not time efficient to compute for time steps smaller than 1 microsecond!'); + assert(val > 1E-9, 'Not time efficient to compute for time steps smaller than 1 nanosecond!'); this.TimeStepSize = val; end function ret = get.TimeStepSize(this) @@ -176,7 +176,6 @@ classdef DipolarGas < handle & matlab.mixin.Copyable ret = this.TimeCutOff; end function set.NumberOfAtoms(this, val) - assert(val <= 1E6, '!!Not time efficient to compute for atom numbers larger than 1,000,000!!'); this.NumberOfAtoms = val; end function ret = get.NumberOfAtoms(this) diff --git a/Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/CleanUp.ps1 b/Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/CleanUp.ps1 deleted file mode 100644 index 47df6f6..0000000 --- a/Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/CleanUp.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -$root = "C:\Users\Karthik\Documents\GitRepositories\Calculations\Dipolar-Gas-Simulator\Results\Data_3D\GradientDescent\Phi020" - -# Step 1: Delete all files except 'psi_gs.mat' -Get-ChildItem -Path $root -Recurse -File -Force | -Where-Object { $_.Name -ne "psi_gs.mat" } | -ForEach-Object { - try { - Remove-Item -Path $_.FullName -Force -ErrorAction Stop - Write-Output "Deleted: $($_.FullName)" - } catch { - Write-Warning "Failed to delete: $($_.FullName)" - } -} - -# Step 2: Delete all empty directories (deepest first) -Get-ChildItem -Path $root -Recurse -Directory -Force | -Sort-Object FullName -Descending | -ForEach-Object { - if (-not (Get-ChildItem -Path $_.FullName -Force)) { - try { - Remove-Item -Path $_.FullName -Force -ErrorAction Stop - Write-Output "Deleted empty folder: $($_.FullName)" - } catch { - Write-Warning "Failed to delete folder: $($_.FullName)" - } - } -} diff --git a/Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/IdentifyMissingFiles.ps1 b/Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/IdentifyMissingFiles.ps1 deleted file mode 100644 index b2fa54e..0000000 --- a/Dipolar-Gas-Simulator/Results/Data_3D/GradientDescent/IdentifyMissingFiles.ps1 +++ /dev/null @@ -1,41 +0,0 @@ -$root = "C:\Users\Karthik\Documents\GitRepositories\Calculations\Dipolar-Gas-Simulator\Results\Data_3D\GradientDescent\Phi030" - -# Define parameter ranges -$SCATTERING_LENGTH_RANGE = @(79.0..90.0) -$POLAR_ANGLE_RANGE = @(30.0) -$AZIMUTHAL_ANGLE_RANGE = @(0.0) -$NUM_ATOMS_LIST = @(50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000) - -# Utility function to format floating point values as zero-padded 3-digit integers -function Format-Value($value) { - return "{0:D3}" -f [int]($value * 1) -} - -# Generate all valid folder names -$expectedFolders = @() -foreach ($aS in $SCATTERING_LENGTH_RANGE) { - $aS_str = Format-Value $aS - foreach ($theta in $POLAR_ANGLE_RANGE) { - $theta_str = Format-Value $theta - foreach ($phi in $AZIMUTHAL_ANGLE_RANGE) { - $phi_str = Format-Value $phi - foreach ($N in $NUM_ATOMS_LIST) { - $folderName = "aS_${aS_str}_theta_${theta_str}_phi_${phi_str}_N_${N}" - $expectedFolders += $folderName - } - } - } -} - -# Get actual folders in the root directory -$actualFolders = Get-ChildItem -Path $root -Directory -Force | Select-Object -ExpandProperty Name - -# Compare and find missing folders -$missingFolders = $expectedFolders | Where-Object { $_ -notin $actualFolders } - -# Output missing folders -Write-Host "Missing folders:" -$missingFolders | ForEach-Object { Write-Host $_ } - -# Optional: Save to a file -$missingFolders | Out-File -FilePath "$root\missing_folders.txt" -Encoding UTF8 \ No newline at end of file diff --git a/Dipolar-Gas-Simulator/submit_jobs_for_phase_boundary.sh b/Dipolar-Gas-Simulator/submit_jobs_for_phase_boundary.sh index df60bde..6437daa 100644 --- a/Dipolar-Gas-Simulator/submit_jobs_for_phase_boundary.sh +++ b/Dipolar-Gas-Simulator/submit_jobs_for_phase_boundary.sh @@ -1,10 +1,10 @@ # ----------- Define scan ranges ----------- # Use space-separated floating-point/integer values -SCATTERING_LENGTH_RANGE="[79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0]" -POLAR_ANGLE_RANGE="[20.0]" +SCATTERING_LENGTH_RANGE="[82.0 84.0 86.0 88.0 90.0 92.0 94.0 96.0 98.0 100.0]" +POLAR_ANGLE_RANGE="[0.0]" AZIMUTHAL_ANGLE_RANGE="[0.0]" -NUM_ATOMS_LIST="[50000 140000 220000 310000 400000 480000 570000 660000 740000 830000 920000 1000000]" +NUM_ATOMS_LIST="[50000 500000 950000 1400000 1850000 2300000 2750000 3200000 3650000 4100000 4550000 5000000]" CHUNK_SIZE=4 # ----------- Count total combinations for SLURM array -----------