Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stresses API #487

Merged
merged 24 commits into from
Jul 27, 2021
Merged

Stresses API #487

merged 24 commits into from
Jul 27, 2021

Conversation

antoine-levitt
Copy link
Member

@antoine-levitt antoine-levitt commented Jul 16, 2021

Built on top of #486

@niklasschmitz I'm getting an error in one of your fallbacks (looks like it's because I forward differentiate wrt several parameters at once), can you take a look?

  • Add tests
  • Add unfolding

@niklasschmitz
Copy link
Collaborator

Indeed my norm rule hadn't covered the case of multiple partials in a Dual yet, I'll extend it shortly!

@antoine-levitt
Copy link
Member Author

Stresses are not correct with symmetries, as expected:

julia> ans
3×3 Matrix{Float64}:
 -0.00159939   7.98518e-5   7.98074e-5
  7.98518e-5  -0.00159939   7.98366e-5
  7.98074e-5   7.98366e-5  -0.00159939
julia> ans
3×3 Matrix{Float64}:
 -0.00181531   -0.000146066  -0.000119765
 -0.000146066  -0.00151338    0.000505329
 -0.000119765   0.000505329  -0.00146946

without and with symmetries, respectively, for a compressed silicon (a=9.26). The first is correct: negative stresses (and therefore positive pressure) that are only in the diagonal direction (because only a is a free parameter)

@antoine-levitt
Copy link
Member Author

So this needs an unfold_BZ(scfres), which is also needed for @LaurentVidal95 's Wannier PR anyway

end
function compute_stresses(scfres)
compute_stresses(scfres.basis, scfres.ψ, scfres.occupation)
end
Copy link
Member

Choose a reason for hiding this comment

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

I guess one should also have a stresses_cart for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not super confortable with stress definitions so I'd rather have just one that matches what's found in the literature. Forces are more intuitive

Copy link
Member

Choose a reason for hiding this comment

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

I see, but forces in the literature are usually cartesian as well. Perhaps we should only support cartesian forces? Or we wait until we understand more and decide then.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well OK, cartesian stresses might make sense. Forces in reduced coordinates definitely makes sense, it's what you want to do for geometry optimization for instance. For stresses I'm not sure what to do about the division by volume, so let's leave it as is for now.

@antoine-levitt
Copy link
Member Author

TODO (reminder to self) add tests

@antoine-levitt
Copy link
Member Author

Good to go from my end

Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

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

I'm not yet fully convinced about the name unfold_BZ, because nothing is really done to the BZ. It is only the symmetry that is undone, so IR-wedge -> full BZ. Maybe remove_symmetries_scfres ? disable_symmetries_scfres ?

test/stresses.jl Outdated Show resolved Hide resolved
test/stresses.jl Outdated Show resolved Hide resolved
test/stresses.jl Outdated Show resolved Hide resolved
test/stresses.jl Outdated Show resolved Hide resolved
test/stresses.jl Outdated Show resolved Hide resolved
src/symmetry.jl Show resolved Hide resolved
src/symmetry.jl Outdated Show resolved Hide resolved
src/symmetry.jl Outdated
for ik_unfolded in 1:length(basis_unfolded.kpoints)
kpt_unfolded = basis_unfolded.kpoints[ik_unfolded]
ik_irred, symop = unfold_mapping(basis_irred, kpt_unfolded)
if !is_ψ
Copy link
Member

Choose a reason for hiding this comment

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

How about better calling this flag apply_symops or something like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't want to give the impression this is a general thing : it's really specialized for psi

src/symmetry.jl Outdated
Comment on lines 307 to 309
ψ = unfold_ψ(scfres.basis, basis_unfolded, scfres.ψ)
eigenvalues = unfold_array(scfres.basis, basis_unfolded, scfres.eigenvalues)
occupation = unfold_array(scfres.basis, basis_unfolded, scfres.occupation)
Copy link
Member

Choose a reason for hiding this comment

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

I think I would structure this differently. For me these three objects are inherently connected and I think it makes sense to fuse the loop, i.e. to handle them simultaneously. That way you also get rid of this strange is_\psi thingy. Also what other k-Point specific objects will we need to transfer in such an unfolding? I don't thing any more.

Copy link
Member Author

Choose a reason for hiding this comment

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

So you'd just merge the unfold_BZ and unfold_array functions? I kind of like the separation. You could have other things, like a partial density, a matrix element for a response computation, etc

Copy link
Member

Choose a reason for hiding this comment

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

True, but in this setup you do a lot of duplicate work unfold_mapping is computed each unfold_array call. I can see us quickly overusing unfold_BZ, so I'm not too happy about this structure. If you have the unfolding as the outer loop it's still easy to add an extra line if you have an additional entry in your scfres.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfold_mapping is cheap. I definitely would wait until we have a better idea of the use cases for this before doing any refactoring. Not convinced merging functions would help here

Copy link
Member

@mfherbst mfherbst Jul 26, 2021

Choose a reason for hiding this comment

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

OTOH is_psi flag is really annoying and the wrapping it into two function names as well. It feels very hackish and I'm not a fan of this solution. If you swap inner and outer loop than you have that info and do not need that strange nested function call structure. I think that is the easiest solution and as you say, when we need more we refactor.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've removed the extra functions which were more confusing than anything (trying to pretend this is a high-level API even if it's pretty hacky). But I really don't want to merge the functions : this is already a pain to write and read, having an extra function does help I feel

src/symmetry.jl Outdated Show resolved Hide resolved
@antoine-levitt
Copy link
Member Author

I'm not yet fully convinced about the name unfold_BZ, because nothing is really done to the BZ. It is only the symmetry that is undone, so IR-wedge -> full BZ. Maybe remove_symmetries_scfres ? disable_symmetries_scfres ?

Well the irreducible BZ gets unfolded into the reducible BZ, so the name works, no? Nothing is done to the symmetries field of scfres, so disable_symmetries would be a bit misleading

@antoine-levitt
Copy link
Member Author

Review done, thanks!

@mfherbst
Copy link
Member

Well the irreducible BZ gets unfolded into the reducible BZ, so the name works, no? Nothing is done to the symmetries field of scfres, so disable_symmetries would be a bit misleading

ok yes, it's only in the scfres where things are really happening that is true. So then unfold_bz_scfres (to match with our capitalisation convention in function calls).

@antoine-levitt
Copy link
Member Author

Not a fan of unfold_bz_scfres(scfres). The long-term plan is for scfres to get a struct, so that this becomes a dispatch.

@mfherbst
Copy link
Member

ok then leave off the scfres if you want.

@mfherbst mfherbst enabled auto-merge (squash) July 27, 2021 06:37
@mfherbst mfherbst disabled auto-merge July 27, 2021 11:10
@mfherbst mfherbst merged commit acb79f9 into master Jul 27, 2021
@mfherbst mfherbst deleted the stresses_API branch July 27, 2021 11:10
@antoine-levitt antoine-levitt mentioned this pull request Jul 28, 2021
2 tasks
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.

3 participants