Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
caf58a4
1
Parent(s):
7aa7884
Ensure julia is loaded as soon as possible
Browse files- pysr/__init__.py +7 -1
- pysr/julia_helpers.py +2 -33
- pysr/julia_import.py +32 -0
- pysr/sr.py +1 -1
pysr/__init__.py
CHANGED
@@ -1,8 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from . import sklearn_monkeypatch
|
2 |
from .deprecated import best, best_callable, best_row, best_tex, pysr
|
3 |
from .export_jax import sympy2jax
|
4 |
from .export_torch import sympy2torch
|
5 |
-
from .sr import PySRRegressor
|
6 |
|
7 |
# This file is created by setuptools_scm during the build process:
|
8 |
from .version import __version__
|
@@ -20,4 +25,5 @@ __all__ = [
|
|
20 |
"best_tex",
|
21 |
"pysr",
|
22 |
"__version__",
|
|
|
23 |
]
|
|
|
1 |
+
# This must be imported as early as possible to prevent
|
2 |
+
# library linking issues caused by numpy/pytorch/etc. importing
|
3 |
+
# old libraries:
|
4 |
+
from .julia_import import jl # isort:skip
|
5 |
+
|
6 |
from . import sklearn_monkeypatch
|
7 |
from .deprecated import best, best_callable, best_row, best_tex, pysr
|
8 |
from .export_jax import sympy2jax
|
9 |
from .export_torch import sympy2torch
|
10 |
+
from .sr import PySRRegressor
|
11 |
|
12 |
# This file is created by setuptools_scm during the build process:
|
13 |
from .version import __version__
|
|
|
25 |
"best_tex",
|
26 |
"pysr",
|
27 |
"__version__",
|
28 |
+
"jl",
|
29 |
]
|
pysr/julia_helpers.py
CHANGED
@@ -1,39 +1,8 @@
|
|
1 |
"""Functions for initializing the Julia environment and installing deps."""
|
2 |
-
import os
|
3 |
-
import sys
|
4 |
-
import warnings
|
5 |
-
|
6 |
-
if "juliacall" in sys.modules:
|
7 |
-
warnings.warn(
|
8 |
-
"juliacall module already imported. Make sure that you have set `PYTHON_JULIACALL_HANDLE_SIGNALS=yes` to avoid segfaults."
|
9 |
-
)
|
10 |
-
|
11 |
-
# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
|
12 |
-
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes") != "yes":
|
13 |
-
warnings.warn(
|
14 |
-
"PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. "
|
15 |
-
+ "You will experience segfaults if running with multithreading."
|
16 |
-
)
|
17 |
-
|
18 |
-
if os.environ.get("JULIA_NUM_THREADS", "auto") != "auto":
|
19 |
-
warnings.warn(
|
20 |
-
"JULIA_NUM_THREADS environment variable is set to something other than 'auto', "
|
21 |
-
"so PySR was not able to set it. You may wish to set it to `'auto'` for full use "
|
22 |
-
"of your CPU."
|
23 |
-
)
|
24 |
-
|
25 |
-
# TODO: Remove these when juliapkg lets you specify this
|
26 |
-
for k, default in (
|
27 |
-
("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes"),
|
28 |
-
("JULIA_NUM_THREADS", "auto"),
|
29 |
-
("JULIA_OPTIMIZE", "3"),
|
30 |
-
):
|
31 |
-
os.environ[k] = os.environ.get(k, default)
|
32 |
-
|
33 |
-
|
34 |
-
from juliacall import Main as jl # type: ignore
|
35 |
from juliacall import convert as jl_convert # type: ignore
|
36 |
|
|
|
|
|
37 |
jl.seval("using Serialization: Serialization")
|
38 |
jl.seval("using PythonCall: PythonCall")
|
39 |
|
|
|
1 |
"""Functions for initializing the Julia environment and installing deps."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from juliacall import convert as jl_convert # type: ignore
|
3 |
|
4 |
+
from .julia_import import jl
|
5 |
+
|
6 |
jl.seval("using Serialization: Serialization")
|
7 |
jl.seval("using PythonCall: PythonCall")
|
8 |
|
pysr/julia_import.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import warnings
|
4 |
+
|
5 |
+
if "juliacall" in sys.modules:
|
6 |
+
warnings.warn(
|
7 |
+
"juliacall module already imported. Make sure that you have set `PYTHON_JULIACALL_HANDLE_SIGNALS=yes` to avoid segfaults."
|
8 |
+
)
|
9 |
+
|
10 |
+
# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
|
11 |
+
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes") != "yes":
|
12 |
+
warnings.warn(
|
13 |
+
"PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. "
|
14 |
+
+ "You will experience segfaults if running with multithreading."
|
15 |
+
)
|
16 |
+
|
17 |
+
if os.environ.get("JULIA_NUM_THREADS", "auto") != "auto":
|
18 |
+
warnings.warn(
|
19 |
+
"JULIA_NUM_THREADS environment variable is set to something other than 'auto', "
|
20 |
+
"so PySR was not able to set it. You may wish to set it to `'auto'` for full use "
|
21 |
+
"of your CPU."
|
22 |
+
)
|
23 |
+
|
24 |
+
# TODO: Remove these when juliapkg lets you specify this
|
25 |
+
for k, default in (
|
26 |
+
("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes"),
|
27 |
+
("JULIA_NUM_THREADS", "auto"),
|
28 |
+
("JULIA_OPTIMIZE", "3"),
|
29 |
+
):
|
30 |
+
os.environ[k] = os.environ.get(k, default)
|
31 |
+
|
32 |
+
from juliacall import Main as jl # type: ignore
|
pysr/sr.py
CHANGED
@@ -35,10 +35,10 @@ from .feature_selection import run_feature_selection
|
|
35 |
from .julia_helpers import (
|
36 |
_escape_filename,
|
37 |
_load_cluster_manager,
|
38 |
-
jl,
|
39 |
jl_array,
|
40 |
jl_deserialize_s,
|
41 |
)
|
|
|
42 |
from .utils import (
|
43 |
_csv_filename_to_pkl_filename,
|
44 |
_preprocess_julia_floats,
|
|
|
35 |
from .julia_helpers import (
|
36 |
_escape_filename,
|
37 |
_load_cluster_manager,
|
|
|
38 |
jl_array,
|
39 |
jl_deserialize_s,
|
40 |
)
|
41 |
+
from .julia_import import jl
|
42 |
from .utils import (
|
43 |
_csv_filename_to_pkl_filename,
|
44 |
_preprocess_julia_floats,
|