Skip to content

Commit

Permalink
[tet.py] Add support user defined path of scalapack.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhangxyz committed Mar 9, 2023
1 parent 6a48f9b commit 17bed81
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.org
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
+ *TAT.py*: Add =dtype= and =btype= class member for =Tensor= object, which makes it easier to communicate with numpy.
+ *scalapack.py*: Add a python wrapper for scalapack.
*** Changed
+ *tetragono*: Use the =PyScalapack= to speed up min-SR method.
+ *tetragono*: Use the =PyScalapack= to speed up min-SR method. User need to specify the path of scalapack dynamic link
libraries by parameter =scalapack_libraries= for =gm_run= when =natural_gradient_by_direct_pseudo_inverse= enabled.
+ *TAT.py*: Change the module alias name convension, =float= and =complex= without bytes specified would be considered
as double precision now.
*** Deprecated
Expand Down
4 changes: 3 additions & 1 deletion tetragono/tetragono/sampling_lattice/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def gradient_descent(
metric_inverse_epsilon=0.01,
cache_natural_delta=None,
use_natural_gradient_by_direct_pseudo_inverse=False,
scalapack_libraries=None,
natural_gradient_r_pinv=1e-12,
natural_gradient_a_pinv=0,
# About gauge fixing
Expand Down Expand Up @@ -270,7 +271,8 @@ def restrict(configuration, replacement=None):
if use_natural_gradient:
if use_natural_gradient_by_direct_pseudo_inverse:
grad = observer.natural_gradient_by_direct_pseudo_inverse(natural_gradient_r_pinv,
natural_gradient_a_pinv)
natural_gradient_a_pinv,
scalapack_libraries.split(","))
else:
grad = observer.natural_gradient_by_conjugate_gradient(conjugate_gradient_method_step,
conjugate_gradient_method_error,
Expand Down
18 changes: 6 additions & 12 deletions tetragono/tetragono/sampling_lattice/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,16 @@ def _array_to_delta(self, array):
index += size
return result

def natural_gradient_by_direct_pseudo_inverse(self, r_pinv, a_pinv):
def natural_gradient_by_direct_pseudo_inverse(self, r_pinv, a_pinv, libraries):
"""
Get the energy natural gradient for every tensor.
Parameters
----------
r_pinv, a_pinv : float
Parameters control how to calculate pseudo inverse.
libraries : list[str]
The dynamic link libraries containing scalapack functions.
Returns
-------
Expand Down Expand Up @@ -714,22 +716,14 @@ def natural_gradient_by_direct_pseudo_inverse(self, r_pinv, a_pinv):

total_n_s = int(self._count)
result = self._array_to_delta(
self._pseudo_inverse_kernel(
Delta,
Energy,
r_pinv,
a_pinv,
total_n_s,
dtype,
btype,
))
self._pseudo_inverse_kernel(Delta, Energy, r_pinv, a_pinv, total_n_s, dtype, btype, libraries))

showln("calculate natural gradient done")
return result * 2

@staticmethod
def _pseudo_inverse_kernel(Delta, Energy, r_pinv, a_pinv, total_n_s, dtype, btype):
scalapack = Scalapack("/usr/lib/libscalapack.so")
def _pseudo_inverse_kernel(Delta, Energy, r_pinv, a_pinv, total_n_s, dtype, btype, libraries):
scalapack = Scalapack(*libraries)

with scalapack(b'C', -1, 1) as context:
n_s, n_p = Delta.shape
Expand Down

0 comments on commit 17bed81

Please sign in to comment.