From b3446b8639b732668c3d596206f15435062c61cf Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:31:52 -0500 Subject: [PATCH 1/7] pushFitHook deprecation --- docs/examples/coreshellnp.py | 2 +- docs/source/extending.rst | 2 +- src/diffpy/srfit/fitbase/fithook.py | 8 ++++---- src/diffpy/srfit/fitbase/fitrecipe.py | 16 +++++++++++++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/docs/examples/coreshellnp.py b/docs/examples/coreshellnp.py index 3f8d5b06..6e8e7af8 100644 --- a/docs/examples/coreshellnp.py +++ b/docs/examples/coreshellnp.py @@ -169,7 +169,7 @@ def main(): recipe = makeRecipe(stru1, stru2, data) from diffpy.srfit.fitbase.fithook import PlotFitHook - recipe.pushFitHook(PlotFitHook()) + recipe.push_fit_hook(PlotFitHook()) recipe.fithooks[0].verbose = 3 # Optimize - we do this in steps to help convergence diff --git a/docs/source/extending.rst b/docs/source/extending.rst index 6e3563de..a7a10be8 100644 --- a/docs/source/extending.rst +++ b/docs/source/extending.rst @@ -263,5 +263,5 @@ overload. * .. automethod:: FitHook.postcall To use a custom ``FitHook``, assign an instance to a ``FitRecipe`` using the -``pushFitHook`` method. All ``FitHook`` instances held by a ``FitRecipe`` will +``push_fit_hook`` method. All ``FitHook`` instances held by a ``FitRecipe`` will be used in sequence during a call to ``FitRecipe.residual``. diff --git a/src/diffpy/srfit/fitbase/fithook.py b/src/diffpy/srfit/fitbase/fithook.py index 14c5811c..be8cdf7c 100644 --- a/src/diffpy/srfit/fitbase/fithook.py +++ b/src/diffpy/srfit/fitbase/fithook.py @@ -37,10 +37,10 @@ class FitHook(object): """Base class for inspecting the progress of a FitRecipe refinement. Can serve as a fithook for the FitRecipe class (see - FitRecipe.pushFitHook method.) The methods in this class are called - during the preparation of the FitRecipe for refinement, and during - the residual call. See the class methods for a description of their - purpose. + FitRecipe.push_fit_hook method.) The methods in this class are + called during the preparation of the FitRecipe for refinement, and + during the residual call. See the class methods for a description of + their purpose. """ def reset(self, recipe): diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index 4568f7a7..5ff73ef4 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -55,6 +55,10 @@ base, "addContribution", "add_contribution", removal_version ) +pushfithook_dep_msg = build_deprecation_message( + base, "pushFitHook", "push_fit_hook", removal_version +) + class FitRecipe(_fitrecipe_interface, RecipeOrganizer): """FitRecipe class. @@ -191,7 +195,7 @@ def __init__(self, name="fit"): } return - def pushFitHook(self, fithook, index=None): + def push_fit_hook(self, fithook, index=None): """Add a FitHook to be called within the residual method. The hook is an object for reporting updates, or more fundamentally, @@ -214,6 +218,16 @@ def pushFitHook(self, fithook, index=None): self._update_configuration() return + @deprecated(pushfithook_dep_msg) + def pushFitHook(self, fithook, index=None): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.srfit.fitbase.FitRecipe.push_fit_hook instead. + """ + self.push_fit_hook(fithook, index) + return + def popFitHook(self, fithook=None, index=-1): """Remove a FitHook by index or reference. From 520e94bce7d13cafef3812d9b55d7402f8366177 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:33:31 -0500 Subject: [PATCH 2/7] popFitHook deprecation --- src/diffpy/srfit/fitbase/fitrecipe.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index 5ff73ef4..4b709fa8 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -59,6 +59,10 @@ base, "pushFitHook", "push_fit_hook", removal_version ) +popfithook_dep_msg = build_deprecation_message( + base, "popFitHook", "pop_fit_hook", removal_version +) + class FitRecipe(_fitrecipe_interface, RecipeOrganizer): """FitRecipe class. @@ -228,7 +232,7 @@ def pushFitHook(self, fithook, index=None): self.push_fit_hook(fithook, index) return - def popFitHook(self, fithook=None, index=-1): + def pop_fit_hook(self, fithook=None, index=-1): """Remove a FitHook by index or reference. Attributes @@ -250,6 +254,15 @@ def popFitHook(self, fithook=None, index=-1): self.fithook.remove(index) return + def popFitHook(self, fithook=None, index=-1): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.srfit.fitbase.FitRecipe.pop_fit_hook instead. + """ + self.pop_fit_hook(fithook, index) + return + def getFitHooks(self): """Get the sequence of FitHook instances.""" return self.fithooks[:] From 61195e3fdd4ee1bae23af12844185c430151b04b Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:33:52 -0500 Subject: [PATCH 3/7] popFitHook dep message --- src/diffpy/srfit/fitbase/fitrecipe.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index 4b709fa8..f1741caa 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -254,6 +254,7 @@ def pop_fit_hook(self, fithook=None, index=-1): self.fithook.remove(index) return + @deprecated(popfithook_dep_msg) def popFitHook(self, fithook=None, index=-1): """This function has been deprecated and will be removed in version 4.0.0. From ca3d83e8e52fbae78d7e6a21f1d1cb739882889f Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:39:17 -0500 Subject: [PATCH 4/7] getFitHooks and clearFitHooks deprecation --- src/diffpy/srfit/fitbase/fitrecipe.py | 29 +++++++++++++++++++++++++-- tests/test_fitrecipe.py | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index f1741caa..b6a10194 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -63,6 +63,14 @@ base, "popFitHook", "pop_fit_hook", removal_version ) +getfithooks_dep_msg = build_deprecation_message( + base, "getFitHooks", "get_fit_hooks", removal_version +) + +clearfithooks_dep_msg = build_deprecation_message( + base, "clearFitHooks", "clear_fit_hooks", removal_version +) + class FitRecipe(_fitrecipe_interface, RecipeOrganizer): """FitRecipe class. @@ -264,15 +272,32 @@ def popFitHook(self, fithook=None, index=-1): self.pop_fit_hook(fithook, index) return - def getFitHooks(self): + def get_fit_hooks(self): """Get the sequence of FitHook instances.""" return self.fithooks[:] - def clearFitHooks(self): + @deprecated(getfithooks_dep_msg) + def getFitHooks(self): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.srfit.fitbase.FitRecipe.get_fit_hooks instead.""" + return self.get_fit_hooks() + + def clear_fit_hooks(self): """Clear the FitHook sequence.""" del self.fithooks[:] return + @deprecated(clearfithooks_dep_msg) + def clearFitHooks(self): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.srfit.fitbase.FitRecipe.clear_fit_hooks instead.""" + self.clear_fit_hooks() + return + def add_contribution(self, con, weight=1.0): """Add a FitContribution to the FitRecipe. diff --git a/tests/test_fitrecipe.py b/tests/test_fitrecipe.py index 0f8761ac..39345fb6 100644 --- a/tests/test_fitrecipe.py +++ b/tests/test_fitrecipe.py @@ -320,7 +320,7 @@ def test_add_contribution(capturestdout): recipe.addVar(fitcontribution.c) recipe.restrain("c", lb=5) - (pfh,) = recipe.getFitHooks() + (pfh,) = recipe.get_fit_hooks() out = capturestdout(recipe.scalarResidual) assert "" == out pfh.verbose = 1 From 9296fc6786d7e82245d3409090671c5fd704c1da Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:42:17 -0500 Subject: [PATCH 5/7] setWeight deprecation --- docs/examples/npintensityII.py | 8 ++++---- docs/examples/nppdfsas.py | 10 +++++----- src/diffpy/srfit/fitbase/fitrecipe.py | 15 ++++++++++++++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/examples/npintensityII.py b/docs/examples/npintensityII.py index d3bd4ef5..e27ef3cb 100644 --- a/docs/examples/npintensityII.py +++ b/docs/examples/npintensityII.py @@ -248,17 +248,17 @@ def main(): # fit. recipe.fix("all") recipe.free("bcoeffs1") - recipe.setWeight(recipe.bucky2, 0) + recipe.set_weight(recipe.bucky2, 0) scipyOptimize(recipe) # Now do the same for the second background recipe.fix("all") recipe.free("bcoeffs1") - recipe.setWeight(recipe.bucky2, 1) - recipe.setWeight(recipe.bucky1, 0) + recipe.set_weight(recipe.bucky2, 1) + recipe.set_weight(recipe.bucky1, 0) scipyOptimize(recipe) # Now refine everything with the structure parameters included recipe.free("all") - recipe.setWeight(recipe.bucky1, 1) + recipe.set_weight(recipe.bucky1, 1) scipyOptimize(recipe) # Generate and print the FitResults diff --git a/docs/examples/nppdfsas.py b/docs/examples/nppdfsas.py index acd6fac7..8e0aa2b1 100644 --- a/docs/examples/nppdfsas.py +++ b/docs/examples/nppdfsas.py @@ -122,7 +122,7 @@ def fitRecipe(recipe): """We refine in stages to help the refinement converge.""" # Tune SAS. - recipe.setWeight(recipe.pdf, 0) + recipe.set_weight(recipe.pdf, 0) recipe.fix("all") recipe.free("radius_a", "radius_b", iqscale=1e8) recipe.constrain("radius_b", "radius_a") @@ -130,15 +130,15 @@ def fitRecipe(recipe): recipe.unconstrain("radius_b") # Tune PDF - recipe.setWeight(recipe.pdf, 1) - recipe.setWeight(recipe.sas, 0) + recipe.set_weight(recipe.pdf, 1) + recipe.set_weight(recipe.sas, 0) recipe.fix("all") recipe.free("a", "Biso_0", "scale", "delta2") scipyOptimize(recipe) # Tune all - recipe.setWeight(recipe.pdf, 1) - recipe.setWeight(recipe.sas, 1) + recipe.set_weight(recipe.pdf, 1) + recipe.set_weight(recipe.sas, 1) recipe.free("all") scipyOptimize(recipe) diff --git a/src/diffpy/srfit/fitbase/fitrecipe.py b/src/diffpy/srfit/fitbase/fitrecipe.py index b6a10194..7bb29b8e 100644 --- a/src/diffpy/srfit/fitbase/fitrecipe.py +++ b/src/diffpy/srfit/fitbase/fitrecipe.py @@ -71,6 +71,10 @@ base, "clearFitHooks", "clear_fit_hooks", removal_version ) +setweight_dep_msg = build_deprecation_message( + base, "setWeight", "set_weight", removal_version +) + class FitRecipe(_fitrecipe_interface, RecipeOrganizer): """FitRecipe class. @@ -326,12 +330,21 @@ def addContribution(self, con, weight=1.0): self.add_contribution(con, weight) return - def setWeight(self, con, weight): + def set_weight(self, con, weight): """Set the weight of a FitContribution.""" idx = list(self._contributions.values()).index(con) self._weights[idx] = weight return + @deprecated(setweight_dep_msg) + def setWeight(self, con, weight): + """This function has been deprecated and will be removed in version + 4.0.0. + + Please use diffpy.srfit.fitbase.FitRecipe.set_weight instead.""" + self.set_weight(con, weight) + return + def addParameterSet(self, parset): """Add a ParameterSet to the hierarchy. From 2af8782ac7f3c8b7fea4a88dbed58ce27421fd86 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:50:29 -0500 Subject: [PATCH 6/7] news --- news/fithook-and-weights-dep.rst | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 news/fithook-and-weights-dep.rst diff --git a/news/fithook-and-weights-dep.rst b/news/fithook-and-weights-dep.rst new file mode 100644 index 00000000..cc3971b6 --- /dev/null +++ b/news/fithook-and-weights-dep.rst @@ -0,0 +1,27 @@ +**Added:** + +* Added ``set_weight`` method to ``FitRecipe`` to replace ``setWeight``. +* Added ``get_fit_hooks`` method to ``FitRecipe`` to replace ``getFitHooks``. +* Added ``clear_fit_hooks`` method to ``FitRecipe`` to replace ``clearFitHooks``. +* Added ``pop_fit_hook`` method to ``FitRecipe`` to replace ``popFitHook``. +* Added ``push_fit_hook`` method to ``FitRecipe`` to replace ``pushFitHook``. + +**Changed:** + +* + +**Deprecated:** + +* Deprecate ``setWeight``, ``getFitHooks``, ``clearFitHooks``, ``popFitHook``, and ``pushFitHook`` in ``FitRecipe`` for removal in 4.0.0. + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* From 69ecbb5e493e286e2b43745c9087f83dea3420f5 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Sun, 8 Feb 2026 14:53:27 -0500 Subject: [PATCH 7/7] news pt2 --- news/fithook-and-weights-dep.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/news/fithook-and-weights-dep.rst b/news/fithook-and-weights-dep.rst index cc3971b6..43157e5a 100644 --- a/news/fithook-and-weights-dep.rst +++ b/news/fithook-and-weights-dep.rst @@ -12,7 +12,11 @@ **Deprecated:** -* Deprecate ``setWeight``, ``getFitHooks``, ``clearFitHooks``, ``popFitHook``, and ``pushFitHook`` in ``FitRecipe`` for removal in 4.0.0. +* Deprecated ``setWeight`` in ``FitRecipe`` for removal in 4.0.0. +* Deprecated ``getFitHooks`` in ``FitRecipe`` for removal in 4.0.0. +* Deprecated ``clearFitHooks`` in ``FitRecipe`` for removal in 4.0.0. +* Deprecated ``popFitHook`` in ``FitRecipe`` for removal in 4.0.0. +* Deprecated ``pushFitHook`` in ``FitRecipe`` for removal in 4.0.0. **Removed:**