---
title: get_clusters (latest version)
description: API reference for samplomatic.graph_utils.get_clusters in the latest version of samplomatic
source: https://quantum.cloud.ibm.com/docs/en/api/samplomatic/auto/graph-utils-get-clusters
---

# get\_clusters

`samplomatic.graph_utils.get_clusters(graph: PyDiGraph[T, S], filter_fn: Callable[[T], bool]) → Iterator[list[int]]`

[GitHub](https://github.com/Qiskit/samplomatic/tree/main/samplomatic/graph_utils/get_clusters.py#L26-L42)

Yield lists of nodes that all pass the filter and are connected in the graph.

**Parameters**

- **graph** – The graph to search.
- **filter\_fn** – A filter function acting on node data that returns booleans.

**Yields**

Lists of nodes, where each list is a maximal weakly connected set of nodes that all pass the filter.
