Skip to content

Conversation

@SamuelBrand1
Copy link
Contributor

This PR closes #561 .

This PR renames instances where a variable is a ChoiceMap to use choice_ prefix consistently, i.e. use 'choice_value' and 'choice_gradient' instead of 'value_trie' and 'gradient_trie' for clarity and alignment with choicemap terminology. I've left variables that are typed to be Tries.

Main danger is that my understanding of the static IR for Gen is that the gensyms for e.g value_trie are also meant to reflect creating a local variable name for a choice map object. If this is incorrect then I should revert those changes.

@ztangent
Copy link
Member

Thanks for this! Everything seems to pass, but could we change choice_gradient to choice_grads? I'm a little worried that choice_gradient is a little too close to the name of the choice_gradients function itself. choice_grads is also what is used within the documentation of the choice_gradients function.

Your understanding of the static IR is correct!

@SamuelBrand1
Copy link
Contributor Author

SamuelBrand1 commented Oct 22, 2025

Thanks for this! Everything seems to pass, but could we change choice_gradient to choice_grads? I'm a little worried that choice_gradient is a little too close to the name of the choice_gradients function itself. choice_grads is also what is used within the documentation of the choice_gradients function.

Your understanding of the static IR is correct!

Thats a good point, I'll make a quick change.

@SamuelBrand1
Copy link
Contributor Author

Having another look at the code base I found

(arg_grads, value_choices, gradient_choices) = choice_gradients(
record.subtrace, record.selection, retval_grad)

this has the other way of representing the variables e.g. gradient_choices etc. I think it would be nice to lock onto one convention to make the src code easier to read?

@ztangent
Copy link
Member

Yes, feel free to change that as well!

@ztangent
Copy link
Member

Now that I've merged #559 into the main branch, it'd be great if you could resolve the merge conflicts with that as well.

Refactored code and tests to consistently use 'choice_value' and 'choice_gradient' instead of 'value_trie' and 'gradient_trie' for clarity and alignment with choicemap terminology. Updated variable names, function signatures, and related comments across inference, static IR, and test files.
Renamed 'values_trie' and 'gradient_trie' to 'value_choices' and 'gradient_choices' in HMC and MAP optimization code, as well as corresponding test cases, to improve code readability and clarity.
@SamuelBrand1
Copy link
Contributor Author

SamuelBrand1 commented Oct 22, 2025

I've gone for value_choices and gradient_choices because those match the field names of the BackpropTraceRecord struct that is used in Gen backpropagation which I think helps make the code read slightly easier.

I've also changed this for the MAP opt and mala but I've let the unit tests be lax on these changes.

Copy link
Member

@ztangent ztangent 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 but let's update the docstring and the static IR code as well.

@SamuelBrand1
Copy link
Contributor Author

It was a bit fiddly because you don't want to collide with the choice_gradient function when refactoring to choice_gradients variable.

@SamuelBrand1 SamuelBrand1 requested a review from ztangent November 3, 2025 11:35
Copy link
Member

@ztangent ztangent 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 to me, thank you!

@ztangent ztangent merged commit 027dbc6 into probcomp:master Nov 3, 2025
5 checks passed
@SamuelBrand1 SamuelBrand1 deleted the vars-to-choice branch November 3, 2025 15:14
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.

Disambiguate use of trie in variable names?

2 participants