gafusion / omas

Ordered Multidimensional Array Structure
http://gafusion.github.io/omas
MIT License
32 stars 15 forks source link

consistency_check in omas_environment #80

Closed smithsp closed 4 years ago

smithsp commented 4 years ago

Is the following supposed to work?

import omas
ods = omas.ODS()
with omas.omas_environment(ods, consistency_check=False):
    ods['nbi']['unit']['this_path_does_not_exist'] = 2

I get the error:

Traceback (most recent call last):
  File "test_omas.py", line 4, in <module>
    ods['nbi']['unit']['this_path_does_not_exist'] = 2
  File "/fusion/projects/codes/atom/omfit_py3/atom_SATURN_GCC/miniconda3/lib/python3.6/contextlib.py", line 88, in __exit__
    next(self.gen)
  File "/home/smithsp/omas/omas/omas_physics.py", line 1007, in omas_environment
    setattr(ods, item, bkp_args[item])
  File "/home/smithsp/omas/omas/omas_core.py", line 371, in consistency_check
    self.getraw(item).consistency_check = consistency_value_propagate
  File "/home/smithsp/omas/omas/omas_core.py", line 371, in consistency_check
    self.getraw(item).consistency_check = consistency_value_propagate
  File "/home/smithsp/omas/omas/omas_core.py", line 358, in consistency_check
    raise LookupError(underline_last(text, len('LookupError: ')) + '\n' + options)
LookupError: Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^
A numerical index is needed with n>=0

when the context exits.

smithsp commented 4 years ago

How about this?

import omas
ods = omas.ODS()
ods.consistency_check = 'warn'
ods['nbi']['unit']['this_path_does_not_exist'] = 2
ods.consistency_check = True

I get the output:

Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
Traceback (most recent call last):
  File "test_omas.py", line 5, in <module>
    ods.consistency_check = True
  File "/home/smithsp/omas/omas/omas_core.py", line 371, in consistency_check
    self.getraw(item).consistency_check = consistency_value_propagate
  File "/home/smithsp/omas/omas/omas_core.py", line 371, in consistency_check
    self.getraw(item).consistency_check = consistency_value_propagate
  File "/home/smithsp/omas/omas/omas_core.py", line 358, in consistency_check
    raise LookupError(underline_last(text, len('LookupError: ')) + '\n' + options)
LookupError: Not a valid IMAS 3.25.0 location: nbi.unit.this_path_does_not_exist
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^
A numerical index is needed with n>=0
smithsp commented 4 years ago

(These were done on the fix_consistency_check branch.)

orso82 commented 4 years ago

fixed with #81

smithsp commented 4 years ago

@orso82, these results actually appeared even on the branch of #81 , so #81 did not fix these problems.

orso82 commented 4 years ago

I read better now what this issue was about. The OMAS behavior was as intended. No ODS with consistency_check=True can violate the IMAS schema. As you pointed out the error was raised when you get out of the omas_environment with consistency_check=False, which is the expected behavior. I have improved the error message to make it clearer that this a feature and not a bug.

smithsp commented 4 years ago

Note that there is some coding in OMFIT that is similar to what I tried with the context, and that should probably be modified or removed.