  Let $T$ be a set, of {\em types}, and let $\iota,o:T\to\oZ_+$. A {\em
$T$-diagram} is a locally ordered directed graph $G$ equipped with a function
$\tau:V(G)\to T$ such that each vertex $v$ of $G$ has indegree $\iota(\tau(v))$
and outdegree $o(\tau(v))$. (A directed graph is {\em locally ordered} if at
each vertex $v$, linear orders of the edges entering $v$ and of the edges
leaving $v$ are specified.)
  Let $V$ be a finite-dimensional $\oF$-linear space, where $\oF$ is an
algebraically closed field of characteristic 0. A function $R$ on $T$ assigning
to each $t\in T$ a tensor $R(t)\in V^{*\otimes \iota(t)}\otimes V^{\otimes
o(t)}$ is called a {\em tensor representation} of $T$. The {\em trace} (or {\em
partition function}) of $R$ is the $\oF$-valued function $p_R$ on the
collection of $T$-diagrams obtained by `decorating' each vertex $v$ of a
$T$-diagram $G$ with the tensor $R(\tau(v))$, and contracting tensors along
each edge of $G$, while respecting the order of the edges entering $v$ and
leaving $v$. In this way we obtain a {\em tensor network}.
  We characterize which functions on $T$-diagrams are traces, and show that
each trace comes from a unique `strongly nondegenerate' tensor representation.
The theorem applies to virtual knot diagrams, chord diagrams, and group
representations.
