Use functools.partial instead of lambdas for lax.cond branches (#245)#303
Open
Elgoghel wants to merge 1 commit into
Open
Use functools.partial instead of lambdas for lax.cond branches (#245)#303Elgoghel wants to merge 1 commit into
Elgoghel wants to merge 1 commit into
Conversation
Replace lambda-wrapped jax.lax.cond branches in game_2048, bin_pack, sliding_tile_puzzle and sokoban with the partial-based direct-call style already used in search_and_rescue. reward and observation are passed as cond operands and extras is bound via functools.partial. This is behaviour preserving: termination has no `discount` parameter, so binding extras by keyword keeps both branches correct. connector is intentionally left unchanged: its lax.switch term_fn adapts termination's differing signature (it drops discount), so that lambda is load-bearing rather than redundant.
418bf9d to
217c304
Compare
sash-a
approved these changes
Jun 24, 2026
sash-a
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for this, much cleaner 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #245. Replaces the lambda-wrapped jax.lax.cond branches with the
functools.partial direct-call style already used in search_and_rescue, in four
environments: game_2048, sliding_tile_puzzle, bin_pack, and sokoban. reward and
observation are passed as cond operands and extras is bound via partial.
Behaviour preserving: termination has no
discountparameter whiletransition/truncation do, so extras is bound by keyword to keep both branches
correct. All existing tests for the four environments pass locally (35 passed).
Note: connector is intentionally left unchanged. Its lax.switch term_fn adapts
termination's differing signature (it drops discount), so that lambda is
load-bearing rather than redundant. Happy to revisit if a named helper is preferred.