[Repo Assist] improve(gcm): add random_seed parameter to interventional_samples, counterfactual_samples, and average_causal_effect#1549
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…unterfactual_samples, and average_causal_effect Addresses the reproducibility problem reported in #1307: calls to interventional_samples() and counterfactual_samples() returned different results each time because the stochastic mechanisms sample from the global numpy random state. Adding random_seed: Optional[int] = None allows callers to seed the global numpy/random state before sampling, making results reproducible for a given seed. When random_seed is None (default), behaviour is unchanged. Two regression tests added to tests/gcm/test_whatif.py confirming that passing the same seed produces bit-identical results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This was referenced May 28, 2026
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.
🤖 This is an automated PR from Repo Assist.
Problem
interventional_samples(),counterfactual_samples(), andaverage_causal_effect()indowhy/gcm/whatif.pyoffered no way to control the random seed. Calls to the same function with the same inputs produced different results each run, making experiments non-reproducible. This was reported in issue #1307.Solution
Added an optional
random_seed: Optional[int] = Noneparameter to all three public functions. When a seed is provided,set_random_seed(random_seed)is called at the start of the function before any stochastic sampling takes place. The defaultNonepreserves the existing behaviour exactly.No new lint errors introduced (3 E501 violations are pre-existing in
test_whatif.py).Closes #1307