Skip to content

Commit 5b47591

Browse files
authored
Merge pull request #86 from Lucaslab-Berkeley/development_v1.1
Backend updates for v1.1 release
2 parents aa87b8c + 54328c1 commit 5b47591

28 files changed

+2485
-468
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ ENV/
119119
# Temporary files
120120
*.tmp
121121

122+
# Log files
123+
*.log
124+
*.out
125+
122126

123127
small_image_test_data/
124128
medium_image_test_data/

benchmark/benchmark_match_template.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import subprocess
1313
import time
1414
from pathlib import Path
15-
from pprint import pprint
16-
from typing import Any, dict
15+
from typing import Any
1716

1817
import click
1918
import numpy as np
@@ -35,6 +34,16 @@ def download_comparison_data() -> None:
3534
["zenodo_get", f"--output-dir={DOWNLOAD_DIR}", ZENODO_URL], check=True
3635
)
3736

37+
# Change the paths pointing to the tests/tmp directory to benchmark/tmp directory
38+
# in the downloaded YAML file
39+
with open(YAML_PATH) as f:
40+
yaml_text = f.read()
41+
42+
yaml_text = yaml_text.replace("tests/tmp", "benchmark/tmp")
43+
44+
with open(YAML_PATH, "w") as f:
45+
f.write(yaml_text)
46+
3847

3948
def setup_match_template_manager() -> MatchTemplateManager:
4049
"""Instantiate the manager object and prepare for template matching."""
@@ -78,7 +87,9 @@ def benchmark_match_template_single_run(
7887
##################################################
7988
# This is using the timing model where the time -- T -- to compute N
8089
# cross-correlations is dependent on some device rate -- r -- and a constant setup
81-
# cost in terms of time (this is what we measure):
90+
# cost in terms of time. This setup time (or core-deadtime) is part of distributing
91+
# data to each device, compiling helper functions, and other overhead. What we can
92+
# measure is the total time:
8293
#
8394
# T_N = N/r + k
8495
#
@@ -229,7 +240,7 @@ def main(orientation_batch_size: int, num_runs: int, output_file: str):
229240
print(f" Output file: {output_file}")
230241

231242
result = run_benchmark(orientation_batch_size, num_runs)
232-
pprint(result)
243+
# pprint(result)
233244
save_benchmark_results(result, output_file)
234245

235246

docs/benchmarks.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Benchmarks of the Leopard-EM package
2+
3+
Identifying freely oriented macromolecules using Two-Dimensional Template Matching (2DTM) is a computationally intensive task since we must compute millions of cross-correlograms on large cryo-EM micrographs.
4+
Efficiency of the `match_template` program is therefore a key consideration going into the Leopard-EM package.
5+
6+
We include some benchmarking results across different GPU hardware to provide an estimate of `match_template` performance.
7+
These results can help guide users in planning out 2DTM analyses of their data using Leopard-EM and serve as a reference for expected performance.
8+
9+
## Benchmarking Setup
10+
11+
Leopard-EM includes a benchmarking script at `benchmark/benchmark_match_template.py` (if downloaded from source) which you can use to determine performance _on your own hardware_.
12+
This script runs the `match_template` program using the following parameters:
13+
14+
- Micrograph size: 4096 x 4096 pixels (Falcon 4i) or 5760 x 4092 pixels (K3)
15+
- Template size: 512 x 512 x 512 pixels
16+
- Number of defocus planes: 11
17+
- Variable orientation batch size configurable using `--orientation-batch-size`
18+
19+
Note that we empirically observe that template size has negligible effect on performance.
20+
Total search times are extrapolated from throughput to a full orientation search of ~1.58 million orientations with 13 defocus planes (~20.5 million total cross-correlations).
21+
22+
## Version 1.1 benchmarks
23+
24+
### Falcon 4i images (4096 x 4096 pixels)
25+
26+
GPU name | VRAM | Image size | Throughput (cross-corr/sec) | 2DTM search time (hours) |
27+
------------------------ | ----- | ---------- | --------------------------- | -------------------------- |
28+
GeForce 2080 Ti | 11 GB | 4096×4096 | 343.0 | 16.70 |
29+
RTX 6000 Ada / L40s | 48 GB | 4096×4096 | 744.5 | 7.69 |
30+
RTX 6000 Blackwell Max-Q | 96 GB | 4096×4096 | 1394.7 | 4.10 |
31+
A100 | 40 GB | 4096x4096 | 923.4 | 6.19 |
32+
H100 | 80 GB | 4096×4096 | 1650.8 | 3.47 |
33+
34+
### K3 images (5760 x 4092 pixels)
35+
36+
GPU name | VRAM | Image size | Throughput (cross-corr/sec) | 2DTM search time (hours) |
37+
------------------------ | ----- | ---------- | --------------------------- | -------------------------- |
38+
GeForce 2080 Ti | 11 GB | 5760×4092 | 217.1 | 26.40 |
39+
RTX 6000 Ada / L40s | 48 GB | 5760×4092 | 431.7 | 13.30 |
40+
RTX 6000 Blackwell Max-Q | 96 GB | 5760×4092 | 799.7 | 7.15 |
41+
A100 | 40 GB | 5760×4092 | 530.2 | 10.79 |
42+
H100 | 80 GB | 5760×4092 | 897.9 | 6.37 |
43+
44+
!!! note "K3 image benchmarks"
45+
Note that we have not optimized Leopard-EM v1.1 for K3 images in particular. Future versions should include optimizations for non-square images which will improve performance on K3 data.

docs/index.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,25 @@ description: Overview of the Leopard-EM package for 2DTM in Python
77

88
Welcome to the **L**ocation & ori**E**ntati**O**n of **PAR**ticles found using two-**D**imensional t**E**mplate **M**atching (Leopard-EM) online documentation!
99
Leopard-EM is a Python implementation of Two-Dimensional Template Matching (2DTM) which itself is a data processing method in cryo-EM for locating and orienting particles using a reference structure.
10-
This package currently reflects the functionality described in Lucas, *et al.* (2021)[^1] with additional programs to maximize the usefulness of 2DTM as well as other user-friendly features for integrating into broader data science workflows.
10+
<!-- This package currently reflects the functionality described in Lucas, *et al.* (2021)[^1] with additional programs to maximize the usefulness of 2DTM as well as other user-friendly features for integrating into broader data science workflows. -->
1111

1212
!!! note "Citing this work"
1313

14-
If you use Leopard-EM in your research, please cite (coming soon!).
14+
If you use Leopard-EM in your research, please cite the [Leopard-EM preprint](https://doi.org/10.1101/2025.08.26.672452):
15+
16+
```
17+
@article {Giammar2025.08.26.672452,
18+
author = {Giammar, Matthew David and Dickerson, Joshua Luke and Hall, Laina Nicole and Lucas, Bronwyn Ayla},
19+
title = {Leopard-EM: An extensible 2DTM package to accelerate in situ structural biology},
20+
elocation-id = {2025.08.26.672452},
21+
year = {2025},
22+
doi = {10.1101/2025.08.26.672452},
23+
publisher = {Cold Spring Harbor Laboratory},
24+
URL = {https://www.biorxiv.org/content/early/2025/08/29/2025.08.26.672452},
25+
eprint = {https://www.biorxiv.org/content/early/2025/08/29/2025.08.26.672452.full.pdf},
26+
journal = {bioRxiv}
27+
}
28+
```
1529

1630
## Installation
1731

@@ -202,6 +216,6 @@ See the [Installation -- For Developers](#for-developers) section for instructio
202216

203217
The code in this repository is licensed under the **BSD 3-Clause License**. See the [LICENSE](LICENSE) file for full details.
204218

205-
## References
219+
<!-- ## References
206220
207-
[^1]: Lucas BA, Himes BA, Xue L, Grant T, Mahamid J, Grigorieff N. Locating macromolecular assemblies in cells by 2D template matching with cisTEM. Elife. 2021 Jun 11;10:e68946. doi: 10.7554/eLife.68946. PMID: 34114559; PMCID: PMC8219381.
221+
[^1]: Lucas BA, Himes BA, Xue L, Grant T, Mahamid J, Grigorieff N. Locating macromolecular assemblies in cells by 2D template matching with cisTEM. Elife. 2021 Jun 11;10:e68946. doi: 10.7554/eLife.68946. PMID: 34114559; PMCID: PMC8219381. -->

docs/tutorials/batch_processing.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,23 @@ if [ -z "$CONFIG_FILE" ]; then
431431
fi
432432

433433
# Run the match_template script with the selected config file
434+
# NOTE: You may need to wrap the `python run_match_template.py $CONFIG_FILE`
435+
# call within an `srun` command depending on your cluster configuration
436+
# to properly expose the GPU devices to the process.
434437
echo "Running match_template with config file: $CONFIG_FILE"
435438
python run_match_template.py $CONFIG_FILE
436439

437440
```
438441

442+
??? Caution "Making GPU devices discoverable within SLURM via srun"
443+
444+
Depending on your cluster configuration, you may need to wrap the `python run_match_template.py $CONFIG_FILE` command within an srun command to properly expose the GPU devices to the command.
445+
For example, this might look like:
446+
447+
```bash
448+
srun --nodes=1 --ntasks=1 --cpus-per-task=8 --gres=gpu:L40:1 python run_match_template.py $CONFIG_FILE
449+
```
450+
439451
## Conclusion
440452

441453
In this tutorial, we walked through how to set up batch processing of micrographs with Leopard-EM using a SLURM array job.

0 commit comments

Comments
 (0)