Skip to content

Improvements of LZSH algorithm#159

Merged
danielhollas merged 64 commits intomasterfrom
lzsh
Jul 31, 2023
Merged

Improvements of LZSH algorithm#159
danielhollas merged 64 commits intomasterfrom
lzsh

Conversation

@JanosJiri
Copy link
Copy Markdown
Contributor

@JanosJiri JanosJiri commented Apr 12, 2023

This commit slightly modifies the LZ code to fix issues we encountered for several molecules.

  1. LZ is computed just for the neighbouring states, not all that are available. Previously, the implementation allowed for unphysical hops like S1 --> S4.
  2. Warning is printed out when the sum of hopping probabilities to the two neighbouring states is larger than one. ABIN somehow deals with that but LZ formula is no longer valid and would need a 3-state generalization.
  3. Warning is printed out when possible discontinuities are encountered. It is based on second derivatives. Testing on azobenzene and bilirubin showed it is able to warn the user when hops due to discontinuity happen.
  4. Warning at the beginning of output if there are more than two states of the same multiplicity. In such cases, LZ works only when the states are well separated. This doesn't hold true for azobenzene, bilirubin, porphyrin and other molecules and LZ should not be used.
  5. Check for dE>deltaE_lz is added at the beginning, otherwise it messes up with probabilities.

Btw, the simple velocity rescaling right be also a problem for LZSH but this was not modified.

Current implementation allows for hops like (05-->01), which is not
compatible with the LZ formula that was derived for two-state problem.
This commit changes it and evaluates it only for closest neighbours.
LZSH exhibits large problems when discontinuities in energies are
encountered. Simple warning based on large change in second derivatives
is added. It was tested on azobenzene and bilirubin and it was able to
warn when suspicious hops occured. Also warning about too many states
was added at the beginning of the output file.
Copy link
Copy Markdown
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! These look like very important fixes. I mostly have just a couple of clarifying questions.
In general, don't be afraid to spell things out a bit more in the code comments to make things super-clear for anybody who might look at this code. Thanks!

(note, the tests are not running because of the old Ubuntu version, I am fixing that in #160

Comment thread src/abin.F90
Comment thread src/landau_zener.F90 Outdated
Comment thread src/landau_zener.F90 Outdated
Comment thread src/landau_zener.F90 Outdated
Comment thread src/landau_zener.F90
Comment thread src/landau_zener.F90
@JanosJiri JanosJiri requested a review from danielhollas April 17, 2023 16:07
Comment thread src/landau_zener.F90
@danielhollas
Copy link
Copy Markdown
Contributor

@JanosJiri are you compiling locally with MPI? Looks like the TERAPI-LZ tests are failing.

@JanosJiri
Copy link
Copy Markdown
Contributor Author

@danielhollas No, I didn't compile it with MPI. I had general issues with MPI here so I even did not try.

@danielhollas
Copy link
Copy Markdown
Contributor

@JanosJiri anything I can help with to get this over the finish line?

@danielhollas danielhollas changed the title Improvements of LZSH algortihm Improvements of LZSH algorithm May 23, 2023
@JanosJiri
Copy link
Copy Markdown
Contributor Author

@JanosJiri anything I can help with to get this over the finish line?

@danielhollas I know the problem is in the TERAPI-LZ test but I was not able to compile ABIN with MPI here. So I don't see where exactly it failed. I just know it did not hop in the test suite. I will try to compile it again but I won't have time to do it soon.

@danielhollas
Copy link
Copy Markdown
Contributor

Cool, thanks! In terms of compiling with MPI, I'd recommend using the dev_scripts/install_mpich.sh to compile your own MPICH version locally, and then rerunning configure with ./configure --mpi /path/to/mpi. This is what we use on Github CI so it should work.

@danielhollas
Copy link
Copy Markdown
Contributor

@JanosJiri I've looked at the failing test TERAPI-LZ, and the issue is that in the original test the system hops from 3rd to 2nd state in the third timestep, but with the new code the output in abin.out says

 Three-point minimum (03->02) dE/a.u.   4.2773499999952946E-003 Probability:  0.95692859086662962
 ERROR: Change of curvature --> discontinuity in PES!
 Probability set to 0!

I am not sure if this is expected, since the PES seems fine to me at first glance. Here are the curves between S2 and S1 states
image

Zoomed out view that includes S0

image

(of course this is a synthetic test but the curves don't seem unrealistic to me)

@JanosJiri
Copy link
Copy Markdown
Contributor Author

@JanosJiri I've looked at the failing test TERAPI-LZ, and the issue is that in the original test the system hops from 3rd to 2nd state in the third timestep, but with the new code the output in abin.out says

 Three-point minimum (03->02) dE/a.u.   4.2773499999952946E-003 Probability:  0.95692859086662962
 ERROR: Change of curvature --> discontinuity in PES!
 Probability set to 0!

I am not sure if this is expected, since the PES seems fine to me at first glance. Here are the curves between S2 and S1 states image

Zoomed out view that includes S0

image

(of course this is a synthetic test but the curves don't seem unrealistic to me)

@danielhollas Thanks for looking at it and also sorry for taking such a long time with it. I believe the problem is in the test, not in the code. The 'smoothness' check I implemented compares the current second derivative of the energy difference with the previous one. However, since this hops on the third step of the algorithm, there is no previous second derivative to compare with. Or rather the 4th energy in the array is still zero generating an artificial second derivative. So I believe this can be solved by adding one more data point before the hopping step. All should be fine then. I will have a look but in a three weeks when I will be back from holidays.

@danielhollas
Copy link
Copy Markdown
Contributor

No worries at all!

Ah, that is tricky indeed. Let's discuss when you get back. Enjoy the well deserved break!

Modification of TERAPI-LZ test to be compatible with the new
modifications of the LZ algorithm. The problem was just three steps.
Thus, the previous second derivative used in the discontinuity check was
still set to 0 which caused the code to think there is a discontinuity.
One more step was artificially added so that it has also the previous
second derivative.
@JanosJiri
Copy link
Copy Markdown
Contributor Author

@danielhollas I modified the test so that it has one more step before hopping. It worked on neon so hopefully it will work also here.

@danielhollas
Copy link
Copy Markdown
Contributor

@JanosJiri Thanks for fixing the test!

I believe the problem is in the test, not in the code. The 'smoothness' check I implemented compares the current second derivative of the energy difference with the previous one. However, since this hops on the third step of the algorithm, there is no previous second derivative to compare with. Or rather the 4th energy in the array is still zero generating an artificial second derivative.

I am not sure I agree that the problem was in the test though (or at least I wouldn't phrase it that way). Before this PR it was perfectly legal to jump on the third step (but not in the first two steps). After this change, we're essentially disallowing any hopping before 4th steps. I guess that is okay, but I am not very happy that there is a misleading warning emitted if the system wants to jump in the third step (i.e. user might think there was discontinuity, even though in reality there wasn't).

@JanosJiri Let me know your thoughts. I am happy to merge this as is, and we can improve upon this later. 🚀

@JanosJiri
Copy link
Copy Markdown
Contributor Author

@JanosJiri Thanks for fixing the test!

I believe the problem is in the test, not in the code. The 'smoothness' check I implemented compares the current second derivative of the energy difference with the previous one. However, since this hops on the third step of the algorithm, there is no previous second derivative to compare with. Or rather the 4th energy in the array is still zero generating an artificial second derivative.

I am not sure I agree that the problem was in the test though (or at least I wouldn't phrase it that way). Before this PR it was perfectly legal to jump on the third step (but not in the first two steps). After this change, we're essentially disallowing any hopping before 4th steps. I guess that is okay, but I am not very happy that there is a misleading warning emitted if the system wants to jump in the third step (i.e. user might think there was discontinuity, even though in reality there wasn't).

@JanosJiri Let me know your thoughts. I am happy to merge this as is, and we can improve upon this later. 🚀

First of all, I agree it is not ideal but there shouldn't be a big problem. The problem is that it won't allow hopping the 2nd step of simulation (not 3rd, 3rd is propagation after hopping) because it has no memory of second derivatives. This should not be a problem when launching the simulations, because in LZ, you should not hop so early, the theory isn't derived for that (it assumes long propagation in the coupling region). The only problem might occur when restarting simulation.

I would merge it and later we can add the second derivative memory to the restart files, which is the only problem I see.

@danielhollas danielhollas requested review from danielhollas and removed request for suchanj July 27, 2023 13:25
Copy link
Copy Markdown
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sounds good, thanks @JanosJiri

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 31, 2023

Codecov Report

Merging #159 (1d1d841) into master (7fba1ee) will decrease coverage by 0.03%.
The diff coverage is 96.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #159      +/-   ##
==========================================
- Coverage   92.39%   92.37%   -0.03%     
==========================================
  Files          43       43              
  Lines        6065     6084      +19     
  Branches      735      741       +6     
==========================================
+ Hits         5604     5620      +16     
- Misses        449      452       +3     
  Partials       12       12              
Flag Coverage Δ
unittests 24.67% <0.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/landau_zener.F90 90.03% <95.23%> (-0.63%) ⬇️
src/abin.F90 93.12% <100.00%> (+0.16%) ⬆️
src/force_abin.F90 93.95% <100.00%> (+0.03%) ⬆️
src/force_terash.F90 97.02% <100.00%> (+0.01%) ⬆️

@danielhollas
Copy link
Copy Markdown
Contributor

Ugh, I thought I had already merged this. Merging now, apologies for the delay.

@danielhollas danielhollas merged commit 542b515 into master Jul 31, 2023
@danielhollas danielhollas deleted the lzsh branch July 31, 2023 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants