diff --git a/Modules/Minimizer.py b/Modules/Minimizer.py index d41130e6..746e0525 100644 --- a/Modules/Minimizer.py +++ b/Modules/Minimizer.py @@ -224,6 +224,9 @@ def run_step(self, gradient, kl_new): # Enlarge the step if not self.fixed_step: self.step *= self.increment_step + + # Perform the minimization step for new direction + self.current_x = self.old_x - self.step * self.direction else: # Proceed with the line minimization @@ -243,14 +246,16 @@ def run_step(self, gradient, kl_new): print("Step too large (scalar = {} | kl_ratio = {}), reducing to {}".format(scalar, kl_ratio, self.step)) #print("Direction: ", self.direction) #print("Gradient: ", gradient) + + # Try again with reduced step + self.current_x = self.old_x - self.step * self.direction else: # The step is good, therefore next step perform a new direction self.new_direction = True if self.verbose: print("Good step found with {}, try increment".format(self.step)) - - # Perform the minimiziation step - self.current_x = self.old_x - self.step * self.direction + # DO NOT update current_x - we accept the current position + # (current_x was already updated in the previous step) def update_dyn(self, new_kl_ratio, dyn_gradient, structure_gradient = None): diff --git a/Modules/SchaMinimizer.py b/Modules/SchaMinimizer.py index c837d5f2..d31e21c0 100644 --- a/Modules/SchaMinimizer.py +++ b/Modules/SchaMinimizer.py @@ -964,11 +964,11 @@ def print_info(self): print (" supercell size = ", " ".join([str(x) for x in self.ensemble.supercell])) # Get the current frequencies - w, pols = self.dyn.GenerateSupercellDyn(self.ensemble.supercell).DyagDinQ(0) + w, pols = self.dyn.DiagonalizeSupercell()#self.dyn.GenerateSupercellDyn(self.ensemble.supercell).DyagDinQ(0) w *= __RyToCm__ # Get the starting frequencies - w0, p0 = self.ensemble.dyn_0.GenerateSupercellDyn(self.ensemble.supercell).DyagDinQ(0) + w0, p0 = self.ensemble.dyn_0.DiagonalizeSupercell() w0 *= __RyToCm__ print () diff --git a/Modules/fourier_gradient.jl b/Modules/fourier_gradient.jl index 94f6014f..1bb78350 100644 --- a/Modules/fourier_gradient.jl +++ b/Modules/fourier_gradient.jl @@ -78,7 +78,7 @@ function get_gradient_fourier!(Φ_grad :: Array{Complex{T}, 3}, for i in 1:n_random tmp = v_tilde[i, j, jq] * conj(δf_tilde[i, k, jq]) Φ_grad[j, k, jq] += tmp * weights[i] - Φ_grad_err[j, k, jq] += tmp * conj(tmp) * weights[i] + Φ_grad_err[j, k, jq] += abs2(tmp) * weights[i] # @views mul!(tmp, v_tilde[:, jq, i], δf_tilde[:, jq, i]') # @. tmp2 = tmp * conj(tmp) @@ -103,9 +103,10 @@ function get_gradient_fourier!(Φ_grad :: Array{Complex{T}, 3}, begin tmp_grad = zeros(Complex{T}, (3*nat, 3*nat, nq)) for iq in 1:nq - @views Φ_grad[:, :, iq] .+= Φ_grad[:, :, iq]' @views tmp_grad[:, :, iq] .= Φ_grad[:, :, iq] + @views tmp_grad[:, :, iq] .+= Φ_grad[:, :, iq]' end + Φ_grad .= tmp_grad for iq in 1:nq @views tmp_grad[:, :, iq] .+= conj.(Φ_grad[:, :, minus_q_index[iq]]') end diff --git a/meson.build b/meson.build index ad2884eb..13dbba80 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('python-sscha', ['c','fortran'], - version : '1.5.0', + version : '1.6.0', license: 'GPL', meson_version: '>= 1.1.0', # <- set min version of meson. default_options : [ diff --git a/pyproject.toml b/pyproject.toml index 2b5e2fce..783c7c42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "mesonpy" [project] name = "python-sscha" -version = "1.5.1" +version = "1.6.0" description = "Python implementation of the sscha code" authors = [{name = "Lorenzo Monacelli"}] # Put here email readme = "README.md"