Skip to content
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

Remove several functions and objects from PyMC root namespace #6973

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Oct 26, 2023

  • All arviz plots must be retrieved from pymc.plots.foo
  • All arviz stats must be retrieved from pymc.stats.foo
  • Removed many rare or non-user facing objects
  • Remove rare or non-user facing VI objects (I am not familiar enough to know which ones should stay and which ones should not)

Closes #6761

Also

  • Move all custom Exceptions to pymc.exceptions.py

The following script prints 174 after and 272 before this PR:

import pymc
from types import ModuleType
len([a for a in dir(pymc) if not isinstance(getattr(pymc, a), ModuleType) and not a.startswith("__")])

The following entries were removed:

CallableTensor
DictToArrayBijection
ELPDData
GeneratorAdapter
ImputationWarning
IncorrectArgumentsError
SamplingError
ShapeError
ShapeWarning
TraceDirectoryError
_calculate_ics
apply_test_function
autocorr
autocorrplot
autocov
bfmi
bool_types
compare
compareplot
complex_types
compute_log_likelihood
cont_inputs
continuous_types
convert_observed_data
densityplot
discrete_types
drop_warning_stat
energyplot
ess
expand_packed_triangular
float_types
forestplot
generator
guess_scaling
hdi
int_types
invlogit
invprobit
isgenerator
join_nonshared_inputs
kde
kdeplot
logaddexp
logit
logsumexp
loo
loo_pit
make_shared_replacements
make_ufunc
mcse
pairplot
plot_autocorr
plot_bf
plot_bpv
plot_compare
plot_density
plot_dist
plot_dist_comparison
plot_dot
plot_ecdf
plot_elpd
plot_energy
plot_ess
plot_forest
plot_hdi
plot_kde
plot_khat
plot_lm
plot_loo_pit
plot_mcse
plot_pair
plot_parallel
plot_posterior
plot_ppc
plot_rank
plot_separation
plot_trace
plot_ts
plot_violin
predictions_to_inference_data
probit
psislw
r2_samples
r2_score
reloo
rhat
smartfloatX
str_for_dist
str_for_model
str_for_potential_or_deterministic
summary
to_inference_data
trace_cov
traceplot
typefilter
waic
weight_predictions
wrap_xarray_ufunc

📚 Documentation preview 📚: https://pymc--6973.org.readthedocs.build/en/6973/

@ricardoV94 ricardoV94 added maintenance major Include in major changes release notes section request discussion labels Oct 26, 2023
@maresb
Copy link
Contributor

maresb commented Oct 26, 2023

Depending on how semver-y people feel, this might be best targeted for PyMC v6.

@ricardoV94
Copy link
Member Author

Depending on how semver-y people feel, this might be best targeted for PyMC v6.

I think that will be a strong argument not to go on with these changes

@codecov
Copy link

codecov bot commented Oct 26, 2023

Codecov Report

Merging #6973 (e7e8a54) into main (419af06) will decrease coverage by 48.10%.
The diff coverage is 63.15%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #6973       +/-   ##
===========================================
- Coverage   88.65%   40.55%   -48.10%     
===========================================
  Files         100      100               
  Lines       16896    16868       -28     
===========================================
- Hits        14979     6841     -8138     
- Misses       1917    10027     +8110     
Files Coverage Δ
pymc/__init__.py 100.00% <100.00%> (ø)
pymc/backends/base.py 64.50% <ø> (-21.34%) ⬇️
pymc/blocking.py 87.23% <ø> (-8.60%) ⬇️
pymc/logprob/utils.py 77.35% <100.00%> (-22.65%) ⬇️
pymc/model/core.py 58.45% <ø> (-32.59%) ⬇️
pymc/plots/__init__.py 100.00% <ø> (+4.16%) ⬆️
pymc/pytensorf.py 58.66% <ø> (-32.23%) ⬇️
pymc/sampling/parallel.py 19.92% <100.00%> (-67.45%) ⬇️
pymc/stats/__init__.py 100.00% <ø> (ø)
pymc/step_methods/hmc/base_hmc.py 82.35% <100.00%> (-8.41%) ⬇️
... and 14 more

... and 58 files with indirect coverage changes

@ColCarroll
Copy link
Member

I'll put in a vote against this -- there are enough pymc scripts and libraries out there that don't follow library updates very closely, but would like to continue to benefit from better sampling routines by having liberal version specifications.

Probably the right way would be to use some deprecations library that issued a warning for ~a year, and provided a copy/paste upgrade path. I'm not sure the benefits (tidier namespace? are there others?) outweigh the work and downsides.

Comment on lines -34 to -56
def alias_deprecation(func, alias: str):
original = func.__name__

@functools.wraps(func)
def wrapped(*args, **kwargs):
raise FutureWarning(
f"The function `{alias}` from PyMC was an alias for `{original}` from ArviZ. "
"It was removed in PyMC 4.0. "
f"Switch to `pymc.{original}` or `arviz.{original}`."
)

return wrapped


# Aliases of ArviZ functions
autocorrplot = alias_deprecation(az.plot_autocorr, alias="autocorrplot")
forestplot = alias_deprecation(az.plot_forest, alias="forestplot")
kdeplot = alias_deprecation(az.plot_kde, alias="kdeplot")
energyplot = alias_deprecation(az.plot_energy, alias="energyplot")
densityplot = alias_deprecation(az.plot_density, alias="densityplot")
pairplot = alias_deprecation(az.plot_pair, alias="pairplot")
traceplot = alias_deprecation(az.plot_trace, alias="traceplot")
compareplot = alias_deprecation(az.plot_compare, alias="compareplot")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like this has already been issuing deprecation warnings. Was this working and warning against using everything slated to be removed since v4?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was just for utilities whose names have changed. Those could be safely removed by now yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, then I agree with @ColCarroll that we should definitely deprecate all the other stuff well in advance of removing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why remove the deprecation warning? In case you want to clear up the namespace then you could refactor it into something like https://peps.python.org/pep-0562/

Copy link
Member Author

@ricardoV94 ricardoV94 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this deprecation warning because I removed the objects that were being deprecated as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These one specifically were deprecated since v4, seems safe no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't there still lots of people who use PyMC3 because of the name recognition and all the SEO? Seems pretty low-effort to provide explicit instructions for them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds silly. This will not be the thing that people switching from v3 to v5 will find challenging

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, I agree it's silly in the case of these ArviZ warnings, but you could do something similar to provide a transition period for the rest of the stuff. Proof-of-concept: ricardoV94#4

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I am going to try and do that!

@twiecki
Copy link
Member

twiecki commented Oct 26, 2023

I'm in favor. Cruft accumulates in any code base and it requires consistent effort to stem the tide, which this attempts. I don't think many people are using these functions and those can easily adjust their imports. In a version or two we'll all have forgotten about it, just like with aesara and pytensor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance major Include in major changes release notes section request discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove some math utilities from the PyMC root scope?
4 participants