Skip to content

Commit

Permalink
Merge branch 'master' into fix-cluster-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Feb 23, 2025
2 parents d0593b1 + 0f448b5 commit 0a133c9
Show file tree
Hide file tree
Showing 13 changed files with 421 additions and 107 deletions.
33 changes: 10 additions & 23 deletions .github/workflows/CI_conda_forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,12 @@ jobs:
timeout-minutes: 60
defaults:
run:
shell: bash -l {0}
shell: bash -el {0}
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11', '3.12']
os: ['ubuntu-latest']
use-mamba: [true, false]
include:
- python-version: '3.10'
os: 'windows-latest'
use-mamba: true
- python-version: '3.12'
os: 'windows-latest'
use-mamba: true
- python-version: '3.10'
os: 'macos-latest'
use-mamba: true
- python-version: '3.12'
os: 'macos-latest'
use-mamba: true
python-version: ['3.10', '3']
os: ['ubuntu-latest', 'windows-latest', 'macos-latest']

steps:
- name: "Set up Conda"
Expand All @@ -46,13 +32,14 @@ jobs:
auto-activate-base: true
python-version: ${{ matrix.python-version }}
activate-environment: pysr-test
- name: "Install pysr with mamba"
run: conda activate pysr-test && mamba install pysr
if: ${{ matrix.use-mamba }}
- name: "Install pysr with conda"
run: conda activate pysr-test && conda install pysr
if: ${{ !matrix.use-mamba }}
- name: "Install pysr"
run: |
conda install -y pysr
python -c "import pysr"
echo "Finished."
- name: "Run tests"
run: |
echo "Running tests"
pip install pytest nbval
python -m pysr test main,startup
echo "Finished."
2 changes: 1 addition & 1 deletion .github/workflows/update_backend_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
major, minor, patch, *dev = pyproject_data["project"]["version"].split(".")
pyproject_data["project"]["version"] = f"{major}.{minor}.{int(patch)+1}"

juliapkg_data["packages"]["SymbolicRegression"]["version"] = f"={new_backend_version}"
juliapkg_data["packages"]["SymbolicRegression"]["version"] = f"~{new_backend_version}"

with open(pyproject_toml, "w") as toml_file:
toml_file.write(tomlkit.dumps(pyproject_data))
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ repos:
- id: check-added-large-files
# General formatting
- repo: https://github.com/psf/black
rev: 24.10.0
rev: 25.1.0
hooks:
- id: black
- id: black-jupyter
exclude: pysr/test/test_nb.ipynb
# Stripping notebooks
- repo: https://github.com/kynan/nbstripout
rev: 0.8.0
rev: 0.8.1
hooks:
- id: nbstripout
exclude: pysr/test/test_nb.ipynb
# Unused imports
- repo: https://github.com/hadialqattan/pycln
rev: "v2.4.0"
rev: "v2.5.0"
hooks:
- id: pycln
# Sorted imports
- repo: https://github.com/PyCQA/isort
rev: "5.13.2"
rev: "6.0.0"
hooks:
- id: isort
additional_dependencies: [toml]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ If you've finished a project with PySR, please submit a PR to showcase your work
- [Why PySR?](#why-pysr)
- [Installation](#installation)
- [Quickstart](#quickstart)
- [→ Documentation](https://ai.damtp.cam.ac.uk/PySR)
- [→ Documentation](https://ai.damtp.cam.ac.uk/pysr)
- [Contributors](#contributors-)

<div align="center">
Expand Down
33 changes: 28 additions & 5 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,9 @@ y = np.sin(X[:, 0] + X[:, 1]) + X[:, 2]**2

# Define template: we want sin(f(x1, x2)) + g(x3)
template = TemplateExpressionSpec(
function_symbols=["f", "g"],
combine="((; f, g), (x1, x2, x3)) -> sin(f(x1, x2)) + g(x3)",
expressions=["f", "g"],
variable_names=["x1", "x2", "x3"],
combine="sin(f(x1, x2)) + g(x3)",
)

model = PySRRegressor(
Expand All @@ -559,15 +560,23 @@ model = PySRRegressor(
model.fit(X, y)
```

You can also use no argument-functions for learning constants, like:
You can also use parameters in your template expressions, which will be optimized during the search:

```python
template = TemplateExpressionSpec(
function_symbols=["a", "f"],
combine="((; a, f), (x, y)) -> a() * sin(f(x, y))",
expressions=["f", "g"],
variable_names=["x1", "x2", "x3"],
parameters={"p1": 2, "p2": 1}, # p1 has length 2, p2 has length 1
combine="p1[1] * sin(f(x1, x2)) + p1[2] * g(x3) + p2[1]",
)
```

This will learn an equation of the form:

$$ y = \alpha_1 \sin(f(x_1, x_2)) + \alpha_2 g(x_3) + \beta $$

where $\alpha_1, \alpha_2$ are stored in `p1` and $\beta$ is stored in `p2`. The parameters will be optimized during the search.

### Parametric Expressions

When your data has categories with shared equation structure but different parameters,
Expand Down Expand Up @@ -609,6 +618,20 @@ model.fit(X, y, category=category)

See [Expression Specifications](/api/#expression-specifications) for more details.

You can also use `TemplateExpressionSpec` in the same way, passing
the category as a column of `X`:

```python
spec = TemplateExpressionSpec(
expressions=["f", "g"],
variable_names=["x1", "x2", "class"],
combine="p1[class] * sin(f(x1, x2)) + p2[class]",
)
```

this column will automatically be converted to integers.


## 12. Using TensorBoard for Logging

You can use TensorBoard to visualize the search progress, as well as
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pysr"
version = "1.3.1"
version = "1.5.0"
authors = [
{name = "Miles Cranmer", email = "miles.cranmer@gmail.com"},
]
Expand All @@ -22,7 +22,7 @@ dependencies = [
"pandas>=0.21.0,<3.0.0",
"numpy>=1.13.0,<3.0.0",
"scikit_learn>=1.0.0,<2.0.0",
"juliacall==0.9.23",
"juliacall==0.9.24",
"click>=7.0.0,<9.0.0",
"setuptools>=50.0.0",
]
Expand Down
7 changes: 7 additions & 0 deletions pysr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import logging
import os

pysr_logger = logging.getLogger("pysr")
pysr_logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.INFO)
pysr_logger.addHandler(handler)

if os.environ.get("PYSR_USE_BEARTYPE", "0") == "1":
from beartype.claw import beartype_this_package

Expand Down
Loading

0 comments on commit 0a133c9

Please sign in to comment.