Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid timeout on SRW frame request for large files #6022

Closed
moellep opened this issue Jun 26, 2023 · 2 comments
Closed

Avoid timeout on SRW frame request for large files #6022

moellep opened this issue Jun 26, 2023 · 2 comments
Assignees
Milestone

Comments

@moellep
Copy link
Member

moellep commented Jun 26, 2023

The simulation below creates large intermediary wavefront files during the simulation process.

When the sim_frame() request is made by the client, the wavefront is read into memory on the server, and then converted into an appropriate SRW output file based on the characteristic requested and written to disk. Then that datafile is read and scaled using scipy.ndimage and returned to the client. The request takes too long and can cause a time-out on the server, or potentially on the client.

Instead, and extra step should be take to make a copy of the wavefront during the simulation process, and reduce the scale at that point. Then the sim_frame() request will be working with a much reduced set of data, and should complete quickly.

https://www.sirepo.com/srw#/beamline/D093hGau

@moellep moellep added this to the support milestone Jun 26, 2023
@mkeilman
Copy link
Contributor

I'd like to check my approach with some pseudo-code before I get too far. In template/srw.py._generate_srw_main:

for n in beamline_info.names:
    ...
    content.append("v.ws_fnep = '{}'".format(prev_wavefront))
    content.append("op = set_optics(v, names, {})".format(is_last_watch))
    if not is_last_watch:
        content.append("srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)")
        # vvv NEW vvv
        content.append("data = pickle load  prev_wavefront file")
        content.append("scipy scale data")
        content.append("pickle save scaled data")
        ...

where "scipy scale data" would emulate _resize_report (which would then be unnecessary?). Do I have the gist of it?

@moellep
Copy link
Member Author

moellep commented Jul 20, 2023

Yes, I think so. We want to keep the input pickle file which SRW uses unscaled, but once it is done with it, we should scale it if it is huge. The sim_frame is looking for the files to become available, so adding a suffix (like "-preprocessed") could keep them from being visible before they have been resized.

So if the generated code has many watchpoints could look like this

    v.ws = True
    v.ws_fne = 'initial-preprocessed.pkl'
    names = ['Aperture','Aperture_CM','CM','CM_M2','M2','M2_Before_Toroid','Before_Toroid']
    v.ws_fnep = 'wid-20-preprocessed.pkl'
    op = set_optics(v, names, False)
    srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)

    # 'initial-preprocessed.pk' can be resized into 'initial.pkl'

    names = ['Toroid','After_Toroid']
    v.ws_fnei = 'wid-20-preprocessed.pkl'
    v.ws_fnep = 'wid-21-preprocessed.pkl'
    op = set_optics(v, names, False)
    srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)

    # 'wid-20-preprocessed.pkl' can be resize now into 'wid-20.pkl'
    # and 'wid-20-preprocessed.pkl' can be deleted

    names = ['After_Toroid_Before_SSA','Before_SSA']
    v.ws_fnei = 'wid-21-preprocessed.pkl'
    v.ws_fnep = 'wid-17-preprocessed.pkl'
    op = set_optics(v, names, True)
    v.wm = False
    srwl_bl.SRWLBeamline(_name=v.name).calc_all(v, op)

    # 'wid-21-preprocessed.pkl' can be resize now into 'wid-21.pkl'
    # and 'wid-21-preprocessed.pkl' can be deleted
    # the same for the final wavefront 'wid-17'

mkeilman pushed a commit that referenced this issue Jul 21, 2023
mkeilman pushed a commit that referenced this issue Jul 21, 2023
mkeilman pushed a commit that referenced this issue Jul 22, 2023
mkeilman pushed a commit that referenced this issue Jul 24, 2023
mkeilman pushed a commit that referenced this issue Jul 25, 2023
mkeilman pushed a commit that referenced this issue Jul 25, 2023
mkeilman pushed a commit that referenced this issue Jul 26, 2023
mkeilman pushed a commit that referenced this issue Jul 27, 2023
mkeilman pushed a commit that referenced this issue Jul 27, 2023
mkeilman pushed a commit that referenced this issue Jul 27, 2023
mkeilman pushed a commit that referenced this issue Jul 27, 2023
mkeilman pushed a commit that referenced this issue Jul 27, 2023
mkeilman pushed a commit that referenced this issue Jul 28, 2023
mkeilman pushed a commit that referenced this issue Jul 28, 2023
mkeilman pushed a commit that referenced this issue Jul 31, 2023
mkeilman pushed a commit that referenced this issue Jul 31, 2023
mkeilman pushed a commit that referenced this issue Jul 31, 2023
mkeilman pushed a commit that referenced this issue Jul 31, 2023
mkeilman pushed a commit that referenced this issue Jul 31, 2023
mkeilman pushed a commit that referenced this issue Aug 1, 2023
mkeilman pushed a commit that referenced this issue Aug 1, 2023
mkeilman pushed a commit that referenced this issue Aug 1, 2023
mkeilman pushed a commit that referenced this issue Aug 1, 2023
mkeilman pushed a commit that referenced this issue Aug 1, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 9, 2023
mkeilman pushed a commit that referenced this issue Aug 10, 2023
mkeilman pushed a commit that referenced this issue Aug 10, 2023
mkeilman pushed a commit that referenced this issue Aug 10, 2023
mkeilman pushed a commit that referenced this issue Aug 10, 2023
mkeilman pushed a commit that referenced this issue Aug 10, 2023
mkeilman pushed a commit that referenced this issue Aug 10, 2023
mkeilman pushed a commit that referenced this issue Aug 11, 2023
mkeilman pushed a commit that referenced this issue Aug 26, 2023
mkeilman pushed a commit that referenced this issue Aug 29, 2023
mkeilman pushed a commit that referenced this issue Aug 29, 2023
mkeilman pushed a commit that referenced this issue Aug 30, 2023
mkeilman pushed a commit that referenced this issue Aug 30, 2023
mkeilman pushed a commit that referenced this issue Aug 30, 2023
mkeilman pushed a commit that referenced this issue Aug 30, 2023
mkeilman pushed a commit that referenced this issue Aug 30, 2023
mkeilman pushed a commit that referenced this issue Aug 30, 2023
moellep added a commit that referenced this issue Sep 16, 2023
- clean up preprocess files after execution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants