Skip to content

Use functools.partial instead of lambdas for lax.cond branches (#245)#303

Open
Elgoghel wants to merge 1 commit into
instadeepai:mainfrom
Elgoghel:refactor-lax-cond-partial
Open

Use functools.partial instead of lambdas for lax.cond branches (#245)#303
Elgoghel wants to merge 1 commit into
instadeepai:mainfrom
Elgoghel:refactor-lax-cond-partial

Conversation

@Elgoghel

Copy link
Copy Markdown

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 discount parameter while
transition/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.

@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.
@Elgoghel Elgoghel force-pushed the refactor-lax-cond-partial branch from 418bf9d to 217c304 Compare June 23, 2026 20:48

@sash-a sash-a left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this, much cleaner 😄

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