Skip to content

Commit

Permalink
Merge ceeb420 into 9a56c67
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesCranmer committed Jan 20, 2022
2 parents 9a56c67 + ceeb420 commit ae7c60a
Show file tree
Hide file tree
Showing 17 changed files with 434 additions and 500 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Expand Up @@ -61,6 +61,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
- name: "Install Coverage tool"
run: pip install coverage coveralls
- name: "Run tests"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/CI_Windows.yml
Expand Up @@ -61,6 +61,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
- name: "Run tests"
run: python -m unittest test.test
shell: bash
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/CI_conda.yml
@@ -0,0 +1,76 @@
name: CI_conda
# This tests whether conda, a statically-linked libpython, works
# with PySR.

on:
push:
branches:
- '*'
paths:
- 'test/**'
- 'pysr/**'
- '.github/workflows/**'
- 'setup.py'
- 'Project.toml'
pull_request:
branches:
- '*'
paths:
- 'test/**'
- 'pysr/**'
- '.github/workflows/**'
- 'setup.py'
- 'Project.toml'

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: ['1.7.1']
python-version: ['3.9']
os: ['ubuntu-latest']

steps:
- uses: actions/checkout@v1.0.0
- name: "Set up Julia"
uses: julia-actions/setup-julia@v1.6.0
with:
version: ${{ matrix.julia-version }}
- name: "Change package server"
shell: bash
env:
JULIA_PKG_SERVER: ""
run: |
julia -e 'using Pkg; Pkg.Registry.add("General")'
- name: "Cache dependencies"
uses: actions/cache@v1 # Thanks FromFile.jl
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: "Set up Conda"
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
auto-activate-base: true
python-version: ${{ matrix.python-version }}
activate-environment: test
environment-file: environment.yml
- name: "Install PySR"
run: |
python3 -m pip install .
python3 -c 'import pysr; pysr.install()'
shell: bash -l {0}
- name: "Ensure that static libpython warning appears"
run: python3 test/test_static_libpython_warning.py
shell: bash -l {0}
- name: "Run tests"
run: python3 -m unittest discover -s test
shell: bash -l {0}
1 change: 1 addition & 0 deletions .github/workflows/CI_mac.yml
Expand Up @@ -61,6 +61,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
python setup.py install
python -c 'import pysr; pysr.install()'
- name: "Run tests"
run: python -m unittest test.test
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,6 @@ dist
*.pyproj
*.sln
pysr/.vs/
pysr.egg-info
Manifest.toml
workflow
32 changes: 23 additions & 9 deletions Dockerfile
@@ -1,30 +1,44 @@
# This builds a dockerfile containing a working copy of PySR
# with all pre-requisites installed.


ARG VERSION=latest

FROM julia:$VERSION

RUN apt-get update && apt-get upgrade -y && apt-get install -y \
build-essential python3 python3-dev python3-pip python3-setuptools \
vim git wget curl \
make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev \
vim git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /pysr

# Install PyEnv to switch Python to dynamically linked version:
RUN curl https://pyenv.run | bash
ENV PATH="/root/.pyenv/bin:$PATH"

ENV PYTHON_VERSION="3.9.10"
RUN PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install ${PYTHON_VERSION}
ENV PATH="/root/.pyenv/versions/${PYTHON_VERSION}/bin:$PATH"

# Install IPython and other useful libraries:
RUN pip install ipython jupyter matplotlib

# Caches install (https://stackoverflow.com/questions/25305788/how-to-avoid-reinstalling-packages-when-building-docker-image-for-python-project)
ADD ./requirements.txt /pysr/requirements.txt
RUN pip3 install -r /pysr/requirements.txt

# Install PySR:
ADD . /pysr/
# We do a minimal copy so it doesn't need to rerun at every file change:
ADD ./setup.py /pysr/setup.py
ADD ./README.md /pysr/README.md
Add ./Project.toml /pysr/Project.toml
ADD ./pysr/ /pysr/pysr/
RUN pip3 install .

# Install Julia pre-requisites:
RUN julia -e 'using Pkg; Pkg.add("SymbolicRegression")'

# Install IPython and other useful libraries:
RUN pip3 install ipython jupyter matplotlib
RUN python3 -c 'import pysr; pysr.install()'

CMD ["bash"]
CMD ["bash"]
2 changes: 1 addition & 1 deletion Project.toml
Expand Up @@ -2,5 +2,5 @@
SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"

[compat]
SymbolicRegression = "0.6.10"
SymbolicRegression = "0.6.18"
julia = "1.5"
13 changes: 10 additions & 3 deletions README.md
Expand Up @@ -62,11 +62,14 @@ and [linux](https://julialang.org/downloads/platform/#linux_and_freebsd).

You can install PySR with:
```bash
pip install pysr
pip3 install pysr
python3 -c 'import pysr; pysr.install()'
```
The second line will install and update the required Julia packages, including
`PyCall.jl`.

The first launch will automatically install the Julia packages
required. Most common issues at this stage are solved

Most common issues at this stage are solved
by [tweaking the Julia package server](https://github.com/MilesCranmer/PySR/issues/27).
to use up-to-date packages.

Expand Down Expand Up @@ -121,6 +124,10 @@ which gives:
x0**2 + 2.000016*cos(x3) - 1.9999845
```

The second and additional calls of `pysr` will be significantly
faster in startup time, since the first call to Julia will compile
and cache functions from the symbolic regression backend.

One can also use `best_tex` to get the LaTeX form,
or `best_callable` to get a function you can call.
This uses a score which balances complexity and error;
Expand Down
20 changes: 9 additions & 11 deletions docs/start.md
Expand Up @@ -7,20 +7,14 @@ Install Julia - see [downloads](https://julialang.org/downloads/), and
then instructions for [mac](https://julialang.org/downloads/platform/#macos)
and [linux](https://julialang.org/downloads/platform/#linux_and_freebsd).
(Don't use the `conda-forge` version; it doesn't seem to work properly.)
Then, at the command line,
install the `Optim` and `SpecialFunctions` packages via:

You can install PySR with:
```bash
julia -e 'import Pkg; Pkg.add("Optim"); Pkg.add("SpecialFunctions")'
```

For python, you need to have Python 3, numpy, sympy, and pandas installed.

You can install this package from PyPI with:

```bash
pip install pysr
pip3 install pysr
python3 -c 'import pysr; pysr.install()'
```
The second line will install and update the required Julia packages, including
`PyCall.jl`.

## Quickstart

Expand Down Expand Up @@ -48,6 +42,10 @@ which gives:
x0**2 + 2.000016*cos(x3) - 1.9999845
```

The second and additional calls of `pysr` will be significantly
faster in startup time, since the first call to Julia will compile
and cache functions from the symbolic regression backend.

One can also use `best_tex` to get the LaTeX form,
or `best_callable` to get a function you can call.
This uses a score which balances complexity and error;
Expand Down
14 changes: 14 additions & 0 deletions environment.yml
@@ -0,0 +1,14 @@
name: test
channels:
- conda-forge
- defaults
dependencies:
- python=3.9
- sympy
- pandas
- numpy
- scikit-learn
- setuptools
- pip
- pip:
- julia
11 changes: 10 additions & 1 deletion pysr/__init__.py
@@ -1,4 +1,13 @@
from .sr import pysr, get_hof, best, best_tex, best_callable, best_row
from .sr import (
pysr,
get_hof,
best,
best_tex,
best_callable,
best_row,
install,
silence_julia_warning,
)
from .feynman_problems import Problem, FeynmanProblem
from .export_jax import sympy2jax
from .export_torch import sympy2torch
13 changes: 3 additions & 10 deletions pysr/feynman_problems.py
@@ -1,6 +1,5 @@
import numpy as np
import csv
import traceback
from .sr import pysr, best
from pathlib import Path
from functools import partial
Expand Down Expand Up @@ -80,20 +79,14 @@ def mk_problems(first=100, gen=False, dp=500, data_dir=FEYNMAN_DATASET):
"""
ret = []
with open(data_dir) as csvfile:
ind = 0
reader = csv.DictReader(csvfile)
for i, row in enumerate(reader):
if ind > first:
if i > first:
break
if row["Filename"] == "":
continue
try:
p = FeynmanProblem(row, gen=gen, dp=dp)
ret.append(p)
except Exception as e:
traceback.print_exc()
print(f"FAILED ON ROW {i} with {e}")
ind += 1
p = FeynmanProblem(row, gen=gen, dp=dp)
ret.append(p)
return ret


Expand Down

0 comments on commit ae7c60a

Please sign in to comment.