<jupyter_start><jupyter_text>*Specify settings:*<jupyter_code>name = 'A1_calib_test'
f = {'tech': directory['data']+"/techdata_adv.xlsx",
     'other': directory['data']+"/Othdata_adv.xlsx",
     'IO':directory['data'] + "/IOdata_adv.xlsx"}
s = ['inputdisp','endofpipe','inputprices']
m = ['ID','EOP'] 
e = {'M': 'vars','M_sets': 'sets'} # dictionary used to load emissions data
other_trees = {'ID_Y': {'s': 'Y', 'read_data': {'Y': 'vars'}, 'Q2P': 'Q2P'}} # the key = tree name, s = sheet that specifies tree structure, read_data (if not None) specifies how to load data.
type_f = {'ID_EC': 'CES_norm',
          'ID_CU': 'MNL',
          'ID_TU': 'CET_norm',
          'ID_TX': 'CES',
          'ID_BU': 'linear_out',
          'ID_BX': 'CES',
          'EOP_CU': 'MNL',
          'EOP_TU': 'CET_norm',
          'EOP_TX': 'CES'}<jupyter_output><empty_output><jupyter_text>*Set up nesting tree:*<jupyter_code>%run ATree.ipynb<jupyter_output><empty_output><jupyter_text>1: Initialize model *Set up gams model from tree:*<jupyter_code>gm = abatement.abate(nts=nts,tech=tech,use_EOP=True,work_folder=directory['work'],**{'data_folder':directory['gams'],'name': name})<jupyter_output><empty_output><jupyter_text>*Add a couple of extra aliases, and update sets with elements:*<jupyter_code>gm.add_aliases([('n','nnnn'),('n','nnnnn')])
gm.model.database.update_all_sets(clean_up=False)
gm.setstate("EOP")<jupyter_output><empty_output><jupyter_text>*Initialise variables at leontief levels, and fill out with simple standard values in potentially missing domains:*<jupyter_code>gm.initialize_variables_leontief()
gm.initialize_variables(**{'check_variables': True})<jupyter_output><empty_output><jupyter_text>2: Solve model *Set up baseline model and solve:*<jupyter_code>gm.write_and_run(name='baseline')
db0 = gm.model_instances['baseline'].out_db<jupyter_output><empty_output><jupyter_text>*Read back solution to main db:*<jupyter_code>gm.model.database.merge_dbs(gm.model.database,db0,'second')<jupyter_output><empty_output><jupyter_text>*Turn exogenous parameters into place*<jupyter_code>db_star = DataBase.GPM_database(**{'name': 'db_star'})
sigma_star = gm.get("sigma").copy()
eta_star = gm.get("eta").copy()
mu_star = gm.get("mu").copy()

eta_star[:] = -3
sigma_star[gm.get("kno_ID_CU")] = 0.4
sigma_star[gm.get("kno_no_ID_BX")] = 0.7
sigma_star["Y"] = 0.5

mu_star[gm.get("map_ID_CU")] = 1.0

db_star["sigma"] = sigma_star
db_star["eta"] = eta_star
db_star["mu"] = mu_star
name='v0'
gm.write_and_run(name=name, add_checkpoint=name)
gm.checkpoints['v1'] = gm.model_instances[name].ws.add_checkpoint()
gm.model_instances[name].solve_sneakily(db_star=db_star,from_cp = True, cp_init = gm.checkpoints[name], options_run={'checkpoint': gm.checkpoints['v1']})
gm.model.database.merge_dbs(gm.model.database,gm.model_instances[name].out_db,'second')
db_star = DataBase.GPM_database(**{'name': 'db_star'})
sigma_star = gm.get("sigma").copy()
sigma_star[gm.get("kno_ID_CU")] = 5
db_star["sigma"] = sigma_star
(shock_db, shock_kwargs) = ShockFunction.sneaky_db(gm.model.database, db_star, n_steps = 200, loop_name = 'sigma_loop')
store_sol = {"PwThat":{'domains': shock_kwargs['loop_name']}, "qD":{'domains': shock_kwargs['loop_name']}, "sigma":{'domains': shock_kwargs['loop_name']}}
mi = gm.model_instances[name]
shock = mi.std_UEVAS_from_db(shock_db, loop_name=shock_kwargs['loop_name'], shock_name=shock_kwargs['shock_name'], store_sol=store_sol)
mi.execute_shock_from_cp(shock=shock, cp=gm.checkpoints['v1'])
gm.model.database.merge_dbs(gm.model.database,mi.out_db,'second')<jupyter_output><empty_output><jupyter_text>*Change to calibration state and resolve:*<jupyter_code>gm.reset_settings()
gm.setstate('ID_calibrate',init=False)
gm.write_and_run(name='ID_calibrate',kwargs_init={'check_variables':True},overwrite=True)
db = gm.model_instances['ID_calibrate'].out_db<jupyter_output><empty_output><jupyter_text>Load in IO data<jupyter_code>gm.add_calib_data(f["IO"])
# db = DataBase.GPM_database()
# qD = gm.get("qD").copy()

# qD[gm.get("bra_ID_BX")] = qD[gm.get("bra_ID_BX")] + 0.25
# qD["Y_oil"] = qD["Y_oil"] - 1
# db["qD"] = qD

# DataBase.GPM_database.merge_dbs(gm.model.database, db, "second")
gm.write_and_run(name='ID_calibrate',kwargs_init={'check_variables':True},overwrite=True)
db = gm.model_instances['ID_calibrate'].out_db<jupyter_output><empty_output><jupyter_text>*Print some... Note that if the ID technologies do not have any overlap with other technologies, the calibration procedure only has one possible solution; i.e. there are not any room for really minimizing the minobj.*<jupyter_code>def compare_plots(db0,db,var):
    return pd.concat([db0.get(var).rename(f"{var}, B"),db.get(var).rename(f"{var}, C")],axis=1).plot.bar();
var = 'PwThat'
compare_plots(db0,db,var)
var = 'qD'
compare_plots(db0,db,var)
var="mu"
compare_plots(db0,db,var)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17964438994481913, 'fraction_numerical': 0.006948702227672185, 'mean_word_length': 8.046210720887245, 'pattern_counts': {'":': 3, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '535348', 'license': 'MIT', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1911, 'n_words': 280, 'path': 'examples/Abatement/A1_ID_Calib_jonathan2.ipynb', 'repo_name': 'ChampionApe/GPM_v05', 'size': '4893'}