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

order of imports matters? #1348

Closed
humnaawan opened this issue Jan 2, 2025 · 2 comments · Fixed by #1357
Closed

order of imports matters? #1348

humnaawan opened this issue Jan 2, 2025 · 2 comments · Fixed by #1357
Labels
bug Something isn't working

Comments

@humnaawan
Copy link

Hello, it seems I get an error if I import anything from sbi.neural_nets without importing something else first. I discovered this when I attempted to just import posterior_nn via from sbi.neural_nets import posterior_nn and I got

ImportError: cannot import name 'classifier_nn' from partially initialized module 'sbi.neural_nets.factory' (most likely due to a circular import) (../lib/python3.9/site-packages/sbi/neural_nets/factory.py)

Same thing happens if I just do import sbi.neural_nets or from sbi.neural_nets.embedding_nets import FCEmbedding

The error goes away if I import other things first, e.g.,
from sbi.analysis import pairplot
from sbi.inference import NPE, simulate_for_sbi
from sbi.utils import BoxUniform
from sbi.diagnostics import check_sbc, run_sbc, check_tarp, run_tarp

It took me a while to debug this so I thought I'd report it here.

@humnaawan humnaawan added the bug Something isn't working label Jan 2, 2025
@janfb
Copy link
Contributor

janfb commented Jan 3, 2025

Yes, unfortunately we still have a circular import problem here, see #1249 for more details.

@manuelgloeckler
Copy link
Contributor

The issue is fixed on the current main and most recent release, 0.23.3.

However, there are still some circular imports. I did improve our tests on circular imports to detect these kind of errors and try to resolve them in #1357.

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

Successfully merging a pull request may close this issue.

3 participants