Spaces:
Sleeping
Sleeping
Johann Brehmer
commited on
Commit
•
5290229
1
Parent(s):
0a0cfdc
Absolute paths for equations file and Julia package
Browse files- pysr/sr.py +11 -10
pysr/sr.py
CHANGED
@@ -11,7 +11,8 @@ import tempfile
|
|
11 |
import shutil
|
12 |
from pathlib import Path
|
13 |
|
14 |
-
|
|
|
15 |
global_n_features = None
|
16 |
global_variable_names = []
|
17 |
global_extra_sympy_mappings = {}
|
@@ -248,7 +249,7 @@ def pysr(X=None, y=None, weights=None,
|
|
248 |
y = eval(eval_str)
|
249 |
print("Running on", eval_str)
|
250 |
|
251 |
-
pkg_directory =
|
252 |
|
253 |
def_hyperparams = ""
|
254 |
|
@@ -280,7 +281,7 @@ def pysr(X=None, y=None, weights=None,
|
|
280 |
elif op == 'mult':
|
281 |
# Make sure the complex expression is in the left side.
|
282 |
if constraints[op][0] == -1:
|
283 |
-
continue
|
284 |
elif constraints[op][1] == -1 or constraints[op][0] < constraints[op][1]:
|
285 |
constraints[op][0], constraints[op][1] = constraints[op][1], constraints[op][0]
|
286 |
|
@@ -402,12 +403,12 @@ const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
|
|
402 |
|
403 |
# Get temporary directory in a system-independent way
|
404 |
tmpdirname = tempfile.mkdtemp(dir=tempdir)
|
405 |
-
#with tempfile.TemporaryDirectory(dir=tempdir) as tmpdirname:
|
406 |
tmpdir = Path(tmpdirname)
|
407 |
|
408 |
-
hyperparam_filename =
|
409 |
-
dataset_filename =
|
410 |
-
runfile_filename =
|
|
|
411 |
|
412 |
with open(hyperparam_filename, 'w') as f:
|
413 |
print(def_hyperparams, file=f)
|
@@ -415,10 +416,10 @@ const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
|
|
415 |
with open(dataset_filename, 'w') as f:
|
416 |
print(def_datasets, file=f)
|
417 |
|
418 |
-
with open(
|
419 |
print(f'@everywhere include("{hyperparam_filename}")', file=f)
|
420 |
print(f'@everywhere include("{dataset_filename}")', file=f)
|
421 |
-
print(f'@everywhere include("{
|
422 |
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)
|
423 |
print(f'rmprocs(nprocs)', file=f)
|
424 |
|
@@ -426,7 +427,7 @@ const varMap = {'["' + '", "'.join(variable_names) + '"]'}"""
|
|
426 |
command = [
|
427 |
f'julia', f'-O{julia_optimization:d}',
|
428 |
f'-p', f'{procs}',
|
429 |
-
runfile_filename,
|
430 |
]
|
431 |
if timeout is not None:
|
432 |
command = [f'timeout', f'{timeout}'] + command
|
|
|
11 |
import shutil
|
12 |
from pathlib import Path
|
13 |
|
14 |
+
|
15 |
+
global_equation_file = str(Path(__file__).parents[1] / 'hall_of_fame.csv')
|
16 |
global_n_features = None
|
17 |
global_variable_names = []
|
18 |
global_extra_sympy_mappings = {}
|
|
|
249 |
y = eval(eval_str)
|
250 |
print("Running on", eval_str)
|
251 |
|
252 |
+
pkg_directory = Path(__file__).parents[1] / 'julia'
|
253 |
|
254 |
def_hyperparams = ""
|
255 |
|
|
|
281 |
elif op == 'mult':
|
282 |
# Make sure the complex expression is in the left side.
|
283 |
if constraints[op][0] == -1:
|
284 |
+
continue
|
285 |
elif constraints[op][1] == -1 or constraints[op][0] < constraints[op][1]:
|
286 |
constraints[op][0], constraints[op][1] = constraints[op][1], constraints[op][0]
|
287 |
|
|
|
403 |
|
404 |
# Get temporary directory in a system-independent way
|
405 |
tmpdirname = tempfile.mkdtemp(dir=tempdir)
|
|
|
406 |
tmpdir = Path(tmpdirname)
|
407 |
|
408 |
+
hyperparam_filename = tmpdir / f'.hyperparams_{rand_string}.jl'
|
409 |
+
dataset_filename = tmpdir / f'.dataset_{rand_string}.jl'
|
410 |
+
runfile_filename = tmpdir / f'.runfile_{rand_string}.jl'
|
411 |
+
pkg_filename = pkg_directory / "sr.jl"
|
412 |
|
413 |
with open(hyperparam_filename, 'w') as f:
|
414 |
print(def_hyperparams, file=f)
|
|
|
416 |
with open(dataset_filename, 'w') as f:
|
417 |
print(def_datasets, file=f)
|
418 |
|
419 |
+
with open(runfile_filename, 'w') as f:
|
420 |
print(f'@everywhere include("{hyperparam_filename}")', file=f)
|
421 |
print(f'@everywhere include("{dataset_filename}")', file=f)
|
422 |
+
print(f'@everywhere include("{pkg_filename}")', file=f)
|
423 |
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)
|
424 |
print(f'rmprocs(nprocs)', file=f)
|
425 |
|
|
|
427 |
command = [
|
428 |
f'julia', f'-O{julia_optimization:d}',
|
429 |
f'-p', f'{procs}',
|
430 |
+
str(runfile_filename),
|
431 |
]
|
432 |
if timeout is not None:
|
433 |
command = [f'timeout', f'{timeout}'] + command
|