Spaces:
Running
Running
Merge pull request #298 from w2ll2am/master
Browse filesAdded CLI to run pysr.install() to install Julia dependencies
- .github/workflows/CI.yml +5 -3
- .github/workflows/CI_Windows.yml +4 -2
- .github/workflows/CI_docker.yml +1 -1
- .github/workflows/CI_docker_large_nightly.yml +1 -1
- .github/workflows/CI_large_nightly.yml +4 -2
- .github/workflows/CI_mac.yml +4 -2
- Dockerfile +1 -1
- environment.yml +2 -1
- pysr/__main__.py +4 -0
- pysr/_cli/__init__.py +0 -0
- pysr/_cli/main.py +37 -0
- pysr/export_latex.py +0 -1
- pysr/julia_helpers.py +4 -6
- pysr/test/__init__.py +1 -0
- pysr/test/__main__.py +4 -2
- pysr/test/test_cli.py +57 -0
- pysr/version.py +1 -1
- requirements.txt +4 -2
.github/workflows/CI.yml
CHANGED
|
@@ -54,11 +54,13 @@ jobs:
|
|
| 54 |
python -m pip install --upgrade pip
|
| 55 |
pip install -r requirements.txt
|
| 56 |
python setup.py install
|
| 57 |
-
python -
|
| 58 |
- name: "Install Coverage tool"
|
| 59 |
run: pip install coverage coveralls
|
| 60 |
- name: "Run tests"
|
| 61 |
-
run:
|
|
|
|
|
|
|
| 62 |
- name: "Install JAX"
|
| 63 |
run: pip install jax jaxlib # (optional import)
|
| 64 |
- name: "Run JAX tests"
|
|
@@ -112,7 +114,7 @@ jobs:
|
|
| 112 |
- name: "Install PySR"
|
| 113 |
run: |
|
| 114 |
python3 -m pip install .
|
| 115 |
-
python3 -
|
| 116 |
- name: "Run tests"
|
| 117 |
run: cd /tmp && python -m pysr.test main
|
| 118 |
|
|
|
|
| 54 |
python -m pip install --upgrade pip
|
| 55 |
pip install -r requirements.txt
|
| 56 |
python setup.py install
|
| 57 |
+
python -m pysr install
|
| 58 |
- name: "Install Coverage tool"
|
| 59 |
run: pip install coverage coveralls
|
| 60 |
- name: "Run tests"
|
| 61 |
+
run: |
|
| 62 |
+
coverage run --source=pysr --omit='*/test/*,*/feynman_problems.py' -m pysr.test main
|
| 63 |
+
coverage run --append --source=pysr --omit='*/test/*,*/feynman_problems.py' -m pysr.test cli
|
| 64 |
- name: "Install JAX"
|
| 65 |
run: pip install jax jaxlib # (optional import)
|
| 66 |
- name: "Run JAX tests"
|
|
|
|
| 114 |
- name: "Install PySR"
|
| 115 |
run: |
|
| 116 |
python3 -m pip install .
|
| 117 |
+
python3 -m pysr install
|
| 118 |
- name: "Run tests"
|
| 119 |
run: cd /tmp && python -m pysr.test main
|
| 120 |
|
.github/workflows/CI_Windows.yml
CHANGED
|
@@ -54,9 +54,11 @@ jobs:
|
|
| 54 |
python -m pip install --upgrade pip
|
| 55 |
pip install -r requirements.txt
|
| 56 |
python setup.py install
|
| 57 |
-
python -
|
| 58 |
- name: "Run tests"
|
| 59 |
-
run:
|
|
|
|
|
|
|
| 60 |
- name: "Install Torch"
|
| 61 |
run: pip install torch # (optional import)
|
| 62 |
- name: "Run Torch tests"
|
|
|
|
| 54 |
python -m pip install --upgrade pip
|
| 55 |
pip install -r requirements.txt
|
| 56 |
python setup.py install
|
| 57 |
+
python -m pysr install
|
| 58 |
- name: "Run tests"
|
| 59 |
+
run: |
|
| 60 |
+
python -m pysr.test main
|
| 61 |
+
python -m pysr.test cli
|
| 62 |
- name: "Install Torch"
|
| 63 |
run: pip install torch # (optional import)
|
| 64 |
- name: "Run Torch tests"
|
.github/workflows/CI_docker.yml
CHANGED
|
@@ -39,4 +39,4 @@ jobs:
|
|
| 39 |
- name: Build docker
|
| 40 |
run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} --build-arg PYVERSION=${{ matrix.python-version }} .
|
| 41 |
- name: Test docker
|
| 42 |
-
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test env'
|
|
|
|
| 39 |
- name: Build docker
|
| 40 |
run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} --build-arg PYVERSION=${{ matrix.python-version }} .
|
| 41 |
- name: Test docker
|
| 42 |
+
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test cli && python3 -m pysr.test env'
|
.github/workflows/CI_docker_large_nightly.yml
CHANGED
|
@@ -33,4 +33,4 @@ jobs:
|
|
| 33 |
- name: Build docker
|
| 34 |
run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} .
|
| 35 |
- name: Test docker
|
| 36 |
-
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test env'
|
|
|
|
| 33 |
- name: Build docker
|
| 34 |
run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} .
|
| 35 |
- name: Test docker
|
| 36 |
+
run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr.test main && python3 -m pysr.test cli && python3 -m pysr.test env'
|
.github/workflows/CI_large_nightly.yml
CHANGED
|
@@ -42,9 +42,11 @@ jobs:
|
|
| 42 |
python -m pip install --upgrade pip
|
| 43 |
pip install -r requirements.txt
|
| 44 |
python setup.py install
|
| 45 |
-
python -
|
| 46 |
- name: "Run tests"
|
| 47 |
-
run:
|
|
|
|
|
|
|
| 48 |
- name: "Run new env test"
|
| 49 |
run: python -m pysr.test env
|
| 50 |
if: ${{ !(matrix.os == 'windows-latest' && matrix.python-version == '3.7') }}
|
|
|
|
| 42 |
python -m pip install --upgrade pip
|
| 43 |
pip install -r requirements.txt
|
| 44 |
python setup.py install
|
| 45 |
+
python -m pysr install
|
| 46 |
- name: "Run tests"
|
| 47 |
+
run: |
|
| 48 |
+
python -m pysr.test main
|
| 49 |
+
python -m pysr.test cli
|
| 50 |
- name: "Run new env test"
|
| 51 |
run: python -m pysr.test env
|
| 52 |
if: ${{ !(matrix.os == 'windows-latest' && matrix.python-version == '3.7') }}
|
.github/workflows/CI_mac.yml
CHANGED
|
@@ -54,9 +54,11 @@ jobs:
|
|
| 54 |
python -m pip install --upgrade pip
|
| 55 |
pip install -r requirements.txt
|
| 56 |
python setup.py install
|
| 57 |
-
python -
|
| 58 |
- name: "Run tests"
|
| 59 |
-
run:
|
|
|
|
|
|
|
| 60 |
- name: "Install JAX"
|
| 61 |
run: pip install jax jaxlib # (optional import)
|
| 62 |
- name: "Run JAX tests"
|
|
|
|
| 54 |
python -m pip install --upgrade pip
|
| 55 |
pip install -r requirements.txt
|
| 56 |
python setup.py install
|
| 57 |
+
python -m pysr install
|
| 58 |
- name: "Run tests"
|
| 59 |
+
run: |
|
| 60 |
+
python -m pysr.test main
|
| 61 |
+
python -m pysr.test cli
|
| 62 |
- name: "Install JAX"
|
| 63 |
run: pip install jax jaxlib # (optional import)
|
| 64 |
- name: "Run JAX tests"
|
Dockerfile
CHANGED
|
@@ -28,7 +28,7 @@ ADD ./pysr/ /pysr/pysr/
|
|
| 28 |
RUN pip3 install .
|
| 29 |
|
| 30 |
# Install Julia pre-requisites:
|
| 31 |
-
RUN python3 -
|
| 32 |
|
| 33 |
# metainformation
|
| 34 |
LABEL org.opencontainers.image.authors = "Miles Cranmer"
|
|
|
|
| 28 |
RUN pip3 install .
|
| 29 |
|
| 30 |
# Install Julia pre-requisites:
|
| 31 |
+
RUN python3 -m pysr install
|
| 32 |
|
| 33 |
# metainformation
|
| 34 |
LABEL org.opencontainers.image.authors = "Miles Cranmer"
|
environment.yml
CHANGED
|
@@ -9,4 +9,5 @@ dependencies:
|
|
| 9 |
- setuptools
|
| 10 |
- pyjulia
|
| 11 |
- openlibm
|
| 12 |
-
- openspecfun
|
|
|
|
|
|
| 9 |
- setuptools
|
| 10 |
- pyjulia
|
| 11 |
- openlibm
|
| 12 |
+
- openspecfun
|
| 13 |
+
- click
|
pysr/__main__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pysr._cli.main import pysr as _cli
|
| 2 |
+
|
| 3 |
+
if __name__ == "__main__":
|
| 4 |
+
_cli(prog_name="pysr")
|
pysr/_cli/__init__.py
ADDED
|
File without changes
|
pysr/_cli/main.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
from ..julia_helpers import install
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
@click.group("pysr")
|
| 6 |
+
@click.pass_context
|
| 7 |
+
def pysr(context):
|
| 8 |
+
ctx = context
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@pysr.command("install", help="Install Julia dependencies for PySR.")
|
| 12 |
+
@click.option(
|
| 13 |
+
"-p",
|
| 14 |
+
"julia_project",
|
| 15 |
+
"--project",
|
| 16 |
+
default=None,
|
| 17 |
+
type=str,
|
| 18 |
+
help="Install in a specific Julia project (e.g., a local copy of SymbolicRegression.jl).",
|
| 19 |
+
metavar="PROJECT_DIRECTORY",
|
| 20 |
+
)
|
| 21 |
+
@click.option("-q", "--quiet", is_flag=True, default=False, help="Disable logging.")
|
| 22 |
+
@click.option(
|
| 23 |
+
"--precompile",
|
| 24 |
+
"precompile",
|
| 25 |
+
flag_value=True,
|
| 26 |
+
default=None,
|
| 27 |
+
help="Force precompilation of Julia libraries.",
|
| 28 |
+
)
|
| 29 |
+
@click.option(
|
| 30 |
+
"--no-precompile",
|
| 31 |
+
"precompile",
|
| 32 |
+
flag_value=False,
|
| 33 |
+
default=None,
|
| 34 |
+
help="Disable precompilation.",
|
| 35 |
+
)
|
| 36 |
+
def _install(julia_project, quiet, precompile):
|
| 37 |
+
install(julia_project, quiet, precompile)
|
pysr/export_latex.py
CHANGED
|
@@ -96,7 +96,6 @@ def generate_single_table(
|
|
| 96 |
"$" + output_variable_name + " = " + latex_equation + "$"
|
| 97 |
)
|
| 98 |
else:
|
| 99 |
-
|
| 100 |
broken_latex_equation = " ".join(
|
| 101 |
[
|
| 102 |
r"\begin{minipage}{0.8\linewidth}",
|
|
|
|
| 96 |
"$" + output_variable_name + " = " + latex_equation + "$"
|
| 97 |
)
|
| 98 |
else:
|
|
|
|
| 99 |
broken_latex_equation = " ".join(
|
| 100 |
[
|
| 101 |
r"\begin{minipage}{0.8\linewidth}",
|
pysr/julia_helpers.py
CHANGED
|
@@ -110,10 +110,8 @@ def install(julia_project=None, quiet=False, precompile=None): # pragma: no cov
|
|
| 110 |
|
| 111 |
def _import_error():
|
| 112 |
return """
|
| 113 |
-
Required dependencies are not installed or built. Run the following
|
| 114 |
-
|
| 115 |
-
>>> import pysr
|
| 116 |
-
>>> pysr.install()
|
| 117 |
"""
|
| 118 |
|
| 119 |
|
|
@@ -286,14 +284,14 @@ def _backend_version_assertion(Main):
|
|
| 286 |
f"does not match expected version {expected_backend_version}. "
|
| 287 |
"Things may break. "
|
| 288 |
"Please update your PySR installation with "
|
| 289 |
-
"`
|
| 290 |
)
|
| 291 |
except JuliaError: # pragma: no cover
|
| 292 |
warnings.warn(
|
| 293 |
"You seem to have an outdated version of SymbolicRegression.jl. "
|
| 294 |
"Things may break. "
|
| 295 |
"Please update your PySR installation with "
|
| 296 |
-
"`
|
| 297 |
)
|
| 298 |
|
| 299 |
|
|
|
|
| 110 |
|
| 111 |
def _import_error():
|
| 112 |
return """
|
| 113 |
+
Required dependencies are not installed or built. Run the following command in your terminal:
|
| 114 |
+
python3 -m pysr install
|
|
|
|
|
|
|
| 115 |
"""
|
| 116 |
|
| 117 |
|
|
|
|
| 284 |
f"does not match expected version {expected_backend_version}. "
|
| 285 |
"Things may break. "
|
| 286 |
"Please update your PySR installation with "
|
| 287 |
+
"`python3 -m pysr install`."
|
| 288 |
)
|
| 289 |
except JuliaError: # pragma: no cover
|
| 290 |
warnings.warn(
|
| 291 |
"You seem to have an outdated version of SymbolicRegression.jl. "
|
| 292 |
"Things may break. "
|
| 293 |
"Please update your PySR installation with "
|
| 294 |
+
"`python3 -m pysr install`."
|
| 295 |
)
|
| 296 |
|
| 297 |
|
pysr/test/__init__.py
CHANGED
|
@@ -2,3 +2,4 @@ from .test import runtests
|
|
| 2 |
from .test_env import runtests as runtests_env
|
| 3 |
from .test_jax import runtests as runtests_jax
|
| 4 |
from .test_torch import runtests as runtests_torch
|
|
|
|
|
|
| 2 |
from .test_env import runtests as runtests_env
|
| 3 |
from .test_jax import runtests as runtests_jax
|
| 4 |
from .test_torch import runtests as runtests_torch
|
| 5 |
+
from .test_cli import runtests as runtests_cli
|
pysr/test/__main__.py
CHANGED
|
@@ -11,7 +11,7 @@ if __name__ == "__main__":
|
|
| 11 |
parser.add_argument(
|
| 12 |
"test",
|
| 13 |
nargs="*",
|
| 14 |
-
help="Test to run. One or more of 'main', 'env', 'jax', 'torch'.",
|
| 15 |
)
|
| 16 |
|
| 17 |
# Parse args:
|
|
@@ -25,7 +25,7 @@ if __name__ == "__main__":
|
|
| 25 |
|
| 26 |
# Run tests:
|
| 27 |
for test in tests:
|
| 28 |
-
if test in {"main", "env", "jax", "torch"}:
|
| 29 |
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
| 30 |
print(f"Running test from {cur_dir}")
|
| 31 |
if test == "main":
|
|
@@ -36,6 +36,8 @@ if __name__ == "__main__":
|
|
| 36 |
runtests_jax()
|
| 37 |
elif test == "torch":
|
| 38 |
runtests_torch()
|
|
|
|
|
|
|
| 39 |
else:
|
| 40 |
parser.print_help()
|
| 41 |
raise SystemExit(1)
|
|
|
|
| 11 |
parser.add_argument(
|
| 12 |
"test",
|
| 13 |
nargs="*",
|
| 14 |
+
help="Test to run. One or more of 'main', 'env', 'jax', 'torch', 'cli'.",
|
| 15 |
)
|
| 16 |
|
| 17 |
# Parse args:
|
|
|
|
| 25 |
|
| 26 |
# Run tests:
|
| 27 |
for test in tests:
|
| 28 |
+
if test in {"main", "env", "jax", "torch", "cli"}:
|
| 29 |
cur_dir = os.path.dirname(os.path.abspath(__file__))
|
| 30 |
print(f"Running test from {cur_dir}")
|
| 31 |
if test == "main":
|
|
|
|
| 36 |
runtests_jax()
|
| 37 |
elif test == "torch":
|
| 38 |
runtests_torch()
|
| 39 |
+
elif test == "cli":
|
| 40 |
+
runtests_cli()
|
| 41 |
else:
|
| 42 |
parser.print_help()
|
| 43 |
raise SystemExit(1)
|
pysr/test/test_cli.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
from click import testing as click_testing
|
| 3 |
+
from .._cli.main import pysr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class TestCli(unittest.TestCase):
|
| 7 |
+
# TODO: Include test for custom project here.
|
| 8 |
+
def setUp(self):
|
| 9 |
+
self.cli_runner = click_testing.CliRunner()
|
| 10 |
+
|
| 11 |
+
def test_help_on_all_commands(self):
|
| 12 |
+
expected = "\n".join(
|
| 13 |
+
[
|
| 14 |
+
"Usage: pysr [OPTIONS] COMMAND [ARGS]...",
|
| 15 |
+
"",
|
| 16 |
+
"Options:",
|
| 17 |
+
" --help Show this message and exit.",
|
| 18 |
+
"",
|
| 19 |
+
"Commands:",
|
| 20 |
+
" install Install Julia dependencies for PySR.",
|
| 21 |
+
"",
|
| 22 |
+
]
|
| 23 |
+
)
|
| 24 |
+
result = self.cli_runner.invoke(pysr, ["--help"])
|
| 25 |
+
self.assertEqual(expected, result.output)
|
| 26 |
+
self.assertEqual(0, result.exit_code)
|
| 27 |
+
|
| 28 |
+
def test_help_on_install(self):
|
| 29 |
+
expected = "\n".join(
|
| 30 |
+
[
|
| 31 |
+
"Usage: pysr install [OPTIONS]",
|
| 32 |
+
"",
|
| 33 |
+
" Install Julia dependencies for PySR.",
|
| 34 |
+
"",
|
| 35 |
+
"Options:",
|
| 36 |
+
" -p, --project PROJECT_DIRECTORY",
|
| 37 |
+
" Install in a specific Julia project (e.g., a",
|
| 38 |
+
" local copy of SymbolicRegression.jl).",
|
| 39 |
+
" -q, --quiet Disable logging.",
|
| 40 |
+
" --precompile Force precompilation of Julia libraries.",
|
| 41 |
+
" --no-precompile Disable precompilation.",
|
| 42 |
+
" --help Show this message and exit.",
|
| 43 |
+
"",
|
| 44 |
+
]
|
| 45 |
+
)
|
| 46 |
+
result = self.cli_runner.invoke(pysr, ["install", "--help"])
|
| 47 |
+
self.assertEqual(expected, result.output)
|
| 48 |
+
self.assertEqual(0, result.exit_code)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def runtests():
|
| 52 |
+
"""Run all tests in cliTest.py."""
|
| 53 |
+
loader = unittest.TestLoader()
|
| 54 |
+
suite = unittest.TestSuite()
|
| 55 |
+
suite.addTests(loader.loadTestsFromTestCase(TestCli))
|
| 56 |
+
runner = unittest.TextTestRunner()
|
| 57 |
+
return runner.run(suite)
|
pysr/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
__version__ = "0.
|
| 2 |
__symbolic_regression_jl_version__ = "0.18.0"
|
|
|
|
| 1 |
+
__version__ = "0.14.0"
|
| 2 |
__symbolic_regression_jl_version__ = "0.18.0"
|
requirements.txt
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
sympy
|
| 2 |
pandas
|
| 3 |
numpy
|
| 4 |
-
scikit_learn
|
| 5 |
-
julia
|
|
|
|
|
|
|
|
|
| 1 |
sympy
|
| 2 |
pandas
|
| 3 |
numpy
|
| 4 |
+
scikit_learn>=1.0.0
|
| 5 |
+
julia>=0.6.0
|
| 6 |
+
click>=7.0.0
|
| 7 |
+
setuptools>=50.0.0
|