Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reinstate ogusa #710

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions deploy/taxbrain_server/celery_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ def elasticity_gdp_task_async(year_n, user_mods, first_budget_year,


@celery_app.task
def ogusa_async(user_mods, ogusa_params, guid):
def ogusa_async(start_year, user_mods, ogusa_params, guid):
print("user mods: ", user_mods)
user_mods = convert_int_key(user_mods)
user_reform = {'policy': user_mods}
for key in EXPECTED_KEYS:
if key not in user_reform:
user_reform[key] = {}
diff_data = run_ogusa.run_micro_macro(reform=user_reform,
diff_data = run_ogusa.run_micro_macro(start_year=start_year,
reform=user_reform,
user_params=ogusa_params,
guid=guid)

Expand Down
8 changes: 7 additions & 1 deletion deploy/taxbrain_server/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,20 @@ def example():

@app.route('/ogusa_start_job', methods=['POST'])
def ogusa_start_job():
start_year = int(request.form["start_year"])
user_mods = json.loads(request.form['user_mods'])
ogusa_params = json.loads(request.form['ogusa_params'])

user_mods = {int(k): v for k, v in user_mods.iteritems()}

with ticket_lock_context():
guid = uuid.uuid1().hex
job = ogusa_async.delay(user_mods=user_mods, ogusa_params=ogusa_params, guid=guid)
job = ogusa_async.delay(
start_year=start_year,
user_mods=user_mods,
ogusa_params=ogusa_params,
guid=guid
)
RUNNING_JOBS[job.id] = job
print('job_id', job)
print('GUID IS ', guid)
Expand Down
43 changes: 25 additions & 18 deletions deploy/taxbrain_server/run_ogusa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@
from ogusa.scripts.execute import runner


def run_micro_macro(reform, user_params, guid):
def run_micro_macro(start_year, reform, user_params, guid):

start_time = time.time()

REFORM_DIR = "./OUTPUT_REFORM_" + guid
BASELINE_DIR = "./OUTPUT_BASELINE_" + guid

# Add start year from reform to user parameters
if isinstance(reform, tuple):
start_year = sorted(reform[0].keys())[0]
else:
start_year = sorted(reform.keys())[0]
user_params['start_year'] = start_year

with open("log_{}.log".format(guid), 'w') as f:
f.write("guid: {}\n".format(guid))
f.write("reform: {}\n".format(reform))
Expand All @@ -37,6 +30,8 @@ def run_micro_macro(reform, user_params, guid):
Run baseline
------------------------------------------------------------------------
'''

user_params["start_year"] = start_year
output_base = BASELINE_DIR
kwargs={'output_base':output_base, 'baseline_dir':BASELINE_DIR,
'test':False, 'time_path':True, 'baseline':True,
Expand Down Expand Up @@ -75,13 +70,25 @@ def run_micro_macro(reform, user_params, guid):
if __name__ == "__main__":

reform = {
2017: {
'_II_rt1': [.09],
'_II_rt2': [.135],
'_II_rt3': [.225],
'_II_rt4': [.252],
'_II_rt5': [.297],
'_II_rt6': [.315],
'_II_rt7': [0.3564],
}, }
run_micro_macro(reform=reform, user_params={'frisch': 0.44}, guid='abc')
u'growdiff_response': {},
u'consumption': {},
u'growdiff_baseline': {},
u'behavior': {},
u'policy': {
2017: {
u'_II_no_em_nu18': [False],
u'_NIIT_PT_taxed': [False],
u'_FICA_ss_trt': [0.1],
u'_ID_BenefitCap_Switch': [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]],
u'_ALD_InvInc_ec_base_RyanBrady': [False],
u'_EITC_indiv': [False],
u'_ID_BenefitSurtax_Switch': [[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]],
u'_CTC_new_refund_limited': [False],
u'_CG_nodiff': [False]
}
},
u'gdp_elasticity': {}
}
user_params = {u'g_y_annual': 0.04, u'frisch': 0.3}

run_micro_macro(start_year=2017, reform=reform, user_params=user_params, guid='abc')
5 changes: 0 additions & 5 deletions templates/dynamic/dynamic_input_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ <h2>Tax-Calculator Code Build</h2>
<div class="sidebar-button">
<a href="#" ></a>
<input id="tax-submit" class="btn btn-secondary btn-block btn-animate {{ is_disabled }}" {{ is_disabled }} type="submit" value="Start Dynamic Simulation!">
<div class="construction text-center">
<div class="progress progress-striped" style="width: 100%">
<div class="progress-bar active progress-bar-custom" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
</div>
</div>
</div>
</div> <!-- sidebar -->
</div>
Expand Down
10 changes: 1 addition & 9 deletions templates/dynamic/landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,14 @@ <h1>Choose a Dynamic Simulation Type</h1>
<p>This approach answers the question, "how would taxpayer behavior (income and deductions) affect revenue if all other prices in the economy could stay the same?" <p>
</td>
</tr>
{% if include_ogusa %}
<tr padding="15px">
<td>
<a href="/dynamic/ogusa/{{pk}}/?start_year={{start_year}}" class="text-white btn btn-secondary disabled">Overlapping Generations Simulation</a>
<a href="/dynamic/ogusa/{{pk}}/?start_year={{start_year}}" class="text-white btn btn-secondary">Overlapping Generations Simulation</a>
</td>
<td>
<div class="construction">
<div class="progress progress-striped" style="min-width: 400px; width: 100%">
<div class="progress-bar active progress-bar-custom" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
</div>
</div>
<p> DISABLED WHILE UNDERGOING MAINTENANCE </p>
<p>This approach answers the question, "how does tax policy affect macroeconomic aggregates and prices?"</p>
</td>
</tr>
{% endif %}
<tr padding="15px">
<td padding-bottom="1em">
<a href="/dynamic/macro/{{pk}}/?start_year={{start_year}}" class="text-white btn btn-secondary">Macro Elasticity Simulation</a>
Expand Down
27 changes: 2 additions & 25 deletions webapp/apps/dynamic/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import taxcalc
from ..taxbrain.compute import DropqCompute, MockCompute
from .models import OGUSAWorkerNodesCounter
from .helpers import filter_ogusa_only
from ..constants import START_YEAR

dqversion_info = taxcalc._version.get_versions()
Expand All @@ -33,27 +32,8 @@ def remote_register_job(self, theurl, data, timeout=TIMEOUT_IN_SECONDS):
response = requests.post(theurl, data=data, timeout=timeout)
return response

def submit_json_ogusa_calculation(self, ogusa_mods, first_budget_year,
microsim_data, pack_up_user_mods):
return self.submit_ogusa_calculation(ogusa_mods, first_budget_year,
microsim_data, pack_up_user_mods=False)

def submit_ogusa_calculation(self, ogusa_mods, first_budget_year, microsim_data,
pack_up_user_mods=True):

print "mods is ", ogusa_mods
ogusa_params = filter_ogusa_only(ogusa_mods)
data = {}
if pack_up_user_mods:
microsim_params = package_up_vars(microsim_data, first_budget_year)
microsim_params = {first_budget_year:microsim_params}
print "microsim data is", microsim_params
else:
data['taxio_format'] = True
data['first_budget_year'] = first_budget_year
microsim_params = microsim_data


def submit_ogusa_calculation(self, data):
print "mods is ", data
print "submit dynamic work"

hostnames = OGUSA_WORKERS
Expand All @@ -62,9 +42,6 @@ def submit_ogusa_calculation(self, ogusa_mods, first_budget_year, microsim_data,
'callback': "http://{}/dynamic/dynamic_finished".format(CALLBACK_HOSTNAME),
}

data['ogusa_params'] = json.dumps(ogusa_params)
data['user_mods'] = json.dumps(microsim_params)
data['first_year'] = first_budget_year
job_ids = []
guids = []

Expand Down
2 changes: 1 addition & 1 deletion webapp/apps/dynamic/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def filter_ogusa_only(user_values):
print "Removing ", k, v
del user_values[k]
else:
user_values[k] = float(v)
user_values[k] = float(v[0]) if isinstance(v, list) else float(v)

return user_values

Expand Down
64 changes: 29 additions & 35 deletions webapp/apps/dynamic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
failure_text, normalize, denormalize, strip_empty_lists,
cc_text_finished, cc_text_failure, dynamic_params_from_model,
send_cc_email, default_behavior_parameters,
elast_results_to_tables, default_elasticity_parameters)
elast_results_to_tables, default_elasticity_parameters,
filter_ogusa_only)

from .compute import DynamicCompute, NUM_BUDGET_YEARS

Expand Down Expand Up @@ -88,54 +89,47 @@ def dynamic_input(request, pk):
if dyn_mod_form.is_valid():
model = dyn_mod_form.save()

#Can't proceed if there is no email address
# Can't proceed if there is no email address
if not (request.user.is_authenticated() or model.user_email):
msg = 'Dynamic simulation must have an email address to send notification to!'
return HttpResponse(msg, status=403)

curr_dict = dict(model.__dict__)
for key, value in curr_dict.items():
print "got this ", key, value
msg = ("Dynamic simulation must have an email "
"address to send notification to!")
return HttpResponse(msg, status=403)

# get macrosim data from form
worker_data = {k:v for k, v in curr_dict.items() if v not in (u'', None, [])}
curr_dict = dict(model.__dict__)
worker_data = parse_fields(curr_dict)

#get microsim data
outputsurl = OutputUrl.objects.get(pk=pk)
model.micro_sim = outputsurl
taxbrain_model = outputsurl.unique_inputs
submitted_ids = None

# necessary for simulations before PR 641
if not taxbrain_model.json_text:
taxbrain_dict = dict(taxbrain_model.__dict__)
growth_fixup(taxbrain_dict)
for key, value in taxbrain_dict.items():
if type(value) == type(unicode()):
try:
taxbrain_dict[key] = [float(x) for x in value.split(',') if x]
except ValueError:
taxbrain_dict[key] = [make_bool(x) for x in value.split(',') if x]
else:
print "missing this: ", key


microsim_data = {k:v for k, v in taxbrain_dict.items() if not (v == [] or v == None)}
(reform_dict, _, _, _,
errors_warnings) = get_reform_from_gui(
request,
taxbrain_model=taxbrain_model,
behavior_model=None
)

#Don't need to pass around the microsim results
if 'tax_result' in microsim_data:
del microsim_data['tax_result']
else:
reform_dict = json.loads(taxbrain_model.json_text.reform_text)

benefit_switch_fixup(request.REQUEST, microsim_data, taxbrain_model)
# package up variables
ogusa_params = filter_ogusa_only(worker_data)
data = {
'taxio_format': True,
'ogusa_params': json.dumps(ogusa_params),
'user_mods': json.dumps(reform_dict),
'start_year': int(start_year)
}
# start model run
submitted_ids, guids = dynamic_compute.submit_ogusa_calculation(
data
)

# start calc job
submitted_ids, guids = dynamic_compute.submit_ogusa_calculation(worker_data, int(start_year), microsim_data)
else:
microsim_data = {"reform": taxbrain_model.json_text.reform_text, "assumptions": taxbrain_model.json_text.assumption_text}
# start calc job
submitted_ids, guids = dynamic_compute.submit_json_ogusa_calculation(worker_data,
int(start_year),
microsim_data,
pack_up_user_mods=False)
# TODO: use OutputUrl class
if submitted_ids:
model.job_ids = denormalize(submitted_ids)
Expand Down