Closed villrv closed 1 year ago
Thanks very much for making this bug report, it is quite helpful.
Could you include the exact Python code you are running? I do have a unittest for this so it is surprising to see this error https://github.com/MilesCranmer/PySR/blob/d38be42d5c71e07f314db5680453d1b54955c050/pysr/test/test.py#L77-L98 . I wonder if it could be some race condition.
Yes, my code is below. I also tried switching out my objective function with the one in your unit test, with the same error.
import numpy as np
X = 2 * np.random.randn(10000, 5)
y = 2.5382 * np.cos(X[:, 3]) + 1/X[:, 0] ** 2 - 0.5
from pysr import PySRRegressor
objective = """
function my_custom_objective(tree, dataset::Dataset{T,L}, options) where {T,L}
# Require root node to be binary, so we can split it,
# otherwise return a large loss:
tree.degree != 2 && return L(Inf)
P = tree.l
Q = tree.r
# Evaluate numerator:
P_prediction, flag = eval_tree_array(P, dataset.X, options)
!flag && return L(Inf)
# Evaluate denominator:
Q_prediction, flag = eval_tree_array(Q, dataset.X, options)
!flag && return L(Inf)
# Impose functional form:
prediction = P_prediction ./ Q_prediction
diffs = prediction .- dataset.y
return sum(diffs .^ 2) / length(diffs)
end
"""
model = PySRRegressor(
niterations=100,
binary_operators=["*", "+", "-"],
full_objective=objective,
)
model.fit(X, y)
print(model)
Actually I want to add that, even without the custom objective function, I occasionally get the following error:
BlockingIOError: [Errno 35] write could not complete without blocking
I don't know if this is related.
I can't reproduce the error on my machine for some reason. Does the error come up randomly or is it every time you run it? And does the error only appear after you have executed some other code first?
Wait, I was just able to reproduce it. I reproduced it by:
Will try to fix it soon
Okay this should be fixed by https://github.com/MilesCranmer/SymbolicRegression.jl/pull/258. Will be ready in PySR v0.16.3 in maybe a few hours after all the CI testing finishes
Fixed by #413
The Conda version should get released in the next ~10 hours or so. Let me know if there are further issues!
What happened?
I am unable to run the custom objective function example. When I run
model.fit
, I get the following error (truncated to what I think is the relevant bit):This error appears in Jupyter notebook and pure python, so I don't believe it is related to my notebook. Running pysr without the custom objective works fine.
Version
0.16.2
Operating System
macOS
Package Manager
Conda
Interface
Jupyter Notebook
Relevant log output
Extra Info
my Julia version is 1.9.2. It has PyCall and Symbolic Regression installed.
Here are my versions for python requirements: sympy - 1.12 pandas - 2.0.2 numpy - 1.24.3 scikit_learn - 1.2.2 julia - 0.6.0 (also tried 0.6.1) click - 8.1.3 setuptools - 68.0.0