Skip to content

Set reward-size on each trial#131

Merged
micahwoodard merged 12 commits into
mainfrom
feat-trial-based-reward-size
Jul 20, 2026
Merged

Set reward-size on each trial#131
micahwoodard merged 12 commits into
mainfrom
feat-trial-based-reward-size

Conversation

@micahwoodard

@micahwoodard micahwoodard commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Move reward size form task logic level to trial level. Allows to give fraction of reward for auto reward. Closes #85

At bonsai level, default reward is set to 2ul at initialization and during session, reward size is updated in calculate reward block

@micahwoodard

micahwoodard commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

@arjunsridhar12345 breaking change here. Reward size changes from task_logic.reward_size.right_valve_volume to trial_outcome.trial.reward_size.right

@bruno-f-cruz bruno-f-cruz changed the title trial based reward size Set reward-size on each trial Jul 8, 2026
Comment thread src/aind_behavior_dynamic_foraging/task_logic/trial_models.py Outdated
Comment thread src/aind_behavior_dynamic_foraging/task_logic/trial_models.py Outdated
Comment thread src/Extensions/TaskEngine.bonsai
Comment thread src/Extensions/ValveUi.bonsai
@micahwoodard

Copy link
Copy Markdown
Collaborator Author

@bruno-f-cruz I moved the calculating reward size to quiescent period. Moving to iti required setting it at the beginning of the session as well so made more sense to me to move into quiescent

@micahwoodard
micahwoodard requested a review from bruno-f-cruz July 8, 2026 22:00
@micahwoodard

micahwoodard commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

@bruno-f-cruz Task engine now includes pre trial select many which sets reward size for each trial

image

@bruno-f-cruz bruno-f-cruz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The distinctUntilChanged being inside the SelectMany doesnt really do anything since the sequence only fires once. The solution is to move it to the subject subscriber, ensuring you add it after filtering by side so you dont get false positives at the operator's input.

@bruno-f-cruz

bruno-f-cruz commented Jul 20, 2026

Copy link
Copy Markdown
Member

I pushed a small change to fix the DistinctUntilChanged logic. As it stood, it would almost always fire since it is added AFTER the merge (which is subject to values from BOTH branches). Also, HarpMessage (https://github.com/bonsai-rx/harp/blob/e7b5e0787c92e84a7eefdd98e797bc16036b5038/src/Bonsai.Harp/HarpMessage.cs#L8) are ref types, so equality defaults to ref equality not by value.

The solution for both is to add the DistinctUntilChanged operator after the value of EACH valve. This filters on the valve-specific stream with the added benefit that we are comparing value types (double).

image

@bruno-f-cruz bruno-f-cruz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to merge!

@micahwoodard
micahwoodard merged commit 98dbce7 into main Jul 20, 2026
4 checks passed
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.

auto water reward fraction

2 participants