Skip to content

Clean up exports #2474

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

Merged
merged 30 commits into from
Mar 18, 2025
Merged

Clean up exports #2474

merged 30 commits into from
Mar 18, 2025

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jan 21, 2025

Closes #2481
Closes #2468

As mentioned in #2468, I don't think we need to export so many things. I've done a bunch of cuts here, with the intention that if we don't feel comfortable cutting something, we can easily revert specific commits. In my opinion, though, even though it looks like many sweeping changes, I don't think any of these are hugely controversial on their own.

Concretely, this PR does the following:

  1. Stops re-exporting the DynamicPPL module.

  2. Stops re-exporting @logprob_str and @prob_str, which were deprecated several months ago (we've killed off deprecated stuff in far shorter timespans)

  3. Stops re-exporting DynamicPPL.LogDensityFunction, this is an implementation detail that users probably don't need to construct themselves.

  4. Bumps the Distributions.jl compat bound (from 0.23 to 0.25.77) and removes code that was required to support old versions of Distributions. Note that DynamicPPL already requires Distributions 0.25.

  5. Removes the blanket re-export of Bijectors and Libtask, as well as the export of Bijectors.ordered. ordered is used in the Gaussian mixture model tutorial, but even there it's imported directly from Bijectors, and I don't think it's unfair to expect users to manually import Bijectors if they want to use this function.

  6. Removes the blanket re-export of AbstractMCMC, replacing it with an explicit export list of sample, MCMCThreads, MCMCDistributed, and MCMCSerial. Note that these are the only four identifiers which AbstractMCMC itself exports (https://github.com/TuringLang/AbstractMCMC.jl/blob/master/src/AbstractMCMC.jl) so the only change is that the module name itself (AbstractMCMC) is no longer accessible as Turing.AbstractMCMC.

  7. For convenience, re-exports LinearAlgebra.I.

  8. Exports DynamicPPL.returned and DynamicPPL.prefix (we forgot to re-export this when doing the submodel stuff).

Will let CI run before requesting a review.

Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.03%. Comparing base (e842e30) to head (1cf5270).
Report is 3 commits behind head on breaking.

Files with missing lines Patch % Lines
src/mcmc/Inference.jl 0.00% 1 Missing ⚠️
src/stdlib/distributions.jl 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           breaking    #2474      +/-   ##
============================================
+ Coverage     85.53%   86.03%   +0.49%     
============================================
  Files            21       21              
  Lines          1466     1454      -12     
============================================
- Hits           1254     1251       -3     
+ Misses          212      203       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls
Copy link

coveralls commented Jan 21, 2025

Pull Request Test Coverage Report for Build 12885951319

Details

  • 0 of 6 (0.0%) changed or added relevant lines in 3 files are covered.
  • 430 unchanged lines in 11 files lost coverage.
  • Overall coverage decreased (-27.7%) to 48.809%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/mcmc/Inference.jl 0 1 0.0%
src/optimisation/Optimisation.jl 0 1 0.0%
src/stdlib/distributions.jl 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
src/mcmc/emcee.jl 2 88.46%
src/variational/VariationalInference.jl 4 0.0%
src/mcmc/particle_mcmc.jl 10 80.13%
src/mcmc/Inference.jl 20 75.15%
ext/TuringDynamicHMCExt.jl 29 0.0%
src/mcmc/mh.jl 34 58.96%
src/stdlib/distributions.jl 47 0.0%
ext/TuringOptimExt.jl 50 0.0%
src/mcmc/sghmc.jl 50 20.29%
src/variational/advi.jl 56 0.0%
Totals Coverage Status
Change from base Build 12786420948: -27.7%
Covered Lines: 758
Relevant Lines: 1553

💛 - Coveralls

@penelopeysm penelopeysm force-pushed the py/imports branch 6 times, most recently from abc1f9b to d4c3547 Compare January 21, 2025 02:39
@mhauru
Copy link
Member

mhauru commented Jan 21, 2025

I think I agree with all the changes listed in OP, although LogDensityFunction makes me pause and wonder how people might be using it. I don't think I should be the main reviewer here, the more senior members of the team understand user needs better.

Rather than merging straight to master, should we bundle this with #2458 to form a new breaking release to go out when we feel like is the right moment?

@penelopeysm
Copy link
Member Author

Happy to release both PRs together!

I can't say I feel particularly bad about LogDensityFunction tbh, it's still accessible via DynamicPPL with the same functionality, so we're really just asking people to import it from where it should be imported.

@penelopeysm
Copy link
Member Author

There's still the wholesale export of MCMCChains which I don't dare to touch. MCMCChains exports a lot of stuff. https://github.com/TuringLang/MCMCChains.jl/blob/master/src/MCMCChains.jl

@penelopeysm penelopeysm force-pushed the py/imports branch 2 times, most recently from 8fd6095 to 2409aa1 Compare January 21, 2025 11:26
@penelopeysm penelopeysm changed the base branch from master to breaking February 14, 2025 17:24
@penelopeysm penelopeysm marked this pull request as ready for review March 17, 2025 15:27
@TuringLang TuringLang deleted a comment from github-actions bot Mar 17, 2025
@TuringLang TuringLang deleted a comment from github-actions bot Mar 17, 2025
@penelopeysm
Copy link
Member Author

penelopeysm commented Mar 17, 2025

I changed my mind on LogDensityFunction, it can stay exported. I suspect that over the course of AbstractMCMC refactoring it'll also start to play a larger role.
Nevertheless, I changed all the Turing.LogDensityFunction calls in the library to DynamicPPL.LogDensityFunction which feels a bit cleaner.

I think it's almost ready for review, will let CI run before requesting one though, as I'm not sure if there are still some imports I need to fix in the test suite.

Docs preview: https://turinglang.org/Turing.jl/previews/PR2474/api/

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

Looks good. Could we get a HISTORY.md entry? Maybe merge the base branch first before writing it.

Other than that, I still need to build the docs to see how they look but I'm happy otherwise.

AutoMooncake,
@logprob_str,
@prob_str
@varname, AutoForwardDiff, AutoReverseDiff, AutoMooncake, @logprob_str, @prob_str
Copy link
Member

Choose a reason for hiding this comment

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

I know this the auto-formatter, but it's quite ugly. Any setting we should set to stop this from happening? It bothers me locally too.

Copy link
Member Author

Choose a reason for hiding this comment

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

tldr is no: domluna/JuliaFormatter.jl#358

We could try doing

export a
export b
export c

instead. Part of me might actually prefer this (even though the keyword export is spammed) because it's more resistant towards moving lines up/down (you can't have a trailing comma at the end of the export list, so

export
    a,
    b,
    c,

doesn't work)

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind spamming export either, or having a few per line that relate to each other if they fit on one line.

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 changed it to

export @model
export @varname
export AutoForwardDiff, AutoReverseDiff, AutoMooncake

and JuliaFormatter seems happy ☺️

(Also removed that stray logprob_str and prob_str, oops.)

penelopeysm and others added 2 commits March 18, 2025 13:33
Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

Built docs look good except for one link.

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

Some proposed changes to HISTORY.md, feel free to reject or edit.

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

Thanks Penny!

@penelopeysm penelopeysm merged commit 625a9c8 into breaking Mar 18, 2025
2 checks passed
@penelopeysm penelopeysm deleted the py/imports branch March 18, 2025 17:33
mhauru added a commit that referenced this pull request Mar 19, 2025
* Bump minor version to v0.37

* Remove selector/space stuff (#2458)

* Remove selector stuff from ESS

* Remove selector stuff from MH

* Remove selector stuff from HMC

* Remove selector stuff from Emcee

* Remove selector stuff from IS

* Add missing getspace methods

* Remove selector stuff for particle methods

* Fix an HMC selector bug

* Code style

* Fix Emcee selector bug

* Fix typo in ESS tests

* Fix some constructor overwrites

* Remove unnecessary tests

* Remove selector stuff from SGHMC

* Remove drop_space and other non-longer-necessary deprecation measures

* Bump minor version 0.37. Add a HISTORY.md entry

* Apply suggestions from code review

Co-authored-by: Penelope Yong <[email protected]>

* Remove unnecessary type parameters

Co-authored-by: Penelope Yong <[email protected]>

* Simplify constructors in particle_mcmc.jl

* Remove calls to setgid and updategid

---------

Co-authored-by: Penelope Yong <[email protected]>

* Bump Mooncake compat to 0.4.95

* Support for DynamicPPL v0.35 (#2488)

* Progress towards compat with DPPL v0.35

* More fixing of DPPL v0.35 stuff

* Fix LogDensityFunction argument order

* More minor bugfixes

* [TEMP] Commit Manifest pointing to DynamicPPL#release-0.35

* remove LogDensityProblemsAD (#2490)

* Remove LogDensityProblemsAD, part 1

* update Optimisation code to not use LogDensityProblemsAD

* Fix field name change

* Don't put chunksize=0

* Remove LogDensityProblemsAD dep

* Improve OptimLogDensity docstring

* Remove unneeded model argument to _optimize

* Fix more tests

* Remove essential/ad from the list of CI groups

* Fix HMC function

* more test fixes (#2491)

* Remove LogDensityProblemsAD, part 1

* update Optimisation code to not use LogDensityProblemsAD

* Fix field name change

* Don't put chunksize=0

* Remove LogDensityProblemsAD dep

* Improve OptimLogDensity docstring

* Remove unneeded model argument to _optimize

* Fix more tests

* Remove essential/ad from the list of CI groups

* Fix HMC function

* More test fixes

* Remove Manifest

* More fixes for DynamicPPL 0.35 (#2494)

* Remove test/dynamicppl/compiler.jl

* Remove old regression tests

* Remove vdemo2

* Fix last test

* Add HISTORY.md entry about DPPL 0.35

* Allow ESS to sample variables with different symbols

* Update a TODO note

---------

Co-authored-by: Penelope Yong <[email protected]>

* Fix call to DynamicPPL.initialize_parameters!!

* Remove `Zygote` (#2505)

* Remove `Zygote`; fix #2504

* Update test/test_utils/ad_utils.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Add HISTORY.md entry about removing support for Zygote

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

* Fix a Gibbs test

* Clean up exports (#2474)

* Regroup exports by package

* Export DynamicPPL.returned and DynamicPPL.prefix

* Stop exporting  @logprob_str and @prob_str

* Remove DynamicPPL module export

* Remove DynamicPPL.LogDensityFunction re-export

* Remove BernoulliLogit, drop support for Distributions < 0.25.77

* Stop blanket re-exporting Libtask and Bijectors

* Manually specify AbstractMCMC exports

* Format

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Remove Bijectors.ordered export

* Re-export LinearAlgebra.I

* Replace Turing.Model -> DynamicPPL.Model

* Format

* Keep exporting LogDensityFunction

* Add note in docs

* Align Turing exports with docs API page

* Fix things like `predict` on docs API page

* Fix a Gibbs test

* Format

* Fix missing Bijectors import

* Update docs/src/api.md

Co-authored-by: Markus Hauru <[email protected]>

* Update docs/src/api.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Clean up broken docs links, remove unneeded deps

* Format

* Add changelog entry for exports

* Clean up exports in essential/Essential

* Apply suggestions from code review

Co-authored-by: Markus Hauru <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

---------

Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This was referenced Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants