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]: Freezes after launching pysr in streamlit app #662

Closed
bahonya opened this issue Jul 6, 2024 · 3 comments
Closed

[BUG]: Freezes after launching pysr in streamlit app #662

bahonya opened this issue Jul 6, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@bahonya
Copy link

bahonya commented Jul 6, 2024

What happened?

I am currently trying to launch pysr from streamlit app and after running model.fit(x_train, y_train)
I see only this and nothing else:
Compiling Julia backend...
[ Info: Started!

running it just as a python script or in jupiter notebook works
I also trying calling pysr using ThreadPoolExecutor and same happens

Would appreciate any suggestions

Version

0.19.0

Operating System

macOS

Package Manager

Conda

Interface

Other (specify below)

Relevant log output

Compiling Julia backend...
[ Info: Started!

Extra Info

No response

@bahonya bahonya added the bug Something isn't working label Jul 6, 2024
@bahonya bahonya changed the title [BUG]: Freezes after starting calling it in streamlit app [BUG]: Freezes after launching pysr in streamlit app Jul 6, 2024
@MilesCranmer
Copy link
Owner

Hi @bahonya,
Can you give a full code example so I can reproduce it? I am not familiar with streamlit.
Thanks,
Miles

@bahonya
Copy link
Author

bahonya commented Jul 7, 2024

Hi @MilesCranmer , thanks for the quick response

I got it, it happens because I change directory during the run, if I remove os.chdir in example below it works. I have to change the directory durung the run. I will look for a workaround. I think I will close this ticket then

`
import streamlit as st
import numpy as np
import pandas as pd
import os
from pysr import PySRRegressor

def generate_data(n_samples):
X = np.random.rand(n_samples, 1) * 10
y = 2 * X.squeeze() + np.random.randn(n_samples) * 2
return X, y
st.title("example app")
st.sidebar.header("parameters to generate data")
n_samples = st.sidebar.slider("number of samples", min_value=10, max_value=1000, value=100)
X, y = generate_data(n_samples)
st.subheader("generated data")
data = pd.DataFrame(data={'X': X.squeeze(), 'y': y})
st.write(data)
model = PySRRegressor(
populations=5,
niterations=100,
binary_operators=["+", "*"],
unary_operators=["sin", "cos"],
)
if st.button("Fit the model"):
os.chdir('subfolder')
model.fit(X, y)
os.chdir('..')
st.subheader("found equations")
st.write(model.equations_)
st.subheader("predictions")
y_pred = model.predict(X)
st.write("predicted values", y_pred)
import matplotlib.pyplot as plt
plt.scatter(X, y, label='ground truth', color='blue')
plt.scatter(X, y_pred, label='predicted values', color='red')
plt.legend()
st.pyplot(plt)
`

@bahonya bahonya closed this as completed Jul 7, 2024
@MilesCranmer
Copy link
Owner

MilesCranmer commented Jul 8, 2024

Cool!

If you are interested, maybe we could work together on a GUI? I have a start on this PR: #589. It's with gradio rather than streamlit but parts are similar. The goal is to have it be compatible with HuggingFace spaces so you can have web version of PySR.

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

2 participants