Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
4ee8cdb
1
Parent(s):
b046fc8
Refactor backend version check
Browse files- pysr/julia_helpers.py +25 -20
pysr/julia_helpers.py
CHANGED
@@ -71,7 +71,7 @@ def install(julia_project=None, quiet=False): # pragma: no cover
|
|
71 |
"""
|
72 |
import julia
|
73 |
|
74 |
-
|
75 |
# Set JULIA_PROJECT so that we install in the pysr environment
|
76 |
processed_julia_project, is_shared = _process_julia_project(julia_project)
|
77 |
_set_julia_project_env(processed_julia_project, is_shared)
|
@@ -158,7 +158,7 @@ def init_julia(julia_project=None, quiet=False):
|
|
158 |
|
159 |
from julia.core import JuliaInfo, UnsupportedPythonError
|
160 |
|
161 |
-
|
162 |
processed_julia_project, is_shared = _process_julia_project(julia_project)
|
163 |
_set_julia_project_env(processed_julia_project, is_shared)
|
164 |
|
@@ -225,7 +225,7 @@ def _escape_filename(filename):
|
|
225 |
return str_repr
|
226 |
|
227 |
|
228 |
-
def
|
229 |
if not is_julia_version_greater_eq(version=(1, 6, 0)):
|
230 |
raise NotImplementedError(
|
231 |
"PySR requires Julia 1.6.0 or greater. "
|
@@ -233,6 +233,27 @@ def _version_assertion():
|
|
233 |
)
|
234 |
|
235 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
def _load_cluster_manager(Main, cluster_manager):
|
237 |
Main.eval(f"import ClusterManagers: addprocs_{cluster_manager}")
|
238 |
return Main.eval(f"addprocs_{cluster_manager}")
|
@@ -253,20 +274,4 @@ def _load_backend(Main, julia_project):
|
|
253 |
except (JuliaError, RuntimeError) as e:
|
254 |
raise ImportError(_import_error_string(julia_project)) from e
|
255 |
|
256 |
-
|
257 |
-
backend_version = Main.eval("string(SymbolicRegression.PACKAGE_VERSION)")
|
258 |
-
expected_backend_version = __symbolic_regression_jl_version__
|
259 |
-
if backend_version != expected_backend_version: # pragma: no cover
|
260 |
-
warnings.warn(
|
261 |
-
f"PySR backend (SymbolicRegression.jl) version {backend_version} "
|
262 |
-
"does not match expected version {expected_backend_version}. "
|
263 |
-
"Things may break. "
|
264 |
-
"Please update your PySR installation."
|
265 |
-
)
|
266 |
-
except JuliaError: # pragma: no cover
|
267 |
-
warnings.warn(
|
268 |
-
"You seem to have an outdated version of SymbolicRegression.jl. "
|
269 |
-
"Things may break. "
|
270 |
-
"Please update your PySR installation with "
|
271 |
-
"`python -c 'import pysr; pysr.install()'`."
|
272 |
-
)
|
|
|
71 |
"""
|
72 |
import julia
|
73 |
|
74 |
+
_julia_version_assertion()
|
75 |
# Set JULIA_PROJECT so that we install in the pysr environment
|
76 |
processed_julia_project, is_shared = _process_julia_project(julia_project)
|
77 |
_set_julia_project_env(processed_julia_project, is_shared)
|
|
|
158 |
|
159 |
from julia.core import JuliaInfo, UnsupportedPythonError
|
160 |
|
161 |
+
_julia_version_assertion()
|
162 |
processed_julia_project, is_shared = _process_julia_project(julia_project)
|
163 |
_set_julia_project_env(processed_julia_project, is_shared)
|
164 |
|
|
|
225 |
return str_repr
|
226 |
|
227 |
|
228 |
+
def _julia_version_assertion():
|
229 |
if not is_julia_version_greater_eq(version=(1, 6, 0)):
|
230 |
raise NotImplementedError(
|
231 |
"PySR requires Julia 1.6.0 or greater. "
|
|
|
233 |
)
|
234 |
|
235 |
|
236 |
+
def _backend_version_assertion(Main):
|
237 |
+
try:
|
238 |
+
backend_version = Main.eval("string(SymbolicRegression.PACKAGE_VERSION)")
|
239 |
+
expected_backend_version = __symbolic_regression_jl_version__
|
240 |
+
if backend_version != expected_backend_version: # pragma: no cover
|
241 |
+
warnings.warn(
|
242 |
+
f"PySR backend (SymbolicRegression.jl) version {backend_version} "
|
243 |
+
"does not match expected version {expected_backend_version}. "
|
244 |
+
"Things may break. "
|
245 |
+
"Please update your PySR installation with "
|
246 |
+
"`python -c 'import pysr; pysr.install()'`."
|
247 |
+
)
|
248 |
+
except JuliaError: # pragma: no cover
|
249 |
+
warnings.warn(
|
250 |
+
"You seem to have an outdated version of SymbolicRegression.jl. "
|
251 |
+
"Things may break. "
|
252 |
+
"Please update your PySR installation with "
|
253 |
+
"`python -c 'import pysr; pysr.install()'`."
|
254 |
+
)
|
255 |
+
|
256 |
+
|
257 |
def _load_cluster_manager(Main, cluster_manager):
|
258 |
Main.eval(f"import ClusterManagers: addprocs_{cluster_manager}")
|
259 |
return Main.eval(f"addprocs_{cluster_manager}")
|
|
|
274 |
except (JuliaError, RuntimeError) as e:
|
275 |
raise ImportError(_import_error_string(julia_project)) from e
|
276 |
|
277 |
+
_backend_version_assertion(Main)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|