Skip to content

Commit

Permalink
Update descent.py
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulaGarciaMolina authored Jan 19, 2024
1 parent 3e50daa commit 1e5cdc7
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions src/seemps/optimization/descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,18 @@ def energy_and_variance(state: MPS) -> tuple[MPS, float, float, float]:
state = CanonicalMPS(state, normalize=True)
for step in range(maxiter):
H_state, E, variance, avg_H2 = energy_and_variance(state)
if callback is not None:
callback(
state
),
)
if DEBUG:
log(f"step = {step:5d}, energy = {E}, variance = {variance}")
energies.append(E)
variances.append(variance)
if E < best_energy:
best_energy, best_vector, _ = E, state, variance
if callback is not None:
callback(
state,
OptimizeResults(
state=best_vector,
energy=best_energy,
converged=converged,
message=message,
trajectory=energies,
variances=variances,
),
)

E_mean: float = np.mean(energies[(-min(k_mean, len(energies)-1))-1 : -1]) # type: ignore
if (E_mean - last_E_mean > 0 and E_mean - last_E_mean >= abs(tol_up)) or (
E_mean - last_E_mean < 0 and E_mean - last_E_mean >= -abs(tol)
Expand All @@ -154,22 +148,15 @@ def energy_and_variance(state: MPS) -> tuple[MPS, float, float, float]:
# which was already calculated
if not converged:
H_state, E, variance, _ = energy_and_variance(state)
if E < best_energy:
best_energy, best_vector, _ = E, state, variance
energies.append(E)
variances.append(variance)
if callback is not None:
callback(
state,
OptimizeResults(
state=best_vector,
energy=best_energy,
converged=converged,
message=message,
trajectory=energies,
variances=variances,
),
)
if E < best_energy:
best_energy, best_vector, _ = E, state, variance
energies.append(E)
variances.append(variance)
return OptimizeResults(
state=best_vector,
energy=best_energy,
Expand Down

0 comments on commit 1e5cdc7

Please sign in to comment.