WolframInstitute/THVMLink

Wolfram Language bridge to thvm - observe and drive the interaction-net runtime.

Paclet Manifest

Web ContentResourceCreateNotebook

Headline ImageResourceCreateNotebook

ImageResize[
    Import[PacletObject["WolframInstitute/THVMLink"]["AssetLocation", "Hero"]],
    {1500, Automatic}
]

Basic DescriptionResourceCreateNotebook

THVMLink exposes (PackageLink[TLam, paclet:WolframInstitute/THVMLink/ref/TLam, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TApp, paclet:WolframInstitute/THVMLink/ref/TApp, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TTensorCreate, paclet:WolframInstitute/THVMLink/ref/TTensorCreate, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TUOpAdd, paclet:WolframInstitute/THVMLink/ref/TUOpAdd, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TUOpMul, paclet:WolframInstitute/THVMLink/ref/TUOpMul, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TUOpReduce, paclet:WolframInstitute/THVMLink/ref/TUOpReduce, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TRealize, paclet:WolframInstitute/THVMLink/ref/TRealize, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TGrad, paclet:WolframInstitute/THVMLink/ref/TGrad, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TKernel, paclet:WolframInstitute/THVMLink/ref/TKernel, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TMemoryPlan, paclet:WolframInstitute/THVMLink/ref/TMemoryPlan, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TFindProof, paclet:WolframInstitute/THVMLink/ref/TFindProof, WolframInstitute/THVMLink Package Symbol]), and many more.

DetailsResourceCreateNotebook

THVMLink is the Wolfram-language driver for thvm, a tensor-aware interaction-net runtime that compiles to CPU, CUDA, and Metal back ends from one symbolic graph.

Construction is purely symbolic. (PackageLink[TLam, paclet:WolframInstitute/THVMLink/ref/TLam, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TApp, paclet:WolframInstitute/THVMLink/ref/TApp, WolframInstitute/THVMLink Package Symbol]), (PackageLink[TSup, paclet:WolframInstitute/THVMLink/ref/TSup, WolframInstitute/THVMLink Package Symbol]), and (PackageLink[TDup, paclet:WolframInstitute/THVMLink/ref/TDup, WolframInstitute/THVMLink Package Symbol]) build interaction-combinator terms; (PackageLink[TUOpAdd, paclet:WolframInstitute/THVMLink/ref/TUOpAdd, WolframInstitute/THVMLink Package Symbol]) and the rest of the TUOp* family build the tensor UOp graph; (PackageLink[TTensorCreate, paclet:WolframInstitute/THVMLink/ref/TTensorCreate, WolframInstitute/THVMLink Package Symbol]) ingests a (RefLink[NumericArray, paclet:ref/NumericArray]) zero-copy on CPU.

Reduction is staged. (PackageLink[TWnf, paclet:WolframInstitute/THVMLink/ref/TWnf, WolframInstitute/THVMLink Package Symbol]) drives a term to weak normal form, (PackageLink[TMaterialize, paclet:WolframInstitute/THVMLink/ref/TMaterialize, WolframInstitute/THVMLink Package Symbol]) schedules the UOp DAG into kernels, and (PackageLink[TRealize, paclet:WolframInstitute/THVMLink/ref/TRealize, WolframInstitute/THVMLink Package Symbol]) fires the whole pipeline (schedule + dispatch).

Differentiation lives in the runtime. (PackageLink[TGrad, paclet:WolframInstitute/THVMLink/ref/TGrad, WolframInstitute/THVMLink Package Symbol]) seeds a single backward walk that auto-grads every reachable float leaf; per-leaf adjoints are readable via (PackageLink[TGradOf, paclet:WolframInstitute/THVMLink/ref/TGradOf, WolframInstitute/THVMLink Package Symbol]).

Introspection is first class. (PackageLink[THeapGraph, paclet:WolframInstitute/THVMLink/ref/THeapGraph, WolframInstitute/THVMLink Package Symbol]) renders the live heap as an IC string diagram, (PackageLink[TMemoryPlan, paclet:WolframInstitute/THVMLink/ref/TMemoryPlan, WolframInstitute/THVMLink Package Symbol]) projects per-buffer alive spans, and (PackageLink[TKernel, paclet:WolframInstitute/THVMLink/ref/TKernel, WolframInstitute/THVMLink Package Symbol]) exposes per-kernel timing, source, and autotune candidates.

The ATP submodule wraps thvm's equational saturation engine via (PackageLink[TFindProof, paclet:WolframInstitute/THVMLink/ref/TFindProof, WolframInstitute/THVMLink Package Symbol]) (a drop-in (RefLink[FindEquationalProof, paclet:ref/FindEquationalProof]) replacement that returns a full ProofObject) and the lower-level (PackageLink[TATP, paclet:WolframInstitute/THVMLink/ref/TATP, WolframInstitute/THVMLink Package Symbol]).

Primary ContextResourceCreateNotebook

WolframInstitute`THVMLink`

Main Guide PageResourceCreateNotebook

ExamplesResourceCreateNotebook

Initialization for ExamplesResourceCreateNotebook

PacletDirectoryLoad[NotebookDirectory[]];

Needs["WolframInstitute`THVMLink`"];

Basic Examples

Build and reduce a tiny term:

Needs["WolframInstitute`THVMLink`"];
TInit[];
TWnf[TApp[TLam[x, x], TLam[y, y]]]

Build a UOp graph and realize it on the active backend:

x = TTensorCreate[{1., 2., 3., 4.}];
y = TTensorCreate[{10., 20., 30., 40.}];
TTensorData @ TRealize[TUOpAdd[x, y]]

Take a gradient through a small expression (every float leaf is auto-graded, no marking):

w = TTensorCreate[{1., 2., 3.}];
x = TTensorCreate[{4., 5., 6.}];
TRealize @ TGrad[TUOpReduce[TUOpMul[w, x], 0, "SUM"]];
TTensorData @ TRealize @ TGradOf[w]

Scope

Render the live interaction-net heap as an IC string diagram, seeded at a particular term:

THeapGraph @ TApp[TLam[w, TUOpAdd[w, w]], TTensorCreate[{1., 2.}]]

Snapshot the live runtime to a transportable Wolfram expression, restore it across a fresh kernel:

snap = TContextSnapshot[TLam[x, TUOpAdd[x, x]]];
TFree[]; TInit[];
TInitialize[snap]

Generalizations & Extensions

Options

Applications

Project the schedule the materializer produces from a small neural-net forward pass and gate it through the memory planner:

W = TGlorot[{4, 10}]; b = TZeros[{10}]; xs = TTensorCreate[ConstantArray[1., {1, 4}]];
loss = TL2Loss @ TLinear[xs, W, b];
TMaterialize[loss];
TMemoryPlanReport @ TMemoryPlan[]

Prove a small equational theorem with the C-engine ATP and reconstruct it as a Wolfram ProofObject:

Needs["WolframInstitute`THVMLink`ATP`"];
TFindProof[
    Inactive[Equal][x ⊗ y ⊗ z, z ⊗ y ⊗ x],
    "AbelianGroupAxioms",
    TimeConstraint -> 10
]

Properties and Relations

Per-kernel introspection - source, autotune candidates, and dispatch counters live on (PackageLink[TKernel, paclet:WolframInstitute/THVMLink/ref/TKernel, WolframInstitute/THVMLink Package Symbol]):

TRealize @ TUOpAdd[TTensorCreate[Range[1., 8.]], TTensorCreate[Range[1., 8.]]];
k = TKernel[1];
{k["DispatchKind"], k["DispatchCount"], TKernelProposed[1]}

Possible Issues

The default make target does not rebuild the WL paclet dynamic library; the host .wlt tests and notebooks dispatch through the stale LibraryResources/THVMLink.dylib. Always run make && make wl from the repository root after touching C sources.

Neat Examples

Source & Additional Information

CreatorResourceCreateNotebook

Wolfram Institute

Source Control RepositoryResourceCreateNotebook

https://github.com/sw1sh/thvm

LicenseResourceCreateNotebook

KeywordsResourceCreateNotebook

interaction net

HVM

tensor

JIT

autodiff

ATP

equational

CategoriesResourceCreateNotebook

Related Resource ObjectsResourceCreateNotebook

Resource Name (resources from any Wolfram repository)

Original Source References and AttributionsResourceCreateNotebook

Source, reference or citation

LinksResourceCreateNotebook

Link to other related material

CompatibilityResourceCreateNotebook

Wolfram Language VersionResourceCreateNotebook

13.0+

Operating SystemResourceCreateNotebook

EnvironmentsResourceCreateNotebook

Cloud SupportResourceCreateNotebook

Required FeaturesResourceCreateNotebook

DisclosuresResourceCreateNotebook

Author NotesResourceCreateNotebook

Drafted with assistance from Claude (Anthropic, model claude-opus-4-7) under human supervision. Frontmatter, section structure, and prose were machine- generated from the in-source ::usage strings; the Wolfram Language examples were reviewed by a human contributor against the live paclet before publishing. The C runtime, the LibraryLink bridge, and the Kernel/*.wl sources THVMLink documents are hand-written and pre-date this documentation pass.