Build a CacheKey from a TraceGraph.
Walks graph.ops once, copying the name + first-output meta from
each node. Device is taken from the most recent non-empty output;
it is the caller's responsibility to ensure the trace is
single-device (the MpsBuilder rejects mixed-device traces before
hashing).
feed_meta maps each external-feed id to its shape and dtype; it
fills CacheKey::feeds.
explicit_outputs are the trace ids the caller will read back, in
order; they fill CacheKey::outputs.
When id_map is non-null, it is populated with the raw-to-canonical
and canonical-to-raw TensorId bijection for this trace.