Merge lp:~nickpapior/siesta/4.1-scf-first into lp:siesta/4.1

Proposed by Nick Papior
Status: Merged
Approved by: Alberto Garcia
Approved revision: 1086
Merged at revision: 1096
Proposed branch: lp:~nickpapior/siesta/4.1-scf-first
Merge into: lp:siesta/4.1
Diff against target: 244 lines (+95/-17) (has conflicts)
5 files modified
Docs/siesta.tex (+39/-4)
Src/m_new_dm.F90 (+44/-12)
Src/read_options.F90 (+7/-1)
Src/siesta_options.F90 (+1/-0)
version.info (+4/-0)
Text conflict in version.info
To merge this branch: bzr merge lp:~nickpapior/siesta/4.1-scf-first
Reviewer Review Type Date Requested Status
Alberto Garcia Approve
Review via email: mp+370711@code.launchpad.net

This proposal supersedes a proposal from 2019-07-29.

Commit message

Fixing SCF-first for re-reading DM files

Previously one could not restart and perform mixing for the
first SCF step. This helps for big systems when needing restart
effects.

In some cases (for really large systems) it *could* be advantegeous
to also allow mixing in the first SCF step since any perturbation
cause huge dDmax/dHmax. In those cases we probably need some kind
of handler to allow mixing first step anyhow.

  SCF.Mix.First.MD <T|F> ?

Description of the change

This is a result of https://bugs.launchpad.net/siesta/+bug/1834949 where restart is not working properly or large systems.

Initially we had disabled scf.mix.first for all simulations which did a restart. This commit fixes this in the sense that iff the sparsity pattern is exactly the same, it will allow one to do mixing in the first iteration, otherwise not.

However, this *could* potentially still be a problem for very large systems where minor displacements are present. In that case it could still be viable to do small linear mixing for a few steps using the final DM from a different geometry.
Perhaps we need to introduce a new keyword (see above).

To post a comment you must log in.
Revision history for this message
Alberto Garcia (albertog) wrote :

The issue is complex enough that in-program heuristics might not be able to treat it in all cases. I think it is better to allow the user to request explicitly the behavior desired, and keeping the current (including this patch) heuristics as default behaviour.

So I would introduce a new flag, something like "SCF.Force.Mix.First.Iter" and let it override all the internal heuristics (even for "dangerous" cases), with proper warnings for the user.

But:

-- Do the worries about non-idempotency or memory effects in the mixed DM apply when one is really mixing the hamiltonian?

-- I missed the orginal discussion of the above bug report, but what I can gather now is that the dH found by the user was unavoidable, and other features (reading H, re-reading more mixing history) would be more helpful.

Revision history for this message
Nick Papior (nickpapior) wrote :

I agree.
I will amend this with a SCF.Mix.First.Force (then it is equivalent to the SCF.Mix.First with another flag).

I will make SCF.Mix.First.Force default to true since this is typically what people *may* expect when going large scale.

-- non-idempotency: probably this has less effects when doing H-mixing. But ideally we should have a simple test that we can use to uncover some of these details. Effectively this is unexplored (from my side?) We should probably have a small test that ensures the DM retains idempotency.

-- Yes.

Revision history for this message
Nick Papior (nickpapior) wrote :

Sorry, will make SCF.Mix.First.Force default false. Just in case ;)

lp:~nickpapior/siesta/4.1-scf-first updated
1085. By Nick Papior

Added SCF.Mix.First.Force to overrule siesta heuristics

Now the user can decide to *always* override the Siesta heuristics
regarding mixing the first SCF step. This may be useful for very large
systems.

Added a print-out to users regarding this forced behaviour when
the heuristic would have chosen another method.

Revision history for this message
Nick Papior (nickpapior) wrote :

I have amended the requested changes.

I'll merge once you approve. :)

lp:~nickpapior/siesta/4.1-scf-first updated
1086. By Alberto Garcia

Longer explanation in manual. Change in warning

Revision history for this message
Nick Papior (nickpapior) wrote :

Is this now ready for merge?

Revision history for this message
Alberto Garcia (albertog) wrote :

Yes. This is ready to merge. I suggest the following commit message:

Added SCF.Mix.First.Force to overrule siesta heuristics

Please see the manual for the rationale and an explanation of the interactions
between this flag and the existing SCF.Mix.First.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Docs/siesta.tex'
--- Docs/siesta.tex 2019-08-15 23:47:04 +0000
+++ Docs/siesta.tex 2019-08-19 08:18:39 +0000
@@ -4102,13 +4102,48 @@
41024102
4103\begin{fdflogicalT}{SCF.Mix!First}4103\begin{fdflogicalT}{SCF.Mix!First}
4104 \fdfindex*{DM.MixSCF1}[|see SCF.Mix.First]4104 \fdfindex*{DM.MixSCF1}[|see SCF.Mix.First]
4105 \fdfdepend{SCF.Mix!First.Force}%
4106
4107 This flag is used to decide whether mixing (of the DM or H) should
4108 be done in the first SCF step. If mixing is not performed the output
4109 DM or H generated in the first SCF step is used as input in the next
4110 SCF step. When mixing the DM, this ``reset'' has the effect of
4111 avoiding potentially undesirable memory effects: for example, a DM
4112 read from file which corresponds to a different structure might not
4113 satisfy the correct symmetry, and mixing will not fix it. On the
4114 other hand, when reusing a DM for a restart of an interrupted
4115 calculation, a full reset might not be advised.
4116
4117 The value of this flag is one of the ingredients used by \siesta\ to
4118 decide what to do. If \fdftrue\ (the default), mixing will be
4119 performed in all cases, except when a DM has been read from file and
4120 the sparsity pattern of the DM on file is different from the current
4121 one. To ensure that a first-step mixing is done even in this case,
4122 \fdf{SCF.Mix!First.Force} should be set to \fdftrue.
4123
4124 If the flag is \fdffalse, no mixing in the first step will be
4125 performed, except if overridden by \fdf{SCF.Mix!First.Force}.
4126
4127 \note that the default value for this flag has changed from the old
4128 (pre-version 4) setting in \siesta. The new setting is most
4129 appropriate for the case of restarting calculations. On the other
4130 hand, it means that mixing in the first SCF step will also be
4131 performed for the standard case in which the initial DM is built as
4132 a (diagonal) superposition of atomic orbital occupation values. In
4133 some cases (e.g. spin-orbit calculations) better results might be
4134 obtained by avoiding this mixing.
41054135
4106 Whether the first SCF should be mixed or it uses the output as input
4107 in the next SCF step. It is generally advised to set this to true,
4108 at least when restarting calculations.
4109
4110\end{fdflogicalT}4136\end{fdflogicalT}
41114137
4138\begin{fdflogicalF}{SCF.Mix!First.Force}
4139
4140 Force the mixing (of DM or H) in the first SCF step, regardless of
4141 what \siesta\ may heuristically decide.
4142
4143 This overrules \fdf{SCF.Mix!First}.
4144
4145\end{fdflogicalF}
4146
41124147
4113In the following the density matrix ($\DM$) will be used in the4148In the following the density matrix ($\DM$) will be used in the
4114equations, while for Hamiltonian mixing, $\DM$, should be replaced by4149equations, while for Hamiltonian mixing, $\DM$, should be replaced by
41154150
=== modified file 'Src/m_new_dm.F90'
--- Src/m_new_dm.F90 2018-09-14 12:29:11 +0000
+++ Src/m_new_dm.F90 2019-08-19 08:18:39 +0000
@@ -79,6 +79,16 @@
79 logical :: DM_init ! Initialize density matrix from file or from atomic density79 logical :: DM_init ! Initialize density matrix from file or from atomic density
80 logical :: read_DM80 logical :: read_DM
81 integer :: DM_in_history, n_depth81 integer :: DM_in_history, n_depth
82
83 ! Variable to signal how the initialization was performed.
84 ! The following table lists the (current) possibilities:
85 ! 0: DM is filled from atomic information (no information present)
86 ! 1: .DM file is read, Siesta continuation
87 ! 2: An extrapolation of previous geometries.
88 ! The DM's from the previous coordinates are kept in memory
89 ! 3: .TSDE file is read, TranSiesta continuation
90 ! If the value is negative it means that one cannot mix in the
91 ! first step, unless SCF.Mix.First.Force is true!
82 integer :: init_method92 integer :: init_method
8393
84 real(dp), pointer :: DM(:,:), EDM(:,:)94 real(dp), pointer :: DM(:,:), EDM(:,:)
@@ -192,8 +202,8 @@
192 call print_type(DM_2D)202 call print_type(DM_2D)
193 end if203 end if
194204
195 ! Defines the initialiazation to be re-using205 ! A negative value specifies that one cannot mix in the initial step
196 init_method = -1206 init_method = -3
197207
198 end if208 end if
199209
@@ -290,7 +300,7 @@
290300
291 old_Ef = Ef301 old_Ef = Ef
292 Ef = fdf_get('TS.Fermi.Initial',Ef,'Ry')302 Ef = fdf_get('TS.Fermi.Initial',Ef,'Ry')
293 if ( init_method == 2 ) then303 if ( abs(init_method) == 3 ) then
294 ! As the fermi-level has been read in from a previous304 ! As the fermi-level has been read in from a previous
295 ! calculation (TSDE), the EDM should only be shifted by the difference305 ! calculation (TSDE), the EDM should only be shifted by the difference
296 diff_Ef = Ef - old_Ef306 diff_Ef = Ef - old_Ef
@@ -301,10 +311,10 @@
301311
302 if ( IONode ) then312 if ( IONode ) then
303 write(*,*) ! new-line313 write(*,*) ! new-line
304 if ( init_method < 2 ) then314 if ( abs(init_method) < 3 ) then
305 write(*,'(a,f9.5,a)')'transiesta: Setting the Fermi-level to: ', &315 write(*,'(a,f9.5,a)')'transiesta: Setting the Fermi-level to: ', &
306 Ef / eV,' eV'316 Ef / eV,' eV'
307 else if ( init_method == 2 ) then317 else if ( abs(init_method) == 3 ) then
308 write(*,'(a,2(f10.6,a))')'transiesta: Changing Fermi-level from -> to: ', &318 write(*,'(a,2(f10.6,a))')'transiesta: Changing Fermi-level from -> to: ', &
309 old_Ef / eV,' -> ',Ef / eV, ' eV'319 old_Ef / eV,' -> ',Ef / eV, ' eV'
310 end if320 end if
@@ -325,7 +335,7 @@
325 ! Determine how the mixing of the first step should be performed335 ! Determine how the mixing of the first step should be performed
326 !336 !
327 ! The idea is that one will allow mixing on the first SCF step337 ! The idea is that one will allow mixing on the first SCF step
328 ! only for atomicly filled orbitals. This will in most cases338 ! only for atomically filled orbitals. This will in most cases
329 ! be a good initial choice, while in certain systems (spin-orbit)339 ! be a good initial choice, while in certain systems (spin-orbit)
330 ! it may not be so good.340 ! it may not be so good.
331 ! Subsequently for any MD steps beyond the initial step, we will not341 ! Subsequently for any MD steps beyond the initial step, we will not
@@ -336,8 +346,19 @@
336 ! iterations. For instance when performing FC runs (externally driven)346 ! iterations. For instance when performing FC runs (externally driven)
337 ! this would lead to non-degenerate transverse eigenmodes for simple molecules347 ! this would lead to non-degenerate transverse eigenmodes for simple molecules
338 if ( init_method == 0 ) then ! atomicly filled data348 if ( init_method == 0 ) then ! atomicly filled data
339 ! allow mix_scf_first349 ! allow mix_scf_first
340 else if ( mix_scf_first ) then350 else if ( mix_scf_first_force ) then
351 ! user requested a mix in the first step
352 mix_scf_first = .true.
353 if ( IONode .and. init_method < 0 ) then
354 ! Warn the user about this
355 write(*,"(a)") "Mixing first scf iteration is *forced* although the sparsity pattern has changed..."
356 write(*,"(a)") "Mixing non-compatible matrices might result in problems."
357 write(*,"(a)") "Please use a linear mixer for the first few steps to remove history effects."
358 end if
359 else if ( mix_scf_first .and. init_method < 0 ) then
360 ! Do not allow mixing first SCF step since we are reusing a DM
361 ! from another geometry.
341 mix_scf_first = .false.362 mix_scf_first = .false.
342 end if363 end if
343 364
@@ -385,7 +406,7 @@
385 ! integer init_method : returns method it has read the data with406 ! integer init_method : returns method it has read the data with
386 ! 0 == atomic filling (possibly user-defined407 ! 0 == atomic filling (possibly user-defined
387 ! 1 == .DM read408 ! 1 == .DM read
388 ! 2 == .TSDE read409 ! 3 == .TSDE read
389 ! *******************************************************************410 ! *******************************************************************
390411
391 ! The spin-configuration that is used to determine the spin-order.412 ! The spin-configuration that is used to determine the spin-order.
@@ -457,7 +478,7 @@
457 else 478 else
458479
459 ! Print-out whether transiesta is starting, or siesta is starting480 ! Print-out whether transiesta is starting, or siesta is starting
460 call ts_method_init( init_method == 2 )481 call ts_method_init( abs(init_method) == 3 )
461482
462 end if483 end if
463484
@@ -559,7 +580,7 @@
559 ! method used to read the DM/EDM580 ! method used to read the DM/EDM
560 ! 0 == not read581 ! 0 == not read
561 ! 1 == .DM read582 ! 1 == .DM read
562 ! 2 == .TSDE read583 ! 3 == .TSDE read
563 ! *******************************************************************584 ! *******************************************************************
564585
565 !> The spin-configuration that is used to determine the spin-order.586 !> The spin-configuration that is used to determine the spin-order.
@@ -592,6 +613,7 @@
592613
593 ! The currently read stuff614 ! The currently read stuff
594 type(dSpData2D) :: DM_read615 type(dSpData2D) :: DM_read
616 type(Sparsity), pointer :: sp_read
595 type(dSpData2D) :: EDM_read617 type(dSpData2D) :: EDM_read
596618
597 ! Signal the file has not been found.619 ! Signal the file has not been found.
@@ -614,7 +636,7 @@
614636
615 if ( TSDE_found ) then637 if ( TSDE_found ) then
616 ! Signal we have read TSDE638 ! Signal we have read TSDE
617 init_method = 2639 init_method = 3
618640
619 DM_found = .true.641 DM_found = .true.
620642
@@ -670,6 +692,16 @@
670 ! Density matrix size checks692 ! Density matrix size checks
671 if ( DM_found ) then693 if ( DM_found ) then
672694
695 ! Specify the *correct* init_method
696 ! In cases where the sparsity pattern changes, we assume this has to do with
697 ! MD simulations and thus a geometry change.
698 ! By default we do not allow mixing the first step when re-using a DM from another
699 ! geometry. This is because of idempotency.
700 sp_read => spar(DM_read)
701 if ( .not. equivalent(sp, sp_read) ) then
702 init_method = -init_method
703 end if
704
673 corrected_nsc = .false.705 corrected_nsc = .false.
674 if ( nsc_read(1) /= 0 .and. any(nsc /= nsc_read) ) then706 if ( nsc_read(1) /= 0 .and. any(nsc /= nsc_read) ) then
675707
676708
=== modified file 'Src/read_options.F90'
--- Src/read_options.F90 2019-07-29 10:25:09 +0000
+++ Src/read_options.F90 2019-08-19 08:18:39 +0000
@@ -413,8 +413,14 @@
413 mix_scf_first = fdf_get('DM.MixSCF1', &413 mix_scf_first = fdf_get('DM.MixSCF1', &
414 .not. compat_pre_v4_DM_H)414 .not. compat_pre_v4_DM_H)
415 mix_scf_first = fdf_get('SCF.Mix.First', mix_scf_first)415 mix_scf_first = fdf_get('SCF.Mix.First', mix_scf_first)
416 mix_scf_first_force = fdf_get('SCF.Mix.First.Force', .false.)
417 if ( mix_scf_first_force ) then
418 ! Also set this, to note the user of mixing first SCF regardless
419 ! of flag.
420 mix_scf_first = .true.
421 end if
416 if (ionode) then422 if (ionode) then
417 write(6,1) 'redata: Mix DM in first SCF step',mix_scf_first423 write(6,1) 'redata: Mix DM in first SCF step',mix_scf_first
418 endif424 endif
419425
420 if (cml_p) then426 if (cml_p) then
421427
=== modified file 'Src/siesta_options.F90'
--- Src/siesta_options.F90 2018-08-24 13:23:21 +0000
+++ Src/siesta_options.F90 2019-08-19 08:18:39 +0000
@@ -29,6 +29,7 @@
2929
30 30
31 logical :: mix_scf_first ! Mix first SCF step?31 logical :: mix_scf_first ! Mix first SCF step?
32 logical :: mix_scf_first_force ! Mix first SCF step? and force it!
32 logical :: mix_charge ! New: mix fourier components of rho33 logical :: mix_charge ! New: mix fourier components of rho
33 logical :: mixH ! Mix H instead of DM34 logical :: mixH ! Mix H instead of DM
34 logical :: h_setup_only ! H Setup only35 logical :: h_setup_only ! H Setup only
3536
=== modified file 'version.info'
--- version.info 2019-08-19 07:06:27 +0000
+++ version.info 2019-08-19 08:18:39 +0000
@@ -1,1 +1,5 @@
1<<<<<<< TREE
1siesta-4.1-10932siesta-4.1-1093
3=======
4siesta-4.1-1083--scf-first-3
5>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches