original_docstring: 
          Function to to make multiple runs of yambo to converge calculation parameters
  
          Arguments:
  
              A dictionary conv that has all the variables to be optimized
              A list fo the name of the variables in the dicitonary that are to be optimized
              A function run that takes as input the name of the inputfile (used to run yambo)
              A boolean ref_run that can disable the submitting of the reference run (see scripts/analyse_gw.py)
  
          
docstring: Function to to make multiple runs of yambo to converge calculation parameters
  Arguments.
  
  A dictionary conv that has all the variables to be optimized
  A list fo the name of the variables in the dicitonary that are to be optimized
  A function run that takes as input the name of the inputfile (used to run yambo)
  A boolean ref_run that can disable the submitting of the reference run
docstring_tokens: Function to to make multiple runs of yambo to converge calculation parameters Arguments . A dictionary conv that has all the variables to be optimized A list fo the name of the variables in the dicitonary that are to be optimized A function run that takes as input the name of the inputfile ( used to run yambo ) A boolean ref_run that can disable the submitting of the reference run
code: def optimize(self,conv,folder='.',variables=('all',),run=lambda x: None,ref_run=True):
          """
          Function to to make multiple runs of yambo to converge calculation parameters
  
          Arguments:
  
              A dictionary conv that has all the variables to be optimized
              A list fo the name of the variables in the dicitonary that are to be optimized
              A function run that takes as input the name of the inputfile (used to run yambo)
              A boolean ref_run that can disable the submitting of the reference run (see scripts/analyse_gw.py)
  
          """
          name_files = []
  
          #check which variables to optimize
          if 'all' in variables:
              variables = list(conv.keys())
  
          #save all the variables
          backup = {}
          for var in variables:
              backup[var] = self[var]
  
          #add units to all the variables (to be improved!)
          for key,value in list(conv.items()):
              if not isinstance(value[-1],str) and type(value[0]) == list:
                  conv[key] = [value,'']
  
          #make a first run with all the first elements
          reference = {}
          for key,value in list(conv.items()):
              values, unit = value
              reference[key] = [values[0],unit]
              self[key] = [values[0],unit]
          #write the file and run
          if ref_run==True:
              self.write( "%s/reference.in"%(folder) )
              run('reference.in')
          else:
              print('Reference run disabled.')
  
          #converge one by one
          for key in [var for var in list(conv.keys()) if var in variables]:
              values, unit = conv[key]
              #put back the original values of the variables
              for var in variables:
                  self[var] = reference[var]
              #change the other variables
              if isinstance(values[0],str):
                  for string in values[1:]:
                      filename = "%s_%s"%(key,string)
                      self[key] = string
                      self.write( folder + filename )
                      run(filename+".in")
                  continue
              if type(values[0])==float:
                  for val in values[1:]:
                      filename = "%s_%12.8lf"%(key,val)
                      self[key] = [val,unit]
                      self.write( "%s/%s.in"%(folder,filename) )
                      run(filename+".in")
                  continue
              if type(values[0])==int:
                  for val in values[1:]:
                      filename = "%s_%05d"%(key,val)
                      self[key] = [val,unit]
                      self.write( "%s/%s.in"%(folder,filename) )
                      run(filename+".in")
                  continue
              if type(values[0])==list:
                  for array in values[1:]:
                      filename = "%s_%s"%(key,"_".join(map(str,array)))
                      self[key] = [array,unit]
                      self.write( "%s/%s.in"%(folder,filename) )
                      run(filename+".in")
                  continue
              if type(values[0])==complex:
                  for value in values[1:]:
                      filename = "%s_%lf_%lf"%(key,value.real,value.imag)
                      self[key] = [value,unit]
                      self.write( "%s/%s.in"%(folder,filename) )
                      run(filename+".in")
                  continue
              raise ValueError( "unknown type for variable:", key )
  
          #put back the original values of the variables
          for var in variables:
              self[var] = backup[var]
  
          return name_files
code_tokens: def optimize ( self , conv , folder = '.' , variables = ( 'all' , ) , run = lambda x : None , ref_run = True ) : name_files = [ ] if 'all' in variables : variables = list ( conv . keys ( ) ) backup = { } for var in variables : backup [ var ] = self [ var ] for key , value in list ( conv . items ( ) ) : if not isinstance ( value [ - 1 ] , str ) and type ( value [ 0 ] ) == list : conv [ key ] = [ value , '' ] reference = { } for key , value in list ( conv . items ( ) ) : values , unit = value reference [ key ] = [ values [ 0 ] , unit ] self [ key ] = [ values [ 0 ] , unit ] if ref_run == True : self . write ( "%s/reference.in" % ( folder ) ) run ( 'reference.in' ) else : print ( 'Reference run disabled.' ) for key in [ var for var in list ( conv . keys ( ) ) if var in variables ] : values , unit = conv [ key ] for var in variables : self [ var ] = reference [ var ] if isinstance ( values [ 0 ] , str ) : for string in values [ 1 : ] : filename = "%s_%s" % ( key , string ) self [ key ] = string self . write ( folder + filename ) run ( filename + ".in" ) continue if type ( values [ 0 ] ) == float : for val in values [ 1 : ] : filename = "%s_%12.8lf" % ( key , val ) self [ key ] = [ val , unit ] self . write ( "%s/%s.in" % ( folder , filename ) ) run ( filename + ".in" ) continue if type ( values [ 0 ] ) == int : for val in values [ 1 : ] : filename = "%s_%05d" % ( key , val ) self [ key ] = [ val , unit ] self . write ( "%s/%s.in" % ( folder , filename ) ) run ( filename + ".in" ) continue if type ( values [ 0 ] ) == list : for array in values [ 1 : ] : filename = "%s_%s" % ( key , "_" . join ( map ( str , array ) ) ) self [ key ] = [ array , unit ] self . write ( "%s/%s.in" % ( folder , filename ) ) run ( filename + ".in" ) continue if type ( values [ 0 ] ) == complex : for value in values [ 1 : ] : filename = "%s_%lf_%lf" % ( key , value . real , value . imag ) self [ key ] = [ value , unit ] self . write ( "%s/%s.in" % ( folder , filename ) ) run ( filename + ".in" ) continue raise ValueError ( "unknown type for variable:" , key ) for var in variables : self [ var ] = backup [ var ] return name_files
short_docstring: Function to to make multiple runs of yambo to converge calculation parameters
  Arguments:
short_docstring_tokens: Function to to make multiple runs of yambo to converge calculation parameters Arguments :
comment: """
          Function to to make multiple runs of yambo to converge calculation parameters
  
          Arguments:
  
              A dictionary conv that has all the variables to be optimized
              A list fo the name of the variables in the dicitonary that are to be optimized
              A function run that takes as input the name of the inputfile (used to run yambo)
              A boolean ref_run that can disable the submitting of the reference run (see scripts/analyse_gw.py)
  
          """$SEP$#check which variables to optimize$SEP$#save all the variables$SEP$#add units to all the variables (to be improved!)$SEP$#make a first run with all the first elements$SEP$#write the file and run$SEP$#converge one by one$SEP$#put back the original values of the variables$SEP$#change the other variables$SEP$#put back the original values of the variables