From 150ece8fc8f384f9735b89be2a51c76f12ec4ef4 Mon Sep 17 00:00:00 2001 From: falletta Date: Fri, 6 Feb 2026 10:04:11 -0800 Subject: [PATCH 1/2] changed location of update forces --- torch_sim/optimizers/lbfgs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/torch_sim/optimizers/lbfgs.py b/torch_sim/optimizers/lbfgs.py index f4dd79a34..4919da2dc 100644 --- a/torch_sim/optimizers/lbfgs.py +++ b/torch_sim/optimizers/lbfgs.py @@ -536,6 +536,9 @@ def lbfgs_step( # noqa: PLR0915, C901 if is_cell_state: cell_filters.compute_cell_forces(model_output, state) + # Update forces + state.set_constrained_forces(new_forces) # [N, 3] + # Build new (s, y) for history in per-system format [S, M_ext, 3] or [S, M, 3] # s = position difference, y = gradient difference if is_cell_state: @@ -603,7 +606,6 @@ def lbfgs_step( # noqa: PLR0915, C901 y_hist = y_hist[:, -max_history:] # Update state - state.set_constrained_forces(new_forces) # [N, 3] state.energy = new_energy # [S] state.stress = new_stress # [S, 3, 3] or None From 237c76b6f52ed2a7a50aa3438430ccfdee36883f Mon Sep 17 00:00:00 2001 From: falletta Date: Fri, 6 Feb 2026 10:06:08 -0800 Subject: [PATCH 2/2] moved up the update state --- torch_sim/optimizers/lbfgs.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/torch_sim/optimizers/lbfgs.py b/torch_sim/optimizers/lbfgs.py index 4919da2dc..58218ca83 100644 --- a/torch_sim/optimizers/lbfgs.py +++ b/torch_sim/optimizers/lbfgs.py @@ -536,8 +536,10 @@ def lbfgs_step( # noqa: PLR0915, C901 if is_cell_state: cell_filters.compute_cell_forces(model_output, state) - # Update forces + # Update state state.set_constrained_forces(new_forces) # [N, 3] + state.energy = new_energy # [S] + state.stress = new_stress # [S, 3, 3] or None # Build new (s, y) for history in per-system format [S, M_ext, 3] or [S, M, 3] # s = position difference, y = gradient difference @@ -605,10 +607,6 @@ def lbfgs_step( # noqa: PLR0915, C901 s_hist = s_hist[:, -max_history:] # [S, max_history, ...] y_hist = y_hist[:, -max_history:] - # Update state - state.energy = new_energy # [S] - state.stress = new_stress # [S, 3, 3] or None - if is_cell_state: # Store fractional/scaled for next iteration state.prev_positions = new_frac_positions.clone() # [N, 3] (fractional)