Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
49212e1
1
Parent(s):
2727648
Fix IO argument for julia 1.5
Browse files- pysr/sr.py +16 -13
pysr/sr.py
CHANGED
@@ -31,17 +31,14 @@ def install(julia_project=None, quiet=False): # pragma: no cover
|
|
31 |
Main = init_julia()
|
32 |
Main.eval("using Pkg")
|
33 |
|
34 |
-
if quiet
|
35 |
-
|
36 |
-
io = "devnull"
|
37 |
-
else:
|
38 |
-
io = "stderr"
|
39 |
|
40 |
# Can't pass IO to Julia call as it evaluates to PyObject, so just directly
|
41 |
# use Main.eval:
|
42 |
-
Main.eval(f'Pkg.activate("{_escape_filename(julia_project)}",
|
43 |
try:
|
44 |
-
Main.eval(f"Pkg.update(
|
45 |
except RuntimeError as e:
|
46 |
raise ModuleNotFoundError(
|
47 |
"Could not update Julia project. "
|
@@ -49,8 +46,8 @@ def install(julia_project=None, quiet=False): # pragma: no cover
|
|
49 |
"To switch to an always-updated registry, "
|
50 |
"see the solution in https://github.com/MilesCranmer/PySR/issues/27."
|
51 |
) from e
|
52 |
-
Main.eval(f"Pkg.instantiate(
|
53 |
-
Main.eval(f"Pkg.precompile(
|
54 |
if not quiet:
|
55 |
warnings.warn(
|
56 |
"It is recommended to restart Python after installing PySR's dependencies,"
|
@@ -300,6 +297,11 @@ def silence_julia_warning():
|
|
300 |
is_julia_warning_silenced = True
|
301 |
|
302 |
|
|
|
|
|
|
|
|
|
|
|
303 |
def init_julia():
|
304 |
"""Initialize julia binary, turning off compiled modules if needed."""
|
305 |
global is_julia_warning_silenced
|
@@ -1046,18 +1048,19 @@ class PySRRegressor(BaseEstimator, RegressorMixin):
|
|
1046 |
if not already_ran:
|
1047 |
Main.eval("using Pkg")
|
1048 |
io = "devnull" if self.params["verbosity"] == 0 else "stderr"
|
|
|
1049 |
|
1050 |
Main.eval(
|
1051 |
-
f'Pkg.activate("{_escape_filename(self.julia_project)}",
|
1052 |
)
|
1053 |
from julia.api import JuliaError
|
1054 |
|
1055 |
try:
|
1056 |
if update:
|
1057 |
-
Main.eval(f"Pkg.resolve(
|
1058 |
-
Main.eval(f"Pkg.instantiate(
|
1059 |
else:
|
1060 |
-
Main.eval(f"Pkg.instantiate(
|
1061 |
except (JuliaError, RuntimeError) as e:
|
1062 |
raise ImportError(import_error_string(self.julia_project)) from e
|
1063 |
Main.eval("using SymbolicRegression")
|
|
|
31 |
Main = init_julia()
|
32 |
Main.eval("using Pkg")
|
33 |
|
34 |
+
io = "devnull" if quiet else "stderr"
|
35 |
+
io_arg = f"io={io}" if is_julia_version_greater(Main, "1.5") else ""
|
|
|
|
|
|
|
36 |
|
37 |
# Can't pass IO to Julia call as it evaluates to PyObject, so just directly
|
38 |
# use Main.eval:
|
39 |
+
Main.eval(f'Pkg.activate("{_escape_filename(julia_project)}", {io_arg})')
|
40 |
try:
|
41 |
+
Main.eval(f"Pkg.update({io_arg})")
|
42 |
except RuntimeError as e:
|
43 |
raise ModuleNotFoundError(
|
44 |
"Could not update Julia project. "
|
|
|
46 |
"To switch to an always-updated registry, "
|
47 |
"see the solution in https://github.com/MilesCranmer/PySR/issues/27."
|
48 |
) from e
|
49 |
+
Main.eval(f"Pkg.instantiate({io_arg})")
|
50 |
+
Main.eval(f"Pkg.precompile({io_arg})")
|
51 |
if not quiet:
|
52 |
warnings.warn(
|
53 |
"It is recommended to restart Python after installing PySR's dependencies,"
|
|
|
297 |
is_julia_warning_silenced = True
|
298 |
|
299 |
|
300 |
+
def is_julia_version_greater(Main, version="1.5"):
|
301 |
+
"""Check if Julia version is greater than specified version."""
|
302 |
+
return Main.eval(f'VERSION >= v"{version}"')
|
303 |
+
|
304 |
+
|
305 |
def init_julia():
|
306 |
"""Initialize julia binary, turning off compiled modules if needed."""
|
307 |
global is_julia_warning_silenced
|
|
|
1048 |
if not already_ran:
|
1049 |
Main.eval("using Pkg")
|
1050 |
io = "devnull" if self.params["verbosity"] == 0 else "stderr"
|
1051 |
+
io_arg = f"io={io}" if is_julia_version_greater(Main, "1.5") else ""
|
1052 |
|
1053 |
Main.eval(
|
1054 |
+
f'Pkg.activate("{_escape_filename(self.julia_project)}", {io_arg})'
|
1055 |
)
|
1056 |
from julia.api import JuliaError
|
1057 |
|
1058 |
try:
|
1059 |
if update:
|
1060 |
+
Main.eval(f"Pkg.resolve({io_arg})")
|
1061 |
+
Main.eval(f"Pkg.instantiate({io_arg})")
|
1062 |
else:
|
1063 |
+
Main.eval(f"Pkg.instantiate({io_arg})")
|
1064 |
except (JuliaError, RuntimeError) as e:
|
1065 |
raise ImportError(import_error_string(self.julia_project)) from e
|
1066 |
Main.eval("using SymbolicRegression")
|