def save(self, filename):
<EOL>dat = self.normalize()<EOL>txt = json.dumps(dat)<EOL>if pimms.is_str(filename):<EOL><INDENT>filename = os.path.expandvars(os.path.expanduser(filename))<EOL>gz = (len(filename) > <NUM_LIT:3> and filename[-<NUM_LIT:3>:] == '<STR_LIT>')<EOL>with (gzip.open(filename, '<STR_LIT>') if gz else open(filename, '<STR_LIT>')) as f: f.write(txt)<EOL><DEDENT>else: filename.write(txt)<EOL>return filename<EOL>
path_trace.save(filename) saves the given path_trace object to the given filename. If
  filename is a stream object, writes path_trace to the stream. This function uses a json
  format for the path_trace; it will fail if the path trace includes any data that cannot
  be rendered as json, e.g. in the path trace's meta-data.