Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
b7ca126
1
Parent(s):
5a99aa3
Only show warnings if juliacall not yet imported
Browse files- pysr/julia_import.py +25 -33
pysr/julia_import.py
CHANGED
@@ -4,40 +4,32 @@ import warnings
|
|
4 |
|
5 |
if "juliacall" in sys.modules:
|
6 |
warnings.warn(
|
7 |
-
"juliacall module already imported.
|
|
|
|
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
if os.environ.get("JULIA_NUM_THREADS", "auto") != "auto":
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
# TODO: Remove these when juliapkg lets you specify this
|
25 |
-
for k, default in (
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
def is_in_jupyter() -> bool:
|
34 |
-
return hasattr(__builtins__, "__IPYTHON__")
|
35 |
-
|
36 |
-
|
37 |
-
if is_in_jupyter():
|
38 |
-
from IPython import get_ipython
|
39 |
-
|
40 |
-
get_ipython().run_line_magic("load_ext", "juliacall")
|
41 |
|
42 |
|
43 |
from juliacall import Main as jl # type: ignore
|
|
|
4 |
|
5 |
if "juliacall" in sys.modules:
|
6 |
warnings.warn(
|
7 |
+
"juliacall module already imported. "
|
8 |
+
"Make sure that you have set the environment variable `PYTHON_JULIACALL_HANDLE_SIGNALS=yes` to avoid segfaults. "
|
9 |
+
"Also note that PySR will not be able to configure `JULIA_NUM_THREADS` or `JULIA_OPTIMIZE` for you."
|
10 |
)
|
11 |
+
else:
|
12 |
+
# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
|
13 |
+
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes") != "yes":
|
14 |
+
warnings.warn(
|
15 |
+
"PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. "
|
16 |
+
+ "You will experience segfaults if running with multithreading."
|
17 |
+
)
|
18 |
+
|
19 |
+
if os.environ.get("JULIA_NUM_THREADS", "auto") != "auto":
|
20 |
+
warnings.warn(
|
21 |
+
"JULIA_NUM_THREADS environment variable is set to something other than 'auto', "
|
22 |
+
"so PySR was not able to set it. You may wish to set it to `'auto'` for full use "
|
23 |
+
"of your CPU."
|
24 |
+
)
|
25 |
+
|
26 |
+
# TODO: Remove these when juliapkg lets you specify this
|
27 |
+
for k, default in (
|
28 |
+
("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes"),
|
29 |
+
("JULIA_NUM_THREADS", "auto"),
|
30 |
+
("JULIA_OPTIMIZE", "3"),
|
31 |
+
):
|
32 |
+
os.environ[k] = os.environ.get(k, default)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
|
35 |
from juliacall import Main as jl # type: ignore
|