code: def connect_model(self, model):
          
  
          # Changed this to allow non-Model models. -AP
          if isinstance(model, pymc.Model):
              self.model = model
          else:
              raise AttributeError('Not a Model instance.')
  
          # Restore the state of the Model from an existing Database.
          # The `load` method will have already created the Trace objects.
          if hasattr(self, '_state_'):
              names = set()
              for morenames in self.trace_names:
                  names.update(morenames)
              for name, fun in six.iteritems(model._funs_to_tally):
                  if name in self._traces:
                      self._traces[name]._getfunc = fun
                      names.remove(name)
              if len(names) > 0:
                  raise RuntimeError(
                      "Some objects from the database have not been assigned a getfunc: %s" %
                      ', '.join(names))
  
          # Create a fresh new state. This is now taken care of in initialize.
          else:
              for name, fun in six.iteritems(model._funs_to_tally):
                  if np.array(fun()).dtype is np.dtype('object'):
                      self._traces[
                          name] = TraceObject(
                              name,
                              getfunc=fun,
                              db=self)
                  else:
                      self._traces[name] = Trace(name, getfunc=fun, db=self)
docs: Link the Database to the Model instance.
  
          In case a new database is created from scratch, ``connect_model``
          creates Trace objects for all tallyable pymc objects defined in
          `model`.
  
          If the database is being loaded from an existing file, ``connect_model``
          restore the objects trace to their stored value.
  
          :Parameters:
          model : pymc.Model instance
            An instance holding the pymc objects defining a statistical
            model (stochastics, deterministics, data, ...)