Skip to content

Commit

Permalink
(v3.4.0) Sinergym parallelism on the same machine (#424)
Browse files Browse the repository at this point in the history
* Modeling: Applying fcntl functionality to output folder name creation for robust parallelism

* Add .lock file to gitignore

* Updated Sinergym version from 3.3.8 to 3.4.0
  • Loading branch information
AlejandroCN7 committed Jul 3, 2024
1 parent d7d8c6e commit 13df06c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ codecov
coverage.xml

#wandb
wandb/
wandb/

#fcntl
.lock
26 changes: 18 additions & 8 deletions sinergym/config/modeling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Class and utilities for backend modeling in Python with Sinergym (extra params, weather_variability, building model modification and files management)"""
import fcntl
import json
import os
import random
Expand Down Expand Up @@ -525,14 +526,23 @@ def _set_experiment_working_dir(self, env_name: str) -> str:
Returns:
str: Experiment path for directory created.
"""
# Generate experiment dir path
experiment_path = self._get_working_folder(
directory_path=CWD,
base_name='-%s-res' %
(env_name))
# Create dir
os.makedirs(experiment_path)
# set path like config attribute
# CRITICAL SECTION for paralell execution
# In order to avoid several folders with the same name
with open(CWD + '/.lock', 'w') as f:
# Exclusive lock
fcntl.flock(f, fcntl.LOCK_EX)
try:
# Generate experiment dir path
experiment_path = self._get_working_folder(
directory_path=CWD,
base_name='-%s-res' %
(env_name))
# Create dir
os.makedirs(experiment_path)
finally:
# Release lock
fcntl.flock(f, fcntl.LOCK_UN)
# Set path like config attribute
self.experiment_path = experiment_path

self.logger.info(
Expand Down
2 changes: 1 addition & 1 deletion sinergym/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.8
3.4.0

0 comments on commit 13df06c

Please sign in to comment.