Skip to content

Commit

Permalink
saving gams path in config
Browse files Browse the repository at this point in the history
  • Loading branch information
squoilin committed Jan 8, 2020
1 parent 8a687d1 commit d65a1d8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions dispaset/misc/gdx_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,23 @@ def _insert_symbols(gdxHandle, sets, parameters):
logging.debug('Set ' + s + ' successfully written')


def write_variables(gams_dir, gdx_out, list_vars):
def write_variables(config, gdx_out, list_vars):
"""
This function performs the following:
* Use the gdxcc library to create a gdxHandle instance
* Check that the gams path is well defined
* Call the 'insert_symbols' function to write all sets and parameters to gdxHandle
:param gams_dir: (Relative) path to the gams directory
:param config: Main config dictionary
:param gdx_out: (Relative) path to the gdx file to be written
:param list_vars: List with the sets and parameters to be written
"""
gams_dir = get_gams_path(gams_dir=gams_dir.encode())
gams_dir = get_gams_path(gams_dir=config['GAMS_folder'].encode())
if not gams_dir: # couldn't locate
logging.critical('GDXCC: Could not find the specified gams directory: ' + gams_dir)
sys.exit(1)
gams_dir = force_str(gams_dir)
config['GAMS_folder'] = gams_dir # updating the config dictionary
gdx_out = force_str(gdx_out)

gdxHandle = gdxcc.new_gdxHandle_tp()
Expand Down
2 changes: 1 addition & 1 deletion dispaset/postprocessing/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_sim_results(path='.', cache=None, temp_path=None, return_xarray=False, r
inputs['param_df'] = ds_to_df(inputs)

# We need to pass the dir in config if we run it in clusters. PBS script fail to autolocate
gams_dir = get_gams_path(gams_dir=inputs['config']['GAMS_folder'].encode()).encode()
gams_dir = get_gams_path(gams_dir=inputs['config']['GAMS_folder'].encode())
if not gams_dir: # couldn't locate
logging.error('GAMS path cannot be located. Cannot parse gdx files')
return False
Expand Down
6 changes: 3 additions & 3 deletions dispaset/preprocessing/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ def build_simulation(config, profiles=None):
# list_vars = []
gdx_out = "Inputs.gdx"
if config['WriteGDX']:
write_variables(config['GAMS_folder'], gdx_out, [sets, parameters])
write_variables(config, gdx_out, [sets, parameters])

# if the sim variable was not defined:
if 'sim' not in locals():
Expand Down Expand Up @@ -838,7 +838,7 @@ def adjust_capacity(inputs,tech_fuel,scaling=1,value=None,singleunit=False,write
with open(os.path.join(dest_path, 'Inputs.p'), 'wb') as pfile:
pickle.dump(SimData, pfile, protocol=pickle.HIGHEST_PROTOCOL)
if write_gdx:
write_variables(SimData['config']['GAMS_folder'], 'Inputs.gdx', [SimData['sets'], SimData['parameters']])
write_variables(SimData['config'], 'Inputs.gdx', [SimData['sets'], SimData['parameters']])
shutil.copy('Inputs.gdx', dest_path + '/')
os.remove('Inputs.gdx')
return SimData
Expand Down Expand Up @@ -904,7 +904,7 @@ def adjust_storage(inputs,tech_fuel,scaling=1,value=None,write_gdx=False,dest_pa
with open(os.path.join(dest_path, 'Inputs.p'), 'wb') as pfile:
cPickle.dump(SimData, pfile, protocol=cPickle.HIGHEST_PROTOCOL)
if write_gdx:
write_variables(SimData['config']['GAMS_folder'], 'Inputs.gdx', [SimData['sets'], SimData['parameters']])
write_variables(SimData['config'], 'Inputs.gdx', [SimData['sets'], SimData['parameters']])
shutil.copy('Inputs.gdx', dest_path + '/')
os.remove('Inputs.gdx')
return SimData
Expand Down

0 comments on commit d65a1d8

Please sign in to comment.