-
Notifications
You must be signed in to change notification settings - Fork 0
doc: add jax-fem example #12
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
Open
jacanchaplais
wants to merge
32
commits into
main
Choose a base branch
from
jacan/example-jax-fem
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
291a214
doc: add jax-fem example
jacanchaplais aa5d36b
fix: update readme paths to new subdir
jacanchaplais f49fa31
fix: untrack examples in docs
jacanchaplais c647a5b
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 4112ec9
doc: remove self-compliment from readme
jacanchaplais 06d7849
fix: use local GitHub repo for jax-fem example
jacanchaplais a521cf3
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais d345b11
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 74ec901
use native platform
dionhaefner e1ccbe8
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais c8e2fa6
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 5785a09
updated readme instructions
NolanBlack 4c3848e
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 9b2898a
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 9d378fe
added von Mises stress to jax_fem OutputSchema
NolanBlack 8cfbace
minor readme fix
NolanBlack bfda5bf
used a cleaner way to calculate ugrad
NolanBlack 6277131
added some useful references
NolanBlack e680cf6
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 2a3bf1f
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 489607d
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 6feb9e1
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais fda7cbb
Merge branch 'jacan/example-jax-fem' of github.com:pasteurlabs/tesser…
jacanchaplais 2d359c5
doc: add jax_fem readme to docs
jacanchaplais f33ceb5
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais 0a45e8d
Merge branch 'main' into jacan/example-jax-fem
dionhaefner 00ca631
add plotter for von mises stresses on tube mesh
dionhaefner f5f185d
lint
dionhaefner 0fcfbba
Merge branch 'main' into jacan/example-jax-fem
dionhaefner 51a9e16
cleanup; bar_params are 2D now
dionhaefner ff5b23f
lint
dionhaefner 08df8aa
Merge branch 'jacan/example-jax-fem' of github.com:pasteurlabs/tesser…
dionhaefner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Using JAX with finite element methods (JAX-FEM) | ||
|
|
||
| In this example, you'll generate a Streamlit app from a Tesseract which models a structure and computes its compliance with finite element methods. | ||
| This is based on the excellent example for [shape optimisation in Tesseract JAX](https://docs.pasteurlabs.ai/projects/tesseract-jax/latest/examples/fem-shapeopt/demo.html) using JAX-FEM. | ||
| This, of course, uses `tesseract-streamlit` to automatically generate an interactive web app, this time with an interactive PyVista plot of the structure! ⚡ | ||
|
|
||
| --- | ||
|
|
||
| ## 📥 Step 1: Download the Example Code | ||
|
|
||
| We've written a custom Tesseract for this example, mashing up the Design Tesseract and FEM Tesseract from the original Tesseract JAX tutorial, so clone `tesseract-streamlit` like so: | ||
|
|
||
| ```shell | ||
| git clone --depth 1 https://github.com/pasteurlabs/tesseract-streamlit.git ~/Downloads/tesseract-streamlit | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 📦 Step 2: Install Requirements | ||
|
|
||
| Enter the example directory, and install the required packages: | ||
|
|
||
| ```bash | ||
| cd ~/Documents/tesseract-streamlit/examples/jax_fem | ||
| pip install -r requirements.txt | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠️ Step 3: Build and Serve the Tesseract | ||
|
|
||
| Use the Tesseract CLI to build and serve `jax-fem`: | ||
|
|
||
| ```bash | ||
| tesseract build ~/Downloads/tesseract-core/examples/jax_fem | ||
| tesseract serve jax-fem | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| > Make note of the `PORT` and `PROJECT ID` printed to stdout — you'll need them shortly. | ||
|
|
||
| --- | ||
|
|
||
| ## ⚡ Step 4: Generate the Streamlit App | ||
|
|
||
| With `tesseract-streamlit` installed, generate a ready-to-run Streamlit app: | ||
|
|
||
| ```bash | ||
| tesseract-streamlit --user-code udf.py "http://localhost:<PORT>" app.py | ||
| ``` | ||
|
|
||
| `udf.py` can be found in under `tesseract-streamlit/examples/jax-fem/`. | ||
| It contains a custom function that takes the Tesseract's inputs to render a PyVista plot of the design structure directly in the UI! ⚙️ | ||
| Check out the [source code to see how it works](https://github.com/pasteurlabs/tesseract-streamlit/examples/jax_fem/udf.py). | ||
|
|
||
| --- | ||
|
|
||
| ## ▶️ Step 5: Launch the App | ||
|
|
||
| Run your new app with: | ||
|
|
||
| ```bash | ||
| streamlit run app.py | ||
| ``` | ||
|
|
||
| This will launch a web interface for submitting inputs, running the Tesseract, and visualising the results. | ||
|
|
||
| The form is populated from sensible defaults defined in `tesseract_api.py`. | ||
| To easily provide the input parameters for the structure itself, you can upload the `bar_params.json` file in the current directory. | ||
|
|
||
| --- | ||
|
|
||
| ## 🖼️ Screenshots | ||
|
|
||
|
|
||
| | | | | ||
| | --- | --- | | ||
| | | | | ||
|
|
||
| --- | ||
|
|
||
| ## 🧹 Step 6: Clean Up | ||
|
|
||
| When you're done, you can stop the Tesseract server with: | ||
|
|
||
| ```bash | ||
| tesseract teardown <PROJECT ID> | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| 🎉 That’s it — you've transformed a running Tesseract into a beautiful Streamlit web app with interactive plots, with minimal effort from the command line! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [[[-30.0,-5.0,0.0],[-18.0,-5.0,0.0],[-6.0,-5.0,0.0],[6.000000953674316,-5.0,0.0],[18.0,-5.0,0.0],[30.0,-5.0,0.0]],[[-30.0,-2.5,0.0],[-18.0,-2.5,0.0],[-6.0,-2.5,0.0],[6.000000953674316,-2.5,0.0],[18.0,-2.5,0.0],[30.0,-2.5,0.0]],[[-30.0,0.0,0.0],[-18.0,0.0,0.0],[-6.0,0.0,0.0],[6.000000953674316,0.0,0.0],[18.0,0.0,0.0],[30.0,0.0,0.0]],[[-30.0,2.5,0.0],[-18.0,2.5,0.0],[-6.0,2.5,0.0],[6.000000953674316,2.5,0.0],[18.0,2.5,0.0],[30.0,2.5,0.0]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pyvista==0.45.2 | ||
| numpy==2.2.5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # the parent dir of this script: | ||
| scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| # a temporary dir to store the downloads for the example: | ||
| tmpdir=$(mktemp -d) | ||
| workdir="${tmpdir}/tesseract-streamlit" | ||
|
|
||
| # clone tesseract-core for its example subdirectory: | ||
| git clone --depth 1 --branch jacan/examples git@github.com:pasteurlabs/tesseract-streamlit.git $workdir | ||
|
|
||
| # install requirements for the udf.py module: | ||
| pip install -r "${scriptdir}/requirements.txt" | ||
|
|
||
| # build and serve the vectoradd_jax example tesseract: | ||
| example=jax_fem | ||
| tesseract build "${workdir}/examples/${example}" | ||
| tessinfo=$(tesseract serve $example) | ||
| tessid=$(echo $tessinfo | jq -r '.project_id') | ||
| tessport=$(echo $tessinfo | jq -r '.containers[0].port') | ||
|
|
||
| # automatically generate the Streamlit app from the served tesseract: | ||
| tesseract-streamlit --user-code "${scriptdir}/udf.py" "http://localhost:${tessport}" "${tmpdir}/app.py" | ||
|
|
||
| # launch the web-app: | ||
| streamlit run "${tmpdir}/app.py" | ||
|
|
||
| # stop serving the tesseract | ||
| tesseract teardown $tessid | ||
|
|
||
| # clean up the temporary directory: | ||
| rm -rf $tmpdir | ||
|
|
||
| exit 0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.