-
Notifications
You must be signed in to change notification settings - Fork 219
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
Optimization improvements #2221
Conversation
The files for Optimisaton.jl and OptimInterface.jl were in the wrong folders: One in `test/optimisation` the other in `test/ext`, but the wrong way around.
This is at a stage where getting a review would be good. Please be pedantic and show no mercy, I need to learn the ways of the project. Some questions I've been wondering about myself:
|
Having a look now:) |
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.
Alrighty, here comes comments! 😬
Do let me know if anything is unclear, as there are quite a few of them.
I think going forward I'll try to keep the reviews a bit "themed" so that there isn't too much feedback at once, but we instead can do several iterations. But given that I'm not feeling 100%, I figured I'd do as much reviewing as possible when I'm feeling okay-ish.
Overall, I also have a few comments:
- See https://docs.julialang.org/en/v1/manual/documentation/#Writing-Documentation for official docs on docstrings 👍
- Though I can see that the
ModeEstimationProblem
is in a way a nice abstraction, now that we're going to depend fully on Optimization.jl, it seems a bit overkill in terms of what is needed. IIUC it's only really used inestimate_mode
, and so can't we just put all this functionailty inestimate_mode
directly? IMO this will make the code a more readable and easier to follow, as it just becomes "1) set upSciMLBase.OptimizationProblem
, 2) solve it, and 3) convert into human readable format". - I'd recommend merging the files
OptimisationCore.jl
andOptimisation.jl
into a single one. Moreover, in particular for the sake of reviewing, try to avoid copy-pasting code form existing files to other files before the majority of the reviewing has been done, as it makes it very difficult to see exactly what is new code and what is simply moved code.
Hope this is helpful!
Thanks! I'll just leave comments now an get to fixing things later. Might take until Monday, tomorrow is quite full of other stuff.
We can put all of it in
Fair point about copy-paste, sorry about that. I would usually make moving and editing separate commits, but this time the code went through a liquefy-and-reassemble stage in the beginning, and the first few commits do a bit of everything. |
I can see that; as I said, I think they make sense. But it does add quite a bit of an overhead for a uninitiated reader who just wants to see what's up.
Makes a lot of sense! But I think after one of the changes suggested, this shouldn't really be a worry anymore. Specifically, you can just do the following once: ld = p.log_density
varinfo = DynamicPPL.link(
DynamicPPL.unflatten(ld.varinfo, copy(p.init_value))
ld.model
)
ld = Accessors.@set ld.varinfo = varinfo if we need to work in unconstrained space, and then use varinfo_new = DynamicPPL.unflatten(varinfo, solution.u)
# `getparams` performs the invlinking, if needed, etc.
vns_vals_iter = getparams(prob.model, varinfo_new)
syms = map(Symbol ∘ first, vns_vals_iter)
vals = map(last, vns_vals_iter)
return ModeResult(
NamedArray(vals, syms),
solution,
-solution.objective,
prob.log_density
) (copy-paste from inline comments above) once you need to convert to a Does that make sense?
No worries:) I also should have mentioned this before, and I every much know what you mean:) |
Pull Request Test Coverage Report for Build 9221611696Details
💛 - Coveralls |
Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
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.
miiiinor final comments, but looking really good now:)
Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com>
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.
Looks good — feel free to merge!
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.
Fantastic stuff @mhauru 👏 I'm very happy about this change and you've done really great here:)
And sorry about the delayed reply; had a busy week with presentations, as you know.
Feel free to merge (and we can bump the Project.toml afterwards to avoid having to re-run tests)
* Update README.md * Export adtype `AutoTapir` (#2236) * Export adtype `AutoTapir` * Update Project.toml * Fix missing AutoTapir (#2242) * Update Essential.jl * Update Project.toml * Drop support for ADTypes 0.2 (#2243) ADTypes 0.2 doesn't support AutoTapir yet. * Optimization improvements (#2221) * initial work on interface * Improving the Optimization.jl interface, work in progress * More work on Optimization.jl, still in progress * Add docstrings to Optimisation.jl * Fix OptimizationOptimJL version constraint * Clean up optimisation TODO notes * Relax OptimizationOptimJL version constraints * Simplify optimization imports * Remove commented out code * Small improvements all over in optimisation * Clean up of Optimisation tests * Add a test for OptimizationBBO * Add tests using OptimizationNLopt * Rename/move the optimisation test files The files for Optimisaton.jl and OptimInterface.jl were in the wrong folders: One in `test/optimisation` the other in `test/ext`, but the wrong way around. * Relax compat bounds on OptimizationBBO and OptimizationNLopt * Split a testset to test/optimisation/OptimisationCore.jl * Import AbstractADType from ADTypes, not SciMLBase * Fix Optimization.jl depwarning * Fix seeds in more tests * Merge OptimizationCore into Optimization * In optimisation, rename init_value to initial_params * Optimisation docstring improvements * Code style adjustments in optimisation * Qualify references in optimisation * Simplify creation of ModeResults * Qualified references in optimization tests * Enforce line length in optimization * Simplify optimisation exports * Enforce line legth in Optim.jl interface * Refactor away ModeEstimationProblem * Style and docstring improvements for optimisation * Add := test to optimisation tests. * Clarify comment * Simplify generate_initial_params * Fix doc references * Rename testsets * Refactor check_success * Make initial_params a kwarg * Remove unnecessary type constrain on kwarg * Fix broken reference in tests * Fix bug in generate_initial_params * Fix qualified references in optimisation tests * Add hasstats checks to optimisation tests * Extend OptimizationOptimJL compat to 0.3 Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com> * Change some `import`s to `using` Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> * Change <keyword arguments> to kwargs... in docstrings * Add a two-argument method to OptimLogDensity as callable --------- Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com> * Update Project.toml * CompatHelper: bump compat for OptimizationOptimJL to 0.3 for package test, (keep existing compat) (#2246) Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org> --------- Co-authored-by: Markus Hauru <markus@mhauru.org> Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org>
* Remove unused test util function * Refactoring ad and optiminterface tests to modules * Add SelectiveTests.jl * Rework tests CI GA * Switch test CI on Mac back to x64 * Remove coverage from CI. Improve matrix. * Wrap all tests in modules. * Remove unused test utils * Remove GA workflows for DynamicHMC and Numerical * Rename TuringCI GA to Tests * Fix test_args passing in CI * Fix for CI test matrix * Fixes to various test files * Add container.jl to test suite * Fix spacing around * in test includes * Split ad.jl and abstractmcmc.jl tests to separate CI jobs * Alphabetise imports in tests * In tests, use import X over using X: X * Add missing imports to abstractmcmc.jl tests * Add some missing imports to tests * Merge ad_utils.jl to ad.jl in tests * Merge testing_functions.jl into mh.jl in tests * Simplify test_utils Turn all of them into modules or merge them into other files that used to `include` them. * Add missing import to numerical_tests.jl * Update Project.toml (#2244) * Update README.md * Export adtype `AutoTapir` (#2236) * Export adtype `AutoTapir` * Update Project.toml * Fix missing AutoTapir (#2242) * Update Essential.jl * Update Project.toml * Drop support for ADTypes 0.2 (#2243) ADTypes 0.2 doesn't support AutoTapir yet. * Optimization improvements (#2221) * initial work on interface * Improving the Optimization.jl interface, work in progress * More work on Optimization.jl, still in progress * Add docstrings to Optimisation.jl * Fix OptimizationOptimJL version constraint * Clean up optimisation TODO notes * Relax OptimizationOptimJL version constraints * Simplify optimization imports * Remove commented out code * Small improvements all over in optimisation * Clean up of Optimisation tests * Add a test for OptimizationBBO * Add tests using OptimizationNLopt * Rename/move the optimisation test files The files for Optimisaton.jl and OptimInterface.jl were in the wrong folders: One in `test/optimisation` the other in `test/ext`, but the wrong way around. * Relax compat bounds on OptimizationBBO and OptimizationNLopt * Split a testset to test/optimisation/OptimisationCore.jl * Import AbstractADType from ADTypes, not SciMLBase * Fix Optimization.jl depwarning * Fix seeds in more tests * Merge OptimizationCore into Optimization * In optimisation, rename init_value to initial_params * Optimisation docstring improvements * Code style adjustments in optimisation * Qualify references in optimisation * Simplify creation of ModeResults * Qualified references in optimization tests * Enforce line length in optimization * Simplify optimisation exports * Enforce line legth in Optim.jl interface * Refactor away ModeEstimationProblem * Style and docstring improvements for optimisation * Add := test to optimisation tests. * Clarify comment * Simplify generate_initial_params * Fix doc references * Rename testsets * Refactor check_success * Make initial_params a kwarg * Remove unnecessary type constrain on kwarg * Fix broken reference in tests * Fix bug in generate_initial_params * Fix qualified references in optimisation tests * Add hasstats checks to optimisation tests * Extend OptimizationOptimJL compat to 0.3 Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com> * Change some `import`s to `using` Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> * Change <keyword arguments> to kwargs... in docstrings * Add a two-argument method to OptimLogDensity as callable --------- Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com> * Update Project.toml * CompatHelper: bump compat for OptimizationOptimJL to 0.3 for package test, (keep existing compat) (#2246) Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org> --------- Co-authored-by: Markus Hauru <markus@mhauru.org> Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org> * Set fail-fast: false for CI test matrix * Add a step to print matrix variables to tests Action * Fix typo in tests Action * ADTypes v0.2 compatibility for test restructuring (#2253) * Restore compat with ADTypes v0.2. Make AutoTapir export conditional. * Fix AutoTapir export in Essential.jl --------- Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com> Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: CompatHelper Julia <compathelper_noreply@julialang.org>
Implementation of the work started in #2214. Work in progress. Needs
@torfjelde
Closes #2227