Spaces:
Running
Running
Commit
·
d42f10b
1
Parent(s):
e644737
Don't activate env twice
Browse files- pysr/julia_helpers.py +10 -2
- pysr/sr.py +3 -10
pysr/julia_helpers.py
CHANGED
|
@@ -11,6 +11,7 @@ from .version import __version__, __symbolic_regression_jl_version__
|
|
| 11 |
juliainfo = None
|
| 12 |
julia_initialized = False
|
| 13 |
julia_kwargs_at_initialization = None
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
def _load_juliainfo():
|
|
@@ -148,12 +149,13 @@ def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
|
| 148 |
"""Initialize julia binary, turning off compiled modules if needed."""
|
| 149 |
global julia_initialized
|
| 150 |
global julia_kwargs_at_initialization
|
|
|
|
| 151 |
|
| 152 |
if not julia_initialized:
|
| 153 |
_check_for_conflicting_libraries()
|
| 154 |
|
| 155 |
if julia_kwargs is None:
|
| 156 |
-
julia_kwargs = {}
|
| 157 |
|
| 158 |
from julia.core import JuliaInfo, UnsupportedPythonError
|
| 159 |
|
|
@@ -188,6 +190,9 @@ def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
|
| 188 |
|
| 189 |
Main = _Main
|
| 190 |
|
|
|
|
|
|
|
|
|
|
| 191 |
if julia_initialized and julia_kwargs_at_initialization is not None:
|
| 192 |
# Check if the kwargs are the same as the previous initialization
|
| 193 |
init_set = set(julia_kwargs_at_initialization.items())
|
|
@@ -202,7 +207,7 @@ def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
|
| 202 |
+ " will be ignored."
|
| 203 |
)
|
| 204 |
|
| 205 |
-
if julia_initialized:
|
| 206 |
Main.eval("using Pkg")
|
| 207 |
|
| 208 |
io_arg = _get_io_arg(quiet)
|
|
@@ -214,6 +219,8 @@ def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
|
| 214 |
f"{io_arg})"
|
| 215 |
)
|
| 216 |
|
|
|
|
|
|
|
| 217 |
if not julia_initialized:
|
| 218 |
julia_kwargs_at_initialization = julia_kwargs
|
| 219 |
|
|
@@ -281,6 +288,7 @@ def _update_julia_project(Main, is_shared, io_arg):
|
|
| 281 |
try:
|
| 282 |
if is_shared:
|
| 283 |
_add_sr_to_julia_project(Main, io_arg)
|
|
|
|
| 284 |
Main.eval(f"Pkg.resolve({io_arg})")
|
| 285 |
except (JuliaError, RuntimeError) as e:
|
| 286 |
raise ImportError(_import_error()) from e
|
|
|
|
| 11 |
juliainfo = None
|
| 12 |
julia_initialized = False
|
| 13 |
julia_kwargs_at_initialization = None
|
| 14 |
+
julia_activated_env = None
|
| 15 |
|
| 16 |
|
| 17 |
def _load_juliainfo():
|
|
|
|
| 149 |
"""Initialize julia binary, turning off compiled modules if needed."""
|
| 150 |
global julia_initialized
|
| 151 |
global julia_kwargs_at_initialization
|
| 152 |
+
global julia_activated_env
|
| 153 |
|
| 154 |
if not julia_initialized:
|
| 155 |
_check_for_conflicting_libraries()
|
| 156 |
|
| 157 |
if julia_kwargs is None:
|
| 158 |
+
julia_kwargs = {"optimize": 3}
|
| 159 |
|
| 160 |
from julia.core import JuliaInfo, UnsupportedPythonError
|
| 161 |
|
|
|
|
| 190 |
|
| 191 |
Main = _Main
|
| 192 |
|
| 193 |
+
if julia_activated_env is None:
|
| 194 |
+
julia_activated_env = processed_julia_project
|
| 195 |
+
|
| 196 |
if julia_initialized and julia_kwargs_at_initialization is not None:
|
| 197 |
# Check if the kwargs are the same as the previous initialization
|
| 198 |
init_set = set(julia_kwargs_at_initialization.items())
|
|
|
|
| 207 |
+ " will be ignored."
|
| 208 |
)
|
| 209 |
|
| 210 |
+
if julia_initialized and julia_activated_env != processed_julia_project:
|
| 211 |
Main.eval("using Pkg")
|
| 212 |
|
| 213 |
io_arg = _get_io_arg(quiet)
|
|
|
|
| 219 |
f"{io_arg})"
|
| 220 |
)
|
| 221 |
|
| 222 |
+
julia_activated_env = processed_julia_project
|
| 223 |
+
|
| 224 |
if not julia_initialized:
|
| 225 |
julia_kwargs_at_initialization = julia_kwargs
|
| 226 |
|
|
|
|
| 288 |
try:
|
| 289 |
if is_shared:
|
| 290 |
_add_sr_to_julia_project(Main, io_arg)
|
| 291 |
+
Main.eval("using Pkg")
|
| 292 |
Main.eval(f"Pkg.resolve({io_arg})")
|
| 293 |
except (JuliaError, RuntimeError) as e:
|
| 294 |
raise ImportError(_import_error()) from e
|
pysr/sr.py
CHANGED
|
@@ -1495,20 +1495,13 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1495 |
if cluster_manager is not None:
|
| 1496 |
cluster_manager = _load_cluster_manager(cluster_manager)
|
| 1497 |
|
| 1498 |
-
if
|
| 1499 |
-
|
| 1500 |
-
Main.eval("using Pkg")
|
| 1501 |
io = "devnull" if update_verbosity == 0 else "stderr"
|
| 1502 |
io_arg = (
|
| 1503 |
f"io={io}" if is_julia_version_greater_eq(version=(1, 6, 0)) else ""
|
| 1504 |
)
|
| 1505 |
-
|
| 1506 |
-
Main.eval(
|
| 1507 |
-
f'Pkg.activate("{_escape_filename(julia_project)}", shared = Bool({int(is_shared)}), {io_arg})'
|
| 1508 |
-
)
|
| 1509 |
-
|
| 1510 |
-
if self.update:
|
| 1511 |
-
_update_julia_project(Main, is_shared, io_arg)
|
| 1512 |
|
| 1513 |
SymbolicRegression = _load_backend(Main)
|
| 1514 |
|
|
|
|
| 1495 |
if cluster_manager is not None:
|
| 1496 |
cluster_manager = _load_cluster_manager(cluster_manager)
|
| 1497 |
|
| 1498 |
+
if self.update:
|
| 1499 |
+
_, is_shared = _process_julia_project(self.julia_project)
|
|
|
|
| 1500 |
io = "devnull" if update_verbosity == 0 else "stderr"
|
| 1501 |
io_arg = (
|
| 1502 |
f"io={io}" if is_julia_version_greater_eq(version=(1, 6, 0)) else ""
|
| 1503 |
)
|
| 1504 |
+
_update_julia_project(Main, is_shared, io_arg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1505 |
|
| 1506 |
SymbolicRegression = _load_backend(Main)
|
| 1507 |
|