Skip to content

Commit

Permalink
Early exit feature for OWM (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
william-dawson authored Dec 11, 2023
1 parent 95b3ba3 commit b2adba2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Source/Fortran/FermiOperatorModule.F90
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MODULE FermiOperatorModule
USE EigenSolversModule, ONLY : EigenDecomposition
USE LoadBalancerModule, ONLY : PermuteMatrix, UndoPermuteMatrix
USE LoggingModule, ONLY : WriteElement, WriteHeader, &
& EnterSubLog, ExitSubLog, WriteListElement
& EnterSubLog, ExitSubLog, WriteListElement, WriteComment
USE PSMatrixAlgebraModule, ONLY : MatrixMultiply, SimilarityTransform, &
& IncrementMatrix, MatrixNorm, ScaleMatrix, DotMatrix, MatrixTrace
USE PSMatrixModule, ONLY : Matrix_ps, ConstructEmptyMatrix, &
Expand Down Expand Up @@ -355,7 +355,7 @@ SUBROUTINE WOM_Implementation(H, ISQ, K, inv_temp, params, &
TYPE(Matrix_ps) :: Temp, W, A, X, KOrth
TYPE(MatrixMemoryPool_p) :: pool
INTEGER :: II
REAL(NTREAL) :: step, B_I, B_I_old, err, sparsity, energy
REAL(NTREAL) :: step, B_I, B_I_old, err, err2, sparsity, energy

GC = PRESENT(mu_in)

Expand Down Expand Up @@ -464,6 +464,16 @@ SUBROUTINE WOM_Implementation(H, ISQ, K, inv_temp, params, &
err = MatrixNorm(Temp)
END DO

!! Early Exit Criteria
CALL CopyMatrix(RK2, Temp)
CALL IncrementMatrix(W, Temp, alpha_in = -1.0_NTREAL, &
& threshold_in = params%threshold)
err2 = MatrixNorm(Temp)
IF (err2 .LT. params%converge_diff) THEN
CALL WriteComment("Early Exit Triggered")
EXIT
END IF

!! Update
CALL CopyMatrix(RK2, W)
B_I_old = B_I
Expand All @@ -478,6 +488,7 @@ SUBROUTINE WOM_Implementation(H, ISQ, K, inv_temp, params, &
CALL WriteElement("Beta", VALUE = B_I_old)
CALL WriteElement("Sparsity", VALUE = sparsity)
CALL WriteElement("Energy", VALUE = energy)
CALL WriteElement("Norm of Change", VALUE = err2)
CALL ExitSubLog
END IF
END DO
Expand Down

0 comments on commit b2adba2

Please sign in to comment.