Skip to content

Commit e3db88e

Browse files
authored
Merge pull request #151 from cadenmyers13/fitrecipe-dep
deprecate: `pushFitHook`, `popFitHook`, `getFitHook`, `clearFitHook`, and `setWeight` in `FitRecipe`
2 parents a1f1f49 + 69ecbb5 commit e3db88e

8 files changed

Lines changed: 118 additions & 21 deletions

File tree

docs/examples/coreshellnp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def main():
169169
recipe = makeRecipe(stru1, stru2, data)
170170
from diffpy.srfit.fitbase.fithook import PlotFitHook
171171

172-
recipe.pushFitHook(PlotFitHook())
172+
recipe.push_fit_hook(PlotFitHook())
173173
recipe.fithooks[0].verbose = 3
174174

175175
# Optimize - we do this in steps to help convergence

docs/examples/npintensityII.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,17 @@ def main():
248248
# fit.
249249
recipe.fix("all")
250250
recipe.free("bcoeffs1")
251-
recipe.setWeight(recipe.bucky2, 0)
251+
recipe.set_weight(recipe.bucky2, 0)
252252
scipyOptimize(recipe)
253253
# Now do the same for the second background
254254
recipe.fix("all")
255255
recipe.free("bcoeffs1")
256-
recipe.setWeight(recipe.bucky2, 1)
257-
recipe.setWeight(recipe.bucky1, 0)
256+
recipe.set_weight(recipe.bucky2, 1)
257+
recipe.set_weight(recipe.bucky1, 0)
258258
scipyOptimize(recipe)
259259
# Now refine everything with the structure parameters included
260260
recipe.free("all")
261-
recipe.setWeight(recipe.bucky1, 1)
261+
recipe.set_weight(recipe.bucky1, 1)
262262
scipyOptimize(recipe)
263263

264264
# Generate and print the FitResults

docs/examples/nppdfsas.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,23 @@ def fitRecipe(recipe):
122122
"""We refine in stages to help the refinement converge."""
123123

124124
# Tune SAS.
125-
recipe.setWeight(recipe.pdf, 0)
125+
recipe.set_weight(recipe.pdf, 0)
126126
recipe.fix("all")
127127
recipe.free("radius_a", "radius_b", iqscale=1e8)
128128
recipe.constrain("radius_b", "radius_a")
129129
scipyOptimize(recipe)
130130
recipe.unconstrain("radius_b")
131131

132132
# Tune PDF
133-
recipe.setWeight(recipe.pdf, 1)
134-
recipe.setWeight(recipe.sas, 0)
133+
recipe.set_weight(recipe.pdf, 1)
134+
recipe.set_weight(recipe.sas, 0)
135135
recipe.fix("all")
136136
recipe.free("a", "Biso_0", "scale", "delta2")
137137
scipyOptimize(recipe)
138138

139139
# Tune all
140-
recipe.setWeight(recipe.pdf, 1)
141-
recipe.setWeight(recipe.sas, 1)
140+
recipe.set_weight(recipe.pdf, 1)
141+
recipe.set_weight(recipe.sas, 1)
142142
recipe.free("all")
143143
scipyOptimize(recipe)
144144

docs/source/extending.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,5 @@ overload.
263263
* .. automethod:: FitHook.postcall
264264

265265
To use a custom ``FitHook``, assign an instance to a ``FitRecipe`` using the
266-
``pushFitHook`` method. All ``FitHook`` instances held by a ``FitRecipe`` will
266+
``push_fit_hook`` method. All ``FitHook`` instances held by a ``FitRecipe`` will
267267
be used in sequence during a call to ``FitRecipe.residual``.

news/fithook-and-weights-dep.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
**Added:**
2+
3+
* Added ``set_weight`` method to ``FitRecipe`` to replace ``setWeight``.
4+
* Added ``get_fit_hooks`` method to ``FitRecipe`` to replace ``getFitHooks``.
5+
* Added ``clear_fit_hooks`` method to ``FitRecipe`` to replace ``clearFitHooks``.
6+
* Added ``pop_fit_hook`` method to ``FitRecipe`` to replace ``popFitHook``.
7+
* Added ``push_fit_hook`` method to ``FitRecipe`` to replace ``pushFitHook``.
8+
9+
**Changed:**
10+
11+
* <news item>
12+
13+
**Deprecated:**
14+
15+
* Deprecated ``setWeight`` in ``FitRecipe`` for removal in 4.0.0.
16+
* Deprecated ``getFitHooks`` in ``FitRecipe`` for removal in 4.0.0.
17+
* Deprecated ``clearFitHooks`` in ``FitRecipe`` for removal in 4.0.0.
18+
* Deprecated ``popFitHook`` in ``FitRecipe`` for removal in 4.0.0.
19+
* Deprecated ``pushFitHook`` in ``FitRecipe`` for removal in 4.0.0.
20+
21+
**Removed:**
22+
23+
* <news item>
24+
25+
**Fixed:**
26+
27+
* <news item>
28+
29+
**Security:**
30+
31+
* <news item>

src/diffpy/srfit/fitbase/fithook.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class FitHook(object):
3737
"""Base class for inspecting the progress of a FitRecipe refinement.
3838
3939
Can serve as a fithook for the FitRecipe class (see
40-
FitRecipe.pushFitHook method.) The methods in this class are called
41-
during the preparation of the FitRecipe for refinement, and during
42-
the residual call. See the class methods for a description of their
43-
purpose.
40+
FitRecipe.push_fit_hook method.) The methods in this class are
41+
called during the preparation of the FitRecipe for refinement, and
42+
during the residual call. See the class methods for a description of
43+
their purpose.
4444
"""
4545

4646
def reset(self, recipe):

src/diffpy/srfit/fitbase/fitrecipe.py

Lines changed: 71 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@
5555
base, "addContribution", "add_contribution", removal_version
5656
)
5757

58+
pushfithook_dep_msg = build_deprecation_message(
59+
base, "pushFitHook", "push_fit_hook", removal_version
60+
)
61+
62+
popfithook_dep_msg = build_deprecation_message(
63+
base, "popFitHook", "pop_fit_hook", removal_version
64+
)
65+
66+
getfithooks_dep_msg = build_deprecation_message(
67+
base, "getFitHooks", "get_fit_hooks", removal_version
68+
)
69+
70+
clearfithooks_dep_msg = build_deprecation_message(
71+
base, "clearFitHooks", "clear_fit_hooks", removal_version
72+
)
73+
74+
setweight_dep_msg = build_deprecation_message(
75+
base, "setWeight", "set_weight", removal_version
76+
)
77+
5878

5979
class FitRecipe(_fitrecipe_interface, RecipeOrganizer):
6080
"""FitRecipe class.
@@ -191,7 +211,7 @@ def __init__(self, name="fit"):
191211
}
192212
return
193213

194-
def pushFitHook(self, fithook, index=None):
214+
def push_fit_hook(self, fithook, index=None):
195215
"""Add a FitHook to be called within the residual method.
196216
197217
The hook is an object for reporting updates, or more fundamentally,
@@ -214,7 +234,17 @@ def pushFitHook(self, fithook, index=None):
214234
self._update_configuration()
215235
return
216236

217-
def popFitHook(self, fithook=None, index=-1):
237+
@deprecated(pushfithook_dep_msg)
238+
def pushFitHook(self, fithook, index=None):
239+
"""This function has been deprecated and will be removed in version
240+
4.0.0.
241+
242+
Please use diffpy.srfit.fitbase.FitRecipe.push_fit_hook instead.
243+
"""
244+
self.push_fit_hook(fithook, index)
245+
return
246+
247+
def pop_fit_hook(self, fithook=None, index=-1):
218248
"""Remove a FitHook by index or reference.
219249
220250
Attributes
@@ -236,15 +266,42 @@ def popFitHook(self, fithook=None, index=-1):
236266
self.fithook.remove(index)
237267
return
238268

239-
def getFitHooks(self):
269+
@deprecated(popfithook_dep_msg)
270+
def popFitHook(self, fithook=None, index=-1):
271+
"""This function has been deprecated and will be removed in version
272+
4.0.0.
273+
274+
Please use diffpy.srfit.fitbase.FitRecipe.pop_fit_hook instead.
275+
"""
276+
self.pop_fit_hook(fithook, index)
277+
return
278+
279+
def get_fit_hooks(self):
240280
"""Get the sequence of FitHook instances."""
241281
return self.fithooks[:]
242282

243-
def clearFitHooks(self):
283+
@deprecated(getfithooks_dep_msg)
284+
def getFitHooks(self):
285+
"""This function has been deprecated and will be removed in version
286+
4.0.0.
287+
288+
Please use diffpy.srfit.fitbase.FitRecipe.get_fit_hooks instead."""
289+
return self.get_fit_hooks()
290+
291+
def clear_fit_hooks(self):
244292
"""Clear the FitHook sequence."""
245293
del self.fithooks[:]
246294
return
247295

296+
@deprecated(clearfithooks_dep_msg)
297+
def clearFitHooks(self):
298+
"""This function has been deprecated and will be removed in version
299+
4.0.0.
300+
301+
Please use diffpy.srfit.fitbase.FitRecipe.clear_fit_hooks instead."""
302+
self.clear_fit_hooks()
303+
return
304+
248305
def add_contribution(self, con, weight=1.0):
249306
"""Add a FitContribution to the FitRecipe.
250307
@@ -273,12 +330,21 @@ def addContribution(self, con, weight=1.0):
273330
self.add_contribution(con, weight)
274331
return
275332

276-
def setWeight(self, con, weight):
333+
def set_weight(self, con, weight):
277334
"""Set the weight of a FitContribution."""
278335
idx = list(self._contributions.values()).index(con)
279336
self._weights[idx] = weight
280337
return
281338

339+
@deprecated(setweight_dep_msg)
340+
def setWeight(self, con, weight):
341+
"""This function has been deprecated and will be removed in version
342+
4.0.0.
343+
344+
Please use diffpy.srfit.fitbase.FitRecipe.set_weight instead."""
345+
self.set_weight(con, weight)
346+
return
347+
282348
def addParameterSet(self, parset):
283349
"""Add a ParameterSet to the hierarchy.
284350

tests/test_fitrecipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def test_add_contribution(capturestdout):
320320

321321
recipe.addVar(fitcontribution.c)
322322
recipe.restrain("c", lb=5)
323-
(pfh,) = recipe.getFitHooks()
323+
(pfh,) = recipe.get_fit_hooks()
324324
out = capturestdout(recipe.scalarResidual)
325325
assert "" == out
326326
pfh.verbose = 1

0 commit comments

Comments
 (0)