-
Notifications
You must be signed in to change notification settings - Fork 24
change: update how the deprecated characteristic functions handle the signature changes #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
94216cb
5fc9751
953ef60
f4c7314
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -941,23 +941,28 @@ def register_function(self, function, name=None, argnames=None): | |
|
|
||
| import inspect | ||
|
|
||
| # A decorator such as `deprecated` replaces the code object with | ||
| # that of its (*args, **kwargs) wrapper, so introspect the | ||
| # function it wraps while still registering the decorated one. | ||
| wrapped_function = inspect.unwrap(function) | ||
|
|
||
| fncode = None | ||
|
|
||
| # This will let us offset the argument list to eliminate 'self' | ||
| offset = 0 | ||
|
|
||
| # check regular functions | ||
| if inspect.isfunction(function): | ||
| fncode = function.__code__ | ||
| if inspect.isfunction(wrapped_function): | ||
| fncode = wrapped_function.__code__ | ||
| # check class method | ||
| elif inspect.ismethod(function): | ||
| fncode = function.__func__.__code__ | ||
| offset = 1 | ||
| # check functor | ||
| elif hasattr(function, "__call__") and hasattr( | ||
| function.__call__, "__func__" | ||
| elif hasattr(wrapped_function, "__call__") and hasattr( | ||
| wrapped_function.__call__, "__func__" | ||
| ): | ||
| fncode = function.__call__.__func__.__code__ | ||
| fncode = wrapped_function.__call__.__func__.__code__ | ||
| offset = 1 | ||
| else: | ||
| m = "Cannot extract name or argnames" | ||
|
|
@@ -1182,15 +1187,15 @@ def add_constraint(self, parameter, constraint_eq, params={}): | |
| return | ||
|
|
||
| @deprecated(constrain_deprecation_msg) | ||
| def constrain(self, parameter, constraint_eq, params={}): | ||
| def constrain(self, par, con, ns={}): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, please keep explicit.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my response above |
||
| """This function has been deprecated and will be removed in | ||
| version 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.fitbase.recipeorganizer.RecipeOrganizer.add_constraint | ||
| instead. | ||
| """ | ||
| self.add_constraint(parameter, constraint_eq, params=params) | ||
| self.add_constraint(par, con, params=ns) | ||
| return | ||
|
|
||
| def is_constrained(self, parameter): | ||
|
|
@@ -1214,15 +1219,15 @@ def is_constrained(self, parameter): | |
| return parameter in self._constraints | ||
|
|
||
| @deprecated(isConstrained_deprecation_msg) | ||
| def isConstrained(self, parameter): | ||
| def isConstrained(self, par): | ||
| """This function has been deprecated and will be removed in | ||
| version 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.fitbase.recipeorganizer.RecipeOrganizer.is_constrained | ||
| instead. | ||
| """ | ||
| return self.is_constrained(parameter) | ||
| return self.is_constrained(par) | ||
|
|
||
| def remove_constraint(self, *pars): | ||
| """Unconstrain a Parameter. | ||
|
|
@@ -1424,15 +1429,7 @@ def add_soft_bounds( | |
| return param_or_eq | ||
|
|
||
| @deprecated(restrain_deprecation_msg) | ||
| def restrain( | ||
| self, | ||
| param_or_eq, | ||
| lower_bound=-inf, | ||
| upper_bound=inf, | ||
| sig=1, | ||
| scaled=False, | ||
| params={}, | ||
| ): | ||
| def restrain(self, res, lb=-inf, ub=inf, sig=1, scaled=False, ns={}): | ||
| """This function has been deprecated and will be removed in | ||
| version 4.0.0. | ||
|
|
||
|
|
@@ -1441,12 +1438,12 @@ def restrain( | |
| instead. | ||
| """ | ||
| return self.add_soft_bounds( | ||
| param_or_eq, | ||
| lower_bound=lower_bound, | ||
| upper_bound=upper_bound, | ||
| res, | ||
| lower_bound=lb, | ||
| upper_bound=ub, | ||
| sig=sig, | ||
| scaled=scaled, | ||
| params=params, | ||
| params=ns, | ||
| ) | ||
|
|
||
| def register_soft_bounds(self, res): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,53 +55,69 @@ | |
| removal_version = "4.0.0" | ||
| cf_base = "diffpy.srfit.pdf.characteristicfunctions" | ||
|
|
||
| sphericalCF_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
|
|
||
| def _build_dep_msg(old_name, new_name, signature_note=None): | ||
| """Build the deprecation message for a camel case function. | ||
|
|
||
| The note describing how the signature changed, when there is one, is | ||
| appended to the standard message from `build_deprecation_message`. | ||
| """ | ||
| message = build_deprecation_message( | ||
| cf_base, old_name, new_name, removal_version | ||
| ) | ||
| if signature_note is None: | ||
| return message | ||
| return f"{message} {signature_note}" | ||
|
|
||
|
|
||
| sphericalCF_dep_msg = _build_dep_msg( | ||
| "sphericalCF", | ||
| "spherical_particle", | ||
| removal_version, | ||
| "Additionally, the signature has changed. Please pass the parameter " | ||
| "'psize' as 'particle_diameter'.", | ||
| ) | ||
|
|
||
| spheroidalCF_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
| spheroidalCF_dep_msg = _build_dep_msg( | ||
| "spheroidalCF", | ||
| "spheroidal_particle", | ||
| removal_version, | ||
| "Additionally, the signature has changed. Please pass the parameters " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, let's not lose our previous work making hte code more readable. keep it self documenting by using full names. |
||
| "'erad' and 'prad' as 'equatorial_radius' and 'polar_radius', " | ||
| "respectively.", | ||
| ) | ||
|
|
||
| spheroidalCF2_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
| spheroidalCF2_dep_msg = _build_dep_msg( | ||
| "spheroidalCF2", | ||
| "spheroidal_particle", | ||
| removal_version, | ||
| "Additionally, the parameterization has changed. 'spheroidalCF2' took " | ||
| "the equatorial diameter 'psize' and the axis ratio 'axrat', while " | ||
| "'spheroidal_particle' takes radii. Please pass " | ||
| "equatorial_radius = psize / 2 and polar_radius = axrat * psize / 2.", | ||
| ) | ||
|
|
||
| lognormalSphericalCF_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
| lognormalSphericalCF_dep_msg = _build_dep_msg( | ||
| "lognormalSphericalCF", | ||
| "lognormal_spherical_particle", | ||
| removal_version, | ||
| "Additionally, the signature has changed. Please pass the parameters " | ||
| "'psize' and 'psig' as 'particle_diameter' and " | ||
| "'particle_diameter_sigma', respectively.", | ||
| ) | ||
|
|
||
| sheetCF_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
| sheetCF_dep_msg = _build_dep_msg( | ||
| "sheetCF", | ||
| "sheet_particle", | ||
| removal_version, | ||
| "Additionally, the signature has changed. Please pass the parameter " | ||
| "'sthick' as 'sheet_thickness'.", | ||
| ) | ||
|
|
||
| shellCF_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
| "shellCF", | ||
| "shell_particle", | ||
| removal_version, | ||
| ) | ||
| shellCF_dep_msg = _build_dep_msg("shellCF", "shell_particle") | ||
|
|
||
| shellCF2_dep_msg = build_deprecation_message( | ||
| cf_base, | ||
| shellCF2_dep_msg = _build_dep_msg( | ||
| "shellCF2", | ||
| "shell_particle", | ||
| removal_version, | ||
| "Additionally, the parameterization has changed. 'shellCF2' took the " | ||
| "central radius 'a' and the shell thickness 'delta', while " | ||
| "'shell_particle' takes the inner radius. Please pass " | ||
| "radius = a - delta / 2 and thickness = delta.", | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -175,18 +191,6 @@ def spherical_particle(r, particle_diameter): | |
| return characteristic_function | ||
|
|
||
|
|
||
| @deprecated(sphericalCF_dep_msg) | ||
| def sphericalCF(r, psize): | ||
| """This function is deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.pdf.characteristicfunctions.spherical_particle | ||
| instead. | ||
| """ | ||
| return spherical_particle(r, psize) | ||
|
|
||
|
|
||
| def spheroidal_particle(r, equatorial_radius, polar_radius): | ||
| """Compute the spheroidal nanoparticle characteristic function. | ||
|
|
||
|
|
@@ -321,32 +325,6 @@ def spheroidal_particle(r, equatorial_radius, polar_radius): | |
| return f | ||
|
|
||
|
|
||
| @deprecated(spheroidalCF_dep_msg) | ||
| def spheroidalCF(r, erad, prad): | ||
| """This function is deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle | ||
| instead. | ||
| """ | ||
| return spheroidal_particle(r, erad, prad) | ||
|
|
||
|
|
||
| @deprecated(spheroidalCF2_dep_msg) | ||
| def spheroidalCF2(r, psize, axrat): | ||
| """This function is deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle | ||
| instead. | ||
| """ | ||
| equatorial_radius = 0.5 * psize | ||
| polar_radius = axrat * equatorial_radius | ||
| return spheroidal_particle(r, equatorial_radius, polar_radius) | ||
|
|
||
|
|
||
| def lognormal_spherical_particle( | ||
| r, particle_diameter, particle_diameter_sigma | ||
| ): | ||
|
|
@@ -443,18 +421,6 @@ def lognormal_spherical_particle( | |
| ) | ||
|
|
||
|
|
||
| @deprecated(lognormalSphericalCF_dep_msg) | ||
| def lognormalSphericalCF(r, psize, psig): | ||
| """This function is deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.pdf.characteristicfunctions.lognormal_spherical_particle | ||
| instead. | ||
| """ | ||
| return lognormal_spherical_particle(r, psize, psig) | ||
|
|
||
|
|
||
| def sheet_particle(r, sheet_thickness): | ||
| """Compute the nanosheet characteristic function. | ||
|
|
||
|
|
@@ -506,17 +472,6 @@ def sheet_particle(r, sheet_thickness): | |
| return characteristic_function | ||
|
|
||
|
|
||
| @deprecated(sheetCF_dep_msg) | ||
| def sheetCF(r, sthick): | ||
| """This function is deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.sheet_particle | ||
| instead. | ||
| """ | ||
| return sheet_particle(r, sthick) | ||
|
|
||
|
|
||
| def shell_particle(r, radius, thickness): | ||
| """Compute the spherical shell characteristic function. | ||
|
|
||
|
|
@@ -582,9 +537,65 @@ def shell_particle(r, radius, thickness): | |
| return f | ||
|
|
||
|
|
||
| @deprecated(sphericalCF_dep_msg) | ||
| def sphericalCF(r, psize): | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.spherical_particle | ||
| instead. | ||
| """ | ||
| return spherical_particle(r, psize) | ||
|
|
||
|
|
||
| @deprecated(spheroidalCF_dep_msg) | ||
| def spheroidalCF(r, erad, prad): | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle | ||
| instead. | ||
| """ | ||
| return spheroidal_particle(r, erad, prad) | ||
|
|
||
|
|
||
| @deprecated(spheroidalCF2_dep_msg) | ||
| def spheroidalCF2(r, psize, axrat): | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle | ||
| instead. | ||
| """ | ||
| return spheroidal_particle(r, psize / 2, axrat * psize / 2) | ||
|
|
||
|
|
||
| @deprecated(lognormalSphericalCF_dep_msg) | ||
| def lognormalSphericalCF(r, psize, psig): | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use | ||
| diffpy.srfit.pdf.characteristicfunctions.lognormal_spherical_particle | ||
| instead. | ||
| """ | ||
| return lognormal_spherical_particle(r, psize, psig) | ||
|
|
||
|
|
||
| @deprecated(sheetCF_dep_msg) | ||
| def sheetCF(r, sthick): | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.sheet_particle | ||
| instead. | ||
| """ | ||
| return sheet_particle(r, sthick) | ||
|
|
||
|
|
||
| @deprecated(shellCF_dep_msg) | ||
| def shellCF(r, radius, thickness): | ||
| """This function is deprecated and will be removed in version | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.shell_particle | ||
|
|
@@ -595,15 +606,13 @@ def shellCF(r, radius, thickness): | |
|
|
||
| @deprecated(shellCF2_dep_msg) | ||
| def shellCF2(r, a, delta): | ||
| """This function is deprecated and will be removed in version | ||
| """This function has been deprecated and will be removed in version | ||
| 4.0.0. | ||
|
|
||
| Please use diffpy.srfit.pdf.characteristicfunctions.shell_particle | ||
| instead. | ||
| """ | ||
| radius = a - 0.5 * delta | ||
| thickness = delta | ||
| return shell_particle(r, radius, thickness) | ||
| return shell_particle(r, a - delta / 2, delta) | ||
|
|
||
|
|
||
| class SASCF(Calculator): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we lengthened these on purpose to make the code more readable. Please can we return these back to being explicit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbillinge we have to have the old signature in the deprecated function or else it will error without giving a useful message if the user has
lb=in their usage. I figured this out when running the example cmi scripts. The function replacing it has the new parameter names so the updated function is betterThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. that makes sense.