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

[Automation] Computation time increases with every image done, regardless of starting z position. It's some issue with calling .propagate again for new frames without restarting. #56

Open
LtqxWYEG opened this issue Oct 10, 2024 · 0 comments

Comments

@LtqxWYEG
Copy link

LtqxWYEG commented Oct 10, 2024

I have been making a program for creating a animation. Currently, my code is thus:
(It starts randomly on 17cm, because I've been executing multiple .py programs for cheap-and-easy multithread "support", and this is one of 11.)

... python
diffractsim.set_backend("CPU")  # because I am blessed with a AMD GPU
...
irrelevant stuff, config etc....
...
F = PolychromaticField(
        spectrum= 1 * cf.illuminant_d65, extent_x= 30 * mm, extent_y= 30 * mm, Nx= 2400, Ny= 2400,
        spectrum_size= 400, spectrum_divisions= 400)  # by default spectrum has a size of 400. If new size, we interpolate

# Add (camera) lens with focal length f?
F.add(Lens(f= 80*cm))
# propagate field to z position or something
F.propagate(17*cm)

count = 17
steps = 1
distance = 24
while count <= distance:
    # plot colors (reconstructed image) at z = 80*cm (Fourier plane)
    rgb = F.get_colors()
    #F.plot_colors(rgb, figsize = (16, 16))
    if count < 10:
        imagefile = "./animation/frame_000" + str(count) + ".png"
    elif count < 100:
        imagefile = "./animation/frame_00" + str(count) + ".png"
    elif count < 1000:
        imagefile = "./animation/frame_0" + str(count) + ".png"
    elif count < 10000:
        imagefile = "./animation/frame_" + str(count) + ".png"
    print(imagefile + " done")
    F.save_plot(rgb, figsize= (16, 16), path= imagefile, tight= True)
    F.propagate(0.01)  # In meters --- trying to fix floating point imprecision, resulting in "8.000000000001 cm". --- Didn't work
    count += 1

(
    ffmpeg  # pip install ffmpeg-python // Put ffmpeg.exe in same folder (or maybe in a path variable)
    .input('./animation/frame_%04d.png', framerate=24)  # Note: pattern_type='glob' and "*" wildcard only works in linux
    .output('./animation/animation.mp4')
    .run(overwrite_output=True)
)

results in:

100% |########################################################################|
Computation Took 2611.535078525543
./animation/frame_0017.png done
100% |########################################################################|
Computation Took 3317.8141679763794
./animation/frame_0018.png done
100% |########################################################################|
Computation Took 4478.07142162323
./animation/frame_0019.png done
100% |########################################################################|
Computation Took 5599.06679558754
./animation/frame_0020.png done
...

same with a simulation with very bad quality:

100% |########################################################################|
Computation Took 9.391652345657349
./animation/frame2_0002.png done
100% |########################################################################|
Computation Took 13.946731328964233
./animation/frame2_0003.png done
100% |########################################################################|
Computation Took 18.43080425262451
./animation/frame2_0004.png done
100% |########################################################################|
Computation Took 22.2238667011261
./animation/frame2_0005.png done
100% |########################################################################|
Computation Took 26.535937309265137
./animation/frame2_0006.png done
100% |########################################################################|
Computation Took 30.913010120391846
./animation/frame2_0007.png done
100% |########################################################################|
Computation Took 35.39558458328247
./animation/frame2_0008.png done
100% |########################################################################|
Computation Took 39.53465270996094
./animation/frame2_0009.png done
100% |########################################################################|
Computation Took 44.112547397613525
./animation/frame2_0010.png done
100% |########################################################################|
Computation Took 47.73128795623779
./animation/frame2_0011.png done
100% |########################################################################|
Computation Took 51.79185438156128
./animation/frame2_0012.png done

Why does the computation time increase so much - in all 11 programs I have running at the same time, starting from a different point in z, all taking similar time for their respective first, second, third ... frame.
If I would start a new instance for frame_0020.png now, it would only take about 2611s, not 5599 seconds.
That's not a cumulative time measurement function, btw. Every comp takes progressively longer.

There must be some issue with calling .propagate again after every computation.

How did you, @rafael-fuente, make your animations? Please share :)
kind regards

@LtqxWYEG LtqxWYEG changed the title [Automation] Computation increases with every image done, regardless of starting z position. It's some issue with calling .propagate again for new frames without restarting. [Automation] Computation time increases with every image done, regardless of starting z position. It's some issue with calling .propagate again for new frames without restarting. Oct 10, 2024
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

1 participant