prepare_graph function

Construct graph from register information