Spaces:
Running
Running
Johann Brehmer
commited on
Commit
·
6b04774
1
Parent(s):
edc0ef8
Escape backslashes in filenames written into julia script
Browse files- pysr/sr.py +10 -7
pysr/sr.py
CHANGED
|
@@ -12,7 +12,7 @@ import shutil
|
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
|
| 15 |
-
global_equation_file =
|
| 16 |
global_n_features = None
|
| 17 |
global_variable_names = []
|
| 18 |
global_extra_sympy_mappings = {}
|
|
@@ -251,7 +251,6 @@ def pysr(X=None, y=None, weights=None,
|
|
| 251 |
|
| 252 |
# Absolute paths are necessary for Windows support
|
| 253 |
pkg_directory = Path(__file__).parents[1] / 'julia'
|
| 254 |
-
equation_file = Path(equation_file)
|
| 255 |
|
| 256 |
def_hyperparams = ""
|
| 257 |
|
|
@@ -419,9 +418,9 @@ const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
|
|
| 419 |
print(def_datasets, file=f)
|
| 420 |
|
| 421 |
with open(runfile_filename, 'w') as f:
|
| 422 |
-
print(f'@everywhere include("{hyperparam_filename}")', file=f)
|
| 423 |
-
print(f'@everywhere include("{dataset_filename}")', file=f)
|
| 424 |
-
print(f'@everywhere include("{pkg_filename}")', file=f)
|
| 425 |
print(f'fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})', file=f)
|
| 426 |
print(f'rmprocs(nprocs)', file=f)
|
| 427 |
|
|
@@ -498,7 +497,7 @@ def get_hof(equation_file=None, n_features=None, variable_names=None, extra_symp
|
|
| 498 |
global_extra_sympy_mappings = extra_sympy_mappings
|
| 499 |
|
| 500 |
try:
|
| 501 |
-
output = pd.read_csv(
|
| 502 |
except FileNotFoundError:
|
| 503 |
print("Couldn't find equation file!")
|
| 504 |
return pd.DataFrame()
|
|
@@ -572,4 +571,8 @@ def best_callable(equations=None):
|
|
| 572 |
if equations is None: equations = get_hof()
|
| 573 |
return best_row(equations)['lambda_format']
|
| 574 |
|
| 575 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
|
| 15 |
+
global_equation_file = 'hall_of_fame.csv'
|
| 16 |
global_n_features = None
|
| 17 |
global_variable_names = []
|
| 18 |
global_extra_sympy_mappings = {}
|
|
|
|
| 251 |
|
| 252 |
# Absolute paths are necessary for Windows support
|
| 253 |
pkg_directory = Path(__file__).parents[1] / 'julia'
|
|
|
|
| 254 |
|
| 255 |
def_hyperparams = ""
|
| 256 |
|
|
|
|
| 418 |
print(def_datasets, file=f)
|
| 419 |
|
| 420 |
with open(runfile_filename, 'w') as f:
|
| 421 |
+
print(f'@everywhere include("{_escape_filename(hyperparam_filename)}")', file=f)
|
| 422 |
+
print(f'@everywhere include("{_escape_filename(dataset_filename)}")', file=f)
|
| 423 |
+
print(f'@everywhere include("{_escape_filename(pkg_filename)}")', file=f)
|
| 424 |
print(f'fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})', file=f)
|
| 425 |
print(f'rmprocs(nprocs)', file=f)
|
| 426 |
|
|
|
|
| 497 |
global_extra_sympy_mappings = extra_sympy_mappings
|
| 498 |
|
| 499 |
try:
|
| 500 |
+
output = pd.read_csv(equation_file + '.bkup', sep="|")
|
| 501 |
except FileNotFoundError:
|
| 502 |
print("Couldn't find equation file!")
|
| 503 |
return pd.DataFrame()
|
|
|
|
| 571 |
if equations is None: equations = get_hof()
|
| 572 |
return best_row(equations)['lambda_format']
|
| 573 |
|
| 574 |
+
def _escape_filename(filename):
|
| 575 |
+
"""Turns a file into a string representation with correctly escaped backslashes"""
|
| 576 |
+
repr = str(filename)
|
| 577 |
+
repr = repr.replace('\\', '\\\\')
|
| 578 |
+
return repr
|