Spaces:
Sleeping
Sleeping
Commit
·
7f24ebe
1
Parent(s):
e87a1d6
Clean up internal function names
Browse files- pysr/julia_helpers.py +9 -9
- pysr/sr.py +2 -2
pysr/julia_helpers.py
CHANGED
|
@@ -11,7 +11,7 @@ juliainfo = None
|
|
| 11 |
julia_initialized = False
|
| 12 |
|
| 13 |
|
| 14 |
-
def
|
| 15 |
"""Execute julia.core.JuliaInfo.load(), and store as juliainfo."""
|
| 16 |
global juliainfo
|
| 17 |
|
|
@@ -63,14 +63,14 @@ def install(julia_project=None, quiet=False): # pragma: no cover
|
|
| 63 |
import julia
|
| 64 |
|
| 65 |
# Set JULIA_PROJECT so that we install in the pysr environment
|
| 66 |
-
julia_project, is_shared =
|
| 67 |
_set_julia_project_env(julia_project, is_shared)
|
| 68 |
|
| 69 |
julia.install(quiet=quiet)
|
| 70 |
|
| 71 |
if is_shared:
|
| 72 |
# is_shared is only true if the julia_project arg was None
|
| 73 |
-
# See
|
| 74 |
Main = init_julia(None)
|
| 75 |
else:
|
| 76 |
Main = init_julia(julia_project)
|
|
@@ -98,7 +98,7 @@ def install(julia_project=None, quiet=False): # pragma: no cover
|
|
| 98 |
)
|
| 99 |
|
| 100 |
|
| 101 |
-
def
|
| 102 |
s = """
|
| 103 |
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
| 104 |
|
|
@@ -113,7 +113,7 @@ def import_error_string(julia_project=None):
|
|
| 113 |
return s
|
| 114 |
|
| 115 |
|
| 116 |
-
def
|
| 117 |
if julia_project is None:
|
| 118 |
is_shared = True
|
| 119 |
julia_project = f"pysr-{__version__}"
|
|
@@ -135,7 +135,7 @@ def is_julia_version_greater_eq(juliainfo=None, version=(1, 6, 0)):
|
|
| 135 |
return current_version >= version
|
| 136 |
|
| 137 |
|
| 138 |
-
def
|
| 139 |
"""Check whether there are conflicting modules, and display warnings."""
|
| 140 |
# See https://github.com/pytorch/pytorch/issues/78829: importing
|
| 141 |
# pytorch before running `pysr.fit` causes a segfault.
|
|
@@ -155,11 +155,11 @@ def init_julia(julia_project=None):
|
|
| 155 |
global julia_initialized
|
| 156 |
|
| 157 |
if not julia_initialized:
|
| 158 |
-
|
| 159 |
|
| 160 |
from julia.core import JuliaInfo, UnsupportedPythonError
|
| 161 |
|
| 162 |
-
julia_project, is_shared =
|
| 163 |
_set_julia_project_env(julia_project, is_shared)
|
| 164 |
|
| 165 |
try:
|
|
@@ -171,7 +171,7 @@ def init_julia(julia_project=None):
|
|
| 171 |
)
|
| 172 |
|
| 173 |
if not info.is_pycall_built():
|
| 174 |
-
raise ImportError(
|
| 175 |
|
| 176 |
Main = None
|
| 177 |
try:
|
|
|
|
| 11 |
julia_initialized = False
|
| 12 |
|
| 13 |
|
| 14 |
+
def _load_juliainfo():
|
| 15 |
"""Execute julia.core.JuliaInfo.load(), and store as juliainfo."""
|
| 16 |
global juliainfo
|
| 17 |
|
|
|
|
| 63 |
import julia
|
| 64 |
|
| 65 |
# Set JULIA_PROJECT so that we install in the pysr environment
|
| 66 |
+
julia_project, is_shared = _process_julia_project(julia_project)
|
| 67 |
_set_julia_project_env(julia_project, is_shared)
|
| 68 |
|
| 69 |
julia.install(quiet=quiet)
|
| 70 |
|
| 71 |
if is_shared:
|
| 72 |
# is_shared is only true if the julia_project arg was None
|
| 73 |
+
# See _process_julia_project
|
| 74 |
Main = init_julia(None)
|
| 75 |
else:
|
| 76 |
Main = init_julia(julia_project)
|
|
|
|
| 98 |
)
|
| 99 |
|
| 100 |
|
| 101 |
+
def _import_error_string(julia_project=None):
|
| 102 |
s = """
|
| 103 |
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
| 104 |
|
|
|
|
| 113 |
return s
|
| 114 |
|
| 115 |
|
| 116 |
+
def _process_julia_project(julia_project):
|
| 117 |
if julia_project is None:
|
| 118 |
is_shared = True
|
| 119 |
julia_project = f"pysr-{__version__}"
|
|
|
|
| 135 |
return current_version >= version
|
| 136 |
|
| 137 |
|
| 138 |
+
def _check_for_conflicting_libraries(): # pragma: no cover
|
| 139 |
"""Check whether there are conflicting modules, and display warnings."""
|
| 140 |
# See https://github.com/pytorch/pytorch/issues/78829: importing
|
| 141 |
# pytorch before running `pysr.fit` causes a segfault.
|
|
|
|
| 155 |
global julia_initialized
|
| 156 |
|
| 157 |
if not julia_initialized:
|
| 158 |
+
_check_for_conflicting_libraries()
|
| 159 |
|
| 160 |
from julia.core import JuliaInfo, UnsupportedPythonError
|
| 161 |
|
| 162 |
+
julia_project, is_shared = _process_julia_project(julia_project)
|
| 163 |
_set_julia_project_env(julia_project, is_shared)
|
| 164 |
|
| 165 |
try:
|
|
|
|
| 171 |
)
|
| 172 |
|
| 173 |
if not info.is_pycall_built():
|
| 174 |
+
raise ImportError(_import_error_string())
|
| 175 |
|
| 176 |
Main = None
|
| 177 |
try:
|
pysr/sr.py
CHANGED
|
@@ -23,7 +23,7 @@ from sklearn.utils.validation import (
|
|
| 23 |
|
| 24 |
from .julia_helpers import (
|
| 25 |
init_julia,
|
| 26 |
-
|
| 27 |
is_julia_version_greater_eq,
|
| 28 |
_escape_filename,
|
| 29 |
_add_sr_to_julia_project,
|
|
@@ -1437,7 +1437,7 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
| 1437 |
cluster_manager = Main.eval(f"addprocs_{cluster_manager}")
|
| 1438 |
|
| 1439 |
if not already_ran:
|
| 1440 |
-
julia_project, is_shared =
|
| 1441 |
Main.eval("using Pkg")
|
| 1442 |
io = "devnull" if update_verbosity == 0 else "stderr"
|
| 1443 |
io_arg = (
|
|
|
|
| 23 |
|
| 24 |
from .julia_helpers import (
|
| 25 |
init_julia,
|
| 26 |
+
_process_julia_project,
|
| 27 |
is_julia_version_greater_eq,
|
| 28 |
_escape_filename,
|
| 29 |
_add_sr_to_julia_project,
|
|
|
|
| 1437 |
cluster_manager = Main.eval(f"addprocs_{cluster_manager}")
|
| 1438 |
|
| 1439 |
if not already_ran:
|
| 1440 |
+
julia_project, is_shared = _process_julia_project(self.julia_project)
|
| 1441 |
Main.eval("using Pkg")
|
| 1442 |
io = "devnull" if update_verbosity == 0 else "stderr"
|
| 1443 |
io_arg = (
|