Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: node_to_symbolic errors even though SymbolicUtils.jl is loaded #368

Open
StevenWhitaker opened this issue Nov 12, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@StevenWhitaker
Copy link

StevenWhitaker commented Nov 12, 2024

What happened?

I ran the following code (almost exactly copy-pasted from different sections of the README):

using SymbolicRegression, SymbolicUtils

X = randn(2, 100)
y = 2 * cos.(X[2, :]) + X[1, :] .^ 2 .- 2

options = Options(
    binary_operators=[+, *, /, -],
    unary_operators=[cos, exp],
    populations=20,
    save_to_file = false
)

hall_of_fame = equation_search(
    X, y, niterations=40, options=options,
    parallelism=:multithreading
)

dominating = calculate_pareto_frontier(hall_of_fame)

eqn = node_to_symbolic(dominating[end].tree)

Result:

ERROR: Please load the `SymbolicUtils` package to use `node_to_symbolic`.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] node_to_symbolic(args::Node{Float64}; kws::@Kwargs{})
   @ DynamicExpressions.ExtensionInterfaceModule ~/.julia/packages/DynamicExpressions/WxB2R/src/ExtensionInterface.jl:4
 [3] node_to_symbolic(args::Node{Float64})
   @ DynamicExpressions.ExtensionInterfaceModule ~/.julia/packages/DynamicExpressions/WxB2R/src/ExtensionInterface.jl:3
 [4] top-level scope
   @ REPL[5]:21

Since SymbolicUtils is loaded, I did not expect to see this error.

Version

v0.24.5

Operating System

Linux

Interface

Julia REPL

Relevant log output

(jl_0elvPY) pkg> st
Status `/tmp/jl_0elvPY/Project.toml`
  [8254be44] SymbolicRegression v0.24.5 ⚲
⌃ [d1185830] SymbolicUtils v1.7.1

Extra Info

No response

@StevenWhitaker StevenWhitaker added the bug Something isn't working label Nov 12, 2024
@StevenWhitaker
Copy link
Author

I just tested with

(jl_0elvPY) pkg> st
Status `/tmp/jl_0elvPY/Project.toml`
  [8254be44] SymbolicRegression v1.0.0 `https://github.com/MilesCranmer/SymbolicRegression.jl.git#v1.0.0-beta4`
⌃ [d1185830] SymbolicUtils v3.4.1

and the code ran as expected. So I guess this issue is resolved, but not on an official release yet.

@MilesCranmer
Copy link
Owner

MilesCranmer commented Nov 12, 2024

ERROR: Please load the SymbolicUtils package to use node_to_symbolic.

If SymbolicUtils is loaded and this error still appears, it could be because there was an error during the precompilation or something else, which prevented the extension from loading. This might happen for example if you load SymbolicUtils from a different environment from the one SymbolicRegression is loaded in. It could be a bug too!

If you see it again, can you try running Base.retry_load_extensions()? You can also write err for a more detailed backtrace, if it does error.

@MilesCranmer
Copy link
Owner

MilesCranmer commented Nov 12, 2024

Ah, I just tried, and I get the same error!

Ok, so the reason is that node_to_symbolic(tree) is specifically for the new API in 1.0.0 – this is what is present on the README. The old API you would also need to pass the options, like this:

eqn = node_to_symbolic(dominating[end].tree, options)

Then it should work!

Sorry for the confusion. I am late in releasing 1.0.0, there are just some things I want to make sure are ready before it's up.

@StevenWhitaker
Copy link
Author

Great, that did it. Thank you!

@joshkamm
Copy link

joshkamm commented Dec 10, 2024

I just ran into a related problem and saw this issue while checking to see if it had already been reported. I think my actual problem was that I wasn't passing the correct arguments to symbolic_to_node, but the error message was about SymbolicUtils not being loaded which led me in the wrong direction. So I was eventually able to get past the issue, but a more accurate error message would be helpful for the next person. Here's a simplified example:

{310B7736-D937-4C16-8A37-703250AC26D8}

@MilesCranmer
Copy link
Owner

Good point! Yes it would be better to give a MethodError here if it’s actually loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants