Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
43a345a
1
Parent(s):
a232b56
Revert "Implement DaemonMode for fast startup"
Browse filesThis reverts commit 009d206ffed02d647c4728d7ed6fd2cab5f4ca23.
- Project.toml +0 -1
- pysr/sr.py +14 -65
Project.toml
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
[deps]
|
2 |
-
DaemonMode = "d749ddd5-2b29-4920-8305-6ff5a704e36e"
|
3 |
SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
|
4 |
|
5 |
[compat]
|
|
|
1 |
[deps]
|
|
|
2 |
SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
|
3 |
|
4 |
[compat]
|
pysr/sr.py
CHANGED
@@ -13,8 +13,6 @@ import shutil
|
|
13 |
from pathlib import Path
|
14 |
from datetime import datetime
|
15 |
import warnings
|
16 |
-
import shlex
|
17 |
-
import time
|
18 |
|
19 |
global_state = dict(
|
20 |
equation_file="hall_of_fame.csv",
|
@@ -28,7 +26,6 @@ global_state = dict(
|
|
28 |
multioutput=False,
|
29 |
nout=1,
|
30 |
selection=None,
|
31 |
-
daemon=None,
|
32 |
)
|
33 |
|
34 |
sympy_mappings = {
|
@@ -135,7 +132,6 @@ def pysr(
|
|
135 |
tournament_selection_p=1.0,
|
136 |
denoise=False,
|
137 |
Xresampled=None,
|
138 |
-
daemon_mode=False,
|
139 |
):
|
140 |
"""Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
|
141 |
Note: most default parameters have been tuned over several example
|
@@ -252,10 +248,6 @@ def pysr(
|
|
252 |
:type tournament_selection_p: float
|
253 |
:param denoise: Whether to use a Gaussian Process to denoise the data before inputting to PySR. Can help PySR fit noisy data.
|
254 |
:type denoise: bool
|
255 |
-
:param Xresampled:
|
256 |
-
:type Xresampled: np.ndarray/None
|
257 |
-
:param daemon_mode: Whether to use DaemonMode.jl for Julia. This will let you quickly restart PySR between calls.
|
258 |
-
:type daemon_mode: bool
|
259 |
:returns: Results dataframe, giving complexity, MSE, and equations (as strings), as well as functional forms. If list, each element corresponds to a dataframe of equations for each output.
|
260 |
:type: pd.DataFrame/list
|
261 |
"""
|
@@ -418,7 +410,6 @@ def pysr(
|
|
418 |
tournament_selection_n=tournament_selection_n,
|
419 |
tournament_selection_p=tournament_selection_p,
|
420 |
denoise=denoise,
|
421 |
-
daemon_mode=daemon_mode,
|
422 |
)
|
423 |
|
424 |
kwargs = {**_set_paths(tempdir), **kwargs}
|
@@ -476,53 +467,12 @@ def _set_globals(X, **kwargs):
|
|
476 |
global_state[key] = value
|
477 |
|
478 |
|
479 |
-
def
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
s = "import Pkg;"
|
487 |
-
if need_install:
|
488 |
-
s += "Pkg.instantiate();"
|
489 |
-
s += "Pkg.update();"
|
490 |
-
s += "Pkg.precompile();"
|
491 |
-
elif update:
|
492 |
-
s += "Pkg.update();"
|
493 |
-
command = shlex.split(
|
494 |
-
f"julia --startup-file=no -O{julia_optimization:d} --project={julia_project} -e"
|
495 |
-
f" '{s}using DaemonMode; println(\"Julia server starting!\"); serve(3000, true)'"
|
496 |
-
)
|
497 |
-
print("Running on", " ".join(command))
|
498 |
-
process = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=-1)
|
499 |
-
while True:
|
500 |
-
line = process.stdout.readline()
|
501 |
-
if not line:
|
502 |
-
break
|
503 |
-
decoded_line = line.decode("utf-8")
|
504 |
-
print(decoded_line, end="")
|
505 |
-
if "Julia server starting!" in decoded_line:
|
506 |
-
break
|
507 |
-
|
508 |
-
time.sleep(5)
|
509 |
-
print("Finished starting Julia daemon.")
|
510 |
-
global_state["daemon"] = process
|
511 |
-
|
512 |
-
|
513 |
-
def _final_pysr_process(
|
514 |
-
julia_optimization, julia_project, runfile_filename, timeout, daemon_mode, **kwargs
|
515 |
-
):
|
516 |
-
if daemon_mode:
|
517 |
-
_start_julia_daemon(
|
518 |
-
julia_optimization=julia_optimization, julia_project=julia_project, **kwargs
|
519 |
-
)
|
520 |
-
command = shlex.split(
|
521 |
-
f"julia --startup-file=no --project={julia_project}"
|
522 |
-
f" -e 'using DaemonMode; runargs()' {runfile_filename}"
|
523 |
-
)
|
524 |
-
else:
|
525 |
-
command = shlex.split(f"julia -O{julia_optimization:d} {runfile_filename}")
|
526 |
if timeout is not None:
|
527 |
command = ["timeout", f"{timeout}"] + command
|
528 |
_cmd_runner(command, **kwargs)
|
@@ -573,7 +523,6 @@ def _create_julia_files(
|
|
573 |
pkg_directory,
|
574 |
need_install,
|
575 |
update,
|
576 |
-
daemon_mode,
|
577 |
**kwargs,
|
578 |
):
|
579 |
with open(hyperparam_filename, "w") as f:
|
@@ -585,14 +534,14 @@ def _create_julia_files(
|
|
585 |
julia_project = pkg_directory
|
586 |
else:
|
587 |
julia_project = Path(julia_project)
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
print(f"using SymbolicRegression", file=f)
|
597 |
print(f'include("{_escape_filename(hyperparam_filename)}")', file=f)
|
598 |
print(f'include("{_escape_filename(dataset_filename)}")', file=f)
|
|
|
13 |
from pathlib import Path
|
14 |
from datetime import datetime
|
15 |
import warnings
|
|
|
|
|
16 |
|
17 |
global_state = dict(
|
18 |
equation_file="hall_of_fame.csv",
|
|
|
26 |
multioutput=False,
|
27 |
nout=1,
|
28 |
selection=None,
|
|
|
29 |
)
|
30 |
|
31 |
sympy_mappings = {
|
|
|
132 |
tournament_selection_p=1.0,
|
133 |
denoise=False,
|
134 |
Xresampled=None,
|
|
|
135 |
):
|
136 |
"""Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
|
137 |
Note: most default parameters have been tuned over several example
|
|
|
248 |
:type tournament_selection_p: float
|
249 |
:param denoise: Whether to use a Gaussian Process to denoise the data before inputting to PySR. Can help PySR fit noisy data.
|
250 |
:type denoise: bool
|
|
|
|
|
|
|
|
|
251 |
:returns: Results dataframe, giving complexity, MSE, and equations (as strings), as well as functional forms. If list, each element corresponds to a dataframe of equations for each output.
|
252 |
:type: pd.DataFrame/list
|
253 |
"""
|
|
|
410 |
tournament_selection_n=tournament_selection_n,
|
411 |
tournament_selection_p=tournament_selection_p,
|
412 |
denoise=denoise,
|
|
|
413 |
)
|
414 |
|
415 |
kwargs = {**_set_paths(tempdir), **kwargs}
|
|
|
467 |
global_state[key] = value
|
468 |
|
469 |
|
470 |
+
def _final_pysr_process(julia_optimization, runfile_filename, timeout, **kwargs):
|
471 |
+
command = [
|
472 |
+
"julia",
|
473 |
+
f"-O{julia_optimization:d}",
|
474 |
+
str(runfile_filename),
|
475 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
if timeout is not None:
|
477 |
command = ["timeout", f"{timeout}"] + command
|
478 |
_cmd_runner(command, **kwargs)
|
|
|
523 |
pkg_directory,
|
524 |
need_install,
|
525 |
update,
|
|
|
526 |
**kwargs,
|
527 |
):
|
528 |
with open(hyperparam_filename, "w") as f:
|
|
|
534 |
julia_project = pkg_directory
|
535 |
else:
|
536 |
julia_project = Path(julia_project)
|
537 |
+
print(f"import Pkg", file=f)
|
538 |
+
print(f'Pkg.activate("{_escape_filename(julia_project)}")', file=f)
|
539 |
+
if need_install:
|
540 |
+
print(f"Pkg.instantiate()", file=f)
|
541 |
+
print("Pkg.update()", file=f)
|
542 |
+
print("Pkg.precompile()", file=f)
|
543 |
+
elif update:
|
544 |
+
print(f"Pkg.update()", file=f)
|
545 |
print(f"using SymbolicRegression", file=f)
|
546 |
print(f'include("{_escape_filename(hyperparam_filename)}")', file=f)
|
547 |
print(f'include("{_escape_filename(dataset_filename)}")', file=f)
|