code: def cache_penalty_model(penalty_model, database=None):
      
  
      # only handles index-labelled nodes
      if not _is_index_labelled(penalty_model.graph):
          mapping, __ = _graph_canonicalization(penalty_model.graph)
          penalty_model = penalty_model.relabel_variables(mapping, inplace=False)
  
      # connect to the database. Note that once the connection is made it cannot be
      # broken up between several processes.
      if database is None:
          conn = cache_connect()
      else:
          conn = cache_connect(database)
  
      # load into the database
      with conn as cur:
          insert_penalty_model(cur, penalty_model)
  
      # close the connection
      conn.close()
docs: Caching function for penaltymodel_cache.
  
      Args:
          penalty_model (:class:`penaltymodel.PenaltyModel`): Penalty model to
              be cached.
          database (str, optional): The path to the desired sqlite database
              file. If None, will use the default.