[PIPE2D-1168] fitPfsReferenceFlux breaks Tiger Created: 22/Feb/23  Updated: 16/Jun/23  Resolved: 01/Mar/23

Status: Done
Project: DRP 2-D Pipeline
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Story Priority: Normal
Reporter: price Assignee: price
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Blocks
blocks SIM2D-151 Incorporate simulated flux standard s... Done
Relates
relates to PIPE2D-1208 Make fitPfsFluxReference even faster Done
relates to PIPE2D-1231 Reduce memory usage of fitPfsReferenc... Done
relates to PIPE2D-1238 fitPfsFluxReference should not brute-... Done

 Description   

Running fitPfsReferenceFlux on our Tiger head node trashes the machine. I am reducing the new weekly:

fitPfsReferenceFlux.py /scratch/pprice/sim2d-151/test --calib=/scratch/pprice/sim2d-151/test/CALIB --rerun=weekly/pipeline/brn/pipeline --doraise -j10 --no-versions --clobber-config --id 'visit=47^48^49^53^54^57' 'arm=b^r^n'

I suspect that the fluxmodeldata is being accessed within a tight loop, which causes a huge load on the disk.



 Comments   
Comment by price [ 23/Feb/23 ]

Moving the fluxmodeldata to a faster disk has alleviated the problem on tiger.

I took the opportunity to look at the fitPfsFluxReference code and made some observations that might help improve it moving forward:

  • Reading the 9 GB fluxModelInterpolator pickle is done in the FitPfsFluxReferenceTask init, which means it's read once at the start, and lives until everything is done. Given that it's so large, it should probably be read, used and then dumped in order to free memory.
    • The interpolator pickle is large because it contains all the spectra. Presumably that means it contains all the information necessary to reproduce the model spectra, so is it necessary to read all the spectra as well?
    • All the spectra are going into the interpolation, even though many are strongly down-weighted. I suggest using the neighbours parameter of the RBFInterpolator.
  • The calculations in FitPfsFluxReferenceTask.correctExtinction should be pre-computed: E(B-V) translates directly to A_X for each band X given R_X: A_X = R_X * E(B-V). So we can pre-compute the R_X and put it in the broadband photometry reference file.
  • The fitting algorithm seems to be brute-force: it's mapping out the entire chi^2 space, which means it reads every spectrum, even though many are effectively eliminated by the photometry (e.g., some have a broad-band photometry probability smaller than 10^-200).

Stepping back from the details of the current implementation, I think that this would go much faster with a modified algorithm:
1. Fit Teff from broad-band photometry.
2. Measure logg,m,alpha from line indices. I confess I don't know exactly how this would work, but I think logg must be a function of the width of Balmer lines (and Paschen lines, if available), and m and alpha must be a function of the equivalent width of different metal lines.
3. Measure radial velocity using the best guess parameters Teff,logg,m,alpha.
4. Create an interpolator using the (RV-corrected, LSF-convolved, whitened) spectra within a hyper-sphere of the best guess parameters Teff,logg,m,alpha +/- twice their errors. I'm guessing that linear interpolation between the closest models is sufficient, but an RBF could be used if necessary.
5. Use a non-linear minimizer (e.g., Powell's method) with the interpolator to fit the spectrum. I think this should converge fairly quickly; if not, a grid search could be done as currently, but over a much-reduced subset of parameter space.

Comment by sogo.mineo [ 27/Feb/23 ]

Thanks for the suggestions. I will think about them a few days later, once my urgent task is done.

Comment by sogo.mineo [ 06/Mar/23 ]

> All the spectra are going into the interpolation, even though many are strongly down-weighted. I suggest using the neighbours parameter of the RBFInterpolator.

I have not tried it, but I don't think any parameter will help reduce memory usage. RBFInterpolator needs all the input spectra to be on memory by nature. Yamashita-san said that we might be able to construct RBFInterpolator every time it is required, from only a few spectra around the initial guess (Teff0, logg0, m0, alpha0) – if we can find the initial guess accurately.

Comment by Takuji Yamashita [ 06/Mar/23 ]

Thank you for your suggestions about the algorithm! Mineo-san has implemented the cut-off threshold to narrow down the models after broad-band fitting in PIPE2D-1145. We can use it for the neighbours parameter. We should try it, probably after the data release this month.

It is worth a try your idea using line indices and a minimizer. Stabilizing and optimizing the current flux calibration is a priority, but we may want to start a study of your algorithm.

 

Generated at Sat Feb 10 16:03:39 JST 2024 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.