MilesCranmer commited on
Commit
976f8d8
1 Parent(s): b933dea

Add pre-commit hook for isort

Browse files
.pre-commit-config.yaml CHANGED
@@ -18,8 +18,14 @@ repos:
18
  rev: 0.6.1
19
  hooks:
20
  - id: nbstripout
21
- # Unused imports:
22
  - repo: https://github.com/hadialqattan/pycln
23
  rev: "v2.2.2"
24
  hooks:
25
  - id: pycln
 
 
 
 
 
 
 
18
  rev: 0.6.1
19
  hooks:
20
  - id: nbstripout
21
+ # Unused imports
22
  - repo: https://github.com/hadialqattan/pycln
23
  rev: "v2.2.2"
24
  hooks:
25
  - id: pycln
26
+ # Sorted imports
27
+ - repo: https://github.com/PyCQA/isort
28
+ rev: "5.12.0"
29
+ hooks:
30
+ - id: isort
31
+ additional_dependencies: [toml]
benchmarks/hyperparamopt.py CHANGED
@@ -1,13 +1,15 @@
1
  """Start a hyperoptimization from a single node"""
2
- import sys
3
- import numpy as np
4
  import pickle as pkl
5
- from pysr import PySRRegressor
 
6
  import hyperopt
7
- from hyperopt import hp, fmin, tpe, Trials
 
8
  from hyperopt.fmin import generate_trials_to_calculate
9
  from space import *
10
 
 
 
11
  # Change the following code to your file
12
  ################################################################################
13
  TRIALS_FOLDER = "trials2"
 
1
  """Start a hyperoptimization from a single node"""
 
 
2
  import pickle as pkl
3
+ import sys
4
+
5
  import hyperopt
6
+ import numpy as np
7
+ from hyperopt import Trials, fmin, hp, tpe
8
  from hyperopt.fmin import generate_trials_to_calculate
9
  from space import *
10
 
11
+ from pysr import PySRRegressor
12
+
13
  # Change the following code to your file
14
  ################################################################################
15
  TRIALS_FOLDER = "trials2"
benchmarks/print_best_model.py CHANGED
@@ -1,11 +1,11 @@
1
  """Print the best model parameters and loss"""
2
- import numpy as np
3
  import pickle as pkl
4
- import hyperopt
5
- from hyperopt import hp, fmin, tpe, Trials
6
- from space import space
7
  from pprint import PrettyPrinter
8
 
 
 
 
 
9
 
10
  # Change the following code to your file
11
  ################################################################################
 
1
  """Print the best model parameters and loss"""
 
2
  import pickle as pkl
 
 
 
3
  from pprint import PrettyPrinter
4
 
5
+ import hyperopt
6
+ import numpy as np
7
+ from hyperopt import Trials, fmin, hp, tpe
8
+ from space import space
9
 
10
  # Change the following code to your file
11
  ################################################################################
benchmarks/space.py CHANGED
@@ -1,5 +1,5 @@
1
  import numpy as np
2
- from hyperopt import hp, fmin, tpe, Trials
3
 
4
  binary_operators = ["*", "/", "+", "-"]
5
  unary_operators = ["sin", "cos", "exp", "log"]
 
1
  import numpy as np
2
+ from hyperopt import Trials, fmin, hp, tpe
3
 
4
  binary_operators = ["*", "/", "+", "-"]
5
  unary_operators = ["sin", "cos", "exp", "log"]
docs/gen_param_docs.py CHANGED
@@ -1,12 +1,14 @@
1
  # Load YAML file param_groupings.yml:
2
- from yaml import safe_load
3
  import sys
4
 
 
 
 
5
  sys.path.append("..")
 
 
6
  from pysr import PySRRegressor
7
- import pysr
8
- import re
9
- from docstring_parser import parse
10
 
11
  found_params = []
12
 
 
1
  # Load YAML file param_groupings.yml:
2
+ import re
3
  import sys
4
 
5
+ from docstring_parser import parse
6
+ from yaml import safe_load
7
+
8
  sys.path.append("..")
9
+
10
+
11
  from pysr import PySRRegressor
 
 
 
12
 
13
  found_params = []
14
 
docs/generate_papers.py CHANGED
@@ -1,7 +1,8 @@
1
  """This script generates the papers.md file from the papers.yml file."""
2
- import yaml
3
  from pathlib import Path
4
 
 
 
5
  data_file = "papers.yml"
6
  papers_header = Path("stylesheets") / "papers_header.txt"
7
  output_file = "papers.md"
 
1
  """This script generates the papers.md file from the papers.yml file."""
 
2
  from pathlib import Path
3
 
4
+ import yaml
5
+
6
  data_file = "papers.yml"
7
  papers_header = Path("stylesheets") / "papers_header.txt"
8
  output_file = "papers.md"
pyproject.toml ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [tool.isort]
2
+ profile = "black"
pysr/__init__.py CHANGED
@@ -1,30 +1,23 @@
1
  from . import sklearn_monkeypatch
2
- from .version import __version__
3
- from .sr import (
4
- pysr,
5
- PySRRegressor,
6
- best,
7
- best_tex,
8
- best_callable,
9
- best_row,
10
- )
11
- from .julia_helpers import install
12
- from .feynman_problems import Problem, FeynmanProblem
13
  from .export_jax import sympy2jax
14
  from .export_torch import sympy2torch
 
 
 
 
15
 
16
  __all__ = [
17
  "sklearn_monkeypatch",
18
- "__version__",
19
- "pysr",
 
 
 
20
  "PySRRegressor",
21
  "best",
22
- "best_tex",
23
  "best_callable",
24
  "best_row",
25
- "install",
26
- "Problem",
27
- "FeynmanProblem",
28
- "sympy2jax",
29
- "sympy2torch",
30
  ]
 
1
  from . import sklearn_monkeypatch
 
 
 
 
 
 
 
 
 
 
 
2
  from .export_jax import sympy2jax
3
  from .export_torch import sympy2torch
4
+ from .feynman_problems import FeynmanProblem, Problem
5
+ from .julia_helpers import install
6
+ from .sr import PySRRegressor, best, best_callable, best_row, best_tex, pysr
7
+ from .version import __version__
8
 
9
  __all__ = [
10
  "sklearn_monkeypatch",
11
+ "sympy2jax",
12
+ "sympy2torch",
13
+ "FeynmanProblem",
14
+ "Problem",
15
+ "install",
16
  "PySRRegressor",
17
  "best",
 
18
  "best_callable",
19
  "best_row",
20
+ "best_tex",
21
+ "pysr",
22
+ "__version__",
 
 
23
  ]
pysr/_cli/main.py CHANGED
@@ -1,4 +1,5 @@
1
  import click
 
2
  from ..julia_helpers import install
3
 
4
 
 
1
  import click
2
+
3
  from ..julia_helpers import install
4
 
5
 
pysr/export_latex.py CHANGED
@@ -1,8 +1,9 @@
1
  """Functions to help export PySR equations to LaTeX."""
 
 
 
2
  import sympy
3
  from sympy.printing.latex import LatexPrinter
4
- import pandas as pd
5
- from typing import List
6
 
7
 
8
  class PreciseLatexPrinter(LatexPrinter):
 
1
  """Functions to help export PySR equations to LaTeX."""
2
+ from typing import List
3
+
4
+ import pandas as pd
5
  import sympy
6
  from sympy.printing.latex import LatexPrinter
 
 
7
 
8
 
9
  class PreciseLatexPrinter(LatexPrinter):
pysr/export_numpy.py CHANGED
@@ -1,8 +1,9 @@
1
  """Code for exporting discovered expressions to numpy"""
 
 
2
  import numpy as np
3
  import pandas as pd
4
  from sympy import lambdify
5
- import warnings
6
 
7
 
8
  class CallableEquation:
 
1
  """Code for exporting discovered expressions to numpy"""
2
+ import warnings
3
+
4
  import numpy as np
5
  import pandas as pd
6
  from sympy import lambdify
 
7
 
8
 
9
  class CallableEquation:
pysr/export_torch.py CHANGED
@@ -5,6 +5,7 @@
5
 
6
  import collections as co
7
  import functools as ft
 
8
  import sympy
9
 
10
 
 
5
 
6
  import collections as co
7
  import functools as ft
8
+
9
  import sympy
10
 
11
 
pysr/feynman_problems.py CHANGED
@@ -1,8 +1,10 @@
1
- import numpy as np
2
  import csv
3
- from .sr import pysr, best
4
- from pathlib import Path
5
  from functools import partial
 
 
 
 
 
6
 
7
  PKG_DIR = Path(__file__).parents[1]
8
  FEYNMAN_DATASET = PKG_DIR / "datasets" / "FeynmanEquations.csv"
@@ -118,6 +120,7 @@ def do_feynman_experiments_parallel(
118
  data_dir=FEYNMAN_DATASET,
119
  ):
120
  import multiprocessing as mp
 
121
  from tqdm import tqdm
122
 
123
  problems = mk_problems(first=first, gen=True, dp=dp, data_dir=data_dir)
 
 
1
  import csv
 
 
2
  from functools import partial
3
+ from pathlib import Path
4
+
5
+ import numpy as np
6
+
7
+ from .sr import best, pysr
8
 
9
  PKG_DIR = Path(__file__).parents[1]
10
  FEYNMAN_DATASET = PKG_DIR / "datasets" / "FeynmanEquations.csv"
 
120
  data_dir=FEYNMAN_DATASET,
121
  ):
122
  import multiprocessing as mp
123
+
124
  from tqdm import tqdm
125
 
126
  problems = mk_problems(first=first, gen=True, dp=dp, data_dir=data_dir)
pysr/julia_helpers.py CHANGED
@@ -1,12 +1,13 @@
1
  """Functions for initializing the Julia environment and installing deps."""
2
- import sys
3
  import subprocess
 
4
  import warnings
5
  from pathlib import Path
6
- import os
7
  from julia.api import JuliaError
8
 
9
- from .version import __version__, __symbolic_regression_jl_version__
10
 
11
  juliainfo = None
12
  julia_initialized = False
 
1
  """Functions for initializing the Julia environment and installing deps."""
2
+ import os
3
  import subprocess
4
+ import sys
5
  import warnings
6
  from pathlib import Path
7
+
8
  from julia.api import JuliaError
9
 
10
+ from .version import __symbolic_regression_jl_version__, __version__
11
 
12
  juliainfo = None
13
  julia_initialized = False
pysr/sr.py CHANGED
@@ -1,40 +1,37 @@
1
  """Define the PySRRegressor scikit-learn interface."""
2
  import copy
3
- from io import StringIO
4
  import os
5
- import sys
6
- import numpy as np
7
- import pandas as pd
8
- import sympy
9
- from sympy import sympify
10
  import re
11
- import tempfile
12
  import shutil
13
- from pathlib import Path
14
- import pickle as pkl
15
- from datetime import datetime
16
  import warnings
 
 
17
  from multiprocessing import cpu_count
18
- from sklearn.base import BaseEstimator, RegressorMixin, MultiOutputMixin
 
 
 
 
 
19
  from sklearn.utils import check_array, check_consistent_length, check_random_state
20
- from sklearn.utils.validation import (
21
- _check_feature_names_in,
22
- check_is_fitted,
23
- )
24
 
 
 
 
25
  from .julia_helpers import (
26
- init_julia,
27
- _process_julia_project,
28
- is_julia_version_greater_eq,
29
  _escape_filename,
 
30
  _load_cluster_manager,
 
31
  _update_julia_project,
32
- _load_backend,
 
33
  )
34
- from .export_numpy import CallableEquation
35
- from .export_latex import generate_single_table, generate_multiple_tables, to_latex
36
- from .deprecated import make_deprecated_kwargs_for_pysr_regressor
37
-
38
 
39
  Main = None # TODO: Rename to more descriptive name like "julia_runtime"
40
 
@@ -2454,7 +2451,7 @@ def idx_model_selection(equations: pd.DataFrame, model_selection: str) -> int:
2454
  def _denoise(X, y, Xresampled=None, random_state=None):
2455
  """Denoise the dataset using a Gaussian process."""
2456
  from sklearn.gaussian_process import GaussianProcessRegressor
2457
- from sklearn.gaussian_process.kernels import RBF, WhiteKernel, ConstantKernel
2458
 
2459
  gp_kernel = RBF(np.ones(X.shape[1])) + WhiteKernel(1e-1) + ConstantKernel()
2460
  gpr = GaussianProcessRegressor(
 
1
  """Define the PySRRegressor scikit-learn interface."""
2
  import copy
 
3
  import os
4
+ import pickle as pkl
 
 
 
 
5
  import re
 
6
  import shutil
7
+ import sys
8
+ import tempfile
 
9
  import warnings
10
+ from datetime import datetime
11
+ from io import StringIO
12
  from multiprocessing import cpu_count
13
+ from pathlib import Path
14
+
15
+ import numpy as np
16
+ import pandas as pd
17
+ import sympy
18
+ from sklearn.base import BaseEstimator, MultiOutputMixin, RegressorMixin
19
  from sklearn.utils import check_array, check_consistent_length, check_random_state
20
+ from sklearn.utils.validation import _check_feature_names_in, check_is_fitted
21
+ from sympy import sympify
 
 
22
 
23
+ from .deprecated import make_deprecated_kwargs_for_pysr_regressor
24
+ from .export_latex import generate_multiple_tables, generate_single_table, to_latex
25
+ from .export_numpy import CallableEquation
26
  from .julia_helpers import (
 
 
 
27
  _escape_filename,
28
+ _load_backend,
29
  _load_cluster_manager,
30
+ _process_julia_project,
31
  _update_julia_project,
32
+ init_julia,
33
+ is_julia_version_greater_eq,
34
  )
 
 
 
 
35
 
36
  Main = None # TODO: Rename to more descriptive name like "julia_runtime"
37
 
 
2451
  def _denoise(X, y, Xresampled=None, random_state=None):
2452
  """Denoise the dataset using a Gaussian process."""
2453
  from sklearn.gaussian_process import GaussianProcessRegressor
2454
+ from sklearn.gaussian_process.kernels import RBF, ConstantKernel, WhiteKernel
2455
 
2456
  gp_kernel = RBF(np.ones(X.shape[1])) + WhiteKernel(1e-1) + ConstantKernel()
2457
  gpr = GaussianProcessRegressor(
pysr/test/__init__.py CHANGED
@@ -1,7 +1,7 @@
1
  from .test import runtests
 
2
  from .test_env import runtests as runtests_env
3
  from .test_jax import runtests as runtests_jax
4
  from .test_torch import runtests as runtests_torch
5
- from .test_cli import runtests as runtests_cli
6
 
7
  __all__ = ["runtests", "runtests_env", "runtests_jax", "runtests_torch", "runtests_cli"]
 
1
  from .test import runtests
2
+ from .test_cli import runtests as runtests_cli
3
  from .test_env import runtests as runtests_env
4
  from .test_jax import runtests as runtests_jax
5
  from .test_torch import runtests as runtests_torch
 
6
 
7
  __all__ = ["runtests", "runtests_env", "runtests_jax", "runtests_torch", "runtests_cli"]
pysr/test/test.py CHANGED
@@ -1,28 +1,28 @@
 
1
  import os
 
 
2
  import traceback
3
- import inspect
4
  import unittest
 
 
 
5
  import numpy as np
 
 
6
  from sklearn import model_selection
7
  from sklearn.utils.estimator_checks import check_estimator
8
- import sympy
9
- import pandas as pd
10
- import warnings
11
- import pickle as pkl
12
- import tempfile
13
- from pathlib import Path
14
 
15
- from .. import julia_helpers
16
- from .. import PySRRegressor
17
  from ..sr import (
18
- run_feature_selection,
19
- _handle_feature_selection,
20
- _csv_filename_to_pkl_filename,
21
- idx_model_selection,
22
  _check_assertions,
 
 
23
  _process_constraints,
 
 
24
  )
25
- from ..export_latex import to_latex
26
 
27
  DEFAULT_PARAMS = inspect.signature(PySRRegressor.__init__).parameters
28
  DEFAULT_NITERATIONS = DEFAULT_PARAMS["niterations"].default
 
1
+ import inspect
2
  import os
3
+ import pickle as pkl
4
+ import tempfile
5
  import traceback
 
6
  import unittest
7
+ import warnings
8
+ from pathlib import Path
9
+
10
  import numpy as np
11
+ import pandas as pd
12
+ import sympy
13
  from sklearn import model_selection
14
  from sklearn.utils.estimator_checks import check_estimator
 
 
 
 
 
 
15
 
16
+ from .. import PySRRegressor, julia_helpers
17
+ from ..export_latex import to_latex
18
  from ..sr import (
 
 
 
 
19
  _check_assertions,
20
+ _csv_filename_to_pkl_filename,
21
+ _handle_feature_selection,
22
  _process_constraints,
23
+ idx_model_selection,
24
+ run_feature_selection,
25
  )
 
26
 
27
  DEFAULT_PARAMS = inspect.signature(PySRRegressor.__init__).parameters
28
  DEFAULT_NITERATIONS = DEFAULT_PARAMS["niterations"].default
pysr/test/test_cli.py CHANGED
@@ -1,5 +1,7 @@
1
  import unittest
 
2
  from click import testing as click_testing
 
3
  from .._cli.main import pysr
4
 
5
 
 
1
  import unittest
2
+
3
  from click import testing as click_testing
4
+
5
  from .._cli.main import pysr
6
 
7
 
pysr/test/test_env.py CHANGED
@@ -1,7 +1,7 @@
1
  """Contains tests for creating and initializing custom Julia projects."""
2
 
3
- import unittest
4
  import os
 
5
  from tempfile import TemporaryDirectory
6
 
7
  from .. import julia_helpers
 
1
  """Contains tests for creating and initializing custom Julia projects."""
2
 
 
3
  import os
4
+ import unittest
5
  from tempfile import TemporaryDirectory
6
 
7
  from .. import julia_helpers
pysr/test/test_jax.py CHANGED
@@ -1,10 +1,11 @@
1
  import unittest
 
 
2
  import numpy as np
3
  import pandas as pd
4
  import sympy
5
- from functools import partial
6
 
7
- from .. import sympy2jax, PySRRegressor
8
 
9
 
10
  class TestJAX(unittest.TestCase):
 
1
  import unittest
2
+ from functools import partial
3
+
4
  import numpy as np
5
  import pandas as pd
6
  import sympy
 
7
 
8
+ from .. import PySRRegressor, sympy2jax
9
 
10
 
11
  class TestJAX(unittest.TestCase):
pysr/test/test_torch.py CHANGED
@@ -1,9 +1,11 @@
 
1
  import unittest
 
2
  import numpy as np
3
  import pandas as pd
4
- import platform
5
  import sympy
6
- from .. import sympy2torch, PySRRegressor
 
7
 
8
  # Need to initialize Julia before importing torch...
9
 
 
1
+ import platform
2
  import unittest
3
+
4
  import numpy as np
5
  import pandas as pd
 
6
  import sympy
7
+
8
+ from .. import PySRRegressor, sympy2torch
9
 
10
  # Need to initialize Julia before importing torch...
11