Spaces:
Running
Running
Commit
·
b3fd9db
1
Parent(s):
e199c99
Make pysr.install() install/update packages
Browse files- .github/workflows/CI.yml +1 -1
- .github/workflows/CI_Windows.yml +1 -1
- .github/workflows/CI_mac.yml +1 -1
- README.md +5 -3
- pysr/sr.py +49 -14
.github/workflows/CI.yml
CHANGED
|
@@ -61,7 +61,7 @@ jobs:
|
|
| 61 |
python -m pip install --upgrade pip
|
| 62 |
pip install -r requirements.txt
|
| 63 |
python setup.py install
|
| 64 |
-
python -c 'import
|
| 65 |
- name: "Install Coverage tool"
|
| 66 |
run: pip install coverage coveralls
|
| 67 |
- name: "Run tests"
|
|
|
|
| 61 |
python -m pip install --upgrade pip
|
| 62 |
pip install -r requirements.txt
|
| 63 |
python setup.py install
|
| 64 |
+
python -c 'import pysr; pysr.install()'
|
| 65 |
- name: "Install Coverage tool"
|
| 66 |
run: pip install coverage coveralls
|
| 67 |
- name: "Run tests"
|
.github/workflows/CI_Windows.yml
CHANGED
|
@@ -61,7 +61,7 @@ jobs:
|
|
| 61 |
python -m pip install --upgrade pip
|
| 62 |
pip install -r requirements.txt
|
| 63 |
python setup.py install
|
| 64 |
-
python -c 'import
|
| 65 |
- name: "Run tests"
|
| 66 |
run: python -m unittest test.test
|
| 67 |
shell: bash
|
|
|
|
| 61 |
python -m pip install --upgrade pip
|
| 62 |
pip install -r requirements.txt
|
| 63 |
python setup.py install
|
| 64 |
+
python -c 'import pysr; pysr.install()'
|
| 65 |
- name: "Run tests"
|
| 66 |
run: python -m unittest test.test
|
| 67 |
shell: bash
|
.github/workflows/CI_mac.yml
CHANGED
|
@@ -61,7 +61,7 @@ jobs:
|
|
| 61 |
python -m pip install --upgrade pip
|
| 62 |
pip install -r requirements.txt
|
| 63 |
python setup.py install
|
| 64 |
-
python -c 'import
|
| 65 |
- name: "Run tests"
|
| 66 |
run: python -m unittest test.test
|
| 67 |
shell: bash
|
|
|
|
| 61 |
python -m pip install --upgrade pip
|
| 62 |
pip install -r requirements.txt
|
| 63 |
python setup.py install
|
| 64 |
+
python -c 'import pysr; pysr.install()'
|
| 65 |
- name: "Run tests"
|
| 66 |
run: python -m unittest test.test
|
| 67 |
shell: bash
|
README.md
CHANGED
|
@@ -62,11 +62,13 @@ and [linux](https://julialang.org/downloads/platform/#linux_and_freebsd).
|
|
| 62 |
|
| 63 |
You can install PySR with:
|
| 64 |
```bash
|
| 65 |
-
|
|
|
|
| 66 |
```
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
by [tweaking the Julia package server](https://github.com/MilesCranmer/PySR/issues/27).
|
| 71 |
to use up-to-date packages.
|
| 72 |
|
|
|
|
| 62 |
|
| 63 |
You can install PySR with:
|
| 64 |
```bash
|
| 65 |
+
pip3 install pysr
|
| 66 |
+
python3 -c 'import pysr; pysr.install()'
|
| 67 |
```
|
| 68 |
+
The second line will install the required Julia packages.
|
| 69 |
|
| 70 |
+
|
| 71 |
+
Most common issues at this stage are solved
|
| 72 |
by [tweaking the Julia package server](https://github.com/MilesCranmer/PySR/issues/27).
|
| 73 |
to use up-to-date packages.
|
| 74 |
|
pysr/sr.py
CHANGED
|
@@ -12,6 +12,22 @@ from datetime import datetime
|
|
| 12 |
import warnings
|
| 13 |
from multiprocessing import cpu_count
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
Main = None
|
| 16 |
global_state = dict(
|
| 17 |
equation_file="hall_of_fame.csv",
|
|
@@ -277,6 +293,18 @@ def pysr(
|
|
| 277 |
if multithreading:
|
| 278 |
os.environ["JULIA_NUM_THREADS"] = str(procs)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
from julia import Main
|
| 281 |
|
| 282 |
buffer_available = "buffer" in sys.stdout.__dir__()
|
|
@@ -380,8 +408,8 @@ def pysr(
|
|
| 380 |
else:
|
| 381 |
X, y = _denoise(X, y, Xresampled=Xresampled)
|
| 382 |
|
| 383 |
-
|
| 384 |
-
|
| 385 |
tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
|
| 386 |
|
| 387 |
if temp_equation_file:
|
|
@@ -390,13 +418,6 @@ def pysr(
|
|
| 390 |
date_time = datetime.now().strftime("%Y-%m-%d_%H%M%S.%f")[:-3]
|
| 391 |
equation_file = "hall_of_fame_" + date_time + ".csv"
|
| 392 |
|
| 393 |
-
if julia_project is None:
|
| 394 |
-
manifest_filepath = pkg_directory / "Manifest.toml"
|
| 395 |
-
julia_project = pkg_directory
|
| 396 |
-
else:
|
| 397 |
-
manifest_filepath = Path(julia_project) / "Manifest.toml"
|
| 398 |
-
julia_project = Path(julia_project)
|
| 399 |
-
|
| 400 |
_create_inline_operators(
|
| 401 |
binary_operators=binary_operators, unary_operators=unary_operators
|
| 402 |
)
|
|
@@ -418,11 +439,18 @@ def pysr(
|
|
| 418 |
from julia import Pkg
|
| 419 |
|
| 420 |
Pkg.activate(f"{_escape_filename(julia_project)}")
|
| 421 |
-
|
| 422 |
-
Pkg.
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
Main.eval("using SymbolicRegression")
|
| 427 |
|
| 428 |
Main.plus = Main.eval("(+)")
|
|
@@ -926,3 +954,10 @@ class CallableEquation:
|
|
| 926 |
if self._selection is not None:
|
| 927 |
return self._lambda(*X[:, self._selection].T)
|
| 928 |
return self._lambda(*X.T)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
import warnings
|
| 13 |
from multiprocessing import cpu_count
|
| 14 |
|
| 15 |
+
|
| 16 |
+
def install(julia_project=None):
|
| 17 |
+
import julia
|
| 18 |
+
|
| 19 |
+
julia.install()
|
| 20 |
+
|
| 21 |
+
julia_project = _get_julia_project(julia_project)
|
| 22 |
+
|
| 23 |
+
from julia import Pkg
|
| 24 |
+
|
| 25 |
+
Pkg.activate(f"{_escape_filename(julia_project)}")
|
| 26 |
+
Pkg.instantiate()
|
| 27 |
+
Pkg.update()
|
| 28 |
+
Pkg.precompile()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
Main = None
|
| 32 |
global_state = dict(
|
| 33 |
equation_file="hall_of_fame.csv",
|
|
|
|
| 293 |
if multithreading:
|
| 294 |
os.environ["JULIA_NUM_THREADS"] = str(procs)
|
| 295 |
|
| 296 |
+
from julia.core import JuliaInfo
|
| 297 |
+
|
| 298 |
+
info = JuliaInfo.load(julia="julia")
|
| 299 |
+
if not info.is_pycall_built():
|
| 300 |
+
raise ImportError(
|
| 301 |
+
"""
|
| 302 |
+
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
| 303 |
+
|
| 304 |
+
>>> import pysr
|
| 305 |
+
>>> pysr.install()"""
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
from julia import Main
|
| 309 |
|
| 310 |
buffer_available = "buffer" in sys.stdout.__dir__()
|
|
|
|
| 408 |
else:
|
| 409 |
X, y = _denoise(X, y, Xresampled=Xresampled)
|
| 410 |
|
| 411 |
+
julia_project = _get_julia_project(julia_project)
|
| 412 |
+
|
| 413 |
tmpdir = Path(tempfile.mkdtemp(dir=tempdir))
|
| 414 |
|
| 415 |
if temp_equation_file:
|
|
|
|
| 418 |
date_time = datetime.now().strftime("%Y-%m-%d_%H%M%S.%f")[:-3]
|
| 419 |
equation_file = "hall_of_fame_" + date_time + ".csv"
|
| 420 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
_create_inline_operators(
|
| 422 |
binary_operators=binary_operators, unary_operators=unary_operators
|
| 423 |
)
|
|
|
|
| 439 |
from julia import Pkg
|
| 440 |
|
| 441 |
Pkg.activate(f"{_escape_filename(julia_project)}")
|
| 442 |
+
try:
|
| 443 |
+
Pkg.resolve()
|
| 444 |
+
except RuntimeError as e:
|
| 445 |
+
raise ImportError(
|
| 446 |
+
f"""
|
| 447 |
+
Required dependencies are not installed or built. Run the following code in the Python REPL:
|
| 448 |
+
|
| 449 |
+
>>> import pysr
|
| 450 |
+
>>> pysr.install()
|
| 451 |
+
|
| 452 |
+
Tried to activate project {julia_project} but failed."""
|
| 453 |
+
) from e
|
| 454 |
Main.eval("using SymbolicRegression")
|
| 455 |
|
| 456 |
Main.plus = Main.eval("(+)")
|
|
|
|
| 954 |
if self._selection is not None:
|
| 955 |
return self._lambda(*X[:, self._selection].T)
|
| 956 |
return self._lambda(*X.T)
|
| 957 |
+
|
| 958 |
+
|
| 959 |
+
def _get_julia_project(julia_project):
|
| 960 |
+
pkg_directory = Path(__file__).parents[1]
|
| 961 |
+
if julia_project is None:
|
| 962 |
+
return pkg_directory
|
| 963 |
+
return Path(julia_project)
|