Let T be an (abstract) set of types, and let ι, o : T → Z + .A T -diagram is a locally ordered directed graph G equipped with a function τ : V (G) → T such that each vertex v of G has indegree ι(τ (v)) and outdegree o(τ (v)). (A directed graph is 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 F-linear space, where F is an algebraically closed field of characteristic 0. A function R on T assigning to each t ∈ T a tensor R(t) ∈ V * ⊗ι(t) ⊗ V ⊗o(t) is called a tensor representation of T . The trace (or partition function) of R is the F-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(τ (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 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.