dkriegner / xrayutilities

xrayutilities - a package with useful scripts for X-ray diffraction physicists
http://xrayutilities.sourceforge.io
GNU General Public License v2.0
81 stars 29 forks source link

Implementation of multiprocessing for simpack.DynamicalModel #140

Open VeryBitter opened 1 year ago

VeryBitter commented 1 year ago

Hello I am a new and happy user of xrayutities, for high resolution omega-2theta scans. My scans extend over several degrees since I analyse GaAs/AlAs SL with period from 20 to 200 nm. Calculations within the DynamicalModel take quite a while, and it would be great to have multiprocessing features as for the powder model. Is that something that could be implemented easily?

Thanks a lot for making rayutilities available open-source, thanks for this great work.

dkriegner commented 1 year ago

How many periods/layers you have in your superlattice? Can you provide an example script and specify what "quite a while" means?

I need to think about the possibilities of parallelization, but I think it's not as easy as in PowderModel. It might be actually easier in this case to look into numexpr.

VeryBitter commented 1 year ago

Thanks for you very fast answer. 555 periods ! I know its a lot (and relaxation may occur). I will have look to numexpr.

dkriegner commented 1 year ago

yes 555 is a lot and the main loop in DynamicalModel goes over the layers and this is one which I think can't be parallelized, but its execution (loop body) could likely be optimized (maybe by numexpr). Any pull requests/patches are certainly welcome.

VeryBitter commented 1 year ago

Hi Dominique back to this topic. I found out that the Darwin model was much faster when dealing with large superlattices. Is it related to the fact that every single layer produced by the loop has its own fitting parameters in the dynamical model? Maybe a superlattice layer model could be implemented, so that the fitting parameters would remain the same for each identical layer of the loop. Not sure I am clear... sorry. And not sure I have the skills to code it... sorry.

dkriegner commented 1 year ago

I don't know why Darwin model could be faster. But I think linking the parameters in a superlattice is already possible by using lmfit features. Basically in the same way as you do in your new example. You have to basically set the parameter to be equal to a different one. In this way all equal layers in a super lattice can be made to be represented by one parameter

See https://github.com/dkriegner/xrayutilities/blob/0af8aa76b60ec5b9b1b14ab92389bd773aac02dd/examples/simpack_xrd_dyn_AlGaAs.py#L118-L120

Note: It would maybe be good for this to be a bit more usable to give a way to during construction of a Layer define a specific name: A change for this is required in this method I guess: https://github.com/dkriegner/xrayutilities/blob/0af8aa76b60ec5b9b1b14ab92389bd773aac02dd/lib/xrayutilities/simpack/smaterials.py#L50-L66

Currently the names of the layers are automatically generated from the underlaying materials name. An optional keyword argument in the mentioned function would likely be better and one can still fall back to using the materials name if nothing is specified.

dkriegner commented 1 year ago

Currently the names of the layers are automatically generated from the underlaying materials name. An optional keyword argument in the mentioned function would likely be better and one can still fall back to using the materials name if nothing is specified.

169 picks up this idea and implements it.