Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c3b7595
doc: nest vectoradd_jax, improve README aesthetic
jacanchaplais Jun 24, 2025
ba31807
doc: mention location of udf.py
jacanchaplais Jun 24, 2025
655fe04
doc: remove emoji from title in README
jacanchaplais Jun 24, 2025
337bd7d
fix: use trame backend for stpyvista
jacanchaplais Jul 4, 2025
d30033c
fix: support single elem array outputs
jacanchaplais Jul 4, 2025
3ae5113
feat: add jax-fem example
jacanchaplais Jul 4, 2025
a0c088a
doc: add examples section to docs
jacanchaplais Jul 4, 2025
f5617ef
Merge branch 'main' into jacan/examples
jacanchaplais Jul 4, 2025
dde4465
fix: regenerate requirements and uv.lock
jacanchaplais Jul 4, 2025
9e23101
fix: regenerate requirements and uv.lock
jacanchaplais Jul 4, 2025
b26bb67
fix: regenerate requirements and uv.lock
jacanchaplais Jul 4, 2025
b6fc4c6
fix: regenerate requirements and uv.lock
jacanchaplais Jul 4, 2025
6710846
fix: regenerate requirements and uv.lock
jacanchaplais Jul 4, 2025
4d3660f
doc: add wip readme for jax-fem example
jacanchaplais Jul 4, 2025
87ccc44
chore: rename jax-fem to jax_fem
jacanchaplais Jul 4, 2025
5472332
doc: add instruction to upload bar_params.json
jacanchaplais Jul 4, 2025
224f589
doc: add bash script to run jax_fem example
jacanchaplais Jul 4, 2025
56c9686
feat: add exp input for small default or cli flag
jacanchaplais Jul 4, 2025
a4ef39a
doc: add descriptive docstring to jax_fem apply
jacanchaplais Jul 4, 2025
df2c234
fix: consistent path delimiter
jacanchaplais Jul 7, 2025
37d28ac
fix: merge conflict with dependency bump
jacanchaplais Jul 7, 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ This setup gives you control over what to display and how to explain it, directl
See the example README for a basic example walk-through, or simply run the following script to see the end result!

```bash
bash examples/run.sh
bash examples/vectoradd_jax/run.sh
```

This will open a browser window with the Streamlit UI where users can input values and visualise the response.

| ![](examples/screenshots/header-vec-a.png) | ![](examples/screenshots/outputs.png) |
| ![](examples/vectoradd_jax/screenshots/header-vec-a.png) | ![](examples/vectoradd_jax/screenshots/outputs.png) |
| --------------------------------- | ---------------------------- |
| ![](examples/screenshots/vec-b.png) | ![](examples/screenshots/plot.png) |
| ![](examples/vectoradd_jax/screenshots/vec-b.png) | ![](examples/vectoradd_jax/screenshots/plot.png) |

## ⚠️ Current Limitations

Expand Down
11 changes: 11 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import re
import shutil
from pathlib import Path

from tesseract_streamlit import __version__

PARENT_DIR = Path(__file__).parent.resolve()

project = "tesseract-streamlit"
copyright = "2024, The tesseract-streamlit Team @ Pasteur Labs"
author = "The tesseract-streamlit Team @ Pasteur Labs"
Expand Down Expand Up @@ -55,3 +59,10 @@

html_theme = "furo"
html_static_path = ["static"]

# Copy example notebooks to docs/examples folder on every build
for example_dir in Path("../examples").glob("*/"):
# Copy the example directory to the docs folder
shutil.copytree(
example_dir, PARENT_DIR / "examples" / example_dir.name, dirs_exist_ok=True
)
2 changes: 2 additions & 0 deletions docs/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*
!.gitignore
8 changes: 8 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@
self
api
```

```{toctree}
:caption: Examples
:maxdepth: 2
:hidden:

examples/vectoradd_jax/README.md
```
72 changes: 0 additions & 72 deletions examples/README.md

This file was deleted.

92 changes: 92 additions & 0 deletions examples/jax_fem/README.md
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!
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
35 changes: 35 additions & 0 deletions examples/jax_fem/run.sh
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 [email protected]: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
Loading
Loading