# \[ANN\] Jello.jl - Manufacturable geometry generation for topology optimization & generative design

**URL:** <https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102>\
**Category:** Package Announcements\
**Tags:** package, announcement, flux, optimization, machine-learning\
**Created:** [November 12, 2023, 2:17am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102 "2023-11-12T02:17:11Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [November 12, 2023, 2:17am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/1 "2023-11-12T02:17:11Z")

</div>

Hello friends [Jello.jl](https://github.com/paulxshen/Jello.jl) uses a Fourier domain algorithm for generating manufacturable geometry for topology optimization & generative inverse design. Will take couple days for merging into general registry. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [November 12, 2023, 8:10am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/2 "2023-11-12T08:10:59Z")

</div>

Nice package and neat idea! I am hoping to integrate some of these ideas in TopOpt.jl if possible. Is there a publication I can read for the theory?

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [November 13, 2023, 2:00am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/3 "2023-11-13T02:00:39Z")

</div>

Thanks! I’m doing a preprint soon. Collaboration welcome. A simple way to interface with a mesh is to interpolate the density array. Some methods in Interpolations.jl work with AD. Here’re papers on Fourier geometry generation though ours presents some improvements:

> **[Toplogical optimization of structures using Fourier representations -...](https://link.springer.com/article/10.1007/s00158-018-1962-y)**
>
> The minimization of compliance subject to a mass constraint is the topology optimization design problem of interest. The goal is to determine the optimal configuration of material within an allowed volume. Our approach builds upon the well-known...

> **[FourierTOuNN.pdf](https://ersl.wisc.edu/publications/2020/FourierTOuNN.pdf)**
>
> 14.13 MB

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [November 13, 2023, 10:56pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/4 "2023-11-13T22:56:24Z")

</div>

Awesome, thanks for the references. I will give them a read.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 14, 2023, 1:23am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/5 "2023-11-14T01:23:12Z")

</div>

> [@pxshen](#):
>
> Hello friends [Jello.jl](https://github.com/paulxshen/Jello.jl) uses a Fourier domain algorithm for generating manufacturable geometry for topology optimization & generative inverse design.

Similar to filtering, using a Fourier representation is not sufficient to ensure manufacturability constraints like a minimum lengthscale — the reason is that once you do a nonlinear projection/thresholding step to binarize the structure, arbitrarily small features can re-appear. That’s why, even with filtering/smoothing, people concerned with manufacturability still impose explicit lengthscale constraints (e.g. see [Hammond et al (2021)](https://opg.optica.org/oe/fulltext.cfm?uri=oe-29-15-23916&id=453270) and references therein). Did you implement something similar?

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [November 14, 2023, 8:48pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/6 "2023-11-14T20:48:21Z")

</div>

Thanks for the comment. While undesirably small features can appear during initialization, they usually disappear during adjoint optimization. The final result usually passes DRC. If not, we tune up the scale parameter or re-initialize, without explicit constraints. Fourier representations are inherently global and can kill off small features during gradient descent. Your reference takes the conventional approach of local morphological transforms.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 14, 2023, 8:52pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/7 "2023-11-14T20:52:04Z")

</div>

> [@pxshen](#):
>
> Fourier representations are inherently global and can kill off small features during gradient descent.

Fourier representations are equivalent (in terms of what functions they allow) to starting with a position-space representation and low-pass filtering, no? So they should hit the same problem — once you threshold/project, the nonlinearity allows small features to re-appear unless you add explicit lengthscale constraints. If the optimization [objective favors small features](https://github.com/NanoComp/photonics-opt-testbed/tree/main/cavity_design), gradient descent will push the design into this regime unless you constrain it.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [November 15, 2023, 5:00pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/8 "2023-11-15T17:00:56Z")

</div>

Yes the global optimum is the same but the local minima are very different as the gradients are wrt a different basis.

If the problem favors a smooth optimum, then our approach does well in not getting gnarled by checkerboard instability or minima.

If the problem favors sharp or fractal features, as you mentioned for narrow band resonant behavior, then they might get resurfaced by the nonlinearity. In such cases, maybe we can add a morphological opening/closing stage to ensure manufacturability.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [January 15, 2024, 5:00am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/9 "2024-01-15T05:00:12Z")

</div>

Pushed new version:

- cleaned up API, use `nbasis` and `contrast` to control design complexity and edge sharpness
- example compares Flux.Adam vs Optim.LBFGS. As with small models, ours trains substantially faster with LBFGS. Zygote AD is used in both cases
- moderate complexity can be done with only dozens of params, marking suitability with gradient free (Optim already set up in example ) or Bayesian methods. Welcome to try

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [January 31, 2024, 7:32pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/10 "2024-01-31T19:32:30Z")

</div>

Realized Optim.LBFGS calls gradient 2-3 times per iteration so it’s not much faster than Flux.Adam  
Better to use Flux because it’s simpler

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [March 11, 2024, 2:25pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/11 "2024-03-11T14:25:09Z")

</div>

Added optional morphological filtering to exactly eliminate small features while still maintaining adjoints. You can also pass in custom structuring elements for such (LMK and I can document this feature). Also remember that the pkg works in 3d as well. Install directly from repo for latest  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/c/1cc77139f812777a17ee800f6b16b0018d724251.png)

---

<div class="post-metadata">

**Author:** ![smartalecH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/smartalech/32/32379_2.png) [@smartalecH](https://discourse.julialang.org/u/smartalecH)\
**Post date:** [March 12, 2024, 5:02am UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/12 "2024-03-12T05:02:20Z")

</div>

How do you preserve differentiability through the morphological transforms (which aren’t differentiable)? Do you use “soft” versions?

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [March 12, 2024, 5:53pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/13 "2024-03-12T17:53:22Z")

</div>

Good question. I binarize the mask and apply morphological transforms. Then I apply the filtered binary mask to the original continuous mask which still retains adjoints.

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [March 29, 2024, 4:01pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/14 "2024-03-29T16:01:36Z")

</div>

Changed default algorithm to real space interpolation, which simply interpolates in between grid of trainable params whose spacing determines length scale . More similar behavior to conventional methods but with benefit of way fewer params. Original fourier alg is still accessible and good for periodic geometry

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/5/25b6adde9470e1bbeb524cd7a78e4495ccad5aa8.png)

---

<div class="post-metadata">

**Author:** ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)\
**Post date:** [December 19, 2024, 10:08pm UTC](https://discourse.julialang.org/t/ann-jello-jl-manufacturable-geometry-generation-for-topology-optimization-generative-design/106102/15 "2024-12-19T22:08:38Z")

</div>

Package has been fixed up. Added a Flux compatible optimizer that keeps track of area change for stable convergence
