@@ -74,7 +74,7 @@ def run_op(solver, operator, **options):
7474 try :
7575 op = getattr (solver , operator )
7676 except AttributeError :
77- raise AttributeError ("Operator %s not implemented for %s" % ( operator , solver ) )
77+ raise AttributeError (f "Operator { operator } not implemented for { solver } " )
7878
7979 # This is a bit ugly but not sure how to make clean input creation for different op
8080 if operator == "forward" :
@@ -95,7 +95,7 @@ def run_op(solver, operator, **options):
9595 args = args [:- 1 ]
9696 return op (* args , ** options )
9797 else :
98- raise ValueError ("Unrecognized operator %s" % operator )
98+ raise ValueError (f "Unrecognized operator { operator } " )
9999
100100
101101@click .group ()
@@ -157,15 +157,14 @@ def from_opt(ctx, param, value):
157157 # E.g., `('advanced', {'par-tile': True})`
158158 value = eval (value )
159159 if not isinstance (value , tuple ) and len (value ) >= 1 :
160- raise click .BadParameter ("Invalid choice `%s ` (`opt` must be "
161- "either str or tuple)" % str ( value ) )
160+ raise click .BadParameter (f "Invalid choice `{ str ( value ) } ` (`opt` must be "
161+ "either str or tuple)" )
162162 opt = value [0 ]
163163 except NameError :
164164 # E.g. `'advanced'`
165165 opt = value
166166 if opt not in configuration ._accepted ['opt' ]:
167- raise click .BadParameter ("Invalid choice `%s` (choose from %s)"
168- % (opt , str (configuration ._accepted ['opt' ])))
167+ raise click .BadParameter ("Invalid choice `{}` (choose from {})" .format (opt , str (configuration ._accepted ['opt' ])))
169168 return value
170169
171170 def config_blockshape (ctx , param , value ):
@@ -188,11 +187,11 @@ def config_blockshape(ctx, param, value):
188187 levels = [bs [x :x + 3 ] for x in range (0 , len (bs ), 3 )]
189188 if any (len (level ) != 3 for level in levels ):
190189 raise ValueError ("Expected 3 entries per block shape level, but got "
191- "one level with less than 3 entries (`%s `)" % levels )
190+ f "one level with less than 3 entries (`{ levels } `)" )
192191 normalized_value .append (levels )
193192 if not all_equal (len (i ) for i in normalized_value ):
194193 raise ValueError ("Found different block shapes with incompatible "
195- "number of levels (`%s `)" % normalized_value )
194+ f "number of levels (`{ normalized_value } `)" )
196195 configuration ['opt-options' ]['blocklevels' ] = len (normalized_value [0 ])
197196 else :
198197 normalized_value = []
@@ -205,8 +204,7 @@ def config_autotuning(ctx, param, value):
205204 elif value != 'off' :
206205 # Sneak-peek at the `block-shape` -- if provided, keep auto-tuning off
207206 if ctx .params ['block_shape' ]:
208- warning ("Skipping autotuning (using explicit block-shape `%s`)"
209- % str (ctx .params ['block_shape' ]))
207+ warning ("Skipping autotuning (using explicit block-shape `{}`)" .format (str (ctx .params ['block_shape' ])))
210208 level = False
211209 else :
212210 # Make sure to always run in preemptive mode
@@ -305,11 +303,11 @@ def run(problem, **kwargs):
305303
306304 dumpfile = kwargs .pop ('dump_norms' )
307305 if dumpfile :
308- norms = ["'%s': %f" % ( i .name , norm (i )) for i in retval [:- 1 ]
306+ norms = [f"' { i .name } ': { norm (i ):f } " for i in retval [:- 1 ]
309307 if isinstance (i , DiscreteFunction )]
310308 if rank == 0 :
311309 with open (dumpfile , 'w' ) as f :
312- f .write ("{%s}" % ', ' .join (norms ))
310+ f .write ("{{{}}}" . format ( ', ' .join (norms ) ))
313311
314312 return retval
315313
@@ -343,13 +341,13 @@ def run_jit_backdoor(problem, **kwargs):
343341 op = solver .op_fwd ()
344342
345343 # Get the filename in the JIT cache
346- cfile = "%s.c" % str (op ._compiler .get_jit_dir ().joinpath (op ._soname ))
344+ cfile = f" { str (op ._compiler .get_jit_dir ().joinpath (op ._soname ))} .c"
347345
348346 if not os .path .exists (cfile ):
349347 # First time we run this problem, let's generate and jit-compile code
350348 op .cfunction
351- info ("You may now edit the generated code in `%s `. "
352- "Then save the file, and re-run this benchmark." % cfile )
349+ info (f "You may now edit the generated code in `{ cfile } `. "
350+ "Then save the file, and re-run this benchmark." )
353351 return
354352
355353 info ("Running wave propagation Operator..." )
@@ -364,7 +362,7 @@ def _run_jit_backdoor():
364362 if dumpnorms :
365363 for i in retval [:- 1 ]:
366364 if isinstance (i , DiscreteFunction ):
367- info ("'%s': %f" % ( i .name , norm (i )) )
365+ info (f"' { i .name } ': { norm (i ):f } " )
368366
369367 return retval
370368
0 commit comments