gafusion / omas

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

Error calling machine mappings with OMFITexpression #227

Closed bclyons12 closed 1 year ago

bclyons12 commented 1 year ago

If you call some of the machine mapping routines in OMFIT, but you set pulse to an OMFITexpression, then the mapping will fail. I don't know if this is the intended behavior and the omas routines should always be called with an explicit int in OMFIT or if it should be handled by omas.

An example in OMFIT:

from omas.machine_mappings.d3d import ec_launcher_active_hardware
pulse = root['SETTINGS']['EXPERIMENT']['shot']
ods = root['INPUTS']['ods'] = ODS()
ec_launcher_active_hardware(ods, pulse)

where root['SETTINGS']['EXPERIMENT']['shot'] is an OMFIT expression to get the shot number from a parent module. This gives an error:

Exception in script of module OMFIT['STEP']['CHEF']['TORAY']:
Error in "OMFIT command box #1" at line  6
    ec_launcher_active_hardware(ods, pulse)
TypeError: Cannot make MDSplus data type from type: <class 'omfit_classes.omfit_base.OMFITexpression'>
 - server: atlas.gat.com:8000
 - treename: RF
 - pulse: 158020
 - TDI: {'NUM_SYSTEMS': '.ECH.NUM_SYSTEMS'}

Press <F6> to see full error report...

Done @ 03/02/2023 19:00:39 took 0.344 s
Traceback (most recent call last):
  File "/fusion/projects/omfit-results/lyonsbc/omas/omas/omas_machine.py", line 788, in raw
    conn.openTree(self.treename, self.pulse)
  File "/fusion/projects/codes/atom/omfit_v3.x/atom_iris_test/miniconda3_unstable/lib/python3.7/site-packages/MDSplus/connection.py", line 203, in openTree
    status=self.get("TreeOpen($,$)",tree,shot)
  File "/fusion/projects/codes/atom/omfit_v3.x/atom_iris_test/miniconda3_unstable/lib/python3.7/site-packages/MDSplus/connection.py", line 253, in get
    self.__sendArg__(arg,idx,num)
  File "/fusion/projects/codes/atom/omfit_v3.x/atom_iris_test/miniconda3_unstable/lib/python3.7/site-packages/MDSplus/connection.py", line 154, in __sendArg__
    val=_data.makeData(value)
  File "/fusion/projects/codes/atom/omfit_v3.x/atom_iris_test/miniconda3_unstable/lib/python3.7/site-packages/MDSplus/mdsdata.py", line 89, in makeData
    raise TypeError('Cannot make MDSplus data type from type: %s' % (str(type(value)),))
TypeError: Cannot make MDSplus data type from type: <class 'omfit_classes.omfit_base.OMFITexpression'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/fusion/projects/omfit-results/lyonsbc/OMFIT-source/omfit/omfit_classes/OMFITx.py", line 4620, in manage_user_errors
    tmp = command(**kw)
  File "/fusion/projects/omfit-results/lyonsbc/OMFIT-source/omfit/utils_tk.py", line 1180, in GlobLoc_tk
    return py.run(_relLoc=self.namespace, _OMFITscriptsDict=False, _OMFITconsoleDict=True, noGUI=None)
  File "/fusion/projects/omfit-results/lyonsbc/OMFIT-source/omfit/omfit_classes/omfit_python.py", line 1105, in run
    result = self.__run__(**kw)
  File "/fusion/projects/omfit-results/lyonsbc/OMFIT-source/omfit/omfit_classes/omfit_python.py", line 954, in __run__
    self, userDict=kw, inputDict=_relLoc, persistentDict=OMFITconsoleDict, runDict={}, prerun=prerun, postrun=postrun
  File "/fusion/projects/omfit-results/lyonsbc/OMFIT-source/omfit/omfit_classes/omfit_python.py", line 129, in f_locked
    return f(*args, **kw)
  File "/fusion/projects/omfit-results/lyonsbc/OMFIT-source/omfit/omfit_classes/omfit_python.py", line 376, in execGlobLoc
    exec(compile(execString, filename, "exec"), GlobLoc)
  File "/local-scratch/lyonsbc/OMFIT/OMFIT_2023-02-03_18_59_27_941586/project/OMFIT command box #1", line 6, in <module>
    ec_launcher_active_hardware(ods, pulse)
  File "/fusion/projects/omfit-results/lyonsbc/omas/omas/omas_machine.py", line 578, in machine_mapping_caller
    out = f(*args, **kwargs)
  File "/fusion/projects/omfit-results/lyonsbc/omas/omas/machine_mappings/d3d.py", line 428, in ec_launcher_active_hardware
    num_systems = mdsvalue('d3d', treename='RF', pulse=pulse, TDI=query).raw()['NUM_SYSTEMS']
  File "/fusion/projects/omfit-results/lyonsbc/omas/omas/omas_machine.py", line 847, in raw
    raise _excp.__class__(str(_excp) + '\n' + '\n'.join(txt))
TypeError: Cannot make MDSplus data type from type: <class 'omfit_classes.omfit_base.OMFITexpression'>
 - server: atlas.gat.com:8000
 - treename: RF
 - pulse: 158020
 - TDI: {'NUM_SYSTEMS': '.ECH.NUM_SYSTEMS'}
bclyons12 commented 1 year ago

@jmcclena This is the issue we discussed earlier.

bclyons12 commented 1 year ago

I have confirmed that either putting an explicit int() in the call to the omas routine, or calling int() inside the omas routine both solve this. Just need to know what's most appropriate.

orso82 commented 1 year ago

@bclyons12 let's put an int() at the lowest possible level, which I think should as soon as one enters these functions: https://github.com/gafusion/omas/blob/5aced3524848d6a79d613f8b03f31f85d17f3649/omas/omas_machine.py#L66 https://github.com/gafusion/omas/blob/5aced3524848d6a79d613f8b03f31f85d17f3649/omas/omas_machine.py#L689 https://github.com/gafusion/omas/blob/5aced3524848d6a79d613f8b03f31f85d17f3649/omas/omas_machine.py#L711 https://github.com/gafusion/omas/blob/5aced3524848d6a79d613f8b03f31f85d17f3649/omas/omas_machine.py#L873

github-actions[bot] commented 1 year ago

Stale issue message

orso82 commented 1 year ago

@bclyons12 I think this got resolved, right?

jmcclena commented 1 year ago

@orso82 I don't think so. @avdeevag recently saw this using EFITtime where we avoided the error with https://github.com/gafusion/OMFIT-source/commit/45e3e7c9b8dad747c90395641a9bf9decaa7611e

orso82 commented 1 year ago

@bclyons12 fixed the issue relating to the pulse, but perhaps something similar should be done for times? https://github.com/gafusion/omas/commit/4e70f2b3d0c527aa4b8a2cf76cc83ae5b30a13bf

bclyons12 commented 1 year ago

Yes, the issue with pulse/shot being an OMFITexpression was resolved. I have not encountered a problem with time, but could absolutely see it causing a similar problem.

orso82 commented 1 year ago

@jmcclena in the example you showed https://github.com/gafusion/OMFIT-source/commit/45e3e7c9b8dad747c90395641a9bf9decaa7611e the issue is that we are calling directly the OMAS machine mapping function thomson_scattering_data(ods, shot).

Instead of doing:

from omas.machine_mappings.nstx import thomson_scattering_data
thomson_scattering_data(ods, shot)
thomson_constraint(
    ods,
    array(times),
    pressure_factor=root['SETTINGS']['PHYSICS']['Pthomson_pressure_factor'],
    error_factor=root['SETTINGS']['PHYSICS']['Pthomson_error_factor'],
    edge_r=root['SETTINGS']['PHYSICS']['Pthomson_edge_r'],
    edge_sig=root['SETTINGS']['PHYSICS']['Pthomson_edge_sig'],
)

I would suggest doing:

with ods.open("nxtx", shot):
    thomson_constraint(
        ods,
        array(times),
        pressure_factor=root['SETTINGS']['PHYSICS']['Pthomson_pressure_factor'],
        error_factor=root['SETTINGS']['PHYSICS']['Pthomson_error_factor'],
        edge_r=root['SETTINGS']['PHYSICS']['Pthomson_edge_r'],
        edge_sig=root['SETTINGS']['PHYSICS']['Pthomson_edge_sig'],
    )

which would handle the pulse/shot being an OMFITexpression (among other things).

github-actions[bot] commented 1 year ago

Stale issue message