holoscan::Graph
Own an editable cold graph declaration and replayable construction factories.
Graph is the only HSDK 5 root authoring abstraction. It performs lazy composition and cold validation but does not compile or execute a graph. The lazy-composition gate is internally synchronized, so concurrent observers share one composer and receive its terminal result. This synchronization does not make general authoring thread-safe: after composition, callers must serialize mutation with every other mutation or observation of the same Graph. Handles do not extend Graph lifetime and become invalid when the Graph is destroyed.
Every successful public compound mutation is atomic. If allocation or an injected exceptional boundary interrupts an in-progress mutation, Graph restores the prior snapshot identity, generation, IDs, ownership claims, and declaration indexes before the exception escapes. A rejected external topic declaration is the deliberate exception to counter rollback: ordinary typed validation failures consume their mixed import/export declaration ordinal, while exceptional failures restore the reserved ordinal.
The complete most-derived Graph object must remain alive until all authoring, observation, and lazy-composition calls have returned. Destruction must not race any Graph access; handle invalidation does not provide concurrent destruction synchronization.
Constructors
Graph
Create an empty named Graph authoring root
Deleted overloads
The following overloads are deleted to prevent misuse:
Destructor
~Graph
Destroy Graph-owned prototypes, factories, and authoring state.
Destruction must not overlap any authoring, observation, composition, or handle operation associated with this Graph.
Assignment operators
operator=
Deleted overloads
The following overloads are deleted to prevent misuse:
Methods
op
Add one typed Operator declaration and replayable factory.
Obvious top-level borrowed forms, move-only values, and Graph authoring handles are rejected at compile time. Function pointers and copyable callables are accepted. String views and string literals normalize to owned strings. Checks are intentionally shallow: nested container elements, user-defined fields, and callable captures remain the application’s lifetime responsibility.
Do not call Graph authoring verbs from a derived Graph constructor; author the reusable body only in the Core-managed compose override.
Each normalized capture must be copy-constructible. Copies follow the captured type’s ordinary C++ semantics, including shared identity for std::shared_ptr and non-owning observation for std::weak_ptr.
Any legacy Operator::start or Operator::stop hook must be public, unambiguous, and have the exact zero-argument void signature. Any advanced lifecycle member callback registered by setup() must be declared by Op itself rather than by a base or unrelated class.
Returns: Copyable authoring handle that dynamically resolves current ports.
Throws: RuntimeError if construction, setup, naming, or registration fails.
Template parameters
Concrete Operator type.
Constructor capture argument types.
Parameters
Nonempty unique bounded UTF-8 declaration name.
Constructor values normalized and copied into replayable state.
add_operator
Add one typed Operator declaration using the exact op alias.
Returns: Copyable typed authoring handle.
Throws: RuntimeError under the same conditions as op.
Template parameters
Concrete Operator type.
Constructor capture argument types.
Parameters
Nonempty unique bounded UTF-8 declaration name.
Constructor values copied under the same ownership precondition as op.
handle
Resolve one existing graph-local root Operator by name and exact concrete type.
This is a cold authoring-time lookup. It does not trigger lazy composition, inspect embedded Graph operators, or participate in per-activation execution.
Whole-aggregate parameter reconstruction does not invalidate either the creation handle or a handle returned by this lookup.
Returns: Copyable typed authoring handle interchangeable with the creation handle.
Throws: RuntimeError with GRAPH_OPERATOR_NOT_FOUND when no root declaration has this name.
Throws: RuntimeError with GRAPH_OPERATOR_TYPE_MISMATCH when the named root declaration has another concrete Operator type.
Template parameters
Expected concrete Operator type.
Parameters
Exact local declaration name from this Graph’s root authoring inventory.
embed
Independently construct, compose, and own one reusable Graph instance.
Child composition reaches a terminal state before one atomic parent publication. The child Graph is never copied or moved and remains owned by the parent until parent retirement.
Unlike replayed Operator and clock factories, embedding constructs the child once, so constructor arguments may transfer move-only ownership. The same shallow top-level borrow checks still apply, and Graph authoring handles remain rejected because they are composition-time identity.
Embedded graphs do not inherit the parent’s default clock. Declare clock dependencies in the child’s compose() using import_clock, and use set_default_clock when an imported clock is the child’s default. After embedding, the immediate parent must supply each import using bind_clock before compilation. Nested reusable graphs require an explicit binding at every boundary; clock resolution never searches ancestor scopes by name.
The handle permits interface inspection only. It does not grant mutable access to the child authoring Graph.
Returns: Read-only typed handle exposing the child’s public interface members.
Throws: RuntimeError if parent/child composition, construction, canonical remapping, name validation, or publication fails.
Template parameters
Concrete reusable Graph type.
Constructor capture argument types.
Parameters
Nonempty unique local embedded-instance name.
Constructor values normalized and forwarded once into the child object.
See also: import_clock, set_default_clock, bind_clock
add_flow
Overload 1
Overload 2
Overload 3
Overload 4
Overload 5
Add one exact-type or exact-contract raw-POD directed queue edge.
Distinct C++ endpoint types participate only when both have explicit raw-POD contracts. Scalar, enum, Tensor, and schema-root edges require the same C++ payload type.
Returns: Typed dynamic flow handle.
Throws: RuntimeError for foreign/stale ports, fan-in, cycles, duplicate topology, unequal complete POD contracts, or invalid options.
Template parameters
Exact admitted source payload type.
Exact admitted target payload type.
Parameters
Graph-owned output declaration.
Graph-owned input declaration.
Cold edge options copied before return.
Add one payload-narrowing edge from a named schema Tensor field to a Tensor input.
Multiple Tensor and schema consumers may share an output. Same-process projection shares the selected data buffer until every consumer releases it. Inter-process delivery uses schema transport and requires bounded, copy-capable Tensor transfer contracts; staging may copy data when the backing cannot be shared. Projection does not convert representation. Runtime setup still allocates bookkeeping state. An explicit converter Operator remains responsible for representation changes.
Returns: Typed dynamic flow handle.
Throws: RuntimeError for the same conditions as an exact-type edge, and when the consumer did not declare InputSpecBuilder::accepts_projected_tensor.
Template parameters
Descriptor-backed schema published by the source Operator.
Parameters
Tensor field named on a Graph-owned schema output.
Cold edge options copied before return.
Add one payload-narrowing edge from a single-Tensor schema output to a Tensor input.
The field is unambiguous only when the schema carries exactly one Tensor. A schema with several requires .project() so the Graph records which field was chosen.
Returns: Typed dynamic flow handle.
Template parameters
Descriptor-backed schema carrying exactly one Tensor field.
Parameters
Graph-owned schema output declaration.
Cold edge options copied before return.
Bind a reusable Graph public input as an alias of an internal input.
This is an interface alias, not a runtime queue edge, and therefore accepts no ConnectionOptions and returns no FlowHandle.
Throws: RuntimeError if either declaration belongs to another Graph or the payload/direction contract differs.
Template parameters
Exact admitted local payload type.
Parameters
Stable public Graph input declaration.
Stable internal Operator input declaration.
Bind a reusable Graph public output as an alias of an internal output.
This is an interface alias, not a runtime queue edge, and therefore accepts no ConnectionOptions and returns no FlowHandle.
Throws: RuntimeError if either declaration belongs to another Graph or the payload/direction contract differs.
Template parameters
Exact admitted local payload type.
Parameters
Stable internal Operator output declaration.
Stable public Graph output declaration.
export_input
Expose an internal input through a reusable Graph input alias.
Throws: RuntimeError if alias validation fails.
Template parameters
Exact admitted local payload type.
Parameters
Public Graph input declaration.
Internal Operator input declaration.
export_output
Expose an internal output through a reusable Graph output alias.
Throws: RuntimeError if alias validation fails.
Template parameters
Exact admitted local payload type.
Parameters
Public Graph output declaration.
Internal Operator output declaration.
configure
Overload 1
Overload 2
Overload 3
Overload 4
Overload 5
Overload 6
Create a throwing configurator for one Graph-owned input.
Returns: Short-lived fluent configurator referencing stable authoring identity.
Throws: RuntimeError if port is foreign, stale, or structurally unknown.
Template parameters
Exact admitted local payload type.
Parameters
Exact input declaration.
Create a throwing configurator for one non-Tensor output.
Returns: Short-lived fluent configurator referencing stable authoring identity.
Throws: RuntimeError if port is foreign, stale, or structurally unknown.
Template parameters
Exact admitted non-Tensor local payload type.
Parameters
Exact output declaration.
Return the stable Graph-owned configurator for a descriptor-backed Tensor output.
Returns: Stable configurator reference valid until Graph destruction.
Template parameters
Admitted descriptor-backed Tensor schema payload.
Parameters
Exact output declaration.
Return the stable Graph-owned configurator for a Tensor output.
Returns: Stable configurator reference valid until Graph destruction.
Throws: RuntimeError if port is foreign, stale, or structurally unknown.
Parameters
Exact mutable output declaration.
Return the stable Graph-owned configurator for a Tensor output.
Returns: Stable configurator reference valid until Graph destruction.
Throws: RuntimeError if port is foreign, stale, or structurally unknown.
Parameters
Exact output declaration.
Create a throwing configurator for one authored flow.
Returns: Short-lived fluent configurator referencing stable edge identity.
Throws: RuntimeError if flow is foreign or stale.
Template parameters
Exact source payload type retained by the flow handle.
Exact target payload type retained by the flow handle.
Parameters
Exact flow handle owned by this Graph.
try_configure
Overload 1
Overload 2
Overload 3
Overload 4
Overload 5
Try to create a flow configurator without throwing
Try to create an input configurator without throwing.
Returns: Configurator or typed lookup/ownership error.
Template parameters
Exact admitted local payload type.
Parameters
Exact input declaration.
Try to create a non-Tensor output configurator without throwing.
Returns: Configurator or typed lookup/ownership error.
Template parameters
Exact admitted non-Tensor local payload type.
Parameters
Exact output declaration.
Try to create a descriptor-backed Tensor output configurator.
Returns: Configurator value or typed lookup/ownership error.
Template parameters
Admitted descriptor-backed Tensor schema payload.
Parameters
Exact output declaration.
Try to create a value Tensor output configurator without throwing.
Returns: Configurator value or typed lookup/ownership error.
Parameters
Try to create a value Tensor output configurator without throwing.
Returns: Configurator value or typed lookup/ownership error.
Parameters
Try to create a flow configurator without throwing.
Returns: Configurator or typed ownership/staleness error.
Template parameters
Exact source payload type retained by the flow handle.
Exact target payload type retained by the flow handle.
Parameters
Exact flow handle owned by this Graph.
import_topic
Overload 1
Overload 2
Declare an intrinsic external-to-Graph typed topic boundary.
On first external use of a derived Graph, Core completes or terminally fails composition before constructing the requested boundary port.
The value parameter is intentional: it defines one immutable authoring snapshot while Core deep-copies every view-bearing field before this call returns.
Ordinary typed validation rejection consumes the next mixed external declaration ordinal. An exception before publication restores that ordinal.
Returns: Typed handle exposing the stable Graph-side output declaration.
Throws: RuntimeError if identity, URI, options, bounds, or name validation fails.
Template parameters
Parameters
Nonempty bounded holomq:// topic URI copied before return.
Complete cold boundary contract copied before return.
Declare a descriptor-backed schema external-to-Graph topic boundary.
Returns: Typed handle exposing the stable Graph-side output declaration.
Throws: RuntimeError if identity, URI, field inventory, bounds, or name validation fails.
Template parameters
Owning singular or multi-Tensor descriptor-backed schema type.
Parameters
Nonempty bounded holomq:// topic URI copied before return.
Common cold boundary contract copied before return.
Complete typed Tensor field inventory copied before return.
export_topic
Overload 1
Overload 2
Declare an intrinsic Graph-to-external typed topic boundary.
On first external use of a derived Graph, Core completes or terminally fails composition before constructing the requested boundary port.
The value parameter is intentional: it defines one immutable authoring snapshot while Core deep-copies every view-bearing field before this call returns.
Ordinary typed validation rejection consumes the next mixed external declaration ordinal. An exception before publication restores that ordinal.
Returns: Typed handle exposing the stable Graph-side input declaration.
Throws: RuntimeError if identity, URI, options, bounds, or name validation fails.
Template parameters
Parameters
Nonempty bounded holomq:// topic URI copied before return.
Complete cold boundary contract copied before return.
Declare a descriptor-backed schema Graph-to-external topic boundary.
Returns: Typed handle exposing the stable Graph-side input declaration.
Throws: RuntimeError if identity, URI, field inventory, bounds, or name validation fails.
Template parameters
Owning singular or multi-Tensor descriptor-backed schema type.
Parameters
Nonempty bounded holomq:// topic URI copied before return.
Common cold boundary contract copied before return.
Complete typed Tensor field inventory copied before return.
region
Add one uniquely named backend-neutral policy region.
Returns: Fluent region handle.
Throws: RuntimeError if name is invalid or duplicated.
Parameters
Nonempty unique bounded UTF-8 name copied before return.
partition
Add one uniquely named developer-preview manual execution partition.
Without auto_partition_remaining or PartitionHandle::include_all, compile requires all partitions to be nonempty and to cover every executable Operator exactly once.
Manual partitions and region declarations are orthogonal; regions may overlap partition boundaries.
Direct root Operators and selected child subtrees may anchor automatic remainder. Selected subtrees include every descendant Operator and must not declare partitions internally. A root PartitionHandle::include_all covers the complete application.
Returns: Fluent partition handle accepting direct Operators and complete embedded instances.
Throws: RuntimeError if name is invalid or duplicated.
Parameters
Nonempty unique bounded UTF-8 name copied before return.
auto_partition_remaining
Automatically partition Operators omitted from exact authored partitions.
The request is idempotent and may precede or follow exact partition authoring. Compilation rejects a request with no nonempty exact partition anchor.
Throws: RuntimeError if a partition already uses PartitionHandle::include_all.
lifecycle
Create a lifecycle ordering/permission authoring builder.
Returns: Short-lived builder tied to this Graph.
view
Freeze and return one immutable deep-owning authoring snapshot.
Returns: Snapshot that remains valid across Graph mutation and destruction.
Throws: RuntimeError if lazy composition failed or observation is reentrant.
add_clock
Add one Graph-owned replayable clock declaration.
On first external use of a derived Graph, Core completes or terminally fails composition before constructing the requested clock factory.
Registration constructs one Clock for validation and discards it. A later compiler or RunSession replays the retained factory to create its own ordinary Clock; only bind_shared_clock() retains a live instance.
Every normalized capture is copy-constructible and follows its ordinary C++ copy semantics. Obvious top-level borrowed forms and Graph authoring handles are rejected. Checks are shallow; nested borrows remain the application’s lifetime responsibility. Construction must be repeatable, and constructor side effects are not authoritative runtime state.
Returns: Owned named cold clock key.
Throws: RuntimeError if construction, naming, or registration fails.
Template parameters
Concrete Clock type.
Constructor capture argument types.
Parameters
Nonempty unique bounded UTF-8 clock name.
Constructor values copied under the same ownership precondition as op.
bind_shared_clock
Bind one explicitly shared live clock into cold Graph ownership.
Returns: Owned named cold clock key.
Throws: RuntimeError if naming or pointer validation fails.
Parameters
Nonempty unique bounded UTF-8 clock name.
Non-null shared clock retained by Graph state.
import_clock
Declare one explicit clock dependency for a reusable Graph.
An import creates no runtime clock. Every embedded instance must be bound explicitly by its direct parent before compilation.
Returns: Owned named import key that contracts and conversions may reference.
Throws: RuntimeError if naming or registration fails.
Parameters
Nonempty unique bounded UTF-8 clock import name.
bind_clock
Bind one embedded Graph clock import to one exact parent clock.
Resolution follows only these instance-qualified records. It never searches an ancestor scope by clock name.
Returns: This Graph.
Throws: RuntimeError for a foreign/stale child handle, a non-import child key, an unknown parent key, or a duplicate/conflicting binding.
Template parameters
Concrete reusable Graph type.
Parameters
Exact live child instance owned by this Graph.
Named clock import declared by that child root.
Named clock declaration or import in this Graph.
set_default_clock
Select one previously declared named clock as Graph default.
Returns: This Graph.
Throws: RuntimeError if key is default, empty, or not declared.
Parameters
Existing non-default named key.
default_clock
Return the selected default clock key.
Returns: Named key, or the distinct default/omitted key when none was selected.
Throws: RuntimeError if lazy composition failed or observation is reentrant.
add_clock_conversion
Add one immutable directed affine clock conversion.
Core reduces the positive ratio to lowest terms. Repeating the same pair with an equivalent canonical ratio and equal offset is idempotent.
Returns: This Graph.
Throws: RuntimeError for missing/self clocks, an invalid scale, a conflicting conversion for the same directed pair, or a directed cycle.
Parameters
Existing named source clock.
Existing distinct named destination clock.
Positive exact rate and signed nanosecond offset.
compose
Author a derived Graph body during Core-managed lazy composition.
Core invokes this override at most once after derived construction. Normal authoring verbs are valid inside the active transaction. Topology observers and other same-Graph paths that re-enter the composition gate fail with GRAPH_COMPOSE_REENTRANT; a terminal failure is retained and replayed.
Do not author from the derived constructor and do not call this virtual function directly. Constructor misuse and direct self-recursion have no promised runtime diagnosis.
The complete most-derived Graph must remain alive for the entire callback; concurrent destruction is outside the Graph lifetime contract.
embedding_type_identity
Supply a process-stable logical type identity for a language-hosted Graph adapter.
Ordinary C++ Graph subclasses should retain the default. Language bindings that host multiple logical graph types behind one C++ adapter may override this hook so recursion checks distinguish those hosted types without weakening cycle detection.
This virtual is deliberately appended after the pre-existing compose() slot so adding the hosted-language hook does not change the slot used by existing Graph subclasses.
Returns: A non-null identity shared by every instance of the same logical hosted type, or nullptr to use the concrete C++ Graph type.
add_operator_with_initial_params
add_flow_projected
Register one schema-to-Tensor edge after the field identity is known.