Skip to content

Commit 28dd7e5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 107b46a commit 28dd7e5

8 files changed

Lines changed: 28 additions & 53 deletions

File tree

docs/gen_param_docs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
placeholder with auto-generated parameter docs from param_groupings.yml
66
and PySRRegressor docstrings.
77
"""
8+
89
import re
910
import sys
1011
from pathlib import Path

examples/pysr_demo.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -770,12 +770,10 @@
770770
"source": [
771771
"from pysr import jl\n",
772772
"\n",
773-
"jl.seval(\n",
774-
" \"\"\"\n",
773+
"jl.seval(\"\"\"\n",
775774
"import Pkg\n",
776775
"Pkg.add(\"Primes\")\n",
777-
"\"\"\"\n",
778-
")"
776+
"\"\"\")"
779777
]
780778
},
781779
{
@@ -834,17 +832,15 @@
834832
},
835833
"outputs": [],
836834
"source": [
837-
"jl.seval(\n",
838-
" \"\"\"\n",
835+
"jl.seval(\"\"\"\n",
839836
"function p(i::T) where T\n",
840837
" if 0.5 < i < 1000\n",
841838
" return T(prime(round(Int, i)))\n",
842839
" else\n",
843840
" return T(NaN)\n",
844841
" end\n",
845842
"end\n",
846-
"\"\"\"\n",
847-
")"
843+
"\"\"\")"
848844
]
849845
},
850846
{

pysr/expression_specs.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,15 @@ def _template_macro_str(self):
275275
template_inputs.append(
276276
f"parameters=({', '.join([f'{p}={self.parameters[p]}' for p in self.parameters]) + ','})"
277277
)
278-
return dedent(
279-
f"""
278+
return dedent(f"""
280279
@template_spec({', '.join(template_inputs) + ','}) do {', '.join(self.variable_names)}
281280
{self.combine}
282281
end
283-
"""
284-
)
282+
""")
285283

286284
def julia_expression_options(self):
287285
f_combine = jl.seval(self.combine)
288-
creator = jl.seval(
289-
"""
286+
creator = jl.seval("""
290287
function _pysr_create_template_structure(
291288
@nospecialize(function_symbols::AbstractVector),
292289
@nospecialize(combine::Function),
@@ -301,8 +298,7 @@ def julia_expression_options(self):
301298
structure = SymbolicRegression.TemplateStructure{tuple_symbol}(combine, num_features)
302299
return (; structure)
303300
end
304-
"""
305-
)
301+
""")
306302
return creator(self.function_symbols, f_combine, self.num_features)
307303

308304
@property
@@ -327,8 +323,7 @@ def parametric_expression_deprecation_warning(
327323
):
328324
function_name = "f"
329325
var_names = list(variable_names)
330-
message = dedent(
331-
f"""
326+
message = dedent(f"""
332327
ParametricExpressionSpec is deprecated. you should switch to TemplateExpressionSpec with explicit parameters indexed by category.
333328
334329
Since you have `max_parameters={max_parameters}` and `variable_names=[{", ".join(f'"{v}"' for v in var_names)}]`, you could migrate like this:
@@ -343,8 +338,7 @@ def parametric_expression_deprecation_warning(
343338
X = np.column_stack([X, category]) # add the category column
344339
345340
Finally, do not pass `category` when calling .fit().
346-
"""
347-
).strip()
341+
""").strip()
348342
wrapped = "\n".join(textwrap.fill(line, 88) for line in message.splitlines())
349343
warnings.warn(wrapped, FutureWarning, stacklevel=3)
350344

@@ -416,7 +410,7 @@ def _search_output_to_callable_expressions(
416410
equations: pd.DataFrame, search_output, i: int | None
417411
) -> pd.DataFrame:
418412
equations = copy.deepcopy(equations)
419-
(_, all_out_hof) = search_output
413+
_, all_out_hof = search_output
420414
out_hof = all_out_hof[i] if i is not None else all_out_hof
421415
expressions = []
422416
callables = []

pysr/logger_specs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,15 @@ class TensorBoardLoggerSpec(AbstractLoggerSpec):
4848

4949
def create_logger(self) -> AnyValue:
5050
# We assume that TensorBoardLogger is already imported via `julia_extensions.py`
51-
make_logger = jl.seval(
52-
"""
51+
make_logger = jl.seval("""
5352
function make_logger(log_dir::AbstractString, overwrite::Bool, log_interval::Int)
5453
base_logger = TensorBoardLogger.TBLogger(
5554
log_dir,
5655
(overwrite ? (TensorBoardLogger.tb_overwrite,) : ())...
5756
)
5857
return SRLogger(; logger=base_logger, log_interval)
5958
end
60-
"""
61-
)
59+
""")
6260
log_dir = str(self.log_dir)
6361
return make_logger(log_dir, self.overwrite, self.log_interval)
6462

pysr/test/test_cli.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def setUp(self):
1515
self.cli_runner = click_testing.CliRunner()
1616

1717
def test_help_on_all_commands(self):
18-
expected = dedent(
19-
"""
18+
expected = dedent("""
2019
Usage: pysr [OPTIONS] COMMAND [ARGS]...
2120
2221
Options:
@@ -25,15 +24,13 @@ def test_help_on_all_commands(self):
2524
Commands:
2625
install DEPRECATED (dependencies are now installed at import).
2726
test Run parts of the PySR test suite.
28-
"""
29-
)
27+
""")
3028
result = self.cli_runner.invoke(pysr, ["--help"])
3129
self.assertEqual(result.output.strip(), expected.strip())
3230
self.assertEqual(result.exit_code, 0)
3331

3432
def test_help_on_install(self):
35-
expected = dedent(
36-
"""
33+
expected = dedent("""
3734
Usage: pysr install [OPTIONS]
3835
3936
DEPRECATED (dependencies are now installed at import).
@@ -44,15 +41,13 @@ def test_help_on_install(self):
4441
--precompile
4542
--no-precompile
4643
--help Show this message and exit.
47-
"""
48-
)
44+
""")
4945
result = self.cli_runner.invoke(pysr, ["install", "--help"])
5046
self.assertEqual(result.output.strip(), expected.strip())
5147
self.assertEqual(result.exit_code, 0)
5248

5349
def test_help_on_test(self):
54-
expected = dedent(
55-
"""
50+
expected = dedent("""
5651
Usage: pysr test [OPTIONS] TESTS
5752
5853
Run parts of the PySR test suite.
@@ -63,8 +58,7 @@ def test_help_on_test(self):
6358
Options:
6459
-k TEXT Filter expressions to select specific tests.
6560
--help Show this message and exit.
66-
"""
67-
)
61+
""")
6862
result = self.cli_runner.invoke(pysr, ["test", "--help"])
6963
self.assertEqual(result.output.strip(), expected.strip())
7064
self.assertEqual(result.exit_code, 0)

pysr/test/test_main.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,14 @@ def _multiprocessing_turbo_custom_objective(self, loss_key):
130130
parallelism="multiprocessing",
131131
turbo=True,
132132
early_stop_condition="stop_if(loss, complexity) = loss < 1e-10 && complexity == 1",
133-
**{
134-
loss_key: f"""
133+
**{loss_key: f"""
135134
function my_objective(tree::{node_type}{{T}}, dataset::Dataset{{T}}, options::Options) where T
136135
prediction, flag = eval_tree_array(tree, dataset.X, options)
137136
!flag && return T(Inf)
138137
abs3(x) = abs(x) ^ 3
139138
return sum(abs3, prediction .- dataset.y) / length(prediction)
140139
end
141-
"""
142-
},
140+
"""},
143141
)
144142
model.fit(self.X, y)
145143
print(model.equations_)
@@ -154,14 +152,12 @@ def _multiprocessing_turbo_custom_objective(self, loss_key):
154152

155153
def test_multiline_seval(self):
156154
# The user should be able to run multiple things in a single seval call:
157-
num = jl.seval(
158-
"""
155+
num = jl.seval("""
159156
function my_new_objective(x)
160157
x^2
161158
end
162159
1.5
163-
"""
164-
)
160+
""")
165161
self.assertEqual(num, 1.5)
166162

167163
def test_high_precision_search_custom_loss(self):

pysr/test/test_startup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def test_warm_start_from_file(self):
6969
[
7070
sys.executable,
7171
"-c",
72-
textwrap.dedent(
73-
f"""
72+
textwrap.dedent(f"""
7473
from pysr import PySRRegressor
7574
import numpy as np
7675
@@ -98,8 +97,7 @@ def test_warm_start_from_file(self):
9897
best_loss = model.equations_.iloc[-1]["loss"]
9998
10099
assert best_loss <= {best_loss}
101-
"""
102-
),
100+
"""),
103101
],
104102
stdout=subprocess.PIPE,
105103
stderr=subprocess.PIPE,

setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# setup.py – retained only for users who still type python setup.py ..."
22
import sys
33

4-
sys.stderr.write(
5-
"""⚠️ PySR uses pyproject.toml instead of setup.py.
4+
sys.stderr.write("""⚠️ PySR uses pyproject.toml instead of setup.py.
65
76
Install from a checkout with:
87
python -m pip install . # normal
98
python -m pip install -e . # editable (pip ≥21.3)
109
1110
Or install from PyPI with:
1211
pip install pysr
13-
"""
14-
)
12+
""")
1513
sys.exit(1)

0 commit comments

Comments
 (0)