Skip to content

Commit 3504ec6

Browse files
committed
test: simplify pysr integration test
1 parent 96bfd1d commit 3504ec6

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

.github/workflows/tests.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,17 @@ jobs:
7878
- name: Install dependencies
7979
run: |
8080
python -m pip install --upgrade pip
81-
pip install flake8 pytest pytest-cov nbval numpy virtualenv
81+
pip install flake8 pytest pytest-cov nbval numpy
8282
cp pysrc/juliacall/juliapkg-dev.json pysrc/juliacall/juliapkg.json
8383
pip install -e .
84+
- name: Install integration test dependencies
85+
if: ${{ matrix.test-type == 'integration' }}
86+
run: |
87+
pip install sympy pandas scikit_learn click setuptools
88+
# Note that the `--no-deps` flag is needed for ensuring
89+
# we avoid installing a newer julicall. The initial `pip install`
90+
# is for the non-juliacall dependencies
91+
pip install --no-deps pysr
8492
- name: Lint with flake8
8593
run: |
8694
# stop the build if there are Python syntax errors or undefined names

pytest/integration/test_pysr.py

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,17 @@
11
def test_integration_pysr():
2-
"Integration tests for PySR"
3-
import os
4-
import platform
5-
import subprocess
6-
import sys
7-
import tempfile
2+
"Simple PySR search"
3+
import pysr
4+
import numpy as np
85

9-
with tempfile.TemporaryDirectory() as tempdir:
10-
subprocess.run([sys.executable, "-m", "virtualenv", tempdir], check=True)
6+
rng = np.random.RandomState(0)
7+
X = rng.randn(100, 5)
8+
y = np.cos(X[:, 0] * 2.1 - 0.5) + X[:, 1] * 0.7
9+
model = pysr.PySRRegressor(
10+
niterations=30,
11+
unary_operators=["cos"],
12+
binary_operators=["*", "+", "-"],
13+
early_stop_condition=1e-5,
14+
)
15+
model.fit(X, y)
16+
assert model.equations_.iloc[-1]["loss"] < 1e-5
1117

12-
virtualenv_path = os.path.join(
13-
tempdir, "Scripts" if platform.system() == "Windows" else "bin"
14-
)
15-
virtualenv_executable = os.path.join(virtualenv_path, "python")
16-
17-
assert os.path.exists(virtualenv_executable)
18-
19-
# Install this package
20-
subprocess.run([virtualenv_executable, "-m", "pip", "install", "."], check=True)
21-
# Install PySR with no requirement on JuliaCall
22-
subprocess.run(
23-
[virtualenv_executable, "-m", "pip", "install", "--no-deps", "pysr"],
24-
check=True,
25-
)
26-
# Install PySR test requirements
27-
subprocess.run(
28-
[
29-
virtualenv_executable,
30-
"-m",
31-
"pip",
32-
"install",
33-
"sympy",
34-
"pandas",
35-
"scikit_learn",
36-
"click",
37-
"setuptools",
38-
"pytest",
39-
],
40-
check=True,
41-
)
42-
# Run PySR main test suite
43-
subprocess.run(
44-
[virtualenv_executable, "-m", "pysr", "test", "main"], check=True
45-
)

0 commit comments

Comments
 (0)