[Repo Assist] feat(gcm): add random_seed to interventional_samples, counterfactual_samples, average_causal_effect - #1731
Draft
github-actions[bot] wants to merge 1 commit into
Conversation
…samples, average_causal_effect Add an optional random_seed: Optional[int] = None parameter to: - interventional_samples() - counterfactual_samples() - average_causal_effect() When provided, set_random_seed(random_seed) is called at function entry, following the existing GCM convention used in falsify_graph, confidence_intervals_bootstrap, model_evaluation, etc. This makes results reproducible across independent calls without requiring the caller to manage global state via set_random_seed(). Reported in #1307 (multiple users experiencing non-reproducible results). Previous fix PR #1489 was closed as stale. Closes #1307 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
78 tasks
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 PR was created by Repo Assist, an automated AI assistant.
Problem
interventional_samples(),counterfactual_samples(), andaverage_causal_effect()indowhy/gcm/whatif.pyhave norandom_seedparameter, making reproducible results across independent Python sessions unnecessarily fragile. Users must currently callset_random_seed()globally before calling these functions — which is order-sensitive, easy to miss, and inconsistent with other GCM functions.Reported in #1307 (multiple users experiencing non-reproducible results across sessions). A previous fix PR #1489 was closed as stale in July 2026 before being merged.
Change
Add an optional
random_seed: Optional[int] = Noneparameter to:interventional_samples()counterfactual_samples()average_causal_effect()When provided,
set_random_seed(random_seed)is called at function entry, following the existing GCM convention used infalsify_graph,model_evaluation, etc.Trade-offs
None(existing call sites unaffected).set_random_seedaffects numpy/torch global state, consistent with the rest of the GCM module's approach.Test Status
Added 3 new unit tests in
tests/gcm/test_whatif.py:test_given_random_seed_when_draw_interventional_samples_then_results_are_reproducible— same seed → identical samples; different seeds → different samples.test_given_random_seed_when_draw_counterfactual_samples_then_results_are_reproducible— same seed → identical counterfactual frames.test_given_random_seed_when_estimate_average_causal_effect_then_results_are_reproducible— same seed → identical ACE; different seeds → different ACE.All 19 tests in
tests/gcm/test_whatif.pypass. Format/lint:blackandisortshow no changes; 3 pre-existingE501lint warnings in the file (unrelated to this PR).Closes #1307