chromatix-team / chromatix

Differentiable wave optics using JAX! Documentation can be found at https://chromatix.readthedocs.io
MIT License
73 stars 13 forks source link

101 docs stale #100

Closed tlambert03 closed 1 year ago

tlambert03 commented 1 year ago

just a courtesy note: the "chromatix 101 docs" appear to be out of date.

import chromatix.functional as cx

# We first create an empty field. 
field = cx.empty_field(shape=(512, 512), dx=1.0, spectrum=0.532, spectral_density=1.0)
AttributeError: module 'chromatix.functional' has no attribute 'empty_field'
tlambert03 commented 1 year ago

also gave the examples a shot:

$ python examples/parallel_psf.py
...

Traceback (most recent call last):
  File "/Users/talley/dev/forks/chromatix/examples/parallel_psf.py", line 33, in <module>
    widefield_psf = compute_psf(z)
  File "/Users/talley/dev/forks/chromatix/examples/parallel_psf.py", line 29, in compute_psf
    return optical_model.apply({}, z).intensity
  File "/Users/talley/dev/forks/chromatix/src/chromatix/systems/optical_system.py", line 31, in __call__
    field = self.elements[0](*args, **kwargs)  # allow field to be initialized
  File "/Users/talley/dev/forks/chromatix/src/chromatix/elements/sources.py", line 115, in __call__
    f = register(self, "f")
  File "/Users/talley/dev/forks/chromatix/src/chromatix/elements/utils.py", line 26, in register
    return module.variable(
flax.errors.ScopeCollectionNotFound: Tried to access "_f" from collection "state" in "/elements_0" but the collection is empty. (https://flax.readthedocs.io/en/latest/api_reference/flax.errors.html#flax.errors.ScopeCollectionNotFound)

and

$ python examples/parallel_psf.py
...

Traceback (most recent call last):
  File "/Users/talley/dev/forks/chromatix/examples/parallel_imaging.py", line 54, in <module>
    params = init_params(jax.random.PRNGKey(6022), volume, z)
  File "/Users/talley/dev/forks/chromatix/examples/parallel_imaging.py", line 43, in init_params
    params = microscope.init(key, volume, z)
  File "/Users/talley/dev/forks/chromatix/src/chromatix/systems/microscopes.py", line 87, in __call__
    system_psf = self.psf(*args, **kwargs)
  File "/Users/talley/dev/forks/chromatix/src/chromatix/systems/microscopes.py", line 99, in psf
    return self.system_psf(self, *args, **kwargs)
  File "/Users/talley/dev/forks/chromatix/src/chromatix/systems/microscopes.py", line 211, in __call__
    psf = system(z)
  File "/Users/talley/dev/forks/chromatix/src/chromatix/systems/optical_system.py", line 33, in __call__
    field = element(field)
  File "/Users/talley/dev/forks/chromatix/src/chromatix/elements/phase_masks.py", line 68, in __call__
    phase = register(
  File "/Users/talley/dev/forks/chromatix/src/chromatix/elements/utils.py", line 24, in register
    return module.param(f"_{name}", parse_init(init.val), *args)
  File "/Users/talley/dev/forks/chromatix/src/chromatix/functional/phase_masks.py", line 49, in flat_phase
    return jnp.full(shape, value)
  File "/Users/talley/mambaforge/envs/chromatix/lib/python3.10/site-packages/jax/_src/numpy/lax_numpy.py", line 2058, in full
    return lax.full(shape, fill_value, dtype)
jaxlib.xla_extension.XlaRuntimeError: UNKNOWN: <unknown>:0: error: invalid shape type=11, dims=[3235068045,3032181039]:
<unknown>:0: note: see current operation: "func.return"(%0) : (tensor<3235068045x3032181039xf32>) -> ()

not complaining! I know how hard it is to develop a very new project and keep the docs/examples working. 😄

anyway, really excited for what's happening here and look forward to digging in some more!

tlambert03 commented 1 year ago

incidentally, if you run the "usage" example in the readme, you get the same flax error:

ScopeCollectionNotFound: Tried to access "_f" from collection "state" in "/elements_0" but the collection is empty.

my environment: Python 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:17:34) [Clang 14.0.6 ] macos 12.6.5

$ conda list ``` # packages in environment at /Users/talley/mambaforge/envs/chromatix: # # Name Version Build Channel absl-py 1.4.0 pypi_0 pypi anyio 3.6.2 pyhd8ed1ab_0 conda-forge aom 3.5.0 hf0c8a7f_0 conda-forge appnope 0.1.3 pyhd8ed1ab_0 conda-forge argon2-cffi 21.3.0 pyhd8ed1ab_0 conda-forge argon2-cffi-bindings 21.2.0 py310h90acd4f_3 conda-forge asttokens 2.2.1 pyhd8ed1ab_0 conda-forge attrs 23.1.0 pyh71513ae_0 conda-forge backcall 0.2.0 pyh9f0ad1d_0 conda-forge backports 1.0 pyhd8ed1ab_3 conda-forge backports.functools_lru_cache 1.6.4 pyhd8ed1ab_0 conda-forge beautifulsoup4 4.12.2 pyha770c72_0 conda-forge black 23.3.0 pypi_0 pypi bleach 6.0.0 pyhd8ed1ab_0 conda-forge blosc 1.21.2 hebb52c4_0 conda-forge brotli 1.0.9 hb7f2c08_8 conda-forge brotli-bin 1.0.9 hb7f2c08_8 conda-forge brotlipy 0.7.0 py310h90acd4f_1005 conda-forge brunsli 0.1 h046ec9c_0 conda-forge bzip2 1.0.8 h0d85af4_4 conda-forge c-ares 1.18.1 h0d85af4_0 conda-forge c-blosc2 2.8.0 had5f71b_1 conda-forge ca-certificates 2022.12.7 h033912b_0 conda-forge cached-property 1.5.2 pypi_0 pypi certifi 2022.12.7 pyhd8ed1ab_0 conda-forge cffi 1.15.1 py310ha78151a_3 conda-forge cfitsio 4.2.0 hd56cc12_0 conda-forge charls 2.4.1 hf0c8a7f_0 conda-forge charset-normalizer 3.1.0 pyhd8ed1ab_0 conda-forge chex 0.1.7 pypi_0 pypi chromatix 0.0.0 pypi_0 pypi click 8.1.3 py310h2ec42d9_1 conda-forge cloudpickle 2.2.1 pyhd8ed1ab_0 conda-forge comm 0.1.3 pyhd8ed1ab_0 conda-forge contourpy 1.0.7 py310ha23aa8a_0 conda-forge cryptography 40.0.2 py310hdd0c95c_0 conda-forge cycler 0.11.0 pyhd8ed1ab_0 conda-forge cytoolz 0.12.0 py310h90acd4f_1 conda-forge dask-core 2023.4.1 pyhd8ed1ab_0 conda-forge dav1d 1.0.0 hac89ed1_1 conda-forge debugpy 1.6.7 py310h7a76584_0 conda-forge decorator 5.1.1 pyhd8ed1ab_0 conda-forge defusedxml 0.7.1 pyhd8ed1ab_0 conda-forge dm-tree 0.1.8 pypi_0 pypi einops 0.6.1 pypi_0 pypi entrypoints 0.4 pyhd8ed1ab_0 conda-forge etils 1.2.0 pypi_0 pypi exceptiongroup 1.1.1 pypi_0 pypi executing 1.2.0 pyhd8ed1ab_0 conda-forge flax 0.6.9 pypi_0 pypi flit-core 3.8.0 pyhd8ed1ab_0 conda-forge fonttools 4.39.3 py310h90acd4f_0 conda-forge freetype 2.12.1 h3f81eb7_1 conda-forge fsspec 2023.4.0 pyh1a96a4e_0 conda-forge gettext 0.21.1 h8a4c099_0 conda-forge giflib 5.2.1 hb7f2c08_3 conda-forge glib 2.76.2 h7d26f99_0 conda-forge glib-tools 2.76.2 h7d26f99_0 conda-forge gst-plugins-base 1.22.0 h37e1711_2 conda-forge gstreamer 1.22.0 h1d18e73_2 conda-forge icu 72.1 h7336db1_0 conda-forge idna 3.4 pyhd8ed1ab_0 conda-forge imagecodecs 2023.1.23 py310hb122b82_2 conda-forge imageio 2.28.1 pyh24c5eb1_0 conda-forge importlib-metadata 6.6.0 pyha770c72_0 conda-forge importlib_metadata 6.6.0 hd8ed1ab_0 conda-forge importlib_resources 5.12.0 pyhd8ed1ab_0 conda-forge iniconfig 2.0.0 pypi_0 pypi ipykernel 6.22.0 pyh736e0ef_0 conda-forge ipython 8.13.1 pyhd1c38e8_0 conda-forge ipython_genutils 0.2.0 py_1 conda-forge ipywidgets 8.0.6 pyhd8ed1ab_0 conda-forge jax 0.4.8 pyhd8ed1ab_0 conda-forge jaxlib 0.4.7 cpu_py310h11349c6_0 conda-forge jedi 0.18.2 pyhd8ed1ab_0 conda-forge jinja2 3.1.2 pyhd8ed1ab_1 conda-forge jsonschema 4.17.3 pyhd8ed1ab_0 conda-forge jupyter 1.0.0 py310h2ec42d9_8 conda-forge jupyter_client 8.2.0 pyhd8ed1ab_0 conda-forge jupyter_console 6.6.3 pyhd8ed1ab_0 conda-forge jupyter_core 5.3.0 py310h2ec42d9_0 conda-forge jupyter_events 0.6.3 pyhd8ed1ab_0 conda-forge jupyter_server 2.5.0 pyhd8ed1ab_0 conda-forge jupyter_server_terminals 0.4.4 pyhd8ed1ab_1 conda-forge jupyterlab_pygments 0.2.2 pyhd8ed1ab_0 conda-forge jupyterlab_widgets 3.0.7 pyhd8ed1ab_0 conda-forge jxrlib 1.1 h35c211d_2 conda-forge kiwisolver 1.4.4 py310ha23aa8a_1 conda-forge krb5 1.20.1 h049b76e_0 conda-forge lazy_loader 0.2 pyhd8ed1ab_0 conda-forge lcms2 2.15 h2dcdeff_1 conda-forge lerc 4.0.0 hb486fe8_0 conda-forge libabseil 20230125.0 cxx17_hf0c8a7f_1 conda-forge libaec 1.0.6 hf0c8a7f_1 conda-forge libavif 0.11.1 he9a59b1_0 conda-forge libblas 3.9.0 16_osx64_openblas conda-forge libbrotlicommon 1.0.9 hb7f2c08_8 conda-forge libbrotlidec 1.0.9 hb7f2c08_8 conda-forge libbrotlienc 1.0.9 hb7f2c08_8 conda-forge libcblas 3.9.0 16_osx64_openblas conda-forge libclang 14.0.6 default_h55ffa42_0 conda-forge libclang13 14.0.6 default_hb5731bd_0 conda-forge libcurl 8.0.1 h1fead75_0 conda-forge libcxx 16.0.2 hd57cbcb_0 conda-forge libdeflate 1.18 hac1461d_0 conda-forge libedit 3.1.20191231 h0678c8f_2 conda-forge libev 4.33 haf1e3a3_1 conda-forge libffi 3.4.2 h0d85af4_5 conda-forge libgfortran 5.0.0 11_3_0_h97931a8_31 conda-forge libgfortran5 12.2.0 he409387_31 conda-forge libglib 2.76.2 hc62aa5d_0 conda-forge libgrpc 1.54.1 h0eeb599_0 conda-forge libiconv 1.17 hac89ed1_0 conda-forge libjpeg-turbo 2.1.5.1 hb7f2c08_0 conda-forge liblapack 3.9.0 16_osx64_openblas conda-forge libllvm14 14.0.6 h5b596cc_1 conda-forge libnghttp2 1.52.0 he2ab024_0 conda-forge libogg 1.3.4 h35c211d_1 conda-forge libopenblas 0.3.21 openmp_h429af6e_3 conda-forge libopus 1.3.1 hc929b4f_1 conda-forge libpng 1.6.39 ha978bb4_0 conda-forge libpq 15.2 h3640bf0_0 conda-forge libprotobuf 3.21.12 hbc0c0cd_0 conda-forge libsodium 1.0.18 hbcb3906_1 conda-forge libsqlite 3.40.0 ha978bb4_1 conda-forge libssh2 1.10.0 h47af595_3 conda-forge libtiff 4.5.0 hedf67fa_6 conda-forge libvorbis 1.3.7 h046ec9c_0 conda-forge libwebp-base 1.3.0 hb7f2c08_0 conda-forge libxcb 1.13 h0d85af4_1004 conda-forge libzlib 1.2.13 hfd90126_4 conda-forge libzopfli 1.0.3 h046ec9c_0 conda-forge llvm-openmp 16.0.2 hff08bdf_0 conda-forge locket 1.0.0 pyhd8ed1ab_0 conda-forge lz4-c 1.9.4 hf0c8a7f_0 conda-forge markdown-it-py 2.2.0 pypi_0 pypi markupsafe 2.1.2 py310h90acd4f_0 conda-forge matplotlib 3.7.1 py310h2ec42d9_0 conda-forge matplotlib-base 3.7.1 py310he725631_0 conda-forge matplotlib-inline 0.1.6 pyhd8ed1ab_0 conda-forge mdurl 0.1.2 pypi_0 pypi mistune 2.0.5 pyhd8ed1ab_0 conda-forge ml_dtypes 0.1.0 py310hecf8f37_0 conda-forge msgpack 1.0.5 pypi_0 pypi munkres 1.1.4 pyh9f0ad1d_0 conda-forge mypy 1.2.0 pypi_0 pypi mypy-extensions 1.0.0 pypi_0 pypi mysql-common 8.0.32 hc4b2c72_1 conda-forge mysql-libs 8.0.32 h8658499_1 conda-forge nbclassic 0.5.6 pyhb4ecaf3_1 conda-forge nbclient 0.7.4 pyhd8ed1ab_0 conda-forge nbconvert 7.3.1 pyhd8ed1ab_0 conda-forge nbconvert-core 7.3.1 pyhd8ed1ab_0 conda-forge nbconvert-pandoc 7.3.1 pyhd8ed1ab_0 conda-forge nbformat 5.8.0 pyhd8ed1ab_0 conda-forge ncurses 6.3 h96cf925_1 conda-forge nest-asyncio 1.5.6 pyhd8ed1ab_0 conda-forge networkx 3.1 pyhd8ed1ab_0 conda-forge notebook 6.5.4 pyha770c72_0 conda-forge notebook-shim 0.2.3 pyhd8ed1ab_0 conda-forge nspr 4.35 hea0b92c_0 conda-forge nss 3.89 h78b00b3_0 conda-forge numpy 1.24.3 py310h7451ae0_0 conda-forge openjpeg 2.5.0 h13ac156_2 conda-forge openssl 3.1.0 h8a1eda9_3 conda-forge opt_einsum 3.3.0 pyhd8ed1ab_1 conda-forge optax 0.1.5 pypi_0 pypi orbax-checkpoint 0.2.1 pypi_0 pypi packaging 23.1 pyhd8ed1ab_0 conda-forge pandoc 2.19.2 h694c41f_2 conda-forge pandocfilters 1.5.0 pyhd8ed1ab_0 conda-forge parso 0.8.3 pyhd8ed1ab_0 conda-forge partd 1.4.0 pyhd8ed1ab_0 conda-forge pathspec 0.11.1 pypi_0 pypi pcre2 10.40 h1c4e4bc_0 conda-forge pexpect 4.8.0 pyh1a96a4e_2 conda-forge pickleshare 0.7.5 py_1003 conda-forge pillow 9.5.0 py310h6b2f720_0 conda-forge pip 23.1.2 pyhd8ed1ab_0 conda-forge pkgutil-resolve-name 1.3.10 pyhd8ed1ab_0 conda-forge platformdirs 3.5.0 pyhd8ed1ab_0 conda-forge pluggy 1.0.0 pypi_0 pypi ply 3.11 py_1 conda-forge pooch 1.7.0 pyha770c72_3 conda-forge prometheus_client 0.16.0 pyhd8ed1ab_0 conda-forge prompt-toolkit 3.0.38 pyha770c72_0 conda-forge prompt_toolkit 3.0.38 hd8ed1ab_0 conda-forge psutil 5.9.5 py310h90acd4f_0 conda-forge pthread-stubs 0.4 hc929b4f_1001 conda-forge ptyprocess 0.7.0 pyhd3deb0d_0 conda-forge pure_eval 0.2.2 pyhd8ed1ab_0 conda-forge pycparser 2.21 pyhd8ed1ab_0 conda-forge pygments 2.15.1 pyhd8ed1ab_0 conda-forge pyobjc-core 9.1.1 py310h4f19300_0 conda-forge pyobjc-framework-cocoa 9.1.1 py310h4f19300_0 conda-forge pyopenssl 23.1.1 pyhd8ed1ab_0 conda-forge pyparsing 3.0.9 pyhd8ed1ab_0 conda-forge pyqt 5.15.7 py310hdd03f62_3 conda-forge pyqt5-sip 12.11.0 py310h415000c_3 conda-forge pyrsistent 0.19.3 py310h90acd4f_0 conda-forge pysocks 1.7.1 py310h2ec42d9_5 conda-forge pytest 7.3.1 pypi_0 pypi python 3.10.10 he7542f4_0_cpython conda-forge python-dateutil 2.8.2 pyhd8ed1ab_0 conda-forge python-fastjsonschema 2.16.3 pyhd8ed1ab_0 conda-forge python-json-logger 2.0.7 pyhd8ed1ab_0 conda-forge python_abi 3.10 3_cp310 conda-forge pywavelets 1.4.1 py310h936d966_0 conda-forge pyyaml 6.0 py310h90acd4f_5 conda-forge pyzmq 25.0.2 py310hf615a82_0 conda-forge qt-main 5.15.8 h0afe88e_9 conda-forge qtconsole 5.4.2 pyhd8ed1ab_0 conda-forge qtconsole-base 5.4.2 pyha770c72_0 conda-forge qtpy 2.3.1 pyhd8ed1ab_0 conda-forge re2 2023.02.02 hf0c8a7f_0 conda-forge readline 8.2 h9e318b2_1 conda-forge requests 2.29.0 pyhd8ed1ab_0 conda-forge rfc3339-validator 0.1.4 pyhd8ed1ab_0 conda-forge rfc3986-validator 0.1.1 pyh9f0ad1d_0 conda-forge rich 13.3.5 pypi_0 pypi ruff 0.0.264 pypi_0 pypi scikit-image 0.20.0 py310hecf8f37_1 conda-forge scipy 1.10.1 py310h240c617_0 conda-forge send2trash 1.8.2 pyhd1c38e8_0 conda-forge setuptools 67.7.2 pyhd8ed1ab_0 conda-forge sip 6.7.9 py310h9e9d8ca_0 conda-forge six 1.16.0 pyh6c4a22f_0 conda-forge snappy 1.1.10 h225ccf5_0 conda-forge sniffio 1.3.0 pyhd8ed1ab_0 conda-forge soupsieve 2.3.2.post1 pyhd8ed1ab_0 conda-forge stack_data 0.6.2 pyhd8ed1ab_0 conda-forge tensorstore 0.1.36 pypi_0 pypi terminado 0.17.1 pyhd1c38e8_0 conda-forge tifffile 2023.4.12 pyhd8ed1ab_0 conda-forge tinycss2 1.2.1 pyhd8ed1ab_0 conda-forge tk 8.6.12 h5dbffcc_0 conda-forge toml 0.10.2 pyhd8ed1ab_0 conda-forge tomli 2.0.1 pyhd8ed1ab_0 conda-forge toolz 0.12.0 pyhd8ed1ab_0 conda-forge tornado 6.3 py310h90acd4f_0 conda-forge traitlets 5.9.0 pyhd8ed1ab_0 conda-forge typing-extensions 4.5.0 hd8ed1ab_0 conda-forge typing_extensions 4.5.0 pyha770c72_0 conda-forge tzdata 2023c h71feb2d_0 conda-forge unicodedata2 15.0.0 py310h90acd4f_0 conda-forge urllib3 1.26.15 pyhd8ed1ab_0 conda-forge wcwidth 0.2.6 pyhd8ed1ab_0 conda-forge webencodings 0.5.1 py_1 conda-forge websocket-client 1.5.1 pyhd8ed1ab_0 conda-forge wheel 0.40.0 pyhd8ed1ab_0 conda-forge widgetsnbextension 4.0.7 pyhd8ed1ab_0 conda-forge xorg-libxau 1.0.9 h35c211d_0 conda-forge xorg-libxdmcp 1.1.3 h35c211d_0 conda-forge xz 5.2.6 h775f41a_0 conda-forge yaml 0.2.5 h0d85af4_2 conda-forge zeromq 4.3.4 he49afe7_1 conda-forge zfp 1.0.0 ha894c9a_3 conda-forge zipp 3.15.0 pyhd8ed1ab_0 conda-forge zlib 1.2.13 hfd90126_4 conda-forge zlib-ng 2.0.7 hb7f2c08_0 conda-forge zstd 1.5.2 hbc0c0cd_6 conda-forge ```
GJBoth commented 1 year ago

Hi @tlambert03, thanks for your interest! You're right - 101 is currently broken. We had a hackathon a few weeks ago and made some changes based on the feedback we got, and we're almost finished with updating the docs - but not quite ;-)

We hope to update 101 next week. There's some small changes to the code, but the main ideas are the same. The examples in our documentation should work though! (https://chromatix.readthedocs.io/en/latest/examples/cgh/ for example).

GJBoth commented 1 year ago

We're working on CI for the docs so hopefully this doesn't happen anymore, but we haven't got around to it.

tlambert03 commented 1 year ago

We had a hackathon a few weeks ago

yeah I was in the audience at your final presentation drooling 🤤 (was at the other hackathon) finally getting around to trying it. will check out the docs examples next. thanks again!

tlambert03 commented 1 year ago

yep, holoscope.ipynb works great. thanks

diptodip commented 1 year ago

Maybe we should have put some warnings up about being in an "alpha" state :slightly_smiling_face:

But thanks for checking things out and pointing out what was broken! I've updated the 101 and all the other examples that you tried that didn't work. We can still improve 101 to make it a better introduction to Chromatix and simulating optics in general, but it'll do for now.

A note about the parallel imaging and PSF examples: those just got updated but you'll need to make sure to either change the number of devices in the code before running the example or run on a system that has 4 GPUs.

tlambert03 commented 1 year ago

No need for alpha warning. It's understood :)