Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PySR integration test #461

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ on:

jobs:
julia:
name: Test (${{ matrix.os }}, julia ${{ matrix.jlversion }})
name: julia-${{ matrix.test-type }}-${{ matrix.os }}-jl${{ matrix.jlversion }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
arch: [x64] # x86 unsupported by MicroMamba
os: [ubuntu-latest, windows-latest, macos-latest]
jlversion: ['1','1.6']
test-type: ['unit']
steps:
- uses: actions/checkout@v2
- name: Set up Julia ${{ matrix.jlversion }}
Expand Down Expand Up @@ -48,16 +49,24 @@ jobs:
uses: julia-actions/julia-processcoverage@v1
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
if: ${{ matrix.test-type == 'unit' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
python:
name: Test (${{ matrix.os }}, python ${{ matrix.pyversion }})
name: python-${{ matrix.test-type }}-${{ matrix.os }}-py${{ matrix.pyversion }}
runs-on: ${{ matrix.os }}
env:
PYTHON_JULIACALL_THREADS: '2'
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
pyversion: ["3.x", "3.8"]
test-type: ['unit']
include:
- os: ubuntu-latest
pyversion: '3.x'
test-type: 'integration'
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.pyversion }}
Expand All @@ -74,18 +83,28 @@ jobs:
pip install flake8 pytest pytest-cov nbval numpy
cp pysrc/juliacall/juliapkg-dev.json pysrc/juliacall/juliapkg.json
pip install -e .
- name: Install integration test dependencies
if: ${{ matrix.test-type == 'integration' }}
run: |
pip install sympy pandas scikit_learn click setuptools
# Note that the `--no-deps` flag is needed for ensuring
# we avoid installing a newer julicall. The initial `pip install`
# is for the non-juliacall dependencies.
pip install --no-deps pysr
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --ignore=F821 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests
run: |
pytest -s --nbval --cov=pysrc ./pytest/
env:
PYTHON_JULIACALL_THREADS: '2'
- name: Run unit tests
if: ${{ matrix.test-type == 'unit' }}
run: pytest -s --nbval --cov=pysrc ./pytest/ -k "not integration"
- name: Run integration tests
if: ${{ matrix.test-type == 'integration' }}
run: pytest -s ./pytest/integration/
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
if: ${{ matrix.test-type == 'unit' }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
19 changes: 19 additions & 0 deletions pytest/integration/test_pysr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def test_integration_pysr():
"Simple PySR search"
import pysr
import numpy as np

rng = np.random.RandomState(0)
X = rng.randn(100, 5)
y = np.cos(X[:, 0] * 2.1 - 0.5) + X[:, 1] * 0.7
model = pysr.PySRRegressor(
niterations=30,
unary_operators=["cos"],
binary_operators=["*", "+", "-"],
early_stop_condition=1e-5,
temp_equation_file=True,
progress=False,
)
model.fit(X, y)
assert model.equations_.iloc[-1]["loss"] < 1e-5

Loading