Spaces:
Running
Running
Commit
·
4300bea
1
Parent(s):
d927d58
Tell user if Julia initialized with different params
Browse files- pysr/julia_helpers.py +22 -1
- pysr/sr.py +1 -2
pysr/julia_helpers.py
CHANGED
|
@@ -10,6 +10,7 @@ from .version import __version__, __symbolic_regression_jl_version__
|
|
| 10 |
|
| 11 |
juliainfo = None
|
| 12 |
julia_initialized = False
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def _load_juliainfo():
|
|
@@ -146,6 +147,7 @@ def _check_for_conflicting_libraries(): # pragma: no cover
|
|
| 146 |
def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
| 147 |
"""Initialize julia binary, turning off compiled modules if needed."""
|
| 148 |
global julia_initialized
|
|
|
|
| 149 |
|
| 150 |
if not julia_initialized:
|
| 151 |
_check_for_conflicting_libraries()
|
|
@@ -180,11 +182,27 @@ def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
|
| 180 |
Main = _Main
|
| 181 |
except UnsupportedPythonError:
|
| 182 |
# Static python binary, so we turn off pre-compiled modules.
|
| 183 |
-
|
|
|
|
| 184 |
from julia import Main as _Main
|
| 185 |
|
| 186 |
Main = _Main
|
| 187 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
if julia_initialized:
|
| 189 |
Main.eval("using Pkg")
|
| 190 |
|
|
@@ -197,6 +215,9 @@ def init_julia(julia_project=None, quiet=False, julia_kwargs=None):
|
|
| 197 |
f"{io_arg})"
|
| 198 |
)
|
| 199 |
|
|
|
|
|
|
|
|
|
|
| 200 |
julia_initialized = True
|
| 201 |
return Main
|
| 202 |
|
|
|
|
| 10 |
|
| 11 |
juliainfo = None
|
| 12 |
julia_initialized = False
|
| 13 |
+
julia_kwargs_at_initialization = None
|
| 14 |
|
| 15 |
|
| 16 |
def _load_juliainfo():
|
|
|
|
| 147 |
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()
|
|
|
|
| 182 |
Main = _Main
|
| 183 |
except UnsupportedPythonError:
|
| 184 |
# Static python binary, so we turn off pre-compiled modules.
|
| 185 |
+
julia_kwargs = {**julia_kwargs, "compiled_modules": False}
|
| 186 |
+
jl = Julia(**julia_kwargs)
|
| 187 |
from julia import Main as _Main
|
| 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 |
+
if julia_kwargs_at_initialization != julia_kwargs:
|
| 194 |
+
# Record different kwargs:
|
| 195 |
+
init_set = set(julia_kwargs_at_initialization.items())
|
| 196 |
+
new_set = set(julia_kwargs.items())
|
| 197 |
+
set_diff = new_set - init_set
|
| 198 |
+
# Remove the `compiled_modules` key, since it is not a user-specified kwarg:
|
| 199 |
+
set_diff = {k: v for k, v in set_diff if k != "compiled_modules"}
|
| 200 |
+
warnings.warn(
|
| 201 |
+
"Julia has already started. The new Julia options "
|
| 202 |
+
+ str(set_diff)
|
| 203 |
+
+ " will be ignored."
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
if julia_initialized:
|
| 207 |
Main.eval("using Pkg")
|
| 208 |
|
|
|
|
| 215 |
f"{io_arg})"
|
| 216 |
)
|
| 217 |
|
| 218 |
+
if not julia_initialized:
|
| 219 |
+
julia_kwargs_at_initialization = julia_kwargs
|
| 220 |
+
|
| 221 |
julia_initialized = True
|
| 222 |
return Main
|
| 223 |
|
pysr/sr.py
CHANGED
|
@@ -1490,8 +1490,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1490 |
julia_kwargs = mutated_params["julia_kwargs"]
|
| 1491 |
|
| 1492 |
# Start julia backend processes
|
| 1493 |
-
|
| 1494 |
-
Main = init_julia(self.julia_project, julia_kwargs=julia_kwargs)
|
| 1495 |
|
| 1496 |
if cluster_manager is not None:
|
| 1497 |
cluster_manager = _load_cluster_manager(cluster_manager)
|
|
|
|
| 1490 |
julia_kwargs = mutated_params["julia_kwargs"]
|
| 1491 |
|
| 1492 |
# Start julia backend processes
|
| 1493 |
+
Main = init_julia(self.julia_project, julia_kwargs=julia_kwargs)
|
|
|
|
| 1494 |
|
| 1495 |
if cluster_manager is not None:
|
| 1496 |
cluster_manager = _load_cluster_manager(cluster_manager)
|