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
1=== modified file 'Docs/siesta.tex'
2--- Docs/siesta.tex 2019-08-15 23:47:04 +0000
3+++ Docs/siesta.tex 2019-08-19 08:18:39 +0000
4@@ -4102,13 +4102,48 @@
5
6 \begin{fdflogicalT}{SCF.Mix!First}
7 \fdfindex*{DM.MixSCF1}[|see SCF.Mix.First]
8+ \fdfdepend{SCF.Mix!First.Force}%
9+
10+ This flag is used to decide whether mixing (of the DM or H) should
11+ be done in the first SCF step. If mixing is not performed the output
12+ DM or H generated in the first SCF step is used as input in the next
13+ SCF step. When mixing the DM, this ``reset'' has the effect of
14+ avoiding potentially undesirable memory effects: for example, a DM
15+ read from file which corresponds to a different structure might not
16+ satisfy the correct symmetry, and mixing will not fix it. On the
17+ other hand, when reusing a DM for a restart of an interrupted
18+ calculation, a full reset might not be advised.
19+
20+ The value of this flag is one of the ingredients used by \siesta\ to
21+ decide what to do. If \fdftrue\ (the default), mixing will be
22+ performed in all cases, except when a DM has been read from file and
23+ the sparsity pattern of the DM on file is different from the current
24+ one. To ensure that a first-step mixing is done even in this case,
25+ \fdf{SCF.Mix!First.Force} should be set to \fdftrue.
26+
27+ If the flag is \fdffalse, no mixing in the first step will be
28+ performed, except if overridden by \fdf{SCF.Mix!First.Force}.
29+
30+ \note that the default value for this flag has changed from the old
31+ (pre-version 4) setting in \siesta. The new setting is most
32+ appropriate for the case of restarting calculations. On the other
33+ hand, it means that mixing in the first SCF step will also be
34+ performed for the standard case in which the initial DM is built as
35+ a (diagonal) superposition of atomic orbital occupation values. In
36+ some cases (e.g. spin-orbit calculations) better results might be
37+ obtained by avoiding this mixing.
38
39- Whether the first SCF should be mixed or it uses the output as input
40- in the next SCF step. It is generally advised to set this to true,
41- at least when restarting calculations.
42-
43 \end{fdflogicalT}
44
45+\begin{fdflogicalF}{SCF.Mix!First.Force}
46+
47+ Force the mixing (of DM or H) in the first SCF step, regardless of
48+ what \siesta\ may heuristically decide.
49+
50+ This overrules \fdf{SCF.Mix!First}.
51+
52+\end{fdflogicalF}
53+
54
55 In the following the density matrix ($\DM$) will be used in the
56 equations, while for Hamiltonian mixing, $\DM$, should be replaced by
57
58=== modified file 'Src/m_new_dm.F90'
59--- Src/m_new_dm.F90 2018-09-14 12:29:11 +0000
60+++ Src/m_new_dm.F90 2019-08-19 08:18:39 +0000
61@@ -79,6 +79,16 @@
62 logical :: DM_init ! Initialize density matrix from file or from atomic density
63 logical :: read_DM
64 integer :: DM_in_history, n_depth
65+
66+ ! Variable to signal how the initialization was performed.
67+ ! The following table lists the (current) possibilities:
68+ ! 0: DM is filled from atomic information (no information present)
69+ ! 1: .DM file is read, Siesta continuation
70+ ! 2: An extrapolation of previous geometries.
71+ ! The DM's from the previous coordinates are kept in memory
72+ ! 3: .TSDE file is read, TranSiesta continuation
73+ ! If the value is negative it means that one cannot mix in the
74+ ! first step, unless SCF.Mix.First.Force is true!
75 integer :: init_method
76
77 real(dp), pointer :: DM(:,:), EDM(:,:)
78@@ -192,8 +202,8 @@
79 call print_type(DM_2D)
80 end if
81
82- ! Defines the initialiazation to be re-using
83- init_method = -1
84+ ! A negative value specifies that one cannot mix in the initial step
85+ init_method = -3
86
87 end if
88
89@@ -290,7 +300,7 @@
90
91 old_Ef = Ef
92 Ef = fdf_get('TS.Fermi.Initial',Ef,'Ry')
93- if ( init_method == 2 ) then
94+ if ( abs(init_method) == 3 ) then
95 ! As the fermi-level has been read in from a previous
96 ! calculation (TSDE), the EDM should only be shifted by the difference
97 diff_Ef = Ef - old_Ef
98@@ -301,10 +311,10 @@
99
100 if ( IONode ) then
101 write(*,*) ! new-line
102- if ( init_method < 2 ) then
103+ if ( abs(init_method) < 3 ) then
104 write(*,'(a,f9.5,a)')'transiesta: Setting the Fermi-level to: ', &
105 Ef / eV,' eV'
106- else if ( init_method == 2 ) then
107+ else if ( abs(init_method) == 3 ) then
108 write(*,'(a,2(f10.6,a))')'transiesta: Changing Fermi-level from -> to: ', &
109 old_Ef / eV,' -> ',Ef / eV, ' eV'
110 end if
111@@ -325,7 +335,7 @@
112 ! Determine how the mixing of the first step should be performed
113 !
114 ! The idea is that one will allow mixing on the first SCF step
115- ! only for atomicly filled orbitals. This will in most cases
116+ ! only for atomically filled orbitals. This will in most cases
117 ! be a good initial choice, while in certain systems (spin-orbit)
118 ! it may not be so good.
119 ! Subsequently for any MD steps beyond the initial step, we will not
120@@ -336,8 +346,19 @@
121 ! iterations. For instance when performing FC runs (externally driven)
122 ! this would lead to non-degenerate transverse eigenmodes for simple molecules
123 if ( init_method == 0 ) then ! atomicly filled data
124- ! allow mix_scf_first
125- else if ( mix_scf_first ) then
126+ ! allow mix_scf_first
127+ else if ( mix_scf_first_force ) then
128+ ! user requested a mix in the first step
129+ mix_scf_first = .true.
130+ if ( IONode .and. init_method < 0 ) then
131+ ! Warn the user about this
132+ write(*,"(a)") "Mixing first scf iteration is *forced* although the sparsity pattern has changed..."
133+ write(*,"(a)") "Mixing non-compatible matrices might result in problems."
134+ write(*,"(a)") "Please use a linear mixer for the first few steps to remove history effects."
135+ end if
136+ else if ( mix_scf_first .and. init_method < 0 ) then
137+ ! Do not allow mixing first SCF step since we are reusing a DM
138+ ! from another geometry.
139 mix_scf_first = .false.
140 end if
141
142@@ -385,7 +406,7 @@
143 ! integer init_method : returns method it has read the data with
144 ! 0 == atomic filling (possibly user-defined
145 ! 1 == .DM read
146- ! 2 == .TSDE read
147+ ! 3 == .TSDE read
148 ! *******************************************************************
149
150 ! The spin-configuration that is used to determine the spin-order.
151@@ -457,7 +478,7 @@
152 else
153
154 ! Print-out whether transiesta is starting, or siesta is starting
155- call ts_method_init( init_method == 2 )
156+ call ts_method_init( abs(init_method) == 3 )
157
158 end if
159
160@@ -559,7 +580,7 @@
161 ! method used to read the DM/EDM
162 ! 0 == not read
163 ! 1 == .DM read
164- ! 2 == .TSDE read
165+ ! 3 == .TSDE read
166 ! *******************************************************************
167
168 !> The spin-configuration that is used to determine the spin-order.
169@@ -592,6 +613,7 @@
170
171 ! The currently read stuff
172 type(dSpData2D) :: DM_read
173+ type(Sparsity), pointer :: sp_read
174 type(dSpData2D) :: EDM_read
175
176 ! Signal the file has not been found.
177@@ -614,7 +636,7 @@
178
179 if ( TSDE_found ) then
180 ! Signal we have read TSDE
181- init_method = 2
182+ init_method = 3
183
184 DM_found = .true.
185
186@@ -670,6 +692,16 @@
187 ! Density matrix size checks
188 if ( DM_found ) then
189
190+ ! Specify the *correct* init_method
191+ ! In cases where the sparsity pattern changes, we assume this has to do with
192+ ! MD simulations and thus a geometry change.
193+ ! By default we do not allow mixing the first step when re-using a DM from another
194+ ! geometry. This is because of idempotency.
195+ sp_read => spar(DM_read)
196+ if ( .not. equivalent(sp, sp_read) ) then
197+ init_method = -init_method
198+ end if
199+
200 corrected_nsc = .false.
201 if ( nsc_read(1) /= 0 .and. any(nsc /= nsc_read) ) then
202
203
204=== modified file 'Src/read_options.F90'
205--- Src/read_options.F90 2019-07-29 10:25:09 +0000
206+++ Src/read_options.F90 2019-08-19 08:18:39 +0000
207@@ -413,8 +413,14 @@
208 mix_scf_first = fdf_get('DM.MixSCF1', &
209 .not. compat_pre_v4_DM_H)
210 mix_scf_first = fdf_get('SCF.Mix.First', mix_scf_first)
211+ mix_scf_first_force = fdf_get('SCF.Mix.First.Force', .false.)
212+ if ( mix_scf_first_force ) then
213+ ! Also set this, to note the user of mixing first SCF regardless
214+ ! of flag.
215+ mix_scf_first = .true.
216+ end if
217 if (ionode) then
218- write(6,1) 'redata: Mix DM in first SCF step',mix_scf_first
219+ write(6,1) 'redata: Mix DM in first SCF step',mix_scf_first
220 endif
221
222 if (cml_p) then
223
224=== modified file 'Src/siesta_options.F90'
225--- Src/siesta_options.F90 2018-08-24 13:23:21 +0000
226+++ Src/siesta_options.F90 2019-08-19 08:18:39 +0000
227@@ -29,6 +29,7 @@
228
229
230 logical :: mix_scf_first ! Mix first SCF step?
231+ logical :: mix_scf_first_force ! Mix first SCF step? and force it!
232 logical :: mix_charge ! New: mix fourier components of rho
233 logical :: mixH ! Mix H instead of DM
234 logical :: h_setup_only ! H Setup only
235
236=== modified file 'version.info'
237--- version.info 2019-08-19 07:06:27 +0000
238+++ version.info 2019-08-19 08:18:39 +0000
239@@ -1,1 +1,5 @@
240+<<<<<<< TREE
241 siesta-4.1-1093
242+=======
243+siesta-4.1-1083--scf-first-3
244+>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches