@@ -111,8 +111,8 @@ def __init_finalize__(self, *args, function=None, **kwargs):
111
111
# case `self._data is None`
112
112
self .data
113
113
else :
114
- raise ValueError ("`initializer` must be callable or buffer, not %s "
115
- % type (initializer ))
114
+ raise ValueError (f "`initializer` must be callable or buffer, "
115
+ f"not { type (initializer )} " )
116
116
117
117
_subs = Differentiable ._subs
118
118
@@ -125,8 +125,8 @@ def wrapper(self):
125
125
# Aliasing Functions must not allocate data
126
126
return
127
127
128
- debug ("Allocating host memory for %s%s [%s] "
129
- % ( self . name , self . shape_allocated , humanbytes (self .nbytes )) )
128
+ debug (f "Allocating host memory for { self . name } { self . shape_allocated } "
129
+ f"[ { humanbytes (self .nbytes )} ]" )
130
130
131
131
# Clear up both SymPy and Devito caches to drop unreachable data
132
132
CacheManager .clear (force = False )
@@ -176,8 +176,8 @@ def __coefficients_setup__(self, **kwargs):
176
176
if coeffs == 'symbolic' :
177
177
deprecations .symbolic_warn
178
178
else :
179
- raise ValueError ("coefficients must be one of %s "
180
- " not %s" % ( str ( fd_weights_registry ), coeffs ) )
179
+ raise ValueError (f "coefficients must be one of { fd_weights_registry } "
180
+ f" not { coeffs } " )
181
181
return coeffs
182
182
183
183
def __staggered_setup__ (self , ** kwargs ):
@@ -352,12 +352,12 @@ def _size_outhalo(self):
352
352
353
353
if self ._distributor .is_parallel and (any (left ) > 0 or any (right )) > 0 :
354
354
try :
355
- warning_msg = """A space order of {0} and a halo size of {1} has been
356
- set but the current rank ({2}) has a domain size of
357
- only {3}""" . format ( self . _space_order ,
358
- max ( self . _size_inhalo ),
359
- self ._distributor . myrank ,
360
- min ( self . grid . shape_local ) )
355
+ warning_msg = (
356
+ f"A space order of { self . _space_order } and a halo size of "
357
+ f" { max ( self . _size_inhalo ) } has been set but the current rank "
358
+ f"( { self . _distributor . myrank } ) has a domain size of only "
359
+ f" { min ( self .grid . shape_local ) } "
360
+ )
361
361
if not self ._distributor .is_boundary_rank :
362
362
warning (warning_msg )
363
363
else :
@@ -768,7 +768,7 @@ def _C_get_field(self, region, dim, side=None):
768
768
offset = 0
769
769
size = ffp (self ._C_field_size , self ._C_make_index (dim ))
770
770
else :
771
- raise ValueError ("Unknown region `%s`" % str ( region ) )
771
+ raise ValueError (f "Unknown region `{ region } `" )
772
772
773
773
return RegionMeta (offset , size )
774
774
@@ -781,8 +781,8 @@ def _halo_exchange(self):
781
781
# Nothing to do
782
782
return
783
783
if MPI .COMM_WORLD .size > 1 and self ._distributor is None :
784
- raise RuntimeError ("`%s ` cannot perform a halo exchange as it has "
785
- " no Grid attached" % self . name )
784
+ raise RuntimeError (f"` { self . name } ` cannot perform a halo exchange "
785
+ f"as it has no Grid attached" )
786
786
787
787
neighborhood = self ._distributor .neighborhood
788
788
comm = self ._distributor .comm
@@ -874,17 +874,16 @@ def _arg_check(self, args, intervals, **kwargs):
874
874
If an incompatibility is detected.
875
875
"""
876
876
if self .name not in args :
877
- raise InvalidArgument ("No runtime value for `%s`" % self .name )
877
+ raise InvalidArgument (f "No runtime value for `{ self .name } `" )
878
878
879
879
data = args [self .name ]
880
880
881
881
if len (data .shape ) != self .ndim :
882
- raise InvalidArgument ("Shape %s of runtime value `%s` does not match "
883
- "dimensions %s" %
884
- (data .shape , self .name , self .dimensions ))
882
+ raise InvalidArgument (f"Shape { data .shape } of runtime value `{ self .name } ` "
883
+ f"does not match dimensions { self .dimensions } " )
885
884
if data .dtype != self .dtype :
886
- warning ("Data type %s of runtime value `%s` does not match the "
887
- "Function data type %s" % ( data . dtype , self . name , self .dtype ) )
885
+ warning (f "Data type { data . dtype } of runtime value `{ self . name } ` "
886
+ f"does not match the Function data type { self .dtype } " )
888
887
889
888
# Check each Dimension for potential OOB accesses
890
889
for i , s in zip (self .dimensions , data .shape ):
@@ -894,11 +893,11 @@ def _arg_check(self, args, intervals, **kwargs):
894
893
args .options ['linearize' ] and \
895
894
self .is_regular and \
896
895
data .size - 1 >= np .iinfo (np .int32 ).max :
897
- raise InvalidArgument ("`%s `, with its %d elements, is too big for "
898
- "int32 pointer arithmetic. Consider using the "
899
- "'index-mode=int64' option, the save=Buffer(..) "
900
- "API (TimeFunction only), or domain "
901
- "decomposition via MPI" % ( self . name , data . size ) )
896
+ raise InvalidArgument (f"` { self . name } `, with its { data . size } elements, "
897
+ "is too big for int32 pointer arithmetic. "
898
+ "Consider using the 'index-mode=int64' option, "
899
+ "the save=Buffer(..) (TimeFunction only), or domain "
900
+ "decomposition via MPI" )
902
901
903
902
def _arg_finalize (self , args , alias = None ):
904
903
key = alias or self
@@ -1134,9 +1133,8 @@ def __shape_setup__(cls, **kwargs):
1134
1133
if d in grid .dimensions :
1135
1134
size = grid .dimension_map [d ]
1136
1135
if size .glb != s and s is not None :
1137
- raise ValueError ("Dimension `%s` is given size `%d`, "
1138
- "while `grid` says `%s` has size `%d` "
1139
- % (d , s , d , size .glb ))
1136
+ raise ValueError (f"Dimension `{ d } ` is given size `{ s } `, "
1137
+ f"while `grid` says `{ d } ` has size `{ size .glb } `" )
1140
1138
else :
1141
1139
loc_shape .append (size .loc )
1142
1140
else :
@@ -1192,7 +1190,7 @@ def __padding_setup__(self, **kwargs):
1192
1190
padding = tuple ((0 , i ) if isinstance (i , int ) else i for i in padding )
1193
1191
1194
1192
else :
1195
- raise TypeError ("`padding` must be int or %d -tuple of ints" % self . ndim )
1193
+ raise TypeError (f "`padding` must be int or { self . ndim } -tuple of ints" )
1196
1194
return DimensionTuple (* padding , getters = self .dimensions )
1197
1195
1198
1196
@property
@@ -1438,7 +1436,7 @@ def __shape_setup__(cls, **kwargs):
1438
1436
elif isinstance (save , int ):
1439
1437
shape .insert (cls ._time_position , save )
1440
1438
else :
1441
- raise TypeError ("`save` can be None, int or Buffer, not %s" % type (save ))
1439
+ raise TypeError (f "`save` can be None, int or Buffer, not { type (save )} " )
1442
1440
elif dimensions is None :
1443
1441
raise TypeError ("`dimensions` required if both `grid` and "
1444
1442
"`shape` are provided" )
@@ -1502,9 +1500,10 @@ def _arg_check(self, args, intervals, **kwargs):
1502
1500
1503
1501
key_time_size = args [self .name ].shape [self ._time_position ]
1504
1502
if self ._time_buffering and self ._time_size != key_time_size :
1505
- raise InvalidArgument ("Expected `time_size=%d` for runtime "
1506
- "value `%s`, found `%d` instead"
1507
- % (self ._time_size , self .name , key_time_size ))
1503
+ raise InvalidArgument (
1504
+ f"Expected `time_size={ self ._time_size } ` for runtime value "
1505
+ f"`{ self .name } `, found `{ key_time_size } ` instead"
1506
+ )
1508
1507
1509
1508
1510
1509
class SubFunction (Function ):
@@ -1533,8 +1532,8 @@ def _arg_values(self, **kwargs):
1533
1532
if self ._parent is not None and self .parent .name not in kwargs :
1534
1533
return self ._parent ._arg_defaults (alias = self ._parent ).reduce_all ()
1535
1534
elif self .name in kwargs :
1536
- raise RuntimeError ("`%s ` is a SubFunction, so it can't be assigned "
1537
- "a value dynamically" % self . name )
1535
+ raise RuntimeError (f"` { self . name } ` is a SubFunction, so it can't "
1536
+ "be assigned a value dynamically" )
1538
1537
else :
1539
1538
return self ._arg_defaults (alias = self )
1540
1539
@@ -1678,8 +1677,8 @@ def make(self, shape=None, initializer=None, allocator=None, **kwargs):
1678
1677
for n , i in enumerate (self .shape ):
1679
1678
v = i .subs (args )
1680
1679
if not v .is_Integer :
1681
- raise ValueError ("Couldn't resolve `shape[%d]=%s ` with the given "
1682
- "kwargs (obtained: `%s `)" % ( n , i , v ) )
1680
+ raise ValueError (f "Couldn't resolve `shape[{ n } ]= { i } ` with the given "
1681
+ f "kwargs (obtained: `{ v } `)" )
1683
1682
shape .append (int (v ))
1684
1683
shape = tuple (shape )
1685
1684
elif len (shape ) != self .ndim :
@@ -1706,6 +1705,6 @@ def _arg_values(self, **kwargs):
1706
1705
# Set new values and re-derive defaults
1707
1706
return new ._arg_defaults ().reduce_all ()
1708
1707
else :
1709
- raise InvalidArgument ("Illegal runtime value for `%s`" % self .name )
1708
+ raise InvalidArgument (f "Illegal runtime value for `{ self .name } `" )
1710
1709
else :
1711
- raise InvalidArgument ("TempFunction `%s ` lacks override" % self . name )
1710
+ raise InvalidArgument (f "TempFunction `{ self . name } ` lacks override" )
0 commit comments