MilesCranmer commited on
Commit
2a98f83
1 Parent(s): 618a3f8

Update test suite to test warm starts

Browse files
.github/workflows/CI.yml CHANGED
@@ -71,8 +71,7 @@ jobs:
71
  run: pip install coverage coveralls
72
  - name: "Run tests"
73
  run: |
74
- coverage run --source=pysr --omit='*/test/*' -m pysr test main
75
- coverage run --append --source=pysr --omit='*/test/*' -m pysr test cli
76
  - name: "Install JAX"
77
  run: pip install jax jaxlib # (optional import)
78
  if: ${{ matrix.test-id == 'main' }}
 
71
  run: pip install coverage coveralls
72
  - name: "Run tests"
73
  run: |
74
+ coverage run --source=pysr --omit='*/test/*' -m pysr test main,cli,warm-start
 
75
  - name: "Install JAX"
76
  run: pip install jax jaxlib # (optional import)
77
  if: ${{ matrix.test-id == 'main' }}
.github/workflows/CI_Windows.yml CHANGED
@@ -56,8 +56,7 @@ jobs:
56
  python -c 'import pysr'
57
  - name: "Run tests"
58
  run: |
59
- python -m pysr test main
60
- python -m pysr test cli
61
  - name: "Install Torch"
62
  run: pip install torch # (optional import)
63
  - name: "Run Torch tests"
 
56
  python -c 'import pysr'
57
  - name: "Run tests"
58
  run: |
59
+ python -m pysr test main,cli,warm-start
 
60
  - name: "Install Torch"
61
  run: pip install torch # (optional import)
62
  - name: "Run Torch tests"
.github/workflows/CI_conda_forge.yml CHANGED
@@ -40,4 +40,4 @@ jobs:
40
  run: conda activate pysr-test && conda install pysr
41
  if: ${{ !matrix.use-mamba }}
42
  - name: "Run tests"
43
- run: python -m pysr test main
 
40
  run: conda activate pysr-test && conda install pysr
41
  if: ${{ !matrix.use-mamba }}
42
  - name: "Run tests"
43
+ run: python -m pysr test main,warm-start
.github/workflows/CI_docker.yml CHANGED
@@ -37,4 +37,4 @@ jobs:
37
  - name: Build docker
38
  run: docker build --platform=${{ matrix.arch }} -t pysr .
39
  - name: Test docker
40
- run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr test main && python3 -m pysr test cli'
 
37
  - name: Build docker
38
  run: docker build --platform=${{ matrix.arch }} -t pysr .
39
  - name: Test docker
40
+ run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr test main,cli,warm-start'
.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 }} --build-arg PYVERSION=${{ matrix.python-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'
 
33
  - name: Build docker
34
  run: docker build --platform=${{ matrix.arch }} -t pysr --build-arg JLVERSION=${{ matrix.julia-version }} --build-arg PYVERSION=${{ matrix.python-version }} .
35
  - name: Test docker
36
+ run: docker run --platform=${{ matrix.arch }} --rm pysr /bin/bash -c 'python3 -m pysr test main,cli,warm-start'
.github/workflows/CI_large_nightly.yml CHANGED
@@ -47,5 +47,4 @@ jobs:
47
  run: python3 -c "from pysr import jl; assert jl.VERSION.major == jl.seval('v\"${{ matrix.julia-version }}\"').major; assert jl.VERSION.minor == jl.seval('v\"${{ matrix.julia-version }}\"').minor"
48
  - name: "Run tests"
49
  run: |
50
- python -m pysr test main
51
- python -m pysr test cli
 
47
  run: python3 -c "from pysr import jl; assert jl.VERSION.major == jl.seval('v\"${{ matrix.julia-version }}\"').major; assert jl.VERSION.minor == jl.seval('v\"${{ matrix.julia-version }}\"').minor"
48
  - name: "Run tests"
49
  run: |
50
+ python -m pysr test main,cli,warm-start
 
.github/workflows/CI_mac.yml CHANGED
@@ -56,8 +56,7 @@ jobs:
56
  python -c 'import pysr'
57
  - name: "Run tests"
58
  run: |
59
- python -m pysr test main
60
- python -m pysr test cli
61
  - name: "Install JAX"
62
  run: pip install jax jaxlib # (optional import)
63
  - name: "Run JAX tests"
 
56
  python -c 'import pysr'
57
  - name: "Run tests"
58
  run: |
59
+ python -m pysr test main,cli,warm-start
 
60
  - name: "Install JAX"
61
  run: pip install jax jaxlib # (optional import)
62
  - name: "Run JAX tests"
pysr/_cli/main.py CHANGED
@@ -17,15 +17,13 @@ def pysr(context):
17
  ctx = context
18
 
19
 
20
- @pysr.command("install", help="Install Julia dependencies for PySR.")
21
  @click.option(
22
  "-p",
23
  "julia_project",
24
  "--project",
25
  default=None,
26
  type=str,
27
- help="Install in a specific Julia project (e.g., a local copy of SymbolicRegression.jl).",
28
- metavar="PROJECT_DIRECTORY",
29
  )
30
  @click.option("-q", "--quiet", is_flag=True, default=False, help="Disable logging.")
31
  @click.option(
@@ -33,14 +31,12 @@ def pysr(context):
33
  "precompile",
34
  flag_value=True,
35
  default=None,
36
- help="Force precompilation of Julia libraries.",
37
  )
38
  @click.option(
39
  "--no-precompile",
40
  "precompile",
41
  flag_value=False,
42
  default=None,
43
- help="Disable precompilation.",
44
  )
45
  def _install(julia_project, quiet, precompile):
46
  warnings.warn(
@@ -51,33 +47,25 @@ def _install(julia_project, quiet, precompile):
51
  TEST_OPTIONS = {"main", "jax", "torch", "cli", "warm_start"}
52
 
53
 
54
- @pysr.command("test", help="Run PySR test suite.")
55
- @click.argument("tests", nargs=-1)
56
  def _tests(tests):
57
- """Run part of the PySR test suite.
58
 
59
- Choose from main, jax, torch, cli, and warm_start.
60
  """
61
- if len(tests) == 0:
62
- raise click.UsageError(
63
- "At least one test must be specified. "
64
- + "The following are available: "
65
- + ", ".join(TEST_OPTIONS)
66
- + "."
67
- )
68
- else:
69
- for test in tests:
70
- if test in TEST_OPTIONS:
71
- if test == "main":
72
- runtests()
73
- elif test == "jax":
74
- runtests_jax()
75
- elif test == "torch":
76
- runtests_torch()
77
- elif test == "cli":
78
- runtests_cli = get_runtests_cli()
79
- runtests_cli()
80
- elif test == "warm_start":
81
- runtests_warm_start()
82
- else:
83
- warnings.warn(f"Invalid test {test}. Skipping.")
 
17
  ctx = context
18
 
19
 
20
+ @pysr.command("install", help="DEPRECATED (dependencies are now installed at import).")
21
  @click.option(
22
  "-p",
23
  "julia_project",
24
  "--project",
25
  default=None,
26
  type=str,
 
 
27
  )
28
  @click.option("-q", "--quiet", is_flag=True, default=False, help="Disable logging.")
29
  @click.option(
 
31
  "precompile",
32
  flag_value=True,
33
  default=None,
 
34
  )
35
  @click.option(
36
  "--no-precompile",
37
  "precompile",
38
  flag_value=False,
39
  default=None,
 
40
  )
41
  def _install(julia_project, quiet, precompile):
42
  warnings.warn(
 
47
  TEST_OPTIONS = {"main", "jax", "torch", "cli", "warm_start"}
48
 
49
 
50
+ @pysr.command("test")
51
+ @click.argument("tests", nargs=1)
52
  def _tests(tests):
53
+ """Run parts of the PySR test suite.
54
 
55
+ Choose from main, jax, torch, cli, and warm_start. You can give multiple tests, separated by commas.
56
  """
57
+ for test in tests.split(","):
58
+ if test in TEST_OPTIONS:
59
+ if test == "main":
60
+ runtests()
61
+ elif test == "jax":
62
+ runtests_jax()
63
+ elif test == "torch":
64
+ runtests_torch()
65
+ elif test == "cli":
66
+ runtests_cli = get_runtests_cli()
67
+ runtests_cli()
68
+ elif test == "warm-start":
69
+ runtests_warm_start()
70
+ else:
71
+ warnings.warn(f"Invalid test {test}. Skipping.")
 
 
 
 
 
 
 
 
pysr/test/test_cli.py CHANGED
@@ -1,4 +1,5 @@
1
  import unittest
 
2
 
3
  from click import testing as click_testing
4
 
@@ -14,43 +15,58 @@ def get_runtests():
14
  self.cli_runner = click_testing.CliRunner()
15
 
16
  def test_help_on_all_commands(self):
17
- expected = "\n".join(
18
- [
19
- "Usage: pysr [OPTIONS] COMMAND [ARGS]...",
20
- "",
21
- "Options:",
22
- " --help Show this message and exit.",
23
- "",
24
- "Commands:",
25
- " install Install Julia dependencies for PySR.",
26
- "",
27
- ]
28
  )
29
  result = self.cli_runner.invoke(pysr, ["--help"])
30
- self.assertEqual(expected, result.output)
31
- self.assertEqual(0, result.exit_code)
32
 
33
  def test_help_on_install(self):
34
- expected = "\n".join(
35
- [
36
- "Usage: pysr install [OPTIONS]",
37
- "",
38
- " Install Julia dependencies for PySR.",
39
- "",
40
- "Options:",
41
- " -p, --project PROJECT_DIRECTORY",
42
- " Install in a specific Julia project (e.g., a",
43
- " local copy of SymbolicRegression.jl).",
44
- " -q, --quiet Disable logging.",
45
- " --precompile Force precompilation of Julia libraries.",
46
- " --no-precompile Disable precompilation.",
47
- " --help Show this message and exit.",
48
- "",
49
- ]
50
  )
51
  result = self.cli_runner.invoke(pysr, ["install", "--help"])
52
- self.assertEqual(expected, result.output)
53
- self.assertEqual(0, result.exit_code)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
  def runtests():
56
  """Run all tests in cliTest.py."""
 
1
  import unittest
2
+ from textwrap import dedent
3
 
4
  from click import testing as click_testing
5
 
 
15
  self.cli_runner = click_testing.CliRunner()
16
 
17
  def test_help_on_all_commands(self):
18
+ expected = dedent(
19
+ """
20
+ Usage: pysr [OPTIONS] COMMAND [ARGS]...
21
+
22
+ Options:
23
+ --help Show this message and exit.
24
+
25
+ Commands:
26
+ install DEPRECATED (dependencies are now installed at import).
27
+ test Run PySR test suite.
28
+ """
29
  )
30
  result = self.cli_runner.invoke(pysr, ["--help"])
31
+ self.assertEqual(result.output, expected)
32
+ self.assertEqual(result.exit_code, 0)
33
 
34
  def test_help_on_install(self):
35
+ expected = dedent(
36
+ """
37
+ Usage: pysr install [OPTIONS]
38
+
39
+ DEPRECATED (dependencies are now installed at import).
40
+
41
+ Options:
42
+ -p, --project TEXT
43
+ -q, --quiet Disable logging.
44
+ --precompile
45
+ --no-precompile
46
+ --help Show this message and exit.
47
+ """
 
 
 
48
  )
49
  result = self.cli_runner.invoke(pysr, ["install", "--help"])
50
+ self.assertEqual(result.output, expected)
51
+ self.assertEqual(result.exit_code, 0)
52
+
53
+ def test_help_on_test(self):
54
+ expected = dedent(
55
+ """
56
+ Usage: pysr test [OPTIONS] TESTS
57
+
58
+ Run parts of the PySR test suite.
59
+
60
+ Choose from main, jax, torch, cli, and warm_start. You can give multiple
61
+ tests, separated by commas.
62
+
63
+ Options:
64
+ --help Show this message and exit.
65
+ """
66
+ )
67
+ result = self.cli_runner.invoke(pysr, ["test", "--help"])
68
+ self.assertEqual(result.output, expected)
69
+ self.assertEqual(result.exit_code, 0)
70
 
71
  def runtests():
72
  """Run all tests in cliTest.py."""