ARTIST-Association / ARTIST

A differentiable ray tracer using the PyTorch machine-learning framework in Python.
MIT License
5 stars 1 forks source link

Problem with ARTIST Imports #72

Closed kalebphipps closed 3 months ago

kalebphipps commented 4 months ago

Describe the bug The ARTIST package structure is leading to circular imports or module not-found errors on certain systems. Locally, everything works as desired. However, there are two cases where this error occurs.

To reproduce Case One - Sphinx:

  1. Navigate to the docs folder in a local clone of the repository.
  2. Run: sphinx-build -b html . _build in the terminal.
  3. The docs compile. However, sphinx throws a warning:

    “WARNING: Cannot resolve cyclic import: artist, artist.scenario, artist.field.heliostat_field, artist.field, artist.field.heliostat_field”


Case Two - Google Colab:

First - Open the notebook in Google Colab:

  1. Navigate to Google Colab
  2. Authorise Google Colab to access your GitHub account.
  3. Select "open notebook" from GitHub.
  4. In the drop-down menu, select the ARTIST repository.
  5. Select the maintenance/tutorials_and_docs branch.
  6. Open the suggested Jupyter notebook, tutorials/01_heliostat_raytracing_notebook.ipynb. Note, you cannot save changes of this notebook to GitHub, if you want to make changes either save a copy of the notebook or make these changes locally and push them to GitHub later.

Second - Generate a GitHub Access Token (only necessary whilst the ARTIST repo remains private:

  1. Go to GitHub and log in to your account.
  2. Navigate to Settings > Developer settings > Personal access tokens.
  3. Click Generate new token.
  4. Select the appropriate scopes for your token. At a minimum, you'll need repo access to install from a private repository.
  5. Click Generate token and copy the generated token. Store it securely.

Third - Adjust the install command of ARTIST in the notebook to include your token:

Finally - generate the error:

1 frames /usr/local/lib/python3.10/dist-packages/artist/scenario.py in 5 from typing_extensions import Self 6 ----> 7 from artist.field.heliostat_field import HeliostatField 8 from artist.field.receiver_field import ReceiverField 9 from artist.scene.light_source_array import LightSourceArray

ModuleNotFoundError: No module named 'artist.field'



**Expected behaviour**
It should be possible to import ``ARTIST`` on all systems without errors!
kalebphipps commented 4 months ago

This was due to installing ARTIST in a non-editable manner and not explicitly defining all subpackages in the project. tool. When installed with -e, this isn't a problem, but without this option Jupyter struggles to import things.

The fix is

[tool.setuptools]
packages = ["artist","artist.field","artist.raytracing","artist.scene","artist.util"]