code: def _objective_qubitcount(self, old, new):
          
          (oldscore, oldthing) = old
          (newscore, newthing) = new
  
          def measure(chains):
              return sum(map(len, chains))
  
          if oldscore is None:
              return True
          if newscore is None:
              return False
          if len(newthing):
              if not len(oldthing):
                  return True
              elif isinstance(newthing, tuple):
                  newlengths = sum(map(measure, newthing))
                  oldlengths = sum(map(measure, oldthing))
                  return newlengths < oldlengths
              else:
                  return measure(newthing) < measure(oldthing)
          else:
              return False
docs: An objective function that returns True if new uses fewer qubits
          than old, and False otherwise.  This objective function should only be
          used to compare embeddings of the same graph (or at least embeddings of
          graphs with the same number of qubits).
  
          INPUTS:
              old (tuple): a tuple (score, embedding)
  
              new (tuple): a tuple (score, embedding)