code: def profile_network(filename):
      
      log = logging.getLogger(filename)
      logfile = os.path.join(LOGS, filename + '.log')
      os.makedirs(os.path.dirname(logfile), exist_ok=True)
      handler = logging.FileHandler(logfile)
      handler.setFormatter(formatter)
      log.addHandler(handler)
      log.setLevel(logging.INFO)
  
      try:
          with open(os.path.join(NETWORKS, filename + '.json')) as f:
  
              network, state = load_json_network(json.load(f))
  
              log.info('Profiling %s...', filename)
              log.info('PyPhi configuration:\n%s',
                       pyphi.config.get_config_string())
  
              start = time()
              pr = cProfile.Profile()
              pr.enable()
  
              results = tuple(pyphi.compute.complexes(network, state))
  
              pr.disable()
              end = time()
  
              pstatsfile = os.path.join(PSTATS, filename + '.pstats')
              os.makedirs(os.path.dirname(pstatsfile), exist_ok=True)
              pr.dump_stats(pstatsfile)
  
              log.info('Finished in %i seconds.', end - start)
  
              resultfile = os.path.join(RESULTS, filename + '-results.pkl')
              os.makedirs(os.path.dirname(resultfile), exist_ok=True)
              with open(resultfile, 'wb') as f:
                  pickle.dump(results, f)
      except Exception as e:
          log.error(e)
          raise e
docs: Profile a network.
  
      Saves PyPhi results, pstats, and logs to respective directories.