Skip to content

Conversation

@penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Nov 5, 2025

The return value of a point optimisation currently includes an array of parameters. Arrays bad. Dict{VarName} good. (In particular, it currently returns a NamedArray which is a really weird data structure!)

This is not meant to be a permanent fix: ModeResult and its associated interface IMO needs a larger overhaul. (There are a few other open issues on the optimisation interface.) But getting this fix in will at least let it be more composable with the rest of Turing, while we figure out how to fix the rest. (See changelog for examples of what I mean by composable)

I reckon it's fair to not make this a breaking change because all of ModeResult's existing fields still behave the same way, the only difference is that there is an extra field. So the only thing it would break is if people were doing something bizarre like fieldnames(...). Also, technically, ModeResult isn't exported (although I think it's effectively public since it is the return value of an exported function).

@penelopeysm penelopeysm changed the title Py/optim results Include parameter dictionary in optimisation return value Nov 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Turing.jl documentation for PR #2710 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2710/

@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.47%. Comparing base (905f7fa) to head (15dd612).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2710      +/-   ##
==========================================
+ Coverage   86.45%   86.47%   +0.01%     
==========================================
  Files          21       21              
  Lines        1418     1420       +2     
==========================================
+ Hits         1226     1228       +2     
  Misses        192      192              

☔ 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.

@penelopeysm penelopeysm requested a review from sunxd3 November 7, 2025 14:16
Copy link
Member

@sunxd3 sunxd3 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

"""
ModeResult{
V<:NamedArrays.NamedArray,
M<:NamedArrays.NamedArray,
Copy link
Member

Choose a reason for hiding this comment

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

doesn't look consistent, probably already wrong and for a while, good to fix

Copy link
Member

Choose a reason for hiding this comment

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

@penelopeysm sorry for review twice 😓

bump this in case you missed

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I agree the NamedArray stuff should be removed, but that would be breaking, right? I was thinking of leaving it to another time. #2634

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, don't ever apologise for double-reviewing!

HISTORY.md Outdated
model = f()
opt_result = maximum_a_posteriori(model)

sample(model, NUTS(), 1000; initial_params=InitFromParams(opt_result.params))
Copy link
Member

Choose a reason for hiding this comment

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

small nit is that this would somewhat makes params fieldname a public interface, with the warrant just following the code example, not big deal, but I thought it might be worth mentioning

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah, I guess we could overload InitFromParams(opt_result) instead so that you don't need to access the params field. I thought we could do that in a separate release, but doing that would avoid having to document the field, so let's bundle it in

@penelopeysm penelopeysm merged commit 4153a83 into main Nov 7, 2025
28 checks passed
@penelopeysm penelopeysm deleted the py/optim-results branch November 7, 2025 19:58
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