Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib][Windows] Windows Invalid Directory Name Error in Ray RLlib #49477

Open
ufukyilmaz opened this issue Dec 28, 2024 · 0 comments
Open

[RLlib][Windows] Windows Invalid Directory Name Error in Ray RLlib #49477

ufukyilmaz opened this issue Dec 28, 2024 · 0 comments
Labels
bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component)

Comments

@ufukyilmaz
Copy link

ufukyilmaz commented Dec 28, 2024

What happened + What you expected to happen

I encountered a NotADirectoryError on creating the temp logging directory while experimenting with the Pong environment "ale_py:ALE/Pong-v5" in Ray RLlib. The error is caused by an unsanitized reserved character (:) in the environment name, which is invalid for directory names on Windows systems.
The env name should be sanitized to remove or replace reserved characters, ensuring that the directory name is valid on all operating systems.
Here is the exception that I encountered:

Traceback (most recent call last):
  File "<redacted_path>\atari.py", line 18, in <module>
    algo = config.build()
           ^^^^^^^^^^^^^^
  File "<redacted_path>\\.venv\Lib\site-packages\ray\rllib\algorithms\algorithm_config.py", line 949, in build
    return algo_class(
           ^^^^^^^^^^^
  File "<redacted_path>\.venv\Lib\site-packages\ray\rllib\algorithms\algorithm.py", line 549, in __init__
    logdir = tempfile.mkdtemp(prefix=logdir_prefix, dir=DEFAULT_STORAGE_PATH)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<redacted_path>\\Python311\Lib\tempfile.py", line 385, in mkdtemp
    _os.mkdir(file, 0o700)
NotADirectoryError: [WinError 267] The directory name is invalid: '<redacted_path>\/ray_results\\PPO_ale_py:ALE-Pong-v5_2024-12-28_16-20-57vy4q_uxa'

The directory name sanitization performed here is not enough to avoid having invalid directory names for the windows systems.

See the reference for the reserved characters in Windows here

...
< (less than)
> (greater than)
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

I can create a simple pull request with the following change to sanitize the environment name:

env_descr_for_dir = re.sub(r'[<>:"/\\|?*]', "-", str(env_descr))

However, I’d appreciate some guidance before proceeding. I wonder if you’d be happy with this solution or prefer a more comprehensive sanitization approach that also addresses other restrictions, such as name length. We can also consider using pathvalidate#sanitize or porting this function and tests.

Versions / Dependencies

OS: Windows

dependencies = [
   "gymnasium[atari]>=1.0.0",
   "ray[rllib]>=2.40.0",
   "torch>=2.5.1"
]

Reproduction script

from ray.rllib.algorithms import PPOConfig
from ray.rllib.connectors.env_to_module import FlattenObservations

config = (
    PPOConfig()
    .environment(
        "ale_py:ALE/Pong-v5"
    )  # Atari pong game
    .env_runners(
        num_env_runners=2,
        env_to_module_connector=lambda _: FlattenObservations(),
    )
    .evaluation(evaluation_num_env_runners=1)
)
algo = config.build()
for _ in range(5):
    print(algo.train())
algo.evaluate()

Issue Severity

Medium: It is a significant difficulty but I can work around it.

@ufukyilmaz ufukyilmaz added bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component)
Projects
None yet
Development

No branches or pull requests

1 participant