Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
291a214
doc: add jax-fem example
jacanchaplais Jul 7, 2025
aa5d36b
fix: update readme paths to new subdir
jacanchaplais Jul 7, 2025
f49fa31
fix: untrack examples in docs
jacanchaplais Jul 7, 2025
c647a5b
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 8, 2025
4112ec9
doc: remove self-compliment from readme
jacanchaplais Jul 8, 2025
06d7849
fix: use local GitHub repo for jax-fem example
jacanchaplais Jul 8, 2025
a521cf3
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 8, 2025
d345b11
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 8, 2025
74ec901
use native platform
dionhaefner Jul 9, 2025
e1ccbe8
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 9, 2025
c8e2fa6
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 14, 2025
5785a09
updated readme instructions
NolanBlack Jul 14, 2025
4c3848e
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 15, 2025
9b2898a
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 16, 2025
9d378fe
added von Mises stress to jax_fem OutputSchema
NolanBlack Jul 18, 2025
8cfbace
minor readme fix
NolanBlack Jul 18, 2025
bfda5bf
used a cleaner way to calculate ugrad
NolanBlack Jul 18, 2025
6277131
added some useful references
NolanBlack Jul 18, 2025
e680cf6
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 21, 2025
2a3bf1f
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 21, 2025
489607d
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 23, 2025
6feb9e1
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Jul 23, 2025
fda7cbb
Merge branch 'jacan/example-jax-fem' of github.com:pasteurlabs/tesser…
jacanchaplais Jul 23, 2025
2d359c5
doc: add jax_fem readme to docs
jacanchaplais Jul 23, 2025
f33ceb5
Merge branch 'main' into jacan/example-jax-fem
jacanchaplais Aug 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ api
:hidden:

examples/vectoradd_jax/README.md
examples/jax_fem/README.md
```
93 changes: 93 additions & 0 deletions examples/jax_fem/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 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 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 ~/Documents/tesseract-streamlit/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
cd ~/Documents/tesseract-streamlit/examples/jax_fem
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!
1 change: 1 addition & 0 deletions examples/jax_fem/bar_params.json
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]]]
2 changes: 2 additions & 0 deletions examples/jax_fem/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyvista==0.45.2
numpy==2.2.5
38 changes: 38 additions & 0 deletions examples/jax_fem/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

# the parent dir of this script:
scriptdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
workdir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

# a temporary dir to store the downloads for the example:
tmpdir=$(mktemp -d)

if [ "$(basename $workdir)" != "tesseract-streamlit" ]; then
echo "Path mismatch: please contact the developers."
echo $workdir
exit 1
fi

# 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
Loading
Loading