Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
31ecc71
1
Parent(s):
56f0425
Remove custom environment tests
Browse files- pysr/_cli/main.py +3 -11
- pysr/sr.py +12 -6
- pysr/test/__init__.py +0 -2
- pysr/test/test_env.py +0 -58
pysr/_cli/main.py
CHANGED
@@ -2,13 +2,7 @@ import warnings
|
|
2 |
|
3 |
import click
|
4 |
|
5 |
-
from ..test import
|
6 |
-
get_runtests_cli,
|
7 |
-
runtests,
|
8 |
-
runtests_env,
|
9 |
-
runtests_jax,
|
10 |
-
runtests_torch,
|
11 |
-
)
|
12 |
|
13 |
|
14 |
@click.group("pysr")
|
@@ -48,7 +42,7 @@ def _install(julia_project, quiet, precompile):
|
|
48 |
)
|
49 |
|
50 |
|
51 |
-
TEST_OPTIONS = {"main", "
|
52 |
|
53 |
|
54 |
@pysr.command("test", help="Run PySR test suite.")
|
@@ -56,7 +50,7 @@ TEST_OPTIONS = {"main", "env", "jax", "torch", "cli"}
|
|
56 |
def _tests(tests):
|
57 |
"""Run part of the PySR test suite.
|
58 |
|
59 |
-
Choose from main,
|
60 |
"""
|
61 |
if len(tests) == 0:
|
62 |
raise click.UsageError(
|
@@ -70,8 +64,6 @@ def _tests(tests):
|
|
70 |
if test in TEST_OPTIONS:
|
71 |
if test == "main":
|
72 |
runtests()
|
73 |
-
elif test == "env":
|
74 |
-
runtests_env()
|
75 |
elif test == "jax":
|
76 |
runtests_jax()
|
77 |
elif test == "torch":
|
|
|
2 |
|
3 |
import click
|
4 |
|
5 |
+
from ..test import get_runtests_cli, runtests, runtests_jax, runtests_torch
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
@click.group("pysr")
|
|
|
42 |
)
|
43 |
|
44 |
|
45 |
+
TEST_OPTIONS = {"main", "jax", "torch", "cli"}
|
46 |
|
47 |
|
48 |
@pysr.command("test", help="Run PySR test suite.")
|
|
|
50 |
def _tests(tests):
|
51 |
"""Run part of the PySR test suite.
|
52 |
|
53 |
+
Choose from main, jax, torch, and cli.
|
54 |
"""
|
55 |
if len(tests) == 0:
|
56 |
raise click.UsageError(
|
|
|
64 |
if test in TEST_OPTIONS:
|
65 |
if test == "main":
|
66 |
runtests()
|
|
|
|
|
67 |
elif test == "jax":
|
68 |
runtests_jax()
|
69 |
elif test == "torch":
|
pysr/sr.py
CHANGED
@@ -531,11 +531,6 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
531 |
delete_tempfiles : bool
|
532 |
Whether to delete the temporary files after finishing.
|
533 |
Default is `True`.
|
534 |
-
julia_project : str
|
535 |
-
A Julia environment location containing a Project.toml
|
536 |
-
(and potentially the source code for SymbolicRegression.jl).
|
537 |
-
Default gives the Python package directory, where a
|
538 |
-
Project.toml file should be present from the install.
|
539 |
update: bool
|
540 |
Whether to automatically update Julia packages when `fit` is called.
|
541 |
You should make sure that PySR is up-to-date itself first, as
|
@@ -740,7 +735,6 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
740 |
temp_equation_file: bool = False,
|
741 |
tempdir: Optional[str] = None,
|
742 |
delete_tempfiles: bool = True,
|
743 |
-
julia_project: Optional[str] = None,
|
744 |
update: bool = False,
|
745 |
output_jax_format: bool = False,
|
746 |
output_torch_format: bool = False,
|
@@ -873,6 +867,18 @@ class PySRRegressor(MultiOutputMixin, RegressorMixin, BaseEstimator):
|
|
873 |
f"Ignoring parameter; please pass {k} during the call to fit instead.",
|
874 |
FutureWarning,
|
875 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
876 |
else:
|
877 |
raise TypeError(
|
878 |
f"{k} is not a valid keyword argument for PySRRegressor."
|
|
|
531 |
delete_tempfiles : bool
|
532 |
Whether to delete the temporary files after finishing.
|
533 |
Default is `True`.
|
|
|
|
|
|
|
|
|
|
|
534 |
update: bool
|
535 |
Whether to automatically update Julia packages when `fit` is called.
|
536 |
You should make sure that PySR is up-to-date itself first, as
|
|
|
735 |
temp_equation_file: bool = False,
|
736 |
tempdir: Optional[str] = None,
|
737 |
delete_tempfiles: bool = True,
|
|
|
738 |
update: bool = False,
|
739 |
output_jax_format: bool = False,
|
740 |
output_torch_format: bool = False,
|
|
|
867 |
f"Ignoring parameter; please pass {k} during the call to fit instead.",
|
868 |
FutureWarning,
|
869 |
)
|
870 |
+
elif k == "julia_project":
|
871 |
+
warnings.warn(
|
872 |
+
"The `julia_project` parameter has been deprecated. To use a custom "
|
873 |
+
"julia project, you should instead:\n"
|
874 |
+
" 1. Clone the PySR repository.\n"
|
875 |
+
" 2. Modify the `pysr/juliapkg.json` file's specification of the "
|
876 |
+
'SymbolicRegression.jl package to have `"dev": true` and `"path": '
|
877 |
+
'"/path/to/custom/project"`.\n'
|
878 |
+
" 3. Install this PySR package with `pip install -e .` from the "
|
879 |
+
"PySR repository root.\n"
|
880 |
+
"You should now be able to use the custom julia project.",
|
881 |
+
)
|
882 |
else:
|
883 |
raise TypeError(
|
884 |
f"{k} is not a valid keyword argument for PySRRegressor."
|
pysr/test/__init__.py
CHANGED
@@ -1,12 +1,10 @@
|
|
1 |
from .test import runtests
|
2 |
from .test_cli import get_runtests as get_runtests_cli
|
3 |
-
from .test_env import runtests as runtests_env
|
4 |
from .test_jax import runtests as runtests_jax
|
5 |
from .test_torch import runtests as runtests_torch
|
6 |
|
7 |
__all__ = [
|
8 |
"runtests",
|
9 |
-
"runtests_env",
|
10 |
"runtests_jax",
|
11 |
"runtests_torch",
|
12 |
"get_runtests_cli",
|
|
|
1 |
from .test import runtests
|
2 |
from .test_cli import get_runtests as get_runtests_cli
|
|
|
3 |
from .test_jax import runtests as runtests_jax
|
4 |
from .test_torch import runtests as runtests_torch
|
5 |
|
6 |
__all__ = [
|
7 |
"runtests",
|
|
|
8 |
"runtests_jax",
|
9 |
"runtests_torch",
|
10 |
"get_runtests_cli",
|
pysr/test/test_env.py
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
"""Contains tests for creating and initializing custom Julia projects."""
|
2 |
-
|
3 |
-
import os
|
4 |
-
import unittest
|
5 |
-
from tempfile import TemporaryDirectory
|
6 |
-
|
7 |
-
from .. import julia_helpers
|
8 |
-
|
9 |
-
|
10 |
-
class TestJuliaProject(unittest.TestCase):
|
11 |
-
"""Various tests for working with Julia projects."""
|
12 |
-
|
13 |
-
def test_custom_shared_env(self):
|
14 |
-
"""Test that we can use PySR in a custom shared env."""
|
15 |
-
with TemporaryDirectory() as tmpdir:
|
16 |
-
# Create a temp depot to store julia packages (and our custom env)
|
17 |
-
Main = julia_helpers.init_julia()
|
18 |
-
|
19 |
-
# Set up env:
|
20 |
-
if "JULIA_DEPOT_PATH" not in os.environ:
|
21 |
-
old_env = None
|
22 |
-
os.environ["JULIA_DEPOT_PATH"] = tmpdir
|
23 |
-
else:
|
24 |
-
old_env = os.environ["JULIA_DEPOT_PATH"]
|
25 |
-
os.environ[
|
26 |
-
"JULIA_DEPOT_PATH"
|
27 |
-
] = f"{tmpdir}:{os.environ['JULIA_DEPOT_PATH']}"
|
28 |
-
Main.eval(
|
29 |
-
f'pushfirst!(DEPOT_PATH, "{julia_helpers._escape_filename(tmpdir)}")'
|
30 |
-
)
|
31 |
-
test_env_name = "@pysr_test_env"
|
32 |
-
julia_helpers.install(julia_project=test_env_name)
|
33 |
-
Main = julia_helpers.init_julia(julia_project=test_env_name)
|
34 |
-
|
35 |
-
# Try to use env:
|
36 |
-
Main.eval("using SymbolicRegression")
|
37 |
-
Main.eval("using Pkg")
|
38 |
-
|
39 |
-
# Assert we actually loaded it:
|
40 |
-
cur_project_dir = Main.eval("splitdir(dirname(Base.active_project()))[1]")
|
41 |
-
potential_shared_project_dirs = Main.eval("Pkg.envdir(DEPOT_PATH[1])")
|
42 |
-
self.assertEqual(cur_project_dir, potential_shared_project_dirs)
|
43 |
-
|
44 |
-
# Clean up:
|
45 |
-
Main.eval("pop!(DEPOT_PATH)")
|
46 |
-
if old_env is None:
|
47 |
-
del os.environ["JULIA_DEPOT_PATH"]
|
48 |
-
else:
|
49 |
-
os.environ["JULIA_DEPOT_PATH"] = old_env
|
50 |
-
|
51 |
-
|
52 |
-
def runtests():
|
53 |
-
"""Run all tests in test_env.py."""
|
54 |
-
loader = unittest.TestLoader()
|
55 |
-
suite = unittest.TestSuite()
|
56 |
-
suite.addTests(loader.loadTestsFromTestCase(TestJuliaProject))
|
57 |
-
runner = unittest.TextTestRunner()
|
58 |
-
return runner.run(suite)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|