Public Access
fix serialization of numpy scalars in job XML under numpy 2
numpy 2 changed repr(np.float64(1e-06)) to 'np.float64(1e-06)', so values taken from lin_range() ended up unparsable in the job file: the result script failed with "could not convert string to float". Description items and state times are now converted to builtin types before writing.
This commit is contained in:
1 parent
ef11824f8b
commit
1fb56e20f9
2 files changed
+34
-6
No files matched your search
@@ -13,7 +13,7 @@ class StateSimple(StateBase):
|
||||
super(StateSimple, self).__init__()
|
||||
if time < 0:
|
||||
raise AssertionError("time for state is negative!")
|
||||
self.time = time
|
||||
self.time = float(time)
|
||||
self.content = content
|
||||
|
||||
def to_xml(self, indent = ""):
|
||||
@@ -190,7 +190,7 @@ class Experiment:
|
||||
|
||||
Typically only used in very special cases.
|
||||
"""
|
||||
self.state_list.append('<state time="%s">\n' % repr(time))
|
||||
self.state_list.append('<state time="%s">\n' % repr(float(time)))
|
||||
self.total_time[-1] += time
|
||||
|
||||
## End of *state_start*
|
||||
@@ -679,19 +679,19 @@ class Experiment:
|
||||
value=""
|
||||
elif type(value) is float or isinstance(value, numpy.floating):
|
||||
type_string="Float"
|
||||
value=repr(value)
|
||||
value=repr(float(value))
|
||||
elif type(value) is int or isinstance(value, numpy.integer):
|
||||
type_string="Int"
|
||||
value=repr(value)
|
||||
value=repr(int(value))
|
||||
elif type(value) is int:
|
||||
type_string="Long"
|
||||
value=repr(value)
|
||||
elif type(value) is complex or isinstance(value, numpy.complexfloating):
|
||||
type_string="Complex"
|
||||
value=repr(value)
|
||||
value=repr(complex(value))
|
||||
elif type(value) is bool or isinstance(value, numpy.bool_):
|
||||
type_string="Boolean"
|
||||
value=repr(value)
|
||||
value=repr(bool(value))
|
||||
elif type(value) in (str,):
|
||||
type_string="String"
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user