radiasoft / sirepo

Sirepo is a framework for scientific cloud computing. Try it out!
https://sirepo.com
Apache License 2.0
64 stars 32 forks source link

srw: python: Incorrect Magnetic Field Container structure #656

Closed robnagler closed 6 years ago

robnagler commented 7 years ago

Running the run.py from the archive results in:

python run.py
Electron trajectory calculation ... Traceback (most recent call last):
  File "run.py", line 225, in <module>
    main()
  File "run.py", line 221, in main
    srwl_bl.SRWLBeamline(_name=v.name, _mag_approx=mag).calc_all(v, op)
  File "/home/vagrant/.pyenv/versions/2.7.10/lib/python2.7/site-packages/srwl_bl.py", line 1495, in calc_all
    _fname = os.path.join(_v.fdir, _v.tr_fn) if(len(_v.tr_fn) > 0) else '')
  File "/home/vagrant/.pyenv/versions/2.7.10/lib/python2.7/site-packages/srwl_bl.py", line 553, in calc_el_trj
    srwl.CalcPartTraj(partTraj, magToUse, arPrecPar)
RuntimeError: Incorrect Magnetic Field Container structure

Attached is the example I used.

Tabulated Undulator Example.zip

mrakitin commented 7 years ago

If you unpack the contents of the archive with the magnetic measurement files to the current dir, you have to specify

    ['und_mdir', 's', './', 'name of magnetic measurements sub-folder'],

instead of

    ['und_mdir', 's', '', 'name of magnetic measurements sub-folder'],

Earlier I met this problem. The logic in SRW is a bit complicated - https://github.com/radiasoft/SRW-light/blob/master/env/work/srw_python/srwl_bl.py#L1381:

        #---setup magnetic field: undulator, tabulated (e.g. measured) magnetic field 
        magnMeasDirExists = False
        if hasattr(_v, 'und_mdir'):
            self.dir_magn_meas = _v.und_mdir
            if(len(self.dir_magn_meas) > 0): magnMeasDirExists = True
        magnMeasSumFileExists = False
        if hasattr(_v, 'und_mfs'):
            self.fn_magn_meas_sum = _v.und_mfs
            if(magnMeasDirExists):
                testPath = os.path.join(os.getcwd(), self.dir_main, self.dir_magn_meas, self.fn_magn_meas_sum)
                magnMeasSumFileExists = os.path.exists(testPath) 

The length of the magnMeasDirExists variable should be non-zero so that the magnMeasSumFileExists flag is set to True.

robnagler commented 7 years ago

I think this should work "out of the box", that is, when the archive is unpacked, the example should run in the mode it was intended (with the file).

mrakitin commented 7 years ago

That's a good expectation :-). Which archive are you talking about? The packed magnetic measurements are not supported by SRW - it currently requires a separate set of unpacked files.

I can update srwlib.py to process the case of the files without an additional folder und_mdir correctly.

robnagler commented 7 years ago

I think the exported Python should do whatever template.srw.MagnMeasZip does.

I don't see this as a priority, just wanted to get it documented.

mrakitin commented 7 years ago

Yes, that's a good point. I'll suggest to include it to SRW.

robnagler commented 7 years ago

We could also just embed some code in the python source that's output.

mrakitin commented 7 years ago

That's a good temporary solution before the related code is ported from Sirepo to SRW in case the tabulated undulator is used (it should not be there in case it's an ideal undulator or a gaussian beam).

moellep commented 6 years ago

This was fixed with b3c7f8f.