Massachusetts Senior Circuit Breaker Credit#
The Massachusetts Senior Circuit Breaker Credit provides a refundable tax credit to seniors, depending on their age, income, household structure, rent, property tax, and property value.
Examples#
Consider households with one or two adults aged 65, paying $1,000 monthly rent and receiving $1,000 monthly Social Security income per person. The Senior Circuit Breaker Credit provides up to $189 to the single person and up to $1,170 to the couple. It spikes up at $15,200 for a single person because they become disqualified from SNAP and lose the generous minimum benefit (thanks to SNAP emergency allotments), and the SCB treats SNAP as income.
from policyengine_us import IndividualSim
import pandas as pd
import plotly.express as px
LIGHT_GRAY = "#F5F5F5"
GRAY = "#BDBDBD"
BLUE = "#5091cc"
LIGHT_BLUE = "lightblue"
DARK_BLUE = "darkblue"
COLOR_MAP = {"0": GRAY, "1": LIGHT_BLUE, "2": BLUE, "3": DARK_BLUE}
def make_scb(adults):
sim = IndividualSim(year=2022)
sim.add_person(name="head", age=65, rent=12_000, social_security=12_000)
members = ["head"]
if adults == 2:
sim.add_person(name="spouse", age=65, social_security=12_000)
members += ["spouse"]
sim.add_tax_unit(name="tax_unit", members=members)
sim.add_spm_unit(name="spm_unit", members=members)
sim.add_household(name="household", members=members, state_code="MA")
sim.vary("employment_income", max=20_000, step=100)
return pd.DataFrame(
dict(
employment_income=sim.calc("employment_income")[0],
ma_senior_circuit_breaker=sim.calc("ma_senior_circuit_breaker")[
0
].round(),
scb_mtr=-sim.deriv(
"ma_senior_circuit_breaker",
"employment_income",
wrt_target="head",
),
adults=adults,
)
)
# Make a table of state taxes for different numbers of adults and children.
l = []
for adults in range(1, 3):
l.append(make_scb(adults))
df = pd.concat(l)
LABELS = dict(
employment_income="Employment income",
ma_senior_circuit_breaker="MA Senior Circuit Breaker Credit",
scb_mtr="Senior Circuit Breaker Credit Marginal Tax Rate",
adults="Adults",
)
fig = px.line(
df,
"employment_income",
"ma_senior_circuit_breaker",
color="adults",
labels=LABELS,
title="Massachusetts Senior Circuit Breaker Credit",
)
fig.update_layout(
xaxis_tickformat="$,",
yaxis_tickformat="$,",
plot_bgcolor="white",
xaxis_gridcolor=LIGHT_GRAY,
yaxis_gridcolor=LIGHT_GRAY,
)
fig.show()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/individual_sim.py:261, in IndividualSim.calc(self, var, period, target, index, map_to, reform)
260 try:
--> 261 result = self.simulation.calculate(var, period)
262 except:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/ma/tax/income/credits/senior_circuit_breaker/ma_senior_circuit_breaker.py:32, in ma_senior_circuit_breaker.formula(tax_unit, period, parameters)
31 # Comparison to income for maximum credit determination.
---> 32 income = tax_unit("ma_scb_total_income", period)
33 income_threshold = income * scb.amount.min_real_estate_tax
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/ma/tax/income/credits/senior_circuit_breaker/ma_scb_total_income.py:20, in ma_scb_total_income.formula(tax_unit, period, parameters)
17 scb = parameters(
18 period
19 ).gov.states.ma.tax.income.credits.senior_circuit_breaker
---> 20 disallowed_deductions = add(
21 tax_unit, period, scb.income.disallowed_deductions
22 )
24 # Re-add some exemptions
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:225, in add(entity, period, variables, options)
211 """Sums a list of variables.
212
213 Args:
(...)
223 ArrayLike: The result of the operation.
224 """
--> 225 return for_each_variable(
226 entity, period, variables, agg_func="add", options=options
227 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:195, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
191 variable_population = entity.simulation.populations[
192 variable_entity.key
193 ]
194 person_shares = variable_population.project(
--> 195 variable_population(variable, period)
196 ) / variable_population.project(variable_population.nb_persons())
197 values = entity.sum(person_shares)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/snap.py:18, in snap.formula(spm_unit, period, parameters)
17 else:
---> 18 added_components = add(spm_unit, period, snap.adds)
19 return added_components
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:225, in add(entity, period, variables, options)
211 """Sums a list of variables.
212
213 Args:
(...)
223 ArrayLike: The result of the operation.
224 """
--> 225 return for_each_variable(
226 entity, period, variables, agg_func="add", options=options
227 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:181, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
180 if variable_entity.key == entity.entity.key:
--> 181 values = entity(variable, period, options=options)
182 elif variable_entity.is_person:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/snap_normal_allotment.py:16, in snap_normal_allotment.formula(spm_unit, period, parameters)
13 def formula(spm_unit, period, parameters):
14 # Federal SNAP rules are defined in U.S.C Title 7, Chapter 51, which
15 # also defines state powers to modify the rules.
---> 16 eligible = spm_unit("is_snap_eligible", period)
17 expected_contribution = spm_unit("snap_expected_contribution", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/eligibility/is_snap_eligible.py:16, in is_snap_eligible.formula(spm_unit, period, parameters)
15 def formula(spm_unit, period, parameters):
---> 16 net = spm_unit("meets_snap_net_income_test", period)
17 gross = spm_unit("meets_snap_gross_income_test", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/eligibility/meets_snap_net_income_test.py:19, in meets_snap_net_income_test.formula(spm_unit, period, parameters)
16 net_income_limit_fpg = parameters(
17 period
18 ).gov.usda.snap.income.limit.net
---> 19 net_income_fpg = spm_unit("snap_net_income_fpg_ratio", period)
20 return net_income_fpg <= net_income_limit_fpg
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:719, in Simulation._run_formula(self, variable, population, period)
718 if formula.__code__.co_argcount == 2:
--> 719 array = formula(population, period)
720 else:
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/income/snap_net_income_fpg_ratio.py:15, in snap_net_income_fpg_ratio.formula(spm_unit, period)
14 def formula(spm_unit, period):
---> 15 income = spm_unit("snap_net_income", period)
16 fpg = spm_unit("spm_unit_fpg", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:719, in Simulation._run_formula(self, variable, population, period)
718 if formula.__code__.co_argcount == 2:
--> 719 array = formula(population, period)
720 else:
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/income/snap_net_income.py:14, in snap_net_income.formula(spm_unit, period)
13 def formula(spm_unit, period):
---> 14 gross_income = spm_unit("snap_gross_income", period)
15 deductions = spm_unit("snap_deductions", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:684, in Simulation._run_formula(self, variable, population, period)
683 for added_variable in adds_list:
--> 684 values = values + self.calculate(
685 added_variable, period, map_to=variable.entity.key
686 )
687 if variable.subtracts is not None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:684, in Simulation._run_formula(self, variable, population, period)
683 for added_variable in adds_list:
--> 684 values = values + self.calculate(
685 added_variable, period, map_to=variable.entity.key
686 )
687 if variable.subtracts is not None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi.py:16, in ssi.formula(person, period, parameters)
15 return 0
---> 16 return max_(0, person("uncapped_ssi", period))
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/uncapped_ssi.py:13, in uncapped_ssi.formula(person, period, parameters)
12 def formula(person, period, parameters):
---> 13 amount = person("ssi_amount_if_eligible", period)
14 meets_resource_test = person("meets_ssi_resource_test", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_amount_if_eligible.py:16, in ssi_amount_if_eligible.formula(person, period, parameters)
13 ssi = parameters(period).gov.ssa.ssi.amount
14 return (
15 where(
---> 16 person("ssi_claim_is_joint", period),
17 ssi.couple,
18 ssi.individual,
19 )
20 * MONTHS_IN_YEAR
21 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_claim_is_joint.py:12, in ssi_claim_is_joint.formula(person, period, parameters)
11 eligible = person("is_ssi_aged_blind_disabled", period)
---> 12 both_eligible = person.marital_unit.sum(eligible) == 2
13 income_is_deemed = (
14 person("ssi_income_deemed_from_ineligible_spouse", period) > 0
15 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:28, in Projector.__getattr__.<locals>.projector_function(*args, **kwargs)
27 result = reference_attr(*args, **kwargs)
---> 28 return self.transform_and_bubble_up(result)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:37, in Projector.transform_and_bubble_up(self, result)
36 def transform_and_bubble_up(self, result):
---> 37 transformed_result = self.transform(result)
38 if self.parent is None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/entity_to_person_projector.py:19, in EntityToPersonProjector.transform(self, result)
18 def transform(self, result: ArrayLike) -> ArrayLike:
---> 19 return self.reference_entity.project(result)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/group_population.py:335, in GroupPopulation.project(self, array, role)
334 def project(self, array: ArrayLike, role: Role = None) -> ArrayLike:
--> 335 self.check_array_compatible_with_entity(array)
336 self.entity.check_role_validity(role)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:60, in Population.check_array_compatible_with_entity(self, array)
59 if not self.count == array.size:
---> 60 raise ValueError(
61 "Input {} is not a valid value for the entity {} (size = {} != {} = count)".format(
62 array, self.entity.key, array.size, self.count
63 )
64 )
ValueError: Input [0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 1. 1. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.] is not a valid value for the entity marital_unit (size = 401 != 402 = count)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/individual_sim.py:264, in IndividualSim.calc(self, var, period, target, index, map_to, reform)
263 try:
--> 264 result = self.sim.calculate_add(var, period)
265 except:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:597, in Simulation.calculate_add(self, variable_name, period, decode_enums)
591 raise ValueError(
592 "Unable to sum constant variable '{}' over period {}: only variables defined daily, monthly, or yearly can be summed over time.".format(
593 variable.name, period
594 )
595 )
--> 597 return sum(
598 self.calculate(variable_name, sub_period)
599 for sub_period in period.get_subperiods(variable.definition_period)
600 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:598, in <genexpr>(.0)
591 raise ValueError(
592 "Unable to sum constant variable '{}' over period {}: only variables defined daily, monthly, or yearly can be summed over time.".format(
593 variable.name, period
594 )
595 )
597 return sum(
--> 598 self.calculate(variable_name, sub_period)
599 for sub_period in period.get_subperiods(variable.definition_period)
600 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/ma/tax/income/credits/senior_circuit_breaker/ma_senior_circuit_breaker.py:32, in ma_senior_circuit_breaker.formula(tax_unit, period, parameters)
31 # Comparison to income for maximum credit determination.
---> 32 income = tax_unit("ma_scb_total_income", period)
33 income_threshold = income * scb.amount.min_real_estate_tax
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/ma/tax/income/credits/senior_circuit_breaker/ma_scb_total_income.py:20, in ma_scb_total_income.formula(tax_unit, period, parameters)
17 scb = parameters(
18 period
19 ).gov.states.ma.tax.income.credits.senior_circuit_breaker
---> 20 disallowed_deductions = add(
21 tax_unit, period, scb.income.disallowed_deductions
22 )
24 # Re-add some exemptions
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:225, in add(entity, period, variables, options)
211 """Sums a list of variables.
212
213 Args:
(...)
223 ArrayLike: The result of the operation.
224 """
--> 225 return for_each_variable(
226 entity, period, variables, agg_func="add", options=options
227 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:195, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
191 variable_population = entity.simulation.populations[
192 variable_entity.key
193 ]
194 person_shares = variable_population.project(
--> 195 variable_population(variable, period)
196 ) / variable_population.project(variable_population.nb_persons())
197 values = entity.sum(person_shares)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/snap.py:18, in snap.formula(spm_unit, period, parameters)
17 else:
---> 18 added_components = add(spm_unit, period, snap.adds)
19 return added_components
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:225, in add(entity, period, variables, options)
211 """Sums a list of variables.
212
213 Args:
(...)
223 ArrayLike: The result of the operation.
224 """
--> 225 return for_each_variable(
226 entity, period, variables, agg_func="add", options=options
227 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:181, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
180 if variable_entity.key == entity.entity.key:
--> 181 values = entity(variable, period, options=options)
182 elif variable_entity.is_person:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/snap_normal_allotment.py:16, in snap_normal_allotment.formula(spm_unit, period, parameters)
13 def formula(spm_unit, period, parameters):
14 # Federal SNAP rules are defined in U.S.C Title 7, Chapter 51, which
15 # also defines state powers to modify the rules.
---> 16 eligible = spm_unit("is_snap_eligible", period)
17 expected_contribution = spm_unit("snap_expected_contribution", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/eligibility/is_snap_eligible.py:16, in is_snap_eligible.formula(spm_unit, period, parameters)
15 def formula(spm_unit, period, parameters):
---> 16 net = spm_unit("meets_snap_net_income_test", period)
17 gross = spm_unit("meets_snap_gross_income_test", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/eligibility/meets_snap_net_income_test.py:19, in meets_snap_net_income_test.formula(spm_unit, period, parameters)
16 net_income_limit_fpg = parameters(
17 period
18 ).gov.usda.snap.income.limit.net
---> 19 net_income_fpg = spm_unit("snap_net_income_fpg_ratio", period)
20 return net_income_fpg <= net_income_limit_fpg
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:719, in Simulation._run_formula(self, variable, population, period)
718 if formula.__code__.co_argcount == 2:
--> 719 array = formula(population, period)
720 else:
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/income/snap_net_income_fpg_ratio.py:15, in snap_net_income_fpg_ratio.formula(spm_unit, period)
14 def formula(spm_unit, period):
---> 15 income = spm_unit("snap_net_income", period)
16 fpg = spm_unit("spm_unit_fpg", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:719, in Simulation._run_formula(self, variable, population, period)
718 if formula.__code__.co_argcount == 2:
--> 719 array = formula(population, period)
720 else:
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/income/snap_net_income.py:14, in snap_net_income.formula(spm_unit, period)
13 def formula(spm_unit, period):
---> 14 gross_income = spm_unit("snap_gross_income", period)
15 deductions = spm_unit("snap_deductions", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:684, in Simulation._run_formula(self, variable, population, period)
683 for added_variable in adds_list:
--> 684 values = values + self.calculate(
685 added_variable, period, map_to=variable.entity.key
686 )
687 if variable.subtracts is not None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:684, in Simulation._run_formula(self, variable, population, period)
683 for added_variable in adds_list:
--> 684 values = values + self.calculate(
685 added_variable, period, map_to=variable.entity.key
686 )
687 if variable.subtracts is not None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi.py:16, in ssi.formula(person, period, parameters)
15 return 0
---> 16 return max_(0, person("uncapped_ssi", period))
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/uncapped_ssi.py:13, in uncapped_ssi.formula(person, period, parameters)
12 def formula(person, period, parameters):
---> 13 amount = person("ssi_amount_if_eligible", period)
14 meets_resource_test = person("meets_ssi_resource_test", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_amount_if_eligible.py:16, in ssi_amount_if_eligible.formula(person, period, parameters)
13 ssi = parameters(period).gov.ssa.ssi.amount
14 return (
15 where(
---> 16 person("ssi_claim_is_joint", period),
17 ssi.couple,
18 ssi.individual,
19 )
20 * MONTHS_IN_YEAR
21 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_claim_is_joint.py:12, in ssi_claim_is_joint.formula(person, period, parameters)
11 eligible = person("is_ssi_aged_blind_disabled", period)
---> 12 both_eligible = person.marital_unit.sum(eligible) == 2
13 income_is_deemed = (
14 person("ssi_income_deemed_from_ineligible_spouse", period) > 0
15 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:28, in Projector.__getattr__.<locals>.projector_function(*args, **kwargs)
27 result = reference_attr(*args, **kwargs)
---> 28 return self.transform_and_bubble_up(result)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:37, in Projector.transform_and_bubble_up(self, result)
36 def transform_and_bubble_up(self, result):
---> 37 transformed_result = self.transform(result)
38 if self.parent is None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/entity_to_person_projector.py:19, in EntityToPersonProjector.transform(self, result)
18 def transform(self, result: ArrayLike) -> ArrayLike:
---> 19 return self.reference_entity.project(result)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/group_population.py:335, in GroupPopulation.project(self, array, role)
334 def project(self, array: ArrayLike, role: Role = None) -> ArrayLike:
--> 335 self.check_array_compatible_with_entity(array)
336 self.entity.check_role_validity(role)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:60, in Population.check_array_compatible_with_entity(self, array)
59 if not self.count == array.size:
---> 60 raise ValueError(
61 "Input {} is not a valid value for the entity {} (size = {} != {} = count)".format(
62 array, self.entity.key, array.size, self.count
63 )
64 )
ValueError: Input [0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 1. 1. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.] is not a valid value for the entity marital_unit (size = 401 != 402 = count)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
Cell In[1], line 44
42 l = []
43 for adults in range(1, 3):
---> 44 l.append(make_scb(adults))
46 df = pd.concat(l)
48 LABELS = dict(
49 employment_income="Employment income",
50 ma_senior_circuit_breaker="MA Senior Circuit Breaker Credit",
51 scb_mtr="Senior Circuit Breaker Credit Marginal Tax Rate",
52 adults="Adults",
53 )
Cell In[1], line 28, in make_scb(adults)
23 sim.add_household(name="household", members=members, state_code="MA")
24 sim.vary("employment_income", max=20_000, step=100)
25 return pd.DataFrame(
26 dict(
27 employment_income=sim.calc("employment_income")[0],
---> 28 ma_senior_circuit_breaker=sim.calc("ma_senior_circuit_breaker")[
29 0
30 ].round(),
31 scb_mtr=-sim.deriv(
32 "ma_senior_circuit_breaker",
33 "employment_income",
34 wrt_target="head",
35 ),
36 adults=adults,
37 )
38 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/individual_sim.py:266, in IndividualSim.calc(self, var, period, target, index, map_to, reform)
264 result = self.sim.calculate_add(var, period)
265 except:
--> 266 result = self.simulation.calculate_divide(var, period)
267 if (
268 target is not None
269 and target not in self.situation_data[entity.plural]
270 ):
271 map_to = self.get_entity(target).key
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:634, in Simulation.calculate_divide(self, variable_name, period, decode_enums)
630 return (
631 self.calculate(variable_name, period=computation_period) / 12.0
632 )
633 elif period.unit == periods.YEAR:
--> 634 return self.calculate(variable_name, period)
636 raise ValueError(
637 "Unable to divide the value of '{}' to match period {}.".format(
638 variable_name, period
639 )
640 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/ma/tax/income/credits/senior_circuit_breaker/ma_senior_circuit_breaker.py:32, in ma_senior_circuit_breaker.formula(tax_unit, period, parameters)
29 real_estate_tax_or_equiv = real_estate_tax + equivalent_rent
31 # Comparison to income for maximum credit determination.
---> 32 income = tax_unit("ma_scb_total_income", period)
33 income_threshold = income * scb.amount.min_real_estate_tax
34 ret_over_threshold = max_(
35 0, real_estate_tax_or_equiv - income_threshold
36 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/states/ma/tax/income/credits/senior_circuit_breaker/ma_scb_total_income.py:20, in ma_scb_total_income.formula(tax_unit, period, parameters)
14 ma_gross_income = tax_unit(
15 "ma_gross_income", period
16 ) # The law specifies to start at AGI and re-add deducted capital losses. We instead start from gross income, on an equivalent path.
17 scb = parameters(
18 period
19 ).gov.states.ma.tax.income.credits.senior_circuit_breaker
---> 20 disallowed_deductions = add(
21 tax_unit, period, scb.income.disallowed_deductions
22 )
24 # Re-add some exemptions
25 person = tax_unit.members
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:225, in add(entity, period, variables, options)
205 def add(
206 entity: Population,
207 period: Period,
208 variables: List[str],
209 options: List[str] = None,
210 ):
211 """Sums a list of variables.
212
213 Args:
(...)
223 ArrayLike: The result of the operation.
224 """
--> 225 return for_each_variable(
226 entity, period, variables, agg_func="add", options=options
227 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:195, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
190 else: # Group-to-group aggregation
191 variable_population = entity.simulation.populations[
192 variable_entity.key
193 ]
194 person_shares = variable_population.project(
--> 195 variable_population(variable, period)
196 ) / variable_population.project(variable_population.nb_persons())
197 values = entity.sum(person_shares)
198 if result is None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/snap.py:18, in snap.formula(spm_unit, period, parameters)
16 return 0
17 else:
---> 18 added_components = add(spm_unit, period, snap.adds)
19 return added_components
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:225, in add(entity, period, variables, options)
205 def add(
206 entity: Population,
207 period: Period,
208 variables: List[str],
209 options: List[str] = None,
210 ):
211 """Sums a list of variables.
212
213 Args:
(...)
223 ArrayLike: The result of the operation.
224 """
--> 225 return for_each_variable(
226 entity, period, variables, agg_func="add", options=options
227 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/commons/formulas.py:181, in for_each_variable(entity, period, variables, agg_func, group_agg_func, options)
179 variable_entity = entity.entity.get_variable(variable).entity
180 if variable_entity.key == entity.entity.key:
--> 181 values = entity(variable, period, options=options)
182 elif variable_entity.is_person:
183 values = group_agg_func(
184 entity.members(variable, period, options=options)
185 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/snap_normal_allotment.py:16, in snap_normal_allotment.formula(spm_unit, period, parameters)
13 def formula(spm_unit, period, parameters):
14 # Federal SNAP rules are defined in U.S.C Title 7, Chapter 51, which
15 # also defines state powers to modify the rules.
---> 16 eligible = spm_unit("is_snap_eligible", period)
17 expected_contribution = spm_unit("snap_expected_contribution", period)
18 max_allotment = spm_unit("snap_max_allotment", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/eligibility/is_snap_eligible.py:16, in is_snap_eligible.formula(spm_unit, period, parameters)
15 def formula(spm_unit, period, parameters):
---> 16 net = spm_unit("meets_snap_net_income_test", period)
17 gross = spm_unit("meets_snap_gross_income_test", period)
18 asset = spm_unit("meets_snap_asset_test", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/eligibility/meets_snap_net_income_test.py:19, in meets_snap_net_income_test.formula(spm_unit, period, parameters)
15 def formula(spm_unit, period, parameters):
16 net_income_limit_fpg = parameters(
17 period
18 ).gov.usda.snap.income.limit.net
---> 19 net_income_fpg = spm_unit("snap_net_income_fpg_ratio", period)
20 return net_income_fpg <= net_income_limit_fpg
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:719, in Simulation._run_formula(self, variable, population, period)
716 parameters_at = self.tax_benefit_system.parameters
718 if formula.__code__.co_argcount == 2:
--> 719 array = formula(population, period)
720 else:
721 array = formula(population, period, parameters_at)
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/income/snap_net_income_fpg_ratio.py:15, in snap_net_income_fpg_ratio.formula(spm_unit, period)
14 def formula(spm_unit, period):
---> 15 income = spm_unit("snap_net_income", period)
16 fpg = spm_unit("spm_unit_fpg", period)
17 return income / fpg
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:719, in Simulation._run_formula(self, variable, population, period)
716 parameters_at = self.tax_benefit_system.parameters
718 if formula.__code__.co_argcount == 2:
--> 719 array = formula(population, period)
720 else:
721 array = formula(population, period, parameters_at)
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/usda/snap/income/snap_net_income.py:14, in snap_net_income.formula(spm_unit, period)
13 def formula(spm_unit, period):
---> 14 gross_income = spm_unit("snap_gross_income", period)
15 deductions = spm_unit("snap_deductions", period)
16 return max_(0, gross_income - deductions)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:684, in Simulation._run_formula(self, variable, population, period)
682 values = 0
683 for added_variable in adds_list:
--> 684 values = values + self.calculate(
685 added_variable, period, map_to=variable.entity.key
686 )
687 if variable.subtracts is not None:
688 if isinstance(variable.subtracts, str):
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:684, in Simulation._run_formula(self, variable, population, period)
682 values = 0
683 for added_variable in adds_list:
--> 684 values = values + self.calculate(
685 added_variable, period, map_to=variable.entity.key
686 )
687 if variable.subtracts is not None:
688 if isinstance(variable.subtracts, str):
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi.py:16, in ssi.formula(person, period, parameters)
14 if parameters(period).gov.ssa.ssi.abolish_ssi:
15 return 0
---> 16 return max_(0, person("uncapped_ssi", period))
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/uncapped_ssi.py:13, in uncapped_ssi.formula(person, period, parameters)
12 def formula(person, period, parameters):
---> 13 amount = person("ssi_amount_if_eligible", period)
14 meets_resource_test = person("meets_ssi_resource_test", period)
15 eligible = person("is_ssi_eligible_individual", period)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_amount_if_eligible.py:16, in ssi_amount_if_eligible.formula(person, period, parameters)
12 def formula(person, period, parameters):
13 ssi = parameters(period).gov.ssa.ssi.amount
14 return (
15 where(
---> 16 person("ssi_claim_is_joint", period),
17 ssi.couple,
18 ssi.individual,
19 )
20 * MONTHS_IN_YEAR
21 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:134, in Population.__call__(self, variable_name, period, options)
130 return self.simulation.calculate_divide(
131 variable_name, period, **calculate_kwargs
132 )
133 else:
--> 134 return self.simulation.calculate(
135 variable_name, period, **calculate_kwargs
136 )
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:320, in Simulation.calculate(self, variable_name, period, map_to, decode_enums)
315 self.tracer.record_calculation_start(
316 variable_name, period, self.branch_name
317 )
319 try:
--> 320 result = self._calculate(variable_name, period)
321 if isinstance(result, EnumArray) and decode_enums:
322 result = result.decode_to_str()
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:481, in Simulation._calculate(self, variable_name, period)
479 try:
480 self._check_for_cycle(variable.name, period)
--> 481 array = self._run_formula(variable, population, period)
483 # If no result, use the default value and cache it
484 if array is None:
485 # Check if the variable has a previously defined value
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/simulations/simulation.py:721, in Simulation._run_formula(self, variable, population, period)
719 array = formula(population, period)
720 else:
--> 721 array = formula(population, period, parameters_at)
723 return array
File ~/work/policyengine-us/policyengine-us/policyengine_us/variables/gov/ssa/ssi/ssi_claim_is_joint.py:12, in ssi_claim_is_joint.formula(person, period, parameters)
10 def formula(person, period, parameters):
11 eligible = person("is_ssi_aged_blind_disabled", period)
---> 12 both_eligible = person.marital_unit.sum(eligible) == 2
13 income_is_deemed = (
14 person("ssi_income_deemed_from_ineligible_spouse", period) > 0
15 )
16 return both_eligible | income_is_deemed
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:28, in Projector.__getattr__.<locals>.projector_function(*args, **kwargs)
26 def projector_function(*args, **kwargs):
27 result = reference_attr(*args, **kwargs)
---> 28 return self.transform_and_bubble_up(result)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/projector.py:37, in Projector.transform_and_bubble_up(self, result)
36 def transform_and_bubble_up(self, result):
---> 37 transformed_result = self.transform(result)
38 if self.parent is None:
39 return transformed_result
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/projectors/entity_to_person_projector.py:19, in EntityToPersonProjector.transform(self, result)
18 def transform(self, result: ArrayLike) -> ArrayLike:
---> 19 return self.reference_entity.project(result)
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/group_population.py:335, in GroupPopulation.project(self, array, role)
334 def project(self, array: ArrayLike, role: Role = None) -> ArrayLike:
--> 335 self.check_array_compatible_with_entity(array)
336 self.entity.check_role_validity(role)
337 if role is None:
File /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/policyengine_core/populations/population.py:60, in Population.check_array_compatible_with_entity(self, array)
58 def check_array_compatible_with_entity(self, array: numpy.ndarray) -> None:
59 if not self.count == array.size:
---> 60 raise ValueError(
61 "Input {} is not a valid value for the entity {} (size = {} != {} = count)".format(
62 array, self.entity.key, array.size, self.count
63 )
64 )
ValueError: Input [0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.
0. 2. 0. 2. 0. 2. 0. 2. 1. 1. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0.
2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2. 0. 2.] is not a valid value for the entity marital_unit (size = 401 != 402 = count)
The credit phases out at 10% of income where it phases out smoothly.
fig = px.line(
df,
"employment_income",
"scb_mtr",
color="adults",
labels=LABELS,
title="Massachusetts Senior Circuit Breaker Credit marginal tax rate",
)
fig.update_layout(
xaxis_tickformat="$,",
yaxis_tickformat=".1%",
plot_bgcolor="white",
xaxis_gridcolor=LIGHT_GRAY,
yaxis_gridcolor=LIGHT_GRAY,
yaxis_range=[0, 0.2],
)
fig.show()