Tax-Brain 2017 law presets on Compute Studio

This post discusses adding a 2017 Law preset for Tax-Brain on its Compute Studio app. I took a shot at adding this today, and I’m interested in others feedback what I have so far.

My approach is to use the C/S REST API to create the simulation. There are two upsides for using the REST API:

  1. I don’t have to painstakingly input each parameter value. This would take a long time, and it’s likely I would make some mistakes.
  2. We can keep the code used to create the simulation and re-run it when Tax-Brain or Tax-Calculator is updated.

Ok, so here are the steps for creating the simulation (If you’d like to run this code yourself, check out the installation instructions at the bottom of this post):

  1. Get the 2017_law.json reform file and convert it to the ParamTools format required by the C/s REST API. I’ve been working on swapping Tax-Calculator over to using ParamTools and as a part of that project, I updated the implement_reform method on the Policy class to convert the TC-styled reforms to the ParamTools styled adjustments. For convenience, that’s what I use here.
from taxcalc import Policy


# https://github.com/hdoupe/Tax-Calculator/tree/use-paramtools 
pol = Policy()
pol.set_state(year=[2017, 2018, 2019]) # silences paramtools warnings
ref = pol.read_json_reform(
    "https://raw.githubusercontent.com/PSLmodels/Tax-Calculator/master/taxcalc/reforms/2017_law.json"
)

Now, that we’ve downloaded the 2017_law.json file, let’s convert it to the correct data format. Remember that implement_reform is now just a wrapper that converts the TC styled reform to the PT styled reform:

adj = pol.implement_reform(ref)

A quick sanity check that the reform was converted correctly:

# we have a personal exemption again
pol.clear_state()
pol.from_array("II_em")

# output:
# [{'year': 2013, 'value': 3874.56},
#  {'year': 2014, 'value': 3931.9},
#  {'year': 2015, 'value': 3994.42},
#  {'year': 2016, 'value': 3999.21},
#  {'year': 2017, 'value': 4050.0},
#  {'year': 2018, 'value': 4135.86},
#  {'year': 2019, 'value': 4238.84},
#  {'year': 2020, 'value': 4328.28},
#  {'year': 2021, 'value': 4439.95},
#  {'year': 2022, 'value': 4552.72},
#  {'year': 2023, 'value': 4667.9},
#  {'year': 2024, 'value': 4782.73},
#  {'year': 2025, 'value': 4895.6},
#  {'year': 2026, 'value': 5010.16},
#  {'year': 2027, 'value': 5128.4},
#  {'year': 2028, 'value': 5247.89},
#  {'year': 2029, 'value': 5371.22}]
  1. Create the C/S simulation using the Python API:
from cs_kit import ComputeStudio

cs = ComputeStudio("PSLmodels", "Tax-Brain")
resp = cs.create(adjustment={"policy": adj})

sim_results = cs.results(model_pk=resp["sim"]["model_pk"])

sim_results["Total Liabilities Change by Calendar Year (Billions).csv"]

# output
#                                           Unnamed: 0     2019     2020     2021     2022     2023     2024     2025     2026     2027     2028     2029
# 0             Individual Income Tax Liability Change  $165.32  $168.83  $170.71  $173.37  $175.40  $178.15  $181.71  $-20.05  $-23.97  $-28.22  $-32.77
# 1                       Payroll Tax Liability Change    $0.00    $0.00    $0.00    $0.00    $0.00    $0.00    $0.00    $0.00    $0.00    $0.00    $0.00
# 2  Combined Payroll and Individual Income Tax Lia...  $165.32  $168.83  $170.71  $173.37  $175.40  $178.15  $181.71  $-20.05  $-23.97  $-28.22  $-32.77

The initial response from cs.create(...) has the URLs to the output page and edit page created for the simulation:

# compute studio outputs url:
f'{cs.host}{resp["sim"]["gui_url"]}'

# output:
# https://compute.studio/PSLmodels/Tax-Brain/44069/

# compute studio edit url:
f'{cs.host}{resp["sim"]["gui_url"]}edit/'

# output
# https://compute.studio/PSLmodels/Tax-Brain/44069/edit/

My questions are:

  1. The GUI edit page shows that a few of the parameters have been updated since the 2017_law.json file was created. Were those parameters removed or renamed? If renamed, what are the new parameter names?

  2. Are there elements that this naive approach is missing?

Install instructions

# clone tax-calculator if you don't have it already:
git clone https://github.com/[your-username]/Tax-Calculator

cd Tax-Calculator

# add my fork to your list of remotes
git remote add hdoupe https://github.com/hdoupe/Tax-Calculator
git fetch hdoupe use-paramtools
git checkout hdoupe/use-paramtools

# create environment
conda env create

# or update if the environment already exists
conda env update

# install c/s rest api wrapper
pip install cs-kit

Also, I have a notebook that I can share. If anyone is interested just let me know.