> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::Subgraph

> A reusable subgraph that directly populates a Fragment's operator graph.

A reusable subgraph that directly populates a [Fragment](fragment)'s operator graph.

`Subgraph` receives Fragment\* during construction and directly adds operators and flows to the [Fragment](fragment)'s main graph during compose().

Usage example:

```cpp showLineNumbers={false}
#include <holoscan/subgraph.hpp>
```

## Example

```cpp showLineNumbers={false}
class CameraSubgraph : public Subgraph {
 public:
  CameraSubgraph(Fragment* fragment, const std::string& name)
      : Subgraph(fragment, name) {}

  void compose() override {
    auto source = make_operator<V4L2VideoOp>("source", from_config("v4l2"));
    auto converter = make_operator<FormatConverterOp>("converter",
                                                       from_config("format_converter"));

    add_flow(source, converter);  // Directly added to Fragment's main graph

    // Expose interface ports for external connections
    // The "tensor" output port of converter will be exposed as "video_out"
    add_output_interface_port("video_out", converter, "tensor");
  }
};

// In Fragment::compose():

// Note that for subgraph name "camera1" and "camera2", the operator names will become
// "camera1_source", "camera2_source", "camera1_converter", "camera2_converter".
auto camera1 = make_subgraph<CameraSubgraph>("camera1");
auto camera2 = make_subgraph<CameraSubgraph>("camera2");
auto visualizer = make_operator<HolovizOp>("visualizer", from_config("holoviz"));

// Direct connection to other operators (or subgraphs) via interface ports
add_flow(camera1, visualizer, {{"video_out", "receivers"}});
add_flow(camera2, visualizer, {{"video_out", "receivers"}});
```

***

## Constructors

### Subgraph \[#subgraph]

```cpp showLineNumbers={false}
holoscan::Subgraph::Subgraph(
    Fragment *fragment,
    const std::string &name,
    const std::string &config_file = ""
)
```

Construct `Subgraph` with target [Fragment](fragment).

**Parameters**

Target [Fragment](fragment) to populate with operators

Unique instance name for operator qualification

Optional path to a `YAML` configuration file for this subgraph. If provided, the configuration is loaded before compose() is called, making from\_config() available during composition.

### Destructor \[#destructor]

### \~Subgraph

```cpp showLineNumbers={false}
virtual holoscan::Subgraph::~Subgraph() = default
```

***

## Methods

### compose \[#compose]

```cpp showLineNumbers={false}
virtual void holoscan::Subgraph::compose()
```

Define the internal structure of the subgraph.

This method should create operators and flows, which will be directly added to the [Fragment](fragment)'s main graph with qualified names.

### name \[#name]

```cpp showLineNumbers={false}
const std::string & holoscan::Subgraph::name() const
```

Get the name for this subgraph.

### instance\_name \[#instancename]

```cpp showLineNumbers={false}
const std::string & holoscan::Subgraph::instance_name() const
```

Get the instance name for this subgraph.

#### Deprecated

Use name() instead. This method will be removed in a future release.

### fragment \[#fragment]

#### Mutable

```cpp showLineNumbers={false}
Fragment * holoscan::Subgraph::fragment()
```

Get the [Fragment](fragment) that this subgraph belongs to.

**Returns:** Pointer to the fragment this subgraph belongs to

#### Const

const

```cpp showLineNumbers={false}
const Fragment * holoscan::Subgraph::fragment() const
```

Get the [Fragment](fragment) that this subgraph belongs to (const version).

**Returns:** Const pointer to the fragment this subgraph belongs to

### get\_qualified\_name \[#getqualifiedname]

```cpp showLineNumbers={false}
std::string holoscan::Subgraph::get_qualified_name(
    const std::string &object_name,
    const std::string &type_name = "operator"
) const
```

Create qualified operator name: subgraph\_name + "\_" + operator\_name.

### make\_operator \[#makeoperator]

#### Overload 1

```cpp showLineNumbers={false}
template <typename OperatorT,
          typename StringT,
          typename... ArgsT,
          typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
std::shared_ptr<OperatorT> holoscan::Subgraph::make_operator(
    StringT name,
    ArgsT &&... args
)
```

#### Overload 2

```cpp showLineNumbers={false}
template <typename OperatorT, typename... ArgsT>
std::shared_ptr<OperatorT> holoscan::Subgraph::make_operator(
    ArgsT &&... args
)
```

### make\_condition \[#makecondition]

#### Overload 1

```cpp showLineNumbers={false}
template <typename ConditionT,
          typename StringT,
          typename... ArgsT,
          typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
std::shared_ptr<ConditionT> holoscan::Subgraph::make_condition(
    StringT name,
    ArgsT &&... args
)
```

#### Overload 2

```cpp showLineNumbers={false}
template <typename ConditionT, typename... ArgsT>
std::shared_ptr<ConditionT> holoscan::Subgraph::make_condition(
    ArgsT &&... args
)
```

### make\_resource \[#makeresource]

#### Overload 1

```cpp showLineNumbers={false}
template <typename ResourceT,
          typename StringT,
          typename... ArgsT,
          typename = std::enable_if_t<std::is_constructible_v<std::string, StringT>>>
std::shared_ptr<ResourceT> holoscan::Subgraph::make_resource(
    StringT name,
    ArgsT &&... args
)
```

#### Overload 2

```cpp showLineNumbers={false}
template <typename ResourceT, typename... ArgsT>
std::shared_ptr<ResourceT> holoscan::Subgraph::make_resource(
    ArgsT &&... args
)
```

### register\_service \[#registerservice]

```cpp showLineNumbers={false}
template <typename ServiceT>
bool holoscan::Subgraph::register_service(
    const std::shared_ptr<ServiceT> &svc,
    std::string_view id = ""
)
```

Register an existing service instance with the fragment.

Registers an already created service instance with the fragment. This allows the service to be retrieved later using Fragment::service().

**Returns:** true if the service was successfully registered, false otherwise.

**Template parameters**

The type of the service (must inherit from [Resource](resource) or [FragmentService](fragmentservice)).

**Parameters**

The shared pointer to the service instance to register.

The identifier for the service registration. If empty, uses the service type or resource name as identifier.

### make\_subgraph \[#makesubgraph]

```cpp showLineNumbers={false}
template <typename SubgraphT, typename... ArgsT>
std::shared_ptr<SubgraphT> holoscan::Subgraph::make_subgraph(
    const std::string &child_name,
    ArgsT &&... args
)
```

Create a nested subgraph within this subgraph.

This enables hierarchical `Subgraph` composition. The nested `Subgraph` will use the same Fragment\* and will have its operators added directly to the [Fragment](fragment)'s main graph with hierarchical qualified names (parent\_name\_child\_name\_operator).

**Returns:** Shared pointer to the nested subgraph

**Template parameters**

The nested subgraph class type

**Parameters**

Name for the nested subgraph

Additional arguments for the nested subgraph constructor

### add\_operator \[#addoperator]

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_operator(
    const std::shared_ptr<Operator> &op
)
```

Add an operator to the [Fragment](fragment)'s main graph with qualified name.

This directly calls fragment\_->add\_operator() with a qualified name, eliminating the need for intermediate graph storage.

### add\_subgraph \[#addsubgraph]

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_subgraph(
    const std::shared_ptr<Subgraph> &subgraph
)
```

Add a pre-constructed subgraph as a nested subgraph, taking ownership.

This method stores the subgraph in nested\_subgraphs\_ for lifetime management and interface port resolution.

Two paths are supported:

* **Not yet composed** (C++ factory pattern): The subgraph's name is qualified with this parent's name prefix, then compose() is called. The subgraph should be constructed with an unqualified name.
* **Already composed** (Python path): The name must already be qualified with this parent's prefix (e.g. constructed with this subgraph as the parent). The subgraph is stored as-is.

Example (C++ factory pattern):

**Throws:** `std::runtime_error` if a nested subgraph with the same name already exists.

**Throws:** `std::runtime_error` if already composed but the name is not properly qualified.

**Parameters**

The subgraph to be added.

**Example**

```cpp showLineNumbers={false}
void compose() override {
  auto camera = camera_factory(fragment(), "camera1", config);
  add_subgraph(camera);  // qualifies name to "parent_camera1", composes, takes ownership
  add_output_interface_port("video_out", camera, "video_out");
}
```

### add\_flow \[#addflow]

#### Overload 1

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Operator> &upstream,
    const std::shared_ptr<Operator> &downstream,
    std::set<std::pair<std::string, std::string>> port_pairs = {}
)
```

Add a flow between two operators directly in the [Fragment](fragment)'s main graph.

This directly calls fragment\_->add\_flow(), eliminating the need for intermediate flow storage.

#### Overload 2

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Operator> &upstream_op,
    const std::shared_ptr<Subgraph> &downstream_subgraph,
    std::set<std::pair<std::string, std::string>> port_pairs = {}
)
```

Connect [Operator](operator) to `Subgraph` within this `Subgraph`.

**Parameters**

The upstream operator

The downstream subgraph

Port connections: \{upstream\_port, subgraph\_interface\_port}

#### Overload 3

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Subgraph> &upstream_subgraph,
    const std::shared_ptr<Operator> &downstream_op,
    std::set<std::pair<std::string, std::string>> port_pairs = {}
)
```

Connect `Subgraph` to [Operator](operator) within this `Subgraph`.

**Parameters**

The upstream subgraph

The downstream operator

Port connections: \{subgraph\_interface\_port, downstream\_port}

#### Overload 4

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Subgraph> &upstream_subgraph,
    const std::shared_ptr<Subgraph> &downstream_subgraph,
    std::set<std::pair<std::string, std::string>> port_pairs = {}
)
```

Connect `Subgraph` to `Subgraph` within this `Subgraph`.

**Parameters**

The upstream subgraph

The downstream subgraph

Port connections: \{upstream\_interface\_port, downstream\_interface\_port}

#### Overload 5

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Operator> &upstream_op,
    const std::shared_ptr<Subgraph> &downstream_subgraph,
    const IOSpec::ConnectorType connector_type
)
```

Connect [Operator](operator) to `Subgraph` with connector type.

**Parameters**

The upstream operator

The downstream subgraph

The connector type

#### Overload 6

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Operator> &upstream_op,
    const std::shared_ptr<Subgraph> &downstream_subgraph,
    std::set<std::pair<std::string, std::string>> port_pairs,
    const IOSpec::ConnectorType connector_type
)
```

Connect [Operator](operator) to `Subgraph` with port pairs and connector type.

**Parameters**

The upstream operator

The downstream subgraph

Port connections: \{upstream\_port, subgraph\_interface\_port}

The connector type

#### Overload 7

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Subgraph> &upstream_subgraph,
    const std::shared_ptr<Operator> &downstream_op,
    const IOSpec::ConnectorType connector_type
)
```

Connect `Subgraph` to [Operator](operator) with connector type.

**Parameters**

The upstream subgraph

The downstream operator

The connector type

#### Overload 8

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Subgraph> &upstream_subgraph,
    const std::shared_ptr<Operator> &downstream_op,
    std::set<std::pair<std::string, std::string>> port_pairs,
    const IOSpec::ConnectorType connector_type
)
```

Connect `Subgraph` to [Operator](operator) with port pairs and connector type.

**Parameters**

The upstream subgraph

The downstream operator

Port connections: \{subgraph\_interface\_port, downstream\_port}

The connector type

#### Overload 9

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Subgraph> &upstream_subgraph,
    const std::shared_ptr<Subgraph> &downstream_subgraph,
    const IOSpec::ConnectorType connector_type
)
```

Connect `Subgraph` to `Subgraph` with connector type.

**Parameters**

The upstream subgraph

The downstream subgraph

The connector type

#### Overload 10

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_flow(
    const std::shared_ptr<Subgraph> &upstream_subgraph,
    const std::shared_ptr<Subgraph> &downstream_subgraph,
    std::set<std::pair<std::string, std::string>> port_pairs,
    const IOSpec::ConnectorType connector_type
)
```

Connect `Subgraph` to `Subgraph` with port pairs and connector type.

**Parameters**

The upstream subgraph

The downstream subgraph

Port connections: \{upstream\_interface\_port, downstream\_interface\_port}

The connector type

### bind\_input\_topic \[#bindinputtopic]

```cpp showLineNumbers={false}
void holoscan::Subgraph::bind_input_topic(
    const std::string &interface_port,
    const std::string &topic,
    const std::optional<nvidia::gxf::QoSProfile> &qos = std::nullopt,
    bool replace_connector = false
)
```

Bind an input interface port to a Pub/Sub topic.

Applies the topic binding to every internal operator port mapped from this interface port.

**Parameters**

Interface port name on this subgraph.

Topic name to subscribe to.

Optional QoS profile override. When nullopt, any QoS already configured on the mapped internal ports is preserved.

If true, replace explicitly non-PubSub connectors on mapped internal ports with Pub/Sub connectors.

### bind\_output\_topic \[#bindoutputtopic]

```cpp showLineNumbers={false}
void holoscan::Subgraph::bind_output_topic(
    const std::string &interface_port,
    const std::string &topic,
    const std::optional<nvidia::gxf::QoSProfile> &qos = std::nullopt,
    bool replace_connector = false
)
```

Bind an output interface port to a Pub/Sub topic.

Applies the topic binding to every internal operator port mapped from this interface port.

**Parameters**

Interface port name on this subgraph.

Topic name to publish to.

Optional QoS profile override. When nullopt, any QoS already configured on the mapped internal ports is preserved.

If true, replace explicitly non-PubSub connectors on mapped internal ports with Pub/Sub connectors.

### set\_dynamic\_flows \[#setdynamicflows]

```cpp showLineNumbers={false}
virtual void holoscan::Subgraph::set_dynamic_flows(
    const std::shared_ptr<Operator> &op,
    const std::function<void(const std::shared_ptr<Operator> &)> &dynamic_flow_func
)
```

Set a callback function to define dynamic flows for an operator at runtime.

This method allows operators to modify their connections with other operators during execution. The callback function is called after the operator executes and can add dynamic flows using the operator's `add_dynamic_flow()` methods.

**Parameters**

The operator to set dynamic flows for

The callback function that defines the dynamic flows. Takes a shared pointer to the operator as input and returns void.

### add\_data\_logger \[#adddatalogger]

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_data_logger(
    const std::shared_ptr<DataLogger> &logger
)
```

Add a data logger to the fragment.

This method dispatches to the fragment's add\_data\_logger method.

**Parameters**

The data logger to add.

### add\_interface\_port \[#addinterfaceport]

#### Overload 1

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Operator> &internal_op,
    const std::optional<std::string> &internal_port = std::nullopt,
    std::optional<bool> is_input = std::nullopt
)
```

Add an interface port that can be connected from external Subgraphs/Operators.

Validates that the internal operator has the specified port. If is\_input is not specified, the method automatically detects whether the port is an input or output. If the port name exists in both inputs and outputs, a runtime\_error is thrown requiring explicit specification.

**Parameters**

The name of the interface port (used in add\_flow calls)

The internal operator that owns the actual port

The port name on the internal operator (defaults to external\_name if not specified)

Whether this is an input port (true) or output port (false). If not specified, the port direction is auto-detected from the operator's port definitions.

#### Overload 2

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Subgraph> &internal_subgraph,
    const std::optional<std::string> &internal_interface_port = std::nullopt,
    std::optional<bool> is_input = std::nullopt
)
```

Add an interface port that exposes a nested subgraph's interface port.

This method enables hierarchical port composition by exposing an interface port from a nested subgraph as an external interface port of the current subgraph. The nested subgraph's interface port is resolved to find the underlying operator and port, which are then registered as the current subgraph's interface port.

If is\_input is not specified, the port direction is auto-detected from the nested subgraph's interface port definition.

**Parameters**

The name of the interface port (used in add\_flow calls)

The nested subgraph whose interface port to expose

The interface port name on the nested subgraph (defaults to external\_name if not specified)

Whether this is an input port (true) or output port (false). If not specified, the port direction is auto-detected from the nested subgraph's interface port.

### add\_input\_interface\_port \[#addinputinterfaceport]

#### Add an input interface port (convenience method)

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_input_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Operator> &internal_op,
    const std::optional<std::string> &internal_port = std::nullopt
)
```

Add an input interface port (convenience method).

**Parameters**

The name of the interface port (used in add\_flow calls)

The internal operator that owns the actual port

The port name on the internal operator (defaults to external\_name if not specified)

#### Overload 2

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_input_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Subgraph> &internal_subgraph,
    const std::optional<std::string> &internal_interface_port = std::nullopt
)
```

Add an input interface port from a nested subgraph (convenience method).

**Parameters**

The name of the interface port (used in add\_flow calls)

The nested subgraph whose interface port to expose

The interface port name on the nested subgraph (defaults to external\_name if not specified)

### add\_output\_interface\_port \[#addoutputinterfaceport]

#### Add an output interface port (convenience method)

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_output_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Operator> &internal_op,
    const std::optional<std::string> &internal_port = std::nullopt
)
```

Add an output interface port (convenience method).

**Parameters**

The name of the interface port (used in add\_flow calls)

The internal operator that owns the actual port

The port name on the internal operator (defaults to external\_name if not specified)

#### Overload 2

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_output_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Subgraph> &internal_subgraph,
    const std::optional<std::string> &internal_interface_port = std::nullopt
)
```

Add an output interface port from a nested subgraph (convenience method).

**Parameters**

The name of the interface port (used in add\_flow calls)

The nested subgraph whose interface port to expose

The interface port name on the nested subgraph (defaults to external\_name if not specified)

### add\_input\_exec\_interface\_port \[#addinputexecinterfaceport]

#### Overload 1

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_input_exec_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Operator> &internal_op
)
```

Add an input execution interface port for control flow.

Exposes an execution port from an internal operator for control flow connections. The internal operator must be a Native operator with an input execution spec.

**Parameters**

The name of the interface port (used in add\_flow calls)

The internal operator that has the execution port

#### Overload 2

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_input_exec_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Subgraph> &internal_subgraph,
    const std::optional<std::string> &internal_interface_port = std::nullopt
)
```

Add an input execution interface port from a nested subgraph.

Exposes an execution interface port from a nested subgraph as this subgraph's execution interface port, enabling hierarchical control flow composition.

**Parameters**

The name of the interface port (used in add\_flow calls)

The nested subgraph whose exec interface port to expose

The exec interface port name on the nested subgraph (defaults to external\_name if not specified)

### add\_output\_exec\_interface\_port \[#addoutputexecinterfaceport]

#### Overload 1

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_output_exec_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Operator> &internal_op
)
```

Add an output execution interface port for control flow.

Exposes an execution port from an internal operator for control flow connections. The internal operator must be a Native operator with an output execution spec.

**Parameters**

The name of the interface port (used in add\_flow calls)

The internal operator that has the execution port

#### Overload 2

```cpp showLineNumbers={false}
void holoscan::Subgraph::add_output_exec_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Subgraph> &internal_subgraph,
    const std::optional<std::string> &internal_interface_port = std::nullopt
)
```

Add an output execution interface port from a nested subgraph.

Exposes an execution interface port from a nested subgraph as this subgraph's execution interface port, enabling hierarchical control flow composition.

**Parameters**

The name of the interface port (used in add\_flow calls)

The nested subgraph whose exec interface port to expose

The exec interface port name on the nested subgraph (defaults to external\_name if not specified)

### interface\_ports \[#interfaceports]

```cpp showLineNumbers={false}
const std::unordered_map<std::string, InterfacePort> & holoscan::Subgraph::interface_ports() const
```

Get data interface ports.

Returns a map of interface port names to [InterfacePort](../structs/interfaceport) objects. Each [InterfacePort](../structs/interfaceport) can contain multiple mappings for broadcast input ports.

### exec\_interface\_ports \[#execinterfaceports]

```cpp showLineNumbers={false}
const std::unordered_map<std::string, InterfacePort> & holoscan::Subgraph::exec_interface_ports() const
```

Get execution interface ports.

### get\_interface\_operator\_port \[#getinterfaceoperatorport]

```cpp showLineNumbers={false}
std::pair<std::shared_ptr<Operator>, std::string> holoscan::Subgraph::get_interface_operator_port(
    const std::string &port_name
) const
```

Get the first operator/port for a data interface port name.

This method first checks local interface ports, then recursively checks nested subgraphs for hierarchical port resolution.

For broadcast input ports that have multiple mappings, this returns only the first mapping. Access the [InterfacePort](../structs/interfaceport) directly via interface\_ports() to get all mappings.

**Returns:** Pair of (operator, actual\_port\_name) or (nullptr, "") if not found

**Parameters**

The interface port name

### get\_exec\_interface\_operator\_port \[#getexecinterfaceoperatorport]

```cpp showLineNumbers={false}
std::pair<std::shared_ptr<Operator>, std::string> holoscan::Subgraph::get_exec_interface_operator_port(
    const std::string &port_name
) const
```

Get the operator/port for an execution interface port name.

This method first checks local exec interface ports, then recursively checks nested subgraphs for hierarchical port resolution.

**Returns:** Pair of (operator, actual\_port\_name) or (nullptr, "") if not found

**Parameters**

The exec interface port name

### is\_composed \[#iscomposed]

```cpp showLineNumbers={false}
bool holoscan::Subgraph::is_composed() const
```

Check if the subgraph has been composed.

### set\_composed \[#setcomposed]

```cpp showLineNumbers={false}
void holoscan::Subgraph::set_composed(
    bool composed
)
```

Set the composed state of the subgraph.

### operators \[#operators]

```cpp showLineNumbers={false}
std::vector<std::shared_ptr<Operator>> holoscan::Subgraph::operators() const
```

Get all operators belonging to this subgraph and its nested subgraphs.

This method returns all operators whose names are prefixed with this subgraph's name followed by an underscore. This includes operators from nested subgraphs since their names are also prefixed with the parent subgraph's name.

**Returns:** [Vector](../typedefs/vector) of shared pointers to the operators.

### nested\_subgraphs \[#nestedsubgraphs]

```cpp showLineNumbers={false}
const std::vector<std::shared_ptr<Subgraph>> & holoscan::Subgraph::nested_subgraphs() const
```

Get the nested subgraphs directly owned by this subgraph.

Returns subgraphs added via make\_subgraph() or add\_subgraph() within this subgraph. Does not recursively include subgraphs nested further down the hierarchy.

**Returns:** A const reference to the vector of nested subgraphs.

### config \[#config]

#### Get the configuration of the subgraph

```cpp showLineNumbers={false}
Config & holoscan::Subgraph::config()
```

Get the configuration of the subgraph.

**Returns:** The reference to the configuration of the subgraph ([`Config`](config) object.)

#### Set the configuration of the subgraph from a file

```cpp showLineNumbers={false}
void holoscan::Subgraph::config(
    const std::string &config_file,
    const std::string &prefix = ""
)
```

Set the configuration of the subgraph from a file.

The configuration file is a `YAML` file that contains parameter values that can be accessed via from\_config(). This is useful when a subgraph needs its own configuration separate from the main application configuration.

This method is protected because configuration must be set before compose() runs. Pass the config\_file to the `Subgraph` constructor instead.

Loading GXF extensions is not supported from the subgraph config file. GXF extensions should be loaded via the application-level configuration only.

**Throws:** `RuntimeError` if the config\_file is non-empty and the file doesn't exist.

**Parameters**

The path to the configuration file.

The prefix string that is prepended to the key of the configuration.

### config\_shared \[#configshared]

```cpp showLineNumbers={false}
std::shared_ptr<Config> holoscan::Subgraph::config_shared()
```

Get the shared pointer to the configuration of the subgraph.

**Returns:** The shared pointer to the configuration of the subgraph.

### from\_config \[#fromconfig]

```cpp showLineNumbers={false}
ArgList holoscan::Subgraph::from_config(
    const std::string &key
)
```

Get the value of a configuration key as an [ArgList](arglist).

This method retrieves the value from the subgraph's configuration for the given key. You can use '.' (dot) to access nested fields. The returned [ArgList](arglist) can be passed directly to make\_operator() or other methods that accept configuration arguments.

Example usage:

**Returns:** The argument list of the configuration for the key.

**Parameters**

The key of the configuration.

**Example**

```cpp showLineNumbers={false}
auto op = make_operator<MyOp>("my_op", from_config("my_op"));
```

### config\_keys \[#configkeys]

```cpp showLineNumbers={false}
std::unordered_set<std::string> holoscan::Subgraph::config_keys()
```

Determine the set of keys present in the subgraph's config.

**Returns:** The set of valid keys.

### format\_port\_list \[#formatportlist]

```cpp showLineNumbers={false}
std::string holoscan::Subgraph::format_port_list(
    const std::unordered_map<std::string, std::shared_ptr<IOSpec>> &ports
)
```

Efficiently format a port list for error messages.

Uses fmt::memory\_buffer for O(n) string building instead of O(n²) string concatenation. This provides better performance and avoids repeated memory reallocations.

**Returns:** Formatted string with port names like "'port1', 'port2', 'port3'"

**Parameters**

The port collection (inputs or outputs from [OperatorSpec](operatorspec))

### validate\_operator\_port \[#validateoperatorport]

```cpp showLineNumbers={false}
bool holoscan::Subgraph::validate_operator_port(
    const std::shared_ptr<Operator> &op,
    const std::string &port_name,
    bool expect_input
)
```

Validate that an operator has a port with the correct type.

**Returns:** true if the port exists and has the correct type, false otherwise

**Parameters**

The operator to validate

The name of the port to check

Whether we expect this to be an input port (true) or output port (false)

### validate\_operator\_exec\_port \[#validateoperatorexecport]

```cpp showLineNumbers={false}
bool holoscan::Subgraph::validate_operator_exec_port(
    const std::shared_ptr<Operator> &op
)
```

Validate that an operator can be used for execution control flow.

Checks that the operator is a Native operator. Execution specs are created automatically by the GXF executor during initialization.

**Returns:** true if the operator can be used for execution control flow, false otherwise

**Parameters**

The operator to validate

### check\_exec\_port\_name\_available \[#checkexecportnameavailable]

```cpp showLineNumbers={false}
bool holoscan::Subgraph::check_exec_port_name_available(
    const std::string &external_name
)
```

Check if an exec interface port name is already in use.

Checks both data and exec interface port maps for name conflicts.

**Returns:** true if the name is available (not already used)

**Throws:** `std::runtime_error` if the name is already in use

**Parameters**

The name to check

### register\_exec\_interface\_port \[#registerexecinterfaceport]

```cpp showLineNumbers={false}
void holoscan::Subgraph::register_exec_interface_port(
    const std::string &external_name,
    const std::shared_ptr<Operator> &internal_op,
    const std::string &internal_port_name,
    bool is_input
)
```

Register an exec interface port.

Creates and stores an [InterfacePort](../structs/interfaceport) in exec\_interface\_ports\_ with the given parameters.

**Parameters**

The external interface port name

The internal operator

The internal port name (kInputExecPortName or kOutputExecPortName)

Whether this is an input port

### resolve\_nested\_exec\_port \[#resolvenestedexecport]

```cpp showLineNumbers={false}
std::pair<std::shared_ptr<Operator>, std::string> holoscan::Subgraph::resolve_nested_exec_port(
    const std::string &external_name,
    const std::shared_ptr<Subgraph> &internal_subgraph,
    const std::string &internal_interface_port,
    bool expect_input
)
```

Resolve a nested subgraph's exec interface port to an operator and port.

Looks up the specified exec interface port in the nested subgraph and validates that it has the expected direction (input vs output).

**Returns:** Pair of (operator, port\_name) or (nullptr, "") if resolution fails

**Parameters**

The name for this subgraph's interface port (for error messages)

The nested subgraph to query

The exec interface port name to look up

Whether we expect an input port (true) or output port (false)

***

## Member variables

| Name                     | Type                                               | Description                                        |
| ------------------------ | -------------------------------------------------- | -------------------------------------------------- |
| `interface_ports_`       | `std::unordered_map< std::string, InterfacePort >` | Data interface ports.                              |
| `exec_interface_ports_`  | `std::unordered_map< std::string, InterfacePort >` | Execution interface ports.                         |
| `nested_subgraphs_`      | `std::vector< std::shared_ptr< Subgraph > >`       | Nested Subgraphs for hierarchical composition.     |
| `nested_subgraph_names_` | `std::unordered_set< std::string >`                | Track nested child names to detect duplicates.     |
| `is_composed_`           | `bool`                                             |                                                    |
| `fragment_`              | `Fragment *`                                       | Target fragment for direct operator/flow addition. |
| `name_`                  | `std::string`                                      | Name for this subgraph.                            |
| `config_`                | `std::shared_ptr< Config >`                        | Subgraph-specific configuration.                   |