Skip to content

Commit 695d9b2

Browse files
MaxGhenisclaude
andauthored
Remove randomness from country package (#1439)
* Remove randomness from country package Move stochastic variable generation to data package. Variables now read pre-computed values from datasets for deterministic, reproducible calculations. Changes: - would_claim_pc, would_claim_uc, would_claim_child_benefit, child_benefit_opts_out, would_evade_tv_licence_fee, household_owns_tv, main_residential_property_purchased_is_first_home, is_disabled_for_benefits: Remove formulas, use default_value - would_claim_marriage_allowance: New variable for take-up decision - marriage_allowance: Use would_claim_marriage_allowance instead of random() - attends_private_school: Use pre-generated random draw from dataset - is_higher_earner: Use age as deterministic tie-breaker instead of random() 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Add tests for deterministic stochastic variables Tests verify: - Default values work correctly in policy calculator mode - Variables can be explicitly overridden in situations - is_higher_earner uses deterministic tie-breaking (older wins) - Calculations are deterministic across multiple runs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Format test file with black * Add Scottish Child Payment with deterministic take-up Add SCP variable and parameters with would_claim_scp for deterministic take-up (matching the pattern for other benefits in this PR). Changes: - Add would_claim_scp variable (default True, generated in dataset) - Add scottish_child_payment variable with defined_for="would_claim_scp" - Add is_scp_eligible_child helper variable - Add SCP parameters with legislation references: - amount.yaml (Regulation 20) - max_age.yaml (Regulation 18) - premium_under_one_amount.yaml (Scottish Budget 2026-27) - qualifying_benefits/ (Regulation 14) - takeup_rate/ (for dataset generation) - Add tests for SCP baby bonus Source: The Scottish Child Payment Regulations 2020 https://www.legislation.gov.uk/ssi/2020/351/contents Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Refactor SCP to Person level with adds=['benunit'] * Add is_scp_eligible Person variable, simplify scottish_child_payment * Split SCP into Person and BenUnit variables - Create scottish_child_payment_person at Person level with defined_for - Keep scottish_child_payment at BenUnit level using adds to aggregate - Maintains backward compatibility with existing tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix SCP parameters: add 2026 rate, correct baby boost start date - Add 2026-04-01: £28.20 rate (inflation increase per Scottish Budget) - Change baby boost start from 2026-04-06 to 2027-04-06 (payments start 2027-28) Source: Scottish Budget 2026-27 confirms "will be paid in 2027-28" https://www.gov.scot/publications/scottish-budget-2026-2027/pages/6/ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix SCP tests: use confirmed rate, baby boost starts 2027 - Remove unconfirmed 2026 rate (£28.20) - belongs in PR #1475 - Update baby bonus tests to use £27.15 standard rate - Baby boost starts 2027-04-06 per Scottish Budget announcement Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Remove baby bonus from takeup migration PR Baby bonus (SCP Premium for under-ones) belongs in draft PR #1475 (Scottish Budget 2026-27), not this deterministic takeup PR. This PR is only about migrating from random() to would_claim_scp. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Simplify SCP to Person level directly Remove BenUnit wrapper - scottish_child_payment is now Person-level with defined_for="is_scp_eligible". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update SCP tests for Person-level output format Tests now specify per-person expected values since scottish_child_payment is a Person-level variable. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 62bb695 commit 695d9b2

20 files changed

Lines changed: 560 additions & 520 deletions

File tree

changelog_entry.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- bump: minor
2+
changes:
3+
changed:
4+
- Remove randomness from country package by moving stochastic variable generation to data package. Variables now read pre-computed values from datasets for deterministic, reproducible calculations.

policyengine_uk/parameters/gov/social_security_scotland/scottish_child_payment/amount.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ metadata:
1111
period: week
1212
label: Scottish Child Payment weekly amount
1313
reference:
14+
- title: The Scottish Child Payment Regulations 2020, Regulation 20
15+
href: https://www.legislation.gov.uk/ssi/2020/351/regulation/20
1416
- title: Scottish Government - Scottish Child Payment
1517
href: https://www.gov.scot/policies/social-security/scottish-child-payment/
16-
- title: Social Security Scotland - SCP statistics
17-
href: https://www.socialsecurity.gov.scot/publications/2024/02/scottish-child-payment-statistics-to-31-december-2023

policyengine_uk/parameters/gov/social_security_scotland/scottish_child_payment/max_age.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ metadata:
88
period: year
99
label: Scottish Child Payment maximum age
1010
reference:
11+
- title: The Scottish Child Payment Regulations 2020, Regulation 18
12+
href: https://www.legislation.gov.uk/ssi/2020/351/regulation/18
1113
- title: Scottish Government - Scottish Child Payment
1214
href: https://www.gov.scot/policies/social-security/scottish-child-payment/

policyengine_uk/tests/policy/baseline/gov/social_security_scotland/scottish_child_payment.yaml

Lines changed: 71 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Scottish Child Payment tests
22
# SCP available from Feb 2021, extended to under-16s from Nov 2022
3+
# scottish_child_payment is a Person-level variable
34

45
- name: SCP for family receiving UC in Scotland (2024)
56
period: 2024
@@ -21,8 +22,11 @@
2122
members: [parent, child_1, child_2]
2223
region: SCOTLAND
2324
output:
24-
# £26.70/week * 52 weeks * 2 children = £2,776.80
25-
scottish_child_payment: 2777
25+
# £26.70/week * 52 weeks = £1,388.40 per child
26+
scottish_child_payment:
27+
parent: 0
28+
child_1: 1388
29+
child_2: 1388
2630

2731
- name: SCP for family receiving UC in Scotland (2023)
2832
period: 2023
@@ -44,8 +48,11 @@
4448
members: [parent, child_1, child_2]
4549
region: SCOTLAND
4650
output:
47-
# £25/week * 52 weeks * 2 children = £2,600
48-
scottish_child_payment: 2600
51+
# £25/week * 52 weeks = £1,300 per child
52+
scottish_child_payment:
53+
parent: 0
54+
child_1: 1300
55+
child_2: 1300
4956

5057
- name: No SCP for families not receiving qualifying benefit
5158
period: 2024
@@ -66,7 +73,9 @@
6673
members: [parent, child_1]
6774
region: SCOTLAND
6875
output:
69-
scottish_child_payment: 0
76+
scottish_child_payment:
77+
parent: 0
78+
child_1: 0
7079

7180
- name: No SCP in England
7281
period: 2024
@@ -86,7 +95,9 @@
8695
members: [parent, child_1]
8796
region: NORTH_EAST
8897
output:
89-
scottish_child_payment: 0
98+
scottish_child_payment:
99+
parent: 0
100+
child_1: 0
90101

91102
- name: No SCP in Wales
92103
period: 2024
@@ -106,7 +117,9 @@
106117
members: [parent, child_1]
107118
region: WALES
108119
output:
109-
scottish_child_payment: 0
120+
scottish_child_payment:
121+
parent: 0
122+
child_1: 0
110123

111124
- name: SCP before Nov 2022 only for under-6s
112125
period: 2022
@@ -129,7 +142,10 @@
129142
region: SCOTLAND
130143
output:
131144
# Only child_young (age 4) eligible, £20/week * 52 = £1,040
132-
scottish_child_payment: 1040
145+
scottish_child_payment:
146+
parent: 0
147+
child_young: 1040
148+
child_older: 0
133149

134150
- name: SCP for family receiving Child Tax Credit (2023 - CTC still qualifies)
135151
period: 2023
@@ -149,8 +165,10 @@
149165
members: [parent, child_1]
150166
region: SCOTLAND
151167
output:
152-
# £25/week * 52 weeks * 1 child = £1,300
153-
scottish_child_payment: 1300
168+
# £25/week * 52 weeks = £1,300
169+
scottish_child_payment:
170+
parent: 0
171+
child_1: 1300
154172

155173
- name: No SCP before Feb 2021
156174
period: 2020
@@ -170,7 +188,9 @@
170188
members: [parent, child_1]
171189
region: SCOTLAND
172190
output:
173-
scottish_child_payment: 0
191+
scottish_child_payment:
192+
parent: 0
193+
child_1: 0
174194

175195
- name: No SCP for child over 16
176196
period: 2024
@@ -190,7 +210,9 @@
190210
members: [parent, child_1]
191211
region: SCOTLAND
192212
output:
193-
scottish_child_payment: 0
213+
scottish_child_payment:
214+
parent: 0
215+
child_1: 0
194216

195217
- name: Large family with multiple eligible children
196218
period: 2024
@@ -216,8 +238,13 @@
216238
members: [parent, child_1, child_2, child_3, child_4]
217239
region: SCOTLAND
218240
output:
219-
# £26.70/week * 52 weeks * 4 children = £5,553.60
220-
scottish_child_payment: 5554
241+
# £26.70/week * 52 weeks = £1,388.40 per child
242+
scottish_child_payment:
243+
parent: 0
244+
child_1: 1388
245+
child_2: 1388
246+
child_3: 1388
247+
child_4: 1388
221248

222249
# New tests for 2025 amount and qualifying benefit changes
223250

@@ -239,8 +266,10 @@
239266
members: [parent, child_1]
240267
region: SCOTLAND
241268
output:
242-
# £27.15/week * 52 weeks * 1 child = £1,411.80
243-
scottish_child_payment: 1412
269+
# £27.15/week * 52 weeks = £1,411.80
270+
scottish_child_payment:
271+
parent: 0
272+
child_1: 1412
244273

245274
- name: CTC no longer qualifies from 2025 (after April 2024)
246275
period: 2025
@@ -262,7 +291,9 @@
262291
region: SCOTLAND
263292
output:
264293
# CTC removed as qualifying benefit from April 2024
265-
scottish_child_payment: 0
294+
scottish_child_payment:
295+
parent: 0
296+
child_1: 0
266297

267298
- name: CTC still qualifies in 2023 (before April 2024)
268299
period: 2023
@@ -283,8 +314,10 @@
283314
members: [parent, child_1]
284315
region: SCOTLAND
285316
output:
286-
# £25/week * 52 weeks * 1 child = £1,300
287-
scottish_child_payment: 1300
317+
# £25/week * 52 weeks = £1,300
318+
scottish_child_payment:
319+
parent: 0
320+
child_1: 1300
288321

289322
- name: WTC no longer qualifies from 2025
290323
period: 2025
@@ -306,7 +339,9 @@
306339
region: SCOTLAND
307340
output:
308341
# WTC removed as qualifying benefit from April 2024
309-
scottish_child_payment: 0
342+
scottish_child_payment:
343+
parent: 0
344+
child_1: 0
310345

311346
- name: Income Support still qualifies in 2025
312347
period: 2025
@@ -327,8 +362,10 @@
327362
members: [parent, child_1]
328363
region: SCOTLAND
329364
output:
330-
# £27.15/week * 52 weeks * 1 child = £1,411.80
331-
scottish_child_payment: 1412
365+
# £27.15/week * 52 weeks = £1,411.80
366+
scottish_child_payment:
367+
parent: 0
368+
child_1: 1412
332369

333370
- name: JSA income-based still qualifies in 2025
334371
period: 2025
@@ -349,8 +386,10 @@
349386
members: [parent, child_1]
350387
region: SCOTLAND
351388
output:
352-
# £27.15/week * 52 weeks * 1 child = £1,411.80
353-
scottish_child_payment: 1412
389+
# £27.15/week * 52 weeks = £1,411.80
390+
scottish_child_payment:
391+
parent: 0
392+
child_1: 1412
354393

355394
- name: ESA income-related still qualifies in 2025
356395
period: 2025
@@ -371,8 +410,10 @@
371410
members: [parent, child_1]
372411
region: SCOTLAND
373412
output:
374-
# £27.15/week * 52 weeks * 1 child = £1,411.80
375-
scottish_child_payment: 1412
413+
# £27.15/week * 52 weeks = £1,411.80
414+
scottish_child_payment:
415+
parent: 0
416+
child_1: 1412
376417

377418
- name: Pension Credit still qualifies in 2025
378419
period: 2025
@@ -393,5 +434,7 @@
393434
members: [grandparent, child_1]
394435
region: SCOTLAND
395436
output:
396-
# £27.15/week * 52 weeks * 1 child = £1,411.80
397-
scottish_child_payment: 1412
437+
# £27.15/week * 52 weeks = £1,411.80
438+
scottish_child_payment:
439+
grandparent: 0
440+
child_1: 1412

0 commit comments

Comments
 (0)