Skip to content

Commit

Permalink
Merge branch 'master' into latex-table
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Aug 10, 2022
2 parents 3ef2b32 + 35e6ab1 commit 0dbee97
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@
*.csv
*.csv.out*
*.bkup
*.pkl
performance*txt
*.out
trials*
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Expand Up @@ -3,9 +3,16 @@

ARG ARCH=linux/amd64
ARG VERSION=latest
ARG PKGVERSION=0.9.5

FROM --platform=$ARCH julia:$VERSION

# metainformation
LABEL org.opencontainers.image.version = $PKGVERSION
LABEL org.opencontainers.image.authors = "Miles Cranmer"
LABEL org.opencontainers.image.source = "https://github.com/MilesCranmer/PySR"
LABEL org.opencontainers.image.licenses = "Apache License 2.0"

# Need to use ARG after FROM, otherwise it won't get passed through.
ARG PYVERSION=3.9.10

Expand Down
32 changes: 29 additions & 3 deletions README.md
@@ -1,30 +1,44 @@
[//]: # (Logo:)

<img src="https://raw.githubusercontent.com/MilesCranmer/PySR/master/docs/images/pysr_logo.svg" width="400" />
<div align="center">

<img src="https://raw.githubusercontent.com/MilesCranmer/PySR/master/docs/images/pysr_logo.svg" width="200" />

# PySR: High-Performance Symbolic Regression in Python

</div>


PySR is built on an extremely optimized pure-Julia backend, and uses regularized evolution, simulated annealing, and gradient-free optimization to search for equations that fit your data.

<div align="center">

| **Docs** | **colab** | **pip** | **conda** | **Stats** |
|---|---|---|---|---|
|[![Documentation](https://github.com/MilesCranmer/PySR/actions/workflows/docs.yml/badge.svg)](https://astroautomata.com/PySR/)|[![Colab](https://img.shields.io/badge/colab-notebook-yellow)](https://colab.research.google.com/github/MilesCranmer/PySR/blob/master/examples/pysr_demo.ipynb)|[![PyPI version](https://badge.fury.io/py/pysr.svg)](https://badge.fury.io/py/pysr)|[![Conda Version](https://img.shields.io/conda/vn/conda-forge/pysr.svg)](https://anaconda.org/conda-forge/pysr)|[![Downloads](https://pepy.tech/badge/pysr)](https://badge.fury.io/py/pysr)|

</div>


(pronounced like *py* as in python, and then *sur* as in surface)

If you find PySR useful, please cite it using the citation information given in [CITATION.md](https://github.com/MilesCranmer/PySR/blob/master/CITATION.md).
If you've finished a project with PySR, please submit a PR to showcase your work on the [Research Showcase page](https://astroautomata.com/PySR/#/papers)!


### Test status:
<div align="center">

### Test status

| **Linux** | **Windows** | **macOS (intel)** |
|---|---|---|
|[![Linux](https://github.com/MilesCranmer/PySR/actions/workflows/CI.yml/badge.svg)](https://github.com/MilesCranmer/PySR/actions/workflows/CI.yml)|[![Windows](https://github.com/MilesCranmer/PySR/actions/workflows/CI_Windows.yml/badge.svg)](https://github.com/MilesCranmer/PySR/actions/workflows/CI_Windows.yml)|[![macOS](https://github.com/MilesCranmer/PySR/actions/workflows/CI_mac.yml/badge.svg)](https://github.com/MilesCranmer/PySR/actions/workflows/CI_mac.yml)|
| **Docker** | **Conda** | **Coverage** |
|[![Docker](https://github.com/MilesCranmer/PySR/actions/workflows/CI_docker.yml/badge.svg)](https://github.com/MilesCranmer/PySR/actions/workflows/CI_docker.yml)|[![conda-forge](https://github.com/MilesCranmer/PySR/actions/workflows/CI_conda_forge.yml/badge.svg)](https://github.com/MilesCranmer/PySR/actions/workflows/CI_conda_forge.yml)|[![Coverage Status](https://coveralls.io/repos/github/MilesCranmer/PySR/badge.svg?branch=master&service=github)](https://coveralls.io/github/MilesCranmer/PySR)|


</div>

Check out [SymbolicRegression.jl](https://github.com/MilesCranmer/SymbolicRegression.jl) for
the pure-Julia backend of this package.

Expand Down Expand Up @@ -58,10 +72,14 @@ python interface.

# Installation

<div align="center">

| pip (macOS, Linux, Windows) | conda (macOS - only Intel, Linux) |
|---|---|
| 1. Install Julia manually (see [downloads](https://julialang.org/downloads/))<br>2. `pip install pysr`<br>3. `python -c 'import pysr; pysr.install()'` | 1. `conda install -c conda-forge pysr`<br>2. `python -c 'import pysr; pysr.install()'`|

</div>

This last step will install and update the required Julia packages, including
`PyCall.jl`.

Expand Down Expand Up @@ -144,7 +162,15 @@ This arrow in the `pick` column indicates which equation is currently selected b
SymPy format (`sympy_format` - which you can also get with `model.sympy()`), and even JAX and PyTorch format
(both of which are differentiable - which you can get with `model.jax()` and `model.pytorch()`).

Note that `PySRRegressor` stores the state of the last search, and will restart from where you left off the next time you call `.fit()`. This will cause problems if significant changes are made to the search parameters (like changing the operators). You can run `model.reset()` to reset the state.
Note that `PySRRegressor` stores the state of the last search, and will restart from where you left off the next time you call `.fit()`, assuming you have set `warm_start=True`.
This will cause problems if significant changes are made to the search parameters (like changing the operators). You can run `model.reset()` to reset the state.

You will notice that PySR will save two files: `hall_of_fame...csv` and `hall_of_fame...pkl`.
The csv file is a list of equations and their losses, and the pkl file is a saved state of the model.
You may load the model from the `pkl` file with:
```python
model = PySRRegressor.from_file("hall_of_fame.2022-08-10_100832.281.pkl")
```

There are several other useful features such as denoising (e.g., `denoising=True`),
feature selection (e.g., `select_k_features=3`).
Expand Down
18 changes: 18 additions & 0 deletions docs/options.md
Expand Up @@ -16,6 +16,7 @@ may find useful include:
- LaTeX, SymPy
- Callable exports: numpy, pytorch, jax
- `loss`
- Model loading

These are described below

Expand Down Expand Up @@ -252,3 +253,20 @@ Can also uses these losses for weighted (weighted-average):
model = PySRRegressor(..., weights=weights, loss="LPDistLoss{3}()")
model.fit(..., weights=weights)
```

## Model loading

PySR will automatically save a pickle file of the model state
when you call `model.fit`, once before the search starts,
and again after the search finishes. The filename will
have the same base name as the input file, but with a `.pkl` extension.
You can load the saved model state with:
```python
model = PySRRegressor.from_file(pickle_filename)
```
If you have a long-running job and would like to load the model
before completion, you can also do this. In this case, the model
loading will use the `csv` file to load the equations, since the
`csv` file is continually updated during the search. Once
the search completes, the model including its equations will
be saved to the pickle file, overwriting the existing version.

0 comments on commit 0dbee97

Please sign in to comment.