CERBSim / webgui_jupyter_widgets

GNU Lesser General Public License v2.1
5 stars 3 forks source link

Interest in supporting Kaggle? #3

Open francesco-ballarin opened 1 year ago

francesco-ballarin commented 1 year ago

Hi @mhochsteger and @JSchoeberl, I got in touch with you a few months ago about my FEM on Colab project, which supports NGSolve, including visualization through the webgui.

A few users have asked me if, by reusing the same build system, I could also package the same libraries for usage on Kaggle. With a bit of work, this is now available in the spin-off project FEM on Kaggle.

Kaggle is based on jupyter lab, but does not support additional widgets unless they are hardcoded in their backend (see https://github.com/Kaggle/docker-python/issues/1190). Since on Colab, at least to my understanding, you do not use widgets either, my thought was to patch https://github.com/CERBSim/webgui_jupyter_widgets/blob/main/webgui_jupyter_widgets/widget.py#L30 changing the bool from False to True while packaging ngsolve for Kaggle, to trick the webgui into thinking that it is on Colab, so that https://github.com/NGSolve/ngsolve/blob/master/python/webgui.py#L592 https://github.com/NGSolve/netgen/blob/master/python/webgui.py#L238 will follow on both Colab and Kaggle the same flow.

You can find the resulting packages at https://fem-on-kaggle.github.io/packages.html and a relevant test at https://kaggle.com/kernels/welcome?src=https://github.com/fem-on-kaggle/fem-on-kaggle.github.io/blob/gh-pages/tests/ngsolve/test-ngsolve-extras.ipynb

If you run that notebook, at the first Draw(mesh) you will get a plot similar to the following screenshot, where some part of the webgui are shown but the mesh is missing, and the overall formatting is clearly wrong. Screenshot from 2022-12-06 09-51-30

If you have any interest in supporting Kaggle I would be happy to test future releases of webgui_jupyter_widgets with my packaging workflow.

Cheers, Francesco

JSchoeberl commented 1 year ago

Hi Francesco,

super - thank you for providing NGSolve within your fem - package on Kaggle.

@Matthias: I had a quick look - can we check for availability of jupyter - widgets, instead of checking explicitely for colab ?

Best, Joachim

On 06.12.2022, at 10:17, Francesco Ballarin @.***> wrote:

Hi @mhochsteger https://github.com/mhochsteger and @JSchoeberl https://github.com/JSchoeberl, I got in touch with you a few months ago about my FEM on Colab https://fem-on-colab.github.io/ project, which supports NGSolve, including visualization through the webgui.

A few users have asked me if, by reusing the same build system, I could also package the same libraries for usage on Kaggle. With a bit of work, this is now available in the spin-off project FEM on Kaggle https://fem-on-kaggle.github.io/.

Kaggle is based on jupyter lab, but does not support additional widgets unless they are hardcoded in their backend (see Kaggle/docker-python#1190 https://github.com/Kaggle/docker-python/issues/1190). Since on Colab, at least to my understanding, you do not use widgets either, my thought was to patch https://github.com/CERBSim/webgui_jupyter_widgets/blob/main/webgui_jupyter_widgets/widget.py#L30 changing the bool from False to True while packaging ngsolve for Kaggle, to trick the webgui into thinking that it is on Colab, so that https://github.com/NGSolve/ngsolve/blob/master/python/webgui.py#L592 https://github.com/NGSolve/netgen/blob/master/python/webgui.py#L238 will follow on both Colab and Kaggle the same flow.

You can find the resulting packages at https://fem-on-kaggle.github.io/packages.html and a relevant test at https://kaggle.com/kernels/welcome?src=https://github.com/fem-on-kaggle/fem-on-kaggle.github.io/blob/gh-pages/tests/ngsolve/test-ngsolve-extras.ipynb

If you run that notebook, at the first Draw(mesh) you will get a plot similar to the following screenshot, where some part of the webgui are shown but the mesh is missing, and the overall formatting is clearly wrong. https://user-images.githubusercontent.com/11783908/205868607-967ca0d8-e04c-4b85-b9ee-04464d78a498.png If you have any interest in supporting Kaggle I would be happy to test future releases of webgui_jupyter_widgets with my packaging workflow.

Cheers, Francesco

— Reply to this email directly, view it on GitHub https://github.com/CERBSim/webgui_jupyter_widgets/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF7QDZKHDCOGBHOLOE6VD3WL4ADLANCNFSM6AAAAAASVIJNPY. You are receiving this because you were mentioned.

francesco-ballarin commented 1 year ago

Hi @JSchoeberl

There is kaggle package that one could use in a try...except block, but that is not necessarily a reliable way to check if one is on kaggle because:

  1. it requires the user to store some kaggle credentials in their home (see the very first cell in my test)
  2. it may give a false positive if a user has locally installed the kaggle package from pypi.

In my notebook those two issues are not a big deal, but I would advise against such a try...except block in an actual package like yours. The easiest way I would suggest instead to check if one is on Kaggle is to see if "KAGGLE_URL_BASE" in os.environ.

I had a quick look - can we check for availability of jupyter - widgets, instead of checking explicitely for colab ?

I am not sure if that would be advisable. The reasoning in the patch that I currently ship is the following: