Skip to content

Commit

Permalink
Merge pull request #425 from MilesCranmer/pre-commit
Browse files Browse the repository at this point in the history
Incorporate pre-commit hooks
  • Loading branch information
MilesCranmer authored Sep 16, 2023
2 parents 57dd7d2 + 976f8d8 commit a512af0
Show file tree
Hide file tree
Showing 52 changed files with 1,644 additions and 1,590 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ body:
attributes:
value: |
Be sure to check out the [PySR forums](https://github.com/MilesCranmer/PySR/discussions) to chat with other users about PySR use-cases!
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
julia-version: ['1.9']
python-version: ['3.10']
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- name: "Set up Julia"
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
matrix:
python-version: ['3.9']
os: ['ubuntu-latest']

steps:
- uses: actions/checkout@v3
- name: "Cache conda"
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:

coveralls:
name: Indicate completion to coveralls.io
needs:
needs:
- test
runs-on: ubuntu-latest
defaults:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
julia-version: ['1.9']
python-version: ['3.10']
os: [windows-latest]

steps:
- uses: actions/checkout@v3
- name: "Set up Julia"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_conda_forge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11']
os: ['ubuntu-latest', 'macos-latest']
use-mamba: [true, false]

steps:
- name: "Set up Conda"
uses: conda-incubator/setup-miniconda@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/CI_docker_large_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
python-version: ['3.10']
os: [ubuntu-latest]
arch: ['linux/amd64', 'linux/arm64']


steps:
- uses: actions/checkout@v3
- name: Set up QEMU
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_large_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
julia-version: ['1.6', '1.8', '1.9']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- name: "Set up Julia"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CI_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
julia-version: ['1.9']
python-version: ['3.10']
os: [macos-latest]

steps:
- uses: actions/checkout@v3
- name: "Set up Julia"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ jobs:
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
Expand All @@ -50,7 +50,7 @@ jobs:
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
tags:
- "v*.*.*"
workflow_dispatch:


jobs:
docker:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
defaults:
run:
shell: bash

steps:
- uses: actions/checkout@v3
- name: "Set up Python"
Expand All @@ -33,4 +33,4 @@ jobs:
- name: "Build API docs"
run: cd docs && ./gen_docs.sh
- name: "Deploy documentation"
run: mkdocs gh-deploy --force
run: mkdocs gh-deploy --force
2 changes: 1 addition & 1 deletion .github/workflows/update_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
CURRENT_PYSR_PATCH_VERSION=$(python -c 'import pysr; print(pysr.version.__version__.split(".")[-1], end="")' 2>/dev/null)
NEW_PYSR_PATCH_VERSION=$((CURRENT_PYSR_PATCH_VERSION + 1))
sed -i "s/^__version__ = .*/__version__ = \"$(python -c 'import pysr; print(".".join(pysr.version.__version__.split(".")[:-1]), end="")' 2>/dev/null).${NEW_PYSR_PATCH_VERSION}\"/" pysr/version.py
# Set SymbolicRegression.jl version:
sed -i "s/^__symbolic_regression_jl_version__ = .*/__symbolic_regression_jl_version__ = \"${{ steps.get-latest.outputs.version }}\"/" pysr/version.py
Expand Down
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
# General linting
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
# General formatting
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- id: black-jupyter
# Stripping notebooks
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: nbstripout
# Unused imports
- repo: https://github.com/hadialqattan/pycln
rev: "v2.2.2"
hooks:
- id: pycln
# Sorted imports
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort
additional_dependencies: [toml]
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ Thanks for being part of the PySR community!
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
</div>
</div>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ The PySR build in conda includes all required dependencies, so you can install i
conda install -c conda-forge pysr
```

from within your target conda environment.
from within your target conda environment.

However, note that the conda install does not support precompilation of Julia libraries, so the
start time may be slightly slower as the JIT-compilation will be running.
Expand Down Expand Up @@ -305,7 +305,7 @@ model = PySRRegressor(
# ^ 2 populations per core, so one is always running.
population_size=50,
# ^ Slightly larger populations, for greater diversity.
ncyclesperiteration=500,
ncyclesperiteration=500,
# ^ Generations between migrations.
niterations=10000000, # Run forever
early_stop_condition=(
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ v0.3.6 | 25900
v0.3.7 | 26600
v0.3.8 | 7470
v0.3.9 | 6760
v0.3.10 |
v0.3.10 |
v0.3.11 | 19500
v0.3.12 | 19000
v0.3.13 | 15200
Expand Down
10 changes: 6 additions & 4 deletions benchmarks/hyperparamopt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Start a hyperoptimization from a single node"""
import sys
import numpy as np
import pickle as pkl
from pysr import PySRRegressor
import sys

import hyperopt
from hyperopt import hp, fmin, tpe, Trials
import numpy as np
from hyperopt import Trials, fmin, hp, tpe
from hyperopt.fmin import generate_trials_to_calculate
from space import *

from pysr import PySRRegressor

# Change the following code to your file
################################################################################
TRIALS_FOLDER = "trials2"
Expand Down
10 changes: 4 additions & 6 deletions benchmarks/print_best_model.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Print the best model parameters and loss"""
import sys
import numpy as np
import pickle as pkl
import hyperopt
from hyperopt import hp, fmin, tpe, Trials
from space import space
from pprint import PrettyPrinter

import hyperopt
import numpy as np
from hyperopt import Trials, fmin, hp, tpe
from space import space

# Change the following code to your file
################################################################################
Expand Down Expand Up @@ -51,7 +50,6 @@ def merge_trials(trials1, trials2_slice):
path = TRIALS_FOLDER + "/*.pkl"
files = 0
for fname in glob.glob(path):

trials_obj = pkl.load(open(fname, "rb"))
n_trials = trials_obj["n"]
trials_obj = trials_obj["trials"]
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/space.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
from hyperopt import hp, fmin, tpe, Trials
from hyperopt import Trials, fmin, hp, tpe

binary_operators = ["*", "/", "+", "-"]
unary_operators = ["sin", "cos", "exp", "log"]
Expand Down
2 changes: 1 addition & 1 deletion datasets/FeynmanEquations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ III.15.14,10,96,m,(h/(2*pi))**2/(2*E_n*d**2),3,h,1,5,E_n,1,5,d,1,5,,,,,,,,,,,,,,
III.15.27,10,97,k,2*pi*alpha/(n*d),3,alpha,1,5,n,1,5,d,1,5,,,,,,,,,,,,,,,,,,,,,
III.17.37,10,98,f,beta*(1+alpha*cos(theta)),3,beta,1,5,alpha,1,5,theta,1,5,,,,,,,,,,,,,,,,,,,,,
III.19.51,10,99,E_n,-m*q**4/(2*(4*pi*epsilon)**2*(h/(2*pi))**2)*(1/n**2),5,m,1,5,q,1,5,h,1,5,n,1,5,epsilon,1,5,,,,,,,,,,,,,,,
III.21.20,10,100,j,-rho_c_0*q*A_vec/m,4,rho_c_0,1,5,q,1,5,A_vec,1,5,m,1,5,,,,,,,,,,,,,,,,,,
III.21.20,10,100,j,-rho_c_0*q*A_vec/m,4,rho_c_0,1,5,q,1,5,A_vec,1,5,m,1,5,,,,,,,,,,,,,,,,,,
2 changes: 1 addition & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build
api.md
index.md.bak
papers.md
papers.md
4 changes: 1 addition & 3 deletions docs/_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Let's look at them below.
PARAMSKEY

## PySRRegressor Functions

::: pysr.PySRRegressor.fit
options:
show_root_heading: true
Expand Down Expand Up @@ -60,5 +60,3 @@ PARAMSKEY
show_root_heading: true
heading_level: 3
show_root_full_path: false


2 changes: 1 addition & 1 deletion docs/assets/pysr_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/assets/pysr_logo_reduced.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Generally you can do this as follows:
git clone https://github.com/MilesCranmer/SymbolicRegression.jl
```
2. Edit the source code in `src/` to your requirements:
- The documentation for the backend is given [here](https://astroautomata.com/SymbolicRegression.jl/dev/).
- The documentation for the backend is given [here](https://astroautomata.com/SymbolicRegression.jl/dev/).
- Throughout the package, you will often see template functions which typically use a symbol `T` (such as in the string `where {T<:Real}`). Here, `T` is simply the datatype of the input data and stored constants, such as `Float32` or `Float64`. Writing functions in this way lets us write functions generic to types, while still having access to the specific type specified at compilation time.
- Expressions are stored as binary trees, using the `Node{T}` type, described [here](https://astroautomata.com/SymbolicRegression.jl/dev/types/#SymbolicRegression.CoreModule.EquationModule.Node).
- Parts of the code which are typically edited by users include:
Expand All @@ -26,4 +26,4 @@ git clone https://github.com/MilesCranmer/SymbolicRegression.jl

If you get comfortable enough with the backend, you might consider using the Julia package directly: the API is given on the [SymbolicRegression.jl documentation](https://astroautomata.com/SymbolicRegression.jl/dev/).

If you make a change that you think could be useful to other users, don't hesitate to open a pull request on either the PySR or SymbolicRegression.jl repositories! Contributions are very appreciated.
If you make a change that you think could be useful to other users, don't hesitate to open a pull request on either the PySR or SymbolicRegression.jl repositories! Contributions are very appreciated.
11 changes: 6 additions & 5 deletions docs/gen_param_docs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Load YAML file param_groupings.yml:
from pathlib import Path
from yaml import safe_load
import re
import sys

from docstring_parser import parse
from yaml import safe_load

sys.path.append("..")


from pysr import PySRRegressor
import pysr
import re
from docstring_parser import parse

found_params = []

Expand Down
5 changes: 3 additions & 2 deletions docs/generate_papers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""This script generates the papers.md file from the papers.yml file."""
import yaml
from pathlib import Path

import yaml

data_file = "papers.yml"
papers_header = Path("stylesheets") / "papers_header.txt"
output_file = "papers.md"
Expand Down Expand Up @@ -49,7 +50,7 @@
<center>
{authors}
<small>{affiliations}</small>
</center>
Expand Down
2 changes: 0 additions & 2 deletions docs/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,3 @@ instead of `1.5e3`, if you write any constant numbers.
Your operator should work with the entire real line (you can use
abs(x) for operators requiring positive input - see `log_abs`); otherwise
the search code will experience domain errors.


2 changes: 1 addition & 1 deletion docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ PySRRegressor(..., loss="loss(x, y) = abs(x * y)")
With weights:

```python
model = PySRRegressor(..., loss="myloss(x, y, w) = w * abs(x - y)")
model = PySRRegressor(..., loss="myloss(x, y, w) = w * abs(x - y)")
model.fit(..., weights=weights)
```

Expand Down
1 change: 0 additions & 1 deletion docs/papers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ papers:
abstract: "We present an approach for using machine learning to automatically discover the governing equations and hidden properties of real physical systems from observations. We train a \"graph neural network\" to simulate the dynamics of our solar system's Sun, planets, and large moons from 30 years of trajectory data. We then use symbolic regression to discover an analytical expression for the force law implicitly learned by the neural network, which our results showed is equivalent to Newton's law of gravitation. The key assumptions that were required were translational and rotational equivariance, and Newton's second and third laws of motion. Our approach correctly discovered the form of the symbolic force law. Furthermore, our approach did not require any assumptions about the masses of planets and moons or physical constants. They, too, were accurately inferred through our methods. Though, of course, the classical law of gravitation has been known since Isaac Newton, our result serves as a validation that our method can discover unknown laws and hidden properties from observed data. More broadly this work represents a key step toward realizing the potential of machine learning for accelerating scientific discovery."
image: rediscovering_gravity.png
date: 2022-02-04
link: https://arxiv.org/abs/2202.02306
- title: (Thesis) On Neural Differential Equations - Section 6.1
authors:
- Patrick Kidger (1)
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mkdocs-material
mkdocs-autorefs
mkdocstrings[python]
docstring_parser
docstring_parser
2 changes: 1 addition & 1 deletion docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
--md-primary-fg-color: #C13245;
--md-primary-fg-color--light: #D35364;
--md-primary-fg-color--dark: #982736;
}
}
1 change: 0 additions & 1 deletion docs/stylesheets/papers_header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ These are sorted by the date of release, with most recent papers at the top.

If you have used PySR in your research,
please submit a pull request to add your paper to [this file](https://github.com/MilesCranmer/PySR/blob/master/docs/papers.yml).

Loading

0 comments on commit a512af0

Please sign in to comment.