Skip to content

Commit 78ba790

Browse files
committed
Sanitize wisdom file name in tune.py
1 parent e101642 commit 78ba790

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

python/kernel_launcher/wisdom.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import math
55
import numpy as np
66
import os.path
7+
import re
78
import socket
89
import subprocess
910

@@ -223,10 +224,11 @@ def _convert_config(config: dict, keys: list):
223224

224225

225226
def _wisdom_file(path, key):
226-
if os.path.isdir(path) and key is not None:
227-
return os.path.join(path, key + ".wisdom")
228-
elif path.endswith(".wisdom"):
227+
if path.endswith(".wisdom"):
229228
return path
229+
elif os.path.isdir(path) and key is not None:
230+
filename = re.sub("[^0-9a-zA-Z_.-]", "_", key) + ".wisdom"
231+
return os.path.join(path, filename)
230232
else:
231233
raise ValueError(f"path must be a directory or a file ending with .wisdom: {path}")
232234

0 commit comments

Comments
 (0)