Spaces:
Running
Running
File size: 2,093 Bytes
caf58a4 fd4c500 caf58a4 b96e8d3 caf58a4 b7ca126 7acebb6 caf58a4 b7ca126 7acebb6 b7ca126 7acebb6 b7ca126 7acebb6 b7ca126 2600822 52f940c a664d90 52f940c fd4c500 cb76a81 52f940c e957e34 59d9435 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import os
import sys
import warnings
from types import ModuleType
from typing import cast
# Check if JuliaCall is already loaded, and if so, warn the user
# about the relevant environment variables. If not loaded,
# set up sensible defaults.
if "juliacall" in sys.modules:
warnings.warn(
"juliacall module already imported. "
"Make sure that you have set the environment variable `PYTHON_JULIACALL_HANDLE_SIGNALS=yes` to avoid segfaults. "
"Also note that PySR will not be able to configure `PYTHON_JULIACALL_THREADS` or `PYTHON_JULIACALL_OPTLEVEL` for you."
)
else:
# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
if os.environ.get("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes") != "yes":
warnings.warn(
"PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. "
+ "You will experience segfaults if running with multithreading."
)
if os.environ.get("PYTHON_JULIACALL_THREADS", "auto") != "auto":
warnings.warn(
"PYTHON_JULIACALL_THREADS environment variable is set to something other than 'auto', "
"so PySR was not able to set it. You may wish to set it to `'auto'` for full use "
"of your CPU."
)
# TODO: Remove these when juliapkg lets you specify this
for k, default in (
("PYTHON_JULIACALL_HANDLE_SIGNALS", "yes"),
("PYTHON_JULIACALL_THREADS", "auto"),
("PYTHON_JULIACALL_OPTLEVEL", "3"),
):
os.environ[k] = os.environ.get(k, default)
autoload_extensions = os.environ.get("PYSR_AUTOLOAD_EXTENSIONS")
if autoload_extensions is not None:
# Deprecated; so just pass to juliacall
os.environ["PYTHON_JULIACALL_AUTOLOAD_IPYTHON_EXTENSION"] = autoload_extensions
from juliacall import Main as jl # type: ignore
jl = cast(ModuleType, jl)
jl_version = (jl.VERSION.major, jl.VERSION.minor, jl.VERSION.patch)
jl.seval("using SymbolicRegression")
SymbolicRegression = jl.SymbolicRegression
jl.seval("using Pkg: Pkg")
Pkg = jl.Pkg
|