---
title: replace_nodes_with_one_node (latest version)
description: API reference for samplomatic.graph_utils.replace_nodes_with_one_node in the latest version of samplomatic
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/samplomatic/auto/graph-utils-replace-nodes-with-one-node
---

# replace\_nodes\_with\_one\_node

`samplomatic.graph_utils.replace_nodes_with_one_node(graph: PyDiGraph[T, S], node_idxs: Iterable[int], new_node: T) → int`

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

Replace given nodes with a single node, preserving all outward/inward edges.

**Parameters**

- **graph** – The graph to mutate.
- **node\_idxs** – The connected nodes to replace.
- **new\_node** – The node to replace them with.

**Returns**

The index of the new node in the graph.
