<jupyter_start><jupyter_text>*GmsPy.GmsModel* Small class used to execute GAMS models from Python. The class works through the GAMS Python API. The class is initialized with two main inputs specifiying (1) the workspace (where should GAMS run), (2) the GAMS options that the model should run with. ```pythonclass GmsPy.GmsModel:    def __init__(self, ws=None, options = {}, **kwargs):```* ```ws``` specifies the ```gams.GamsWorkspace``` that is available as attribute ```self.ws```. Can be initialized using (```None```, ```str```, ```gams.GamsWorkspace```).* ```options``` specifies the ```gams.GamsOptions``` that is available as attribute ```self.opt```. Uses three arguments: ```opt,opt_file,opt_name```.    * ```opt```: Can either be a string or an instance of ```gams.GamsOptions```. If it is a string, an options file is written to the working repository with the name ```opt_name``` (defaults to "options.opt" if non is provided).    * ```opt_file```: Initializes a ```gams.GamsOptions``` instance from the specified file.         If ```opt = opt_file = None``` an empty ```gams.GamsOptions``` instance is initialized.* ```**kwargs```: Are used to specify attributes to ```self.opt```.  1: Methods and properties The GmsModel class contains a few useful methods/properties that employ methods from the GAMS Python API:* ```self.work_folder```: Repository that GAMS executes in.* ```self.addlocal(placeholder,local)```: Defines a local variable used in GAMS code (with syntax %placeholder%).* ```self.add_job(run=None, runfile=None, options={})```: Defines a ```GamsJob``` from string (if ```run```) or from a file (if ```runfile```). The options are passed to the job.* ```self.run_job(options={})```: Runs the job ```self.job``` with gams options ```self.opt``` and passes ```options``` as kwargs. * ```self.run(run=None, runfile = None, options_add={},options_run = {}, db_as_gpy=True)```:  Adds a job from ```run``` or ```runfile``` and passes ```options_add```, then runs the job passing ```options_run```. If ```db_as_gpy``` the database with solutions from ```self.job.out_db``` are stored as a ```GpyDB``` database that can be accessed through ```self.out_db```.  2: Examples  Example 2.1: Run a gams model specified in a file. Use specific solver + add local variable *Initialize a model from the 'work folder'. Add that we want the 'cns' model to be solved using conopt4:*<jupyter_code>m = GmsPy.GmsModel(ws=d['work'], **{'cns': 'CONOPT4'})<jupyter_output><empty_output><jupyter_text>*This specific model needs a local variable that points to the relevant database:*<jupyter_code>repo = os.path.join(d['main'],'gams\\AbatementExample')
m.addlocal('V01_DB', os.path.join(repo,'V01_DB.gdx'))<jupyter_output><empty_output><jupyter_text>*Run model from file:*<jupyter_code>m.run(runfile = os.path.join(repo, 'CollectAndRun.gmy'))<jupyter_output><empty_output><jupyter_text>Example 2.2: Add a checkpoint *As before, initialize an instance and specify that we should use 'CONOPT4' to use 'cns' models:*<jupyter_code>m = GmsPy.GmsModel(ws=d['work'], **{'cns': 'CONOPT4'})<jupyter_output><empty_output><jupyter_text>*Add local:*<jupyter_code>repo = os.path.join(d['main'],'gams\\AbatementExample')
m.addlocal('V01_DB', os.path.join(repo,'V01_DB.gdx'))<jupyter_output><empty_output><jupyter_text>*Initialize an empty checkpoint:*<jupyter_code>cp = m.ws.add_checkpoint()<jupyter_output><empty_output><jupyter_text>*Add checkpoint to run statement:*<jupyter_code>m.run(runfile = os.path.join(repo, 'CollectAndRun.gmy'), options_run = {'checkpoint':cp})
db_before = m.out_db<jupyter_output><empty_output><jupyter_text>*We can initialize a new run from this checkpoint by adding it to a new job. Here, we increase the price on capital by 50%:*<jupyter_code>run = f"""pD.fx[s,n]$(v01_dur[s,n]) = pD.l[s,n]*1.5;
solve V01_B using CNS;"""
m.run(run = run, options_add = {'checkpoint': cp})<jupyter_output><empty_output><jupyter_text>*We can now check how much demand for the inputs have changed:*<jupyter_code>pd.DataFrame({'Before': rc_pd(db_before['qD'],m.out_db['V01_inp']), 
              'After':  rc_pd(m.out_db['qD'], m.out_db['V01_inp'])}).plot.bar();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16873508353221958, 'fraction_numerical': 0.0076372315035799524, 'mean_word_length': 6.4973166368515205, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '603941', 'license': 'MIT', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1421, 'n_words': 412, 'path': 'Class_GmsPy_GmsModel.ipynb', 'repo_name': 'ChampionApe/GPM_v06', 'size': '4190'}