ugr-sail / sinergym

Gym environment for building simulation and control using reinforcement learning
https://ugr-sail.github.io/sinergym/
MIT License
131 stars 35 forks source link

[Bug]: Unhandled Critical Section for applying parallelism in Sinergym experiments. #423

Closed AlejandroCN7 closed 3 months ago

AlejandroCN7 commented 3 months ago

Bug 🐛

Initially, Sinergym was not designed to run multiple experiments in parallel on a single machine. The intended use was to run one experiment per machine.

However, running multiple experiments in parallel is a common use case that needs to be addressed. Parallelism can generally be applied to Sinergym using typical libraries like multiprocessing, as each execution is saved in a separate output folder, meaning there are no shared factors between processes that could cause errors.

There is one exception: the creation of output folder names. If two or more processes attempt to create the same folder simultaneously, this can result in errors due to the FileExistsError.

To Reproduce

You can test this by using multiprocessing to create many environments simultaneously. You will find that some folders may not be created, and you'll encounter this type of error:

Captura desde 2024-07-03 14-00-49

Expected behavior

To resolve this, the critical section handling described earlier should ensure that all folders are created without issues.

Checklist

:pencil: Please, don't forget to include more labels besides bug if it is necessary.