MilesCranmer commited on
Commit
92eb30b
1 Parent(s): 7049740

Extend startup tests to other warning messages

Browse files
.github/workflows/CI.yml CHANGED
@@ -71,7 +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,cli,warm-start
75
  - name: "Install JAX"
76
  run: pip install jax jaxlib # (optional import)
77
  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,startup
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,7 +56,7 @@ jobs:
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"
 
56
  python -c 'import pysr'
57
  - name: "Run tests"
58
  run: |
59
+ python -m pysr test main,cli,startup
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,warm-start
 
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,startup
.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,cli,warm-start'
 
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,startup'
.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,cli,warm-start'
 
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,startup'
.github/workflows/CI_large_nightly.yml CHANGED
@@ -47,4 +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,cli,warm-start
 
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,startup
.github/workflows/CI_mac.yml CHANGED
@@ -56,7 +56,7 @@ jobs:
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"
 
56
  python -c 'import pysr'
57
  - name: "Run tests"
58
  run: |
59
+ python -m pysr test main,cli,startup
60
  - name: "Install JAX"
61
  run: pip install jax jaxlib # (optional import)
62
  - name: "Run JAX tests"
pysr/_cli/main.py CHANGED
@@ -6,8 +6,8 @@ from ..test import (
6
  get_runtests_cli,
7
  runtests,
8
  runtests_jax,
 
9
  runtests_torch,
10
- runtests_warm_start,
11
  )
12
 
13
 
@@ -44,7 +44,7 @@ def _install(julia_project, quiet, precompile):
44
  )
45
 
46
 
47
- TEST_OPTIONS = {"main", "jax", "torch", "cli", "warm-start"}
48
 
49
 
50
  @pysr.command("test")
@@ -52,7 +52,7 @@ TEST_OPTIONS = {"main", "jax", "torch", "cli", "warm-start"}
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 == "main":
@@ -64,7 +64,7 @@ def _tests(tests):
64
  elif test == "cli":
65
  runtests_cli = get_runtests_cli()
66
  runtests_cli()
67
- elif test == "warm-start":
68
- runtests_warm_start()
69
  else:
70
  warnings.warn(f"Invalid test {test}. Skipping.")
 
6
  get_runtests_cli,
7
  runtests,
8
  runtests_jax,
9
+ runtests_startup,
10
  runtests_torch,
 
11
  )
12
 
13
 
 
44
  )
45
 
46
 
47
+ TEST_OPTIONS = {"main", "jax", "torch", "cli", "startup"}
48
 
49
 
50
  @pysr.command("test")
 
52
  def _tests(tests):
53
  """Run parts of the PySR test suite.
54
 
55
+ Choose from main, jax, torch, cli, and startup. You can give multiple tests, separated by commas.
56
  """
57
  for test in tests.split(","):
58
  if test == "main":
 
64
  elif test == "cli":
65
  runtests_cli = get_runtests_cli()
66
  runtests_cli()
67
+ elif test == "startup":
68
+ runtests_startup()
69
  else:
70
  warnings.warn(f"Invalid test {test}. Skipping.")
pysr/test/__init__.py CHANGED
@@ -1,13 +1,13 @@
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
- from .test_warm_start import runtests as runtests_warm_start
6
 
7
  __all__ = [
8
  "runtests",
9
  "runtests_jax",
10
  "runtests_torch",
11
  "get_runtests_cli",
12
- "runtests_warm_start",
13
  ]
 
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_startup import runtests as runtests_startup
5
  from .test_torch import runtests as runtests_torch
 
6
 
7
  __all__ = [
8
  "runtests",
9
  "runtests_jax",
10
  "runtests_torch",
11
  "get_runtests_cli",
12
+ "runtests_startup",
13
  ]
pysr/test/test.py CHANGED
@@ -638,6 +638,50 @@ class TestMiscellaneous(unittest.TestCase):
638
  model.fit(X, y, variable_names=["f{c}"])
639
  self.assertIn("Invalid variable name", str(cm.exception))
640
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
641
  def test_pickle_with_temp_equation_file(self):
642
  """If we have a temporary equation file, unpickle the estimator."""
643
  model = PySRRegressor(
 
638
  model.fit(X, y, variable_names=["f{c}"])
639
  self.assertIn("Invalid variable name", str(cm.exception))
640
 
641
+ def test_bad_kwargs(self):
642
+ bad_kwargs = [
643
+ dict(
644
+ kwargs=dict(
645
+ elementwise_loss="g(x, y) = 0.0", loss_function="f(*args) = 0.0"
646
+ ),
647
+ error=ValueError,
648
+ ),
649
+ dict(
650
+ kwargs=dict(maxsize=3),
651
+ error=ValueError,
652
+ ),
653
+ dict(
654
+ kwargs=dict(tournament_selection_n=10, population_size=3),
655
+ error=ValueError,
656
+ ),
657
+ dict(
658
+ kwargs=dict(optimizer_algorithm="COBYLA"),
659
+ error=NotImplementedError,
660
+ ),
661
+ dict(
662
+ kwargs=dict(
663
+ constraints={
664
+ "+": (3, 5),
665
+ }
666
+ ),
667
+ error=NotImplementedError,
668
+ ),
669
+ dict(
670
+ kwargs=dict(binary_operators=["α(x, y) = x - y"]),
671
+ error=ValueError,
672
+ ),
673
+ dict(
674
+ kwargs=dict(model_selection="unknown"),
675
+ error=NotImplementedError,
676
+ ),
677
+ ]
678
+ for opt in bad_kwargs:
679
+ model = PySRRegressor(**opt["kwargs"], niterations=1)
680
+ with self.assertRaises(opt["error"]):
681
+ model.fit([[1]], [1])
682
+ model.get_best()
683
+ print("Failed", opt["kwargs"])
684
+
685
  def test_pickle_with_temp_equation_file(self):
686
  """If we have a temporary equation file, unpickle the estimator."""
687
  model = PySRRegressor(
pysr/test/test_cli.py CHANGED
@@ -57,7 +57,7 @@ def get_runtests():
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:
 
57
 
58
  Run parts of the PySR test suite.
59
 
60
+ Choose from main, jax, torch, cli, and startup. You can give multiple
61
  tests, separated by commas.
62
 
63
  Options:
pysr/test/{test_warm_start.py → test_startup.py} RENAMED
@@ -10,7 +10,9 @@ from .. import PySRRegressor
10
  from .params import DEFAULT_NITERATIONS, DEFAULT_POPULATIONS
11
 
12
 
13
- class TestWarmStart(unittest.TestCase):
 
 
14
  def setUp(self):
15
  # Using inspect,
16
  # get default niterations from PySRRegressor, and double them:
@@ -94,10 +96,37 @@ class TestWarmStart(unittest.TestCase):
94
  self.assertIn("Loading model from file", result.stdout.decode())
95
  self.assertIn("Started!", result.stderr.decode())
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  def runtests():
99
  suite = unittest.TestSuite()
100
  loader = unittest.TestLoader()
101
- suite.addTests(loader.loadTestsFromTestCase(TestWarmStart))
102
  runner = unittest.TextTestRunner()
103
  return runner.run(suite)
 
10
  from .params import DEFAULT_NITERATIONS, DEFAULT_POPULATIONS
11
 
12
 
13
+ class TestStartup(unittest.TestCase):
14
+ """Various tests related to starting up PySR."""
15
+
16
  def setUp(self):
17
  # Using inspect,
18
  # get default niterations from PySRRegressor, and double them:
 
96
  self.assertIn("Loading model from file", result.stdout.decode())
97
  self.assertIn("Started!", result.stderr.decode())
98
 
99
+ def test_bad_startup_options(self):
100
+ warning_tests = [
101
+ dict(
102
+ code='import os; os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = "no"; import pysr',
103
+ msg="PYTHON_JULIACALL_HANDLE_SIGNALS environment variable is set",
104
+ ),
105
+ dict(
106
+ code='import os; os.environ["JULIA_NUM_THREADS"] = "1"; import pysr',
107
+ msg="JULIA_NUM_THREADS environment variable is set",
108
+ ),
109
+ dict(
110
+ code="import juliacall; import pysr",
111
+ msg="juliacall module already imported.",
112
+ ),
113
+ dict(
114
+ code='import os; os.environ["PYSR_AUTOLOAD_EXTENSIONS"] = "foo"; import pysr',
115
+ msg="PYSR_AUTOLOAD_EXTENSIONS environment variable is set",
116
+ ),
117
+ ]
118
+ for warning_test in warning_tests:
119
+ result = subprocess.run(
120
+ ["python", "-c", warning_test["code"]],
121
+ stdout=subprocess.PIPE,
122
+ stderr=subprocess.PIPE,
123
+ )
124
+ self.assertIn(warning_test["msg"], result.stderr.decode())
125
+
126
 
127
  def runtests():
128
  suite = unittest.TestSuite()
129
  loader = unittest.TestLoader()
130
+ suite.addTests(loader.loadTestsFromTestCase(TestStartup))
131
  runner = unittest.TextTestRunner()
132
  return runner.run(suite)