If None value is assigned as default, for any attribute under the Parameters class an ambiguous error is generated
Created originally on Bitbucket by avmo (Ashwin Vishnu)
In the old Fluiddyn.simul implementation it was OK to put a None value. Not anymore?
How to reproduce the error
For eg, let's say I wanted eta_max = None as follows:
#!python
def _complete_params_with_default(cls, params):
super(InitFieldsWave, cls)._complete_params_with_default(params)
params.init_fields._set_child(cls.tag, attribs={
'eta_max': None,
'ikx': 2})
But if I do so, while writing these parameters into a hdf5 file an ambiguous error is generated, which I traced to line number 300 in the following function:
#!python
285 def _save_as_hdf5(self, path_file=None, hdf5_object=None,
286 hdf5_parent=None):
287 """Save in a hdf5 file."""
288
289 if hdf5_parent is not None:
290 hdf5_object = hdf5_parent.create_group(self._tag)
291
292 if hdf5_object is None:
293 if path_file is None or not path_file.endswith('.h5'):
294 path_file = os.path.join(path_file, self._tag + '.h5')
295 with H5File(path_file, 'w') as f:
296 f.attrs.create('_tag', self._tag)
297 self._save_as_hdf5(hdf5_object=f)
298 elif path_file is None:
299 for key in self._attribs:
300 hdf5_object.attrs.create(key, self.__dict__[key])
301 for key in self._tag_children:
302 group = hdf5_object.create_group(key)
303 self.__dict__[key]._save_as_hdf5(hdf5_object=group)
The error stack looks like this:
#!python
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/avmo/src/test.py in <module>()
21 params.output.periods_plot.phys_fields = 0.0
22 params.preprocess.enable = True
---> 23 sim = Simul(params)
24 sim.time_stepping.start()
25 sim.output.phys_fields.animate()
/home/avmo/src/geofluiddyn/fluidsim/solvers/sw1l/solver.pyc in __init__(self, params)
57 params.kd2 = params.f**2/params.c2
58
---> 59 super(Simul, self).__init__(params)
60
61 if mpi.rank == 0:
/home/avmo/src/geofluiddyn/fluidsim/base/solvers/base.pyc in __init__(self, params)
128
129 # complete the initialisation of the object output
--> 130 self.output.init_with_oper_and_state()
131
132 # preprocess flow parameters
/home/avmo/src/geofluiddyn/fluidsim/base/output/base.pyc in init_with_oper_and_state(self)
330 # self.rotfft_from_vecfft = oper.rotfft_from_vecfft
331
--> 332 super(OutputBasePseudoSpectral, self).init_with_oper_and_state()
333
334
/home/avmo/src/geofluiddyn/fluidsim/base/output/base.pyc in init_with_oper_and_state(self)
215
216 if self.sim.state.is_initialized:
--> 217 self.init_with_initialized_state()
218
219 def init_with_initialized_state(self):
/home/avmo/src/geofluiddyn/fluidsim/base/output/base.pyc in init_with_initialized_state(self)
237 if mpi.rank == 0:
238 print(Class, Class._tag)
--> 239 self.__dict__[Class._tag] = Class(self)
240
241 print_memory_usage(
/home/avmo/src/geofluiddyn/fluidsim/base/output/increments.pyc in __init__(self, output)
501
502 def __init__(self, output):
--> 503 super(IncrementsSW1L, self).__init__(output)
504 params = output.sim.params
505 self.c2 = params.c2
/home/avmo/src/geofluiddyn/fluidsim/base/output/increments.pyc in __init__(self, output)
69 period_save=params.output.periods_save.increments,
70 has_to_plot_saved=params.output.increments.HAS_TO_PLOT_SAVED,
---> 71 dico_arrays_1time=dico_arrays_1time)
72
73 def init_online_plot(self):
/home/avmo/src/geofluiddyn/fluidsim/base/output/base.pyc in __init__(self, output, name_file, period_save, period_plot, has_to_plot_saved, dico_arrays_1time)
378
379 if self.period_save != 0.:
--> 380 self.init_files(dico_arrays_1time)
381
382 def init_path_files(self):
/home/avmo/src/geofluiddyn/fluidsim/base/output/base.pyc in init_files(self, dico_arrays_1time)
390 if not os.path.exists(self.path_file):
391 self.create_file_from_dico_arrays(
--> 392 self.path_file, dico_results, dico_arrays_1time)
393 self.nb_saved_times = 1
394 else:
/home/avmo/src/geofluiddyn/fluidsim/base/output/base.pyc in create_file_from_dico_arrays(self, path_file, dico_matrix, dico_arrays_1time)
450 f.attrs['name_run'] = self.output.name_run
451
--> 452 self.sim.info._save_as_hdf5(hdf5_parent=f)
453
454 times = np.array([self.sim.time_stepping.t], dtype=np.float64)
/home/avmo/src/fluiddyn/fluiddyn/util/paramcontainer.pyc in _save_as_hdf5(self, path_file, hdf5_object, hdf5_parent)
301 for key in self._tag_children:
302 group = hdf5_object.create_group(key)
--> 303 self.__dict__[key]._save_as_hdf5(hdf5_object=group)
304 else:
305 raise ValueError('If hdf5_object is not None,'
/home/avmo/src/fluiddyn/fluiddyn/util/paramcontainer.pyc in _save_as_hdf5(self, path_file, hdf5_object, hdf5_parent)
301 for key in self._tag_children:
302 group = hdf5_object.create_group(key)
--> 303 self.__dict__[key]._save_as_hdf5(hdf5_object=group)
304 else:
305 raise ValueError('If hdf5_object is not None,'
/home/avmo/src/fluiddyn/fluiddyn/util/paramcontainer.pyc in _save_as_hdf5(self, path_file, hdf5_object, hdf5_parent)
301 for key in self._tag_children:
302 group = hdf5_object.create_group(key)
--> 303 self.__dict__[key]._save_as_hdf5(hdf5_object=group)
304 else:
305 raise ValueError('If hdf5_object is not None,'
/home/avmo/src/fluiddyn/fluiddyn/util/paramcontainer.pyc in _save_as_hdf5(self, path_file, hdf5_object, hdf5_parent)
298 elif path_file is None:
299 for key in self._attribs:
--> 300 hdf5_object.attrs.create(key, self.__dict__[key])
301 for key in self._tag_children:
302 group = hdf5_object.create_group(key)
/scratch/avmo/opt/mypy/lib/python2.7/site-packages/h5py/_hl/attrs.pyc in create(self, name, data, shape, dtype)
114
115 if shape is None:
--> 116 raise ValueError('At least one of "shape" or "data" must be given')
117
118 data = data.reshape(shape)
Is this functionality intended or accidental?