Spaces:
Running
Running
Disable PythonCall GC during equation search
Browse files- pysr/julia_helpers.py +13 -0
- pysr/sr.py +9 -1
pysr/julia_helpers.py
CHANGED
|
@@ -1,6 +1,16 @@
|
|
| 1 |
"""Functions for initializing the Julia environment and installing deps."""
|
|
|
|
| 2 |
import warnings
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import juliacall
|
| 5 |
import juliapkg
|
| 6 |
|
|
@@ -8,6 +18,9 @@ jl = juliacall.newmodule("PySR")
|
|
| 8 |
|
| 9 |
from juliacall import convert as jl_convert
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
juliainfo = None
|
| 12 |
julia_initialized = False
|
| 13 |
julia_kwargs_at_initialization = None
|
|
|
|
| 1 |
"""Functions for initializing the Julia environment and installing deps."""
|
| 2 |
+
import os
|
| 3 |
import warnings
|
| 4 |
|
| 5 |
+
# Required to avoid segfaults (https://juliapy.github.io/PythonCall.jl/dev/faq/)
|
| 6 |
+
if os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] not in {"yes", ""}:
|
| 7 |
+
warnings.warn(
|
| 8 |
+
"PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set to something other than 'yes' or ''. "
|
| 9 |
+
+ "You will experience segfaults if running with multithreading."
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = "yes"
|
| 13 |
+
|
| 14 |
import juliacall
|
| 15 |
import juliapkg
|
| 16 |
|
|
|
|
| 18 |
|
| 19 |
from juliacall import convert as jl_convert
|
| 20 |
|
| 21 |
+
jl.seval("using PythonCall: PythonCall")
|
| 22 |
+
PythonCall = jl.PythonCall
|
| 23 |
+
|
| 24 |
juliainfo = None
|
| 25 |
julia_initialized = False
|
| 26 |
julia_kwargs_at_initialization = None
|
pysr/sr.py
CHANGED
|
@@ -32,7 +32,13 @@ from .export_numpy import sympy2numpy
|
|
| 32 |
from .export_sympy import assert_valid_sympy_symbol, create_sympy_symbols, pysr2sympy
|
| 33 |
from .export_torch import sympy2torch
|
| 34 |
from .feature_selection import run_feature_selection
|
| 35 |
-
from .julia_helpers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
from .utils import (
|
| 37 |
_csv_filename_to_pkl_filename,
|
| 38 |
_preprocess_julia_floats,
|
|
@@ -1716,6 +1722,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1716 |
jl.Vector, self.display_feature_names_in_.tolist()
|
| 1717 |
)
|
| 1718 |
|
|
|
|
| 1719 |
# Call to Julia backend.
|
| 1720 |
# See https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/SymbolicRegression.jl
|
| 1721 |
self.raw_julia_state_ = SymbolicRegression.equation_search(
|
|
@@ -1738,6 +1745,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1738 |
progress=progress and self.verbosity > 0 and len(y.shape) == 1,
|
| 1739 |
verbosity=int(self.verbosity),
|
| 1740 |
)
|
|
|
|
| 1741 |
|
| 1742 |
# Set attributes
|
| 1743 |
self.equations_ = self.get_hof()
|
|
|
|
| 32 |
from .export_sympy import assert_valid_sympy_symbol, create_sympy_symbols, pysr2sympy
|
| 33 |
from .export_torch import sympy2torch
|
| 34 |
from .feature_selection import run_feature_selection
|
| 35 |
+
from .julia_helpers import (
|
| 36 |
+
PythonCall,
|
| 37 |
+
_escape_filename,
|
| 38 |
+
_load_cluster_manager,
|
| 39 |
+
jl,
|
| 40 |
+
jl_convert,
|
| 41 |
+
)
|
| 42 |
from .utils import (
|
| 43 |
_csv_filename_to_pkl_filename,
|
| 44 |
_preprocess_julia_floats,
|
|
|
|
| 1722 |
jl.Vector, self.display_feature_names_in_.tolist()
|
| 1723 |
)
|
| 1724 |
|
| 1725 |
+
PythonCall.GC.disable()
|
| 1726 |
# Call to Julia backend.
|
| 1727 |
# See https://github.com/MilesCranmer/SymbolicRegression.jl/blob/master/src/SymbolicRegression.jl
|
| 1728 |
self.raw_julia_state_ = SymbolicRegression.equation_search(
|
|
|
|
| 1745 |
progress=progress and self.verbosity > 0 and len(y.shape) == 1,
|
| 1746 |
verbosity=int(self.verbosity),
|
| 1747 |
)
|
| 1748 |
+
PythonCall.GC.enable()
|
| 1749 |
|
| 1750 |
# Set attributes
|
| 1751 |
self.equations_ = self.get_hof()
|