<jupyter_start><jupyter_text>**Static, partial equilibrium model** **Production module, example 2:***In some cases, it can be usefull to allow for a sector to use the same type of inputs more than once in the nesting tree (see the AbatementProject for an example). In such a case, the prices and quantities of the sector are defined over different, but overlapping sets. This example shows how to adjust the nesting trees, and subsequently the production module to account for this.**In this example, a sector uses $E_i$-types of input with $i\in\lbrace 1,2\rbrace$, and $B_j$-types with $j\in \lbrace 1,2\rbrace$. However, $B_j$ are utilized under both $E_i$ branches. Thus there are components of the form 'Ei_Bj' that mesaures the use of $B_j$ under branch $E_i$.* Import standard collection of packages:<jupyter_code>clean_up=True # removes gams-related files in work-folder if true
%run StdPackages.ipynb<jupyter_output>The file_gams_py_gdb1.gdx is still active and was not deleted.<jupyter_text>**Nesting structure:** *Nesting trees:*<jupyter_code>tree_in = {'Y': ['E1', 'E2'],
           'E1': ['E1_B1','E1_B2','K'],
           'E2': ['E2_B1','E2_B2']}
tree_out = {'Y': ['Y1','Y2']}<jupyter_output><empty_output><jupyter_text>*Initialize empty class with some name:*<jupyter_code>nt = nesting_tree.nesting_tree(name='test')<jupyter_output><empty_output><jupyter_text>*Add trees to the class. Note that the 'input' tree is now of version Q2P, whereas the output-type is standard ('std'):*<jupyter_code>nt.add_tree(tree_in,'in',**{'tree_name': 'test_in','version': 'Q2P'})
nt.add_tree(tree_out,'out',**{'tree_name': 'test_out','type_io': 'output','version': 'std'})<jupyter_output><empty_output><jupyter_text>*Define the Q2P settings. This includes a multiindex (mapping) from Ei_Bj types to Bj types, included in a dictionary for the trees:*<jupyter_code>q2p = pd.MultiIndex.from_tuples([('E1_B1', 'B1'), ('E1_B2', 'B2'),('E2_B1', 'B1'), ('E2_B2','B2')],names=['n','nn'])
Q2Ps = {'in': q2p}<jupyter_output><empty_output><jupyter_text>*Run all, with Q2Ps settings:*<jupyter_code>nt.run_all(Q2Ps=Q2Ps)<jupyter_output><empty_output><jupyter_text>**Create production module:** *Partial equilibrium model, production module from nesting tree:*<jupyter_code>pm = PE.GPM_STA_PE.production(nt,**{'work_folder': work_folder})<jupyter_output><empty_output><jupyter_text>*Write gams files to a repo called TESTS/example_1, and export the 'settings' as well:*<jupyter_code>pm.df_write(repo=os.getcwd()+'\\PE_P\\Example_2')<jupyter_output><empty_output><jupyter_text>*Create model instance and run:*<jupyter_code>pm.create_model_instance()
pm.df_run()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14584891548242335, 'fraction_numerical': 0.016080777860882575, 'mean_word_length': 7.465189873417722, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '6200', 'license': 'MIT', 'n_tokens_mistral': 974, 'n_tokens_neox': 951, 'n_words': 248, 'path': 'Examples/PE_Production_2.ipynb', 'repo_name': 'ChampionApe/GamsPythonModels', 'size': '2674'}