From 8399a26a5d0d011175b922fe9c593a867b054e23 Mon Sep 17 00:00:00 2001 From: kaelyndunnell Date: Fri, 15 Nov 2024 12:14:51 -0500 Subject: [PATCH 1/5] fix bug in milestone timestep implementation --- src/festim/stepsize.py | 2 +- test/test_stepsize.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/festim/stepsize.py b/src/festim/stepsize.py index 1e9ff35e0..a94910f03 100644 --- a/src/festim/stepsize.py +++ b/src/festim/stepsize.py @@ -141,7 +141,7 @@ def modify_value(self, value, nb_iterations, t=None): if updated_value > time_to_milestone and not np.isclose( t, next_milestone, atol=0 ): - updated_value = next_milestone + updated_value = time_to_milestone return updated_value diff --git a/test/test_stepsize.py b/test/test_stepsize.py index 5f8bf346b..86c0dce5a 100644 --- a/test/test_stepsize.py +++ b/test/test_stepsize.py @@ -185,7 +185,7 @@ def test_overshoot_milestone(nb_its=1, target=4): value=current_value, nb_iterations=nb_its, t=0.9 ) - expected_value = 1.3 + expected_value = 1.3 - current_value assert new_value == expected_value From ad583ec461aa2b309ece8f14426d4cdb5a86774c Mon Sep 17 00:00:00 2001 From: kaelyndunnell Date: Fri, 15 Nov 2024 13:02:38 -0500 Subject: [PATCH 2/5] fix test --- test/test_stepsize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_stepsize.py b/test/test_stepsize.py index 86c0dce5a..d0f059fc7 100644 --- a/test/test_stepsize.py +++ b/test/test_stepsize.py @@ -175,7 +175,7 @@ def test_overshoot_milestone(nb_its=1, target=4): """ my_stepsize = F.Stepsize(initial_value=0.1) - my_stepsize.growth_factor = 2.0 + my_stepsize.growth_factor = 5.0 my_stepsize.target_nb_iterations = target my_stepsize.milestones = [1.3] From d3c07eaa98d6c05c0400559aed3e3f1bc4728856 Mon Sep 17 00:00:00 2001 From: kaelyndunnell Date: Fri, 15 Nov 2024 14:42:09 -0500 Subject: [PATCH 3/5] fix test --- test/test_stepsize.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_stepsize.py b/test/test_stepsize.py index d0f059fc7..6bd1b297d 100644 --- a/test/test_stepsize.py +++ b/test/test_stepsize.py @@ -175,17 +175,17 @@ def test_overshoot_milestone(nb_its=1, target=4): """ my_stepsize = F.Stepsize(initial_value=0.1) - my_stepsize.growth_factor = 5.0 + my_stepsize.growth_factor = 1 my_stepsize.target_nb_iterations = target my_stepsize.milestones = [1.3] - current_value = 0.5 + current_value = 100000 new_value = my_stepsize.modify_value( - value=current_value, nb_iterations=nb_its, t=0.9 + value=current_value, nb_iterations=nb_its, t=1 ) - expected_value = 1.3 - current_value + expected_value = 1.3 - 1 assert new_value == expected_value From 3ac7748637972ef0bdab6add5f67b2ce2365cd46 Mon Sep 17 00:00:00 2001 From: kaelyndunnell Date: Fri, 15 Nov 2024 16:39:36 -0500 Subject: [PATCH 4/5] black formatted --- test/test_stepsize.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_stepsize.py b/test/test_stepsize.py index 6bd1b297d..a0397e77a 100644 --- a/test/test_stepsize.py +++ b/test/test_stepsize.py @@ -181,9 +181,7 @@ def test_overshoot_milestone(nb_its=1, target=4): my_stepsize.milestones = [1.3] current_value = 100000 - new_value = my_stepsize.modify_value( - value=current_value, nb_iterations=nb_its, t=1 - ) + new_value = my_stepsize.modify_value(value=current_value, nb_iterations=nb_its, t=1) expected_value = 1.3 - 1 From 933650d87016270d3831e1f904c946f744548130 Mon Sep 17 00:00:00 2001 From: kaelyndunnell Date: Fri, 15 Nov 2024 16:41:09 -0500 Subject: [PATCH 5/5] clean test function --- test/test_stepsize.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_stepsize.py b/test/test_stepsize.py index a0397e77a..3556c5661 100644 --- a/test/test_stepsize.py +++ b/test/test_stepsize.py @@ -169,19 +169,19 @@ def test_next_milestone(milestones, current_time, expected_value): assert expected_value == next_milestone -def test_overshoot_milestone(nb_its=1, target=4): +def test_overshoot_milestone(): """Test that stepsize is modified when going to overshoot a milestone. """ my_stepsize = F.Stepsize(initial_value=0.1) my_stepsize.growth_factor = 1 - my_stepsize.target_nb_iterations = target + my_stepsize.target_nb_iterations = 4 my_stepsize.milestones = [1.3] current_value = 100000 - new_value = my_stepsize.modify_value(value=current_value, nb_iterations=nb_its, t=1) + new_value = my_stepsize.modify_value(value=current_value, nb_iterations=1, t=1) expected_value = 1.3 - 1