We introduce a framework to create mechanical metamaterials with a given nonlinear stress-strain response via video denoising diffusion as described in Inverse design of nonlinear mechanical metamaterials via video denoising diffusion models.
This code is based on the video denoising diffusion implementation by Phil Wang proposed in Imagen Video.
To conduct similar studies as those presented in the publication, start by cloning this repository via
git clone https://github.com/jhbastek/VideoMetamaterials.git
Next, download the data and model checkpoints provided in the ETHZ Research Collection. Unzip the training data lagrangian.zip
in the data
folder and the pre-trained model pretrained.zip
in the runs
folder, as shown below. Note that eulerian.zip
must only be provided when training the model in the Eulerian frame, which was only used in preliminary studies.
.
├── data
│ ├── target_responses.csv
│ └── lagrangian
│ │ └── ...
│ └── eulerian (optional)
│ └── ...
└── runs
└── pretrained
└── ...
We use the Accelerate library to speed up training when a multi GPU environment is available. Please first configure your setup via accelerate config
(note that accelerate
can also be used in single GPU/CPU setups).
To generate new metamaterial samples conditioned on the four stress-strain responses shown in the publication simply run
accelerate launch main.py
The generated samples will then be stored in runs/pretrained/eval_target_w_<guidance_weight>/
and should perform similar to the presented samples. We arrange all generated samples in a single grid, in which the row corresponds to row of data/target_responses.csv
.
To condition the denoising process on your own stress-strain responses, simply adjust data/target_responses.csv
accordingly. Sample generation takes around 1 minute on a single Nvidia Quadro RTX 6000. In case of interest, we store the normalization constants to rescale the pixel values to their physical equivalent in data/<reference_frame>/training/min_max_values.csv
.
To experiment with different setups simply change the user input in main.py
. Here you can adjust the number of generated samples per conditioning, change the guidance scaling w
or also train denoising models from scratch based on the hyperparameters defined in model.yaml
(including the option to log to Weights & Biases).
For further information, please first refer to the publication, the Supplementary Information or reach out to Jan-Hendrik Bastek.
We also provide the scripts to evaluate the generated designs via Abaqus CAE 2020. For this, run eval_abaqus.py
with the path to the predicted samples that should contain a geometries.csv
file with the binary pixel predictions. Predictions are stored in row-wise order in this file, and you must provide the sample_index
corresponding to the row you want to evaluate. Note that eval_abaqus.py
is a wrapper that will call abaqus cae
, therefore make sure that you can run Abaqus from the command line. Functionality was verified on Microsoft Windows 10 OS. As mentioned in the publication, we have typically generated 10 samples and provided the best match. Similarly, more samples are likely necessary to obtain a good match for highly exotic stress-strain responses, while a single sample may suffice for simpler curves (such as the one presented in Fig. 3a of the publication).
The framework was developed and tested on Python 3.11 using CUDA 12.0 and requires the following Python packages.
Package | Version (>=) |
---|---|
pytorch |
2.0.1 |
einops |
0.6.1 |
einops-exts |
0.6.1 |
rotary_embedding_torch |
0.2.3 |
accelerate |
0.19.0 |
imageio |
2.28.1 |
tqdm |
4.65.0 |
networkx |
2.8.4 |
wandb (optional) |
0.15.2 |
To run the FEM simulations a license of Abaqus CAE 2020 is required.
If this code is useful for your research, please cite our publication.
@article{Bastek2023,
author = {Bastek, Jan-Hendrik and Kochmann, Dennis M.},
doi = {10.1038/s42256-023-00762-x},
journal = {Nature Machine Intelligence},
title = {{Inverse design of nonlinear mechanical metamaterials via video denoising diffusion models}},
url = {https://doi.org/10.1038/s42256-023-00762-x},
volume = {12},
year = {2023}
}