def convert_to_real_indices(seq, qubit_map):
 if isinstance(seq, Mul):
  seq = seq.args
 if (not isinstance(qubit_map, dict)):
  msg = ('Expected dict for qubit_map, got %r.' % qubit_map)
  raise TypeError(msg)
 qubit_map = _sympify_qubit_map(qubit_map)
 real_seq = ()
 for item in seq:
  if isinstance(item, Gate):
   real_item = convert_to_real_indices(item.args, qubit_map)
  elif (isinstance(item, tuple) or isinstance(item, Tuple)):
   real_item = convert_to_real_indices(item, qubit_map)
  else:
   real_item = qubit_map[item]
  if isinstance(item, Gate):
   real_item = item.__class__(*real_item)
  real_seq = (real_seq + (real_item,))
 return real_seq

def convert_to_real_indices ( seq , qubit_map ) : if isinstance ( seq , Mul ) : seq = seq . args if ( not isinstance ( qubit_map , dict ) ) : msg = ( 'Expected dict for qubit_map, got %r.' % qubit_map ) raise TypeError ( msg ) qubit_map = _sympify_qubit_map ( qubit_map ) real_seq = ( ) for item in seq : if isinstance ( item , Gate ) : real_item = convert_to_real_indices ( item . args , qubit_map ) elif ( isinstance ( item , tuple ) or isinstance ( item , Tuple ) ) : real_item = convert_to_real_indices ( item , qubit_map ) else : real_item = qubit_map [ item ] if isinstance ( item , Gate ) : real_item = item . __class__ ( * real_item ) real_seq = ( real_seq + ( real_item , ) ) return real_seq
returns the circuit with real indices .