Repository navigation
Turn off Hypothesis's explain phase for the owners' draw simulation properties - #10823
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis
marked this pull request as ready for review
November 13, 2026 18:10
Contributor
Author
|
US + core hub merge audit, us#10823 at
🤖 Generated with Claude Code |
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 gives
SIMULATION_SETTINGSinpolicyengine_us/tests/reforms/test_owners_draw.pyevery Hypothesis phase exceptPhase.explain. Three properties share those settings and build full simulations inside@given: the raised-cap property, the disabled-reform property and the benefit-credit property. We keep every assertion, strategy and explicit example.The settings previously named no phases, so Hypothesis kept all six phases enabled. Under ordinary test settings, Hypothesis starts tracing after a property fails. When a change breaks one of these properties, Hypothesis keeps calling it before pytest reports the failing example:
_should_trace). Python calls that tracer on each line event. The tracer records pairs of consecutive lines outside Hypothesis's files (trace_line).MAX_SHRINKING_SECONDS, deadline check).One-machine timings
Every timing below comes from one macOS machine that also ran other work. For #10548, we made copies of two properties fail after their simulation work, on Python 3.14.7 with policyengine-core 3.34.1:
On Python 3.13.9 with policyengine-core 3.33.2 and Hypothesis 6.168.5, we called the disabled-reform property's body at
3f6e604bwithout the tracer and then inside it. The traced call took 25.6 seconds against 10.4. We then ran the same body as a Hypothesis property that fails after its simulation work:Phase.explainOther work on the machine changed between the rows, so compare the columns within each row. These historical timings do not measure a passing-run speedup.
Reproduction
This script needs Hypothesis and Python 3.12 or later. It copies the disabled-reform property's previous settings, strategy and explicit example. Its body fails when a batch holds an age other than 20, 45, 62 or 85, so the explicit example and Hypothesis's simplest batch pass.
Python 3.13.9 with Hypothesis 6.168.5 prints:
Each call here returns at once, so Hypothesis finishes its explain phase. A call of the real properties runs one or two simulations. The raised-cap copy reached the five-minute limit after 142 shrinking and explaining calls.
Failure behavior
Without
Phase.explain, Hypothesis runs ordinary failing calls untraced and makes 76 calls after the first failure in the script, against 2,007 with the previous settings. A failure report then loses two diagnostics: the "Explanation" lines, which Hypothesis builds from the traced calls (explanatory_lines), and its comments on arguments it could vary without losing the failure (explain gate). Hypothesis still shrinks a failure under the same 300-second limit. A property that takes ten seconds per call can still run to that limit.For example,
test_state_income_tax_accounting_invariants.pynames only explicit and generate. Hypothesis then reports a failing example unshrunk. We retain shrinking for the owners' draw properties.Invariants and validation
Pull request run 43480011691 at
003ab5b7f1passed all 36 jobs on GitHub's merge with maina93cc58d7e.SIMULATION_SETTINGS.phases. An AST comparison with freshmainmatches after removing the newPhaseimport andphasesentry.Methodology choices
Phase.explain, including shrinking and its 300-second limit.SIMULATION_SETTINGS; formula-level properties retain their settings.A follow-up can decide whether to load a suite-wide Hypothesis profile without
Phase.explainbefore test modules import, so that Hypothesis applies it to properties that name no phases.Microsimulation impact
This PR edits Hypothesis settings in one test file and adds a changelog fragment, so it changes no formula, parameter or dataset and leaves nothing to measure.
impact: none: the change touches one test file's Hypothesis settings and a changelog fragment
axiom: n/a: Hypothesis test settings and a changelog fragment; no policy change
🤖 Generated with Claude Code