hlsfactory.harp._programl_compat

Compatibility shims for the pinned programl release used by HARP.

programl 0.3.2 is the latest published release and predates several dependency changes. Importing and using it on a modern stack needs four adjustments, all applied by load_programl():

  1. Its generated *_pb2.py modules were built with protoc < 3.19 and are rejected by modern protobuf unless the pure-Python implementation is used.

  2. programl.transform_ops imports dgl unconditionally to provide to_dgl, which HARP never calls. A real dgl drags in torch plus a libgraphbolt built for one exact torch version, so a stub is injected instead.

  3. programl.to_networkx calls node_link_graph without naming the edges key. networkx >= 3.4 changed that default from links to edges while programl still emits links, so program_graph_to_networkx() does the conversion explicitly rather than pinning networkx.

  4. The bundled llvm2graph-10 binary needs libtinfo.so.5. That is an environment prerequisite and cannot be fixed from Python; see check_programl_runtime().

Module Contents

Functions

_install_dgl_stub

load_programl

Import and return the programl module with all shims applied.

program_graph_to_networkx

Convert a ProGraML ProgramGraph to a networkx MultiDiGraph.

check_programl_runtime

Verify that the bundled ProGraML binary can actually run.

Data

API

hlsfactory.harp._programl_compat.PROTOBUF_IMPL_ENV_VAR = 'PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION'
hlsfactory.harp._programl_compat._INSTALL_HINT = <Multiline-String>
hlsfactory.harp._programl_compat._install_dgl_stub() → None[source]
hlsfactory.harp._programl_compat.load_programl() → Any[source]

Import and return the programl module with all shims applied.

Returns:

Any: The imported programl module.

Raises:

ImportError: If programl or networkx is not installed.

hlsfactory.harp._programl_compat.program_graph_to_networkx(program_graph: Any) → Any[source]

Convert a ProGraML ProgramGraph to a networkx MultiDiGraph.

Replaces programl.to_networkx, which breaks on networkx >= 3.4.

Args:

program_graph (Any): A ProGraML ProgramGraph.

Returns:

Any: The graph as a networkx MultiDiGraph.

hlsfactory.harp._programl_compat.check_programl_runtime() → None[source]

Verify that the bundled ProGraML binary can actually run.

The llvm2graph binaries link against libtinfo.so.5, which modern distributions no longer ship. Failing here gives a clearer message than the GraphCreationError raised on first use.

Raises:

RuntimeError: If the bundled binary cannot be executed.