This repository contains the code for the paper "Style-constrained inverse design of microstructures with tailored mechanical properties using unconditional diffusion models". The workflow is summarized as follows:

net/: Contains the implementation of the unconditional diffusion model architecture and training procedures.fem/: Contains the finite element analysis code for evaluating the mechanical properties of generated microstructures.helper/: Contains utility functions for optimization, logging, and visualization.figures/: Contains figures used in the respository.- The scripts in the root directory are the implementation for each numerical example in the paper, including 1D Gaussian mixture as well as 2D microstructure design with tailoed homogenized, hyperelastic, and elasto-plastic properties.
The finite element analysis code is implemented via JAX-FEM. Please first follow the installation instructions to install jax_fem in a conda environment. All the subsequent procedures should be run in the conda environment with jax_fem installed.
Some basic dependencies are installed when installing jax_fem. Additional dependencies include flax, optax, tensorflow, tensorflow-datasets, and tqdm. You can follow the official installation instructions to install them or just run:
pip install -r requirements.txtgit clone https://github.com/CMSL-HKUST/genopt.git
cd genoptFor the 1D Gaussian mixture example, run train_gaussian.py in net/flax_gaussian/ to train the diffusion model.
For the MNIST dataset, run train_mnist.py in net/flax_diffusion/ to train the diffusion model.
For the 2D orthotropic metamaterials microstructure dataset, please first download the dataset and prepare the data following the procedure in the paper. Then run train_micro.py in net/flax_diffusion/ to train the diffusion model.
After training the diffusion model, you can run the optimization examples provided in the root directory. Each script corresponds to a specific example discussed in the paper. For instance, to run the 1D Gaussian mixture optimization, execute:
python ddpm_gaussian.py If you find this code useful for your research, please consider citing our paper:
@article{xu2026style,
title={Style-Constrained Inverse Design of Microstructures With Tailored Mechanical Properties Using Unconditional Diffusion Models},
author={Xu, Weipeng and Xie, Ziyuan and Lin, Haoju and Wang, Xinyu and Mou, Guangjin and Xue, Tianju},
journal={International Journal for Numerical Methods in Engineering},
volume={127},
number={13},
pages={e70376},
year={2026},
publisher={Wiley Online Library}
}