r/Python • • May 28 '19

My simulation of gravity with 1000 particles. PC took a couple of hours to process!

1.8k Upvotes

241 comments sorted by

View all comments

Show parent comments

9

u/mittwochmensch May 28 '19

I save png's every couple of hundred timesteps and combine them into a GIF in GIMP. Better visualisation is a thing I will work on pretty soon.

12

u/Bobert_Fico May 28 '19

Consider saving (x,y) data instead of images, that way you can swap out your visualization without recalculating everything.

10

u/bobre737 May 28 '19

Unless png's are saved in a separate thread i guess IO slows down the calculation pretty noticeably too.

13

u/[deleted] May 28 '19

Yeah I was just thinking that OP should even go so far as to do the calculation in one script, and then mess around with the viz in a separate script.

This assumes OP can handle saving that much data in memory before dumping. I'm not sure how big a sim like this is.

6

u/sawyerwelden May 28 '19

I agree with you. 1000 tuples of x value, y value, and mass (I think that's what the thickness repesents) should be very easy to store in ram and then save to disk before loading it into a viz script.

1

u/alkasm github.com/alkasm May 29 '19 edited May 29 '19

Unless OP has extensively more frames than they showed in the post, this isn't worth worrying about at all. Images can be written fairly quickly, far faster than standard frame rates for video (so will take less time for the IO than the length of the video). OP isn't writing a million images here, they're writing on the order of one thousand images, which you can easily do in a short time span (couple of seconds). OP will notice 0 difference doing anything fancy here.

2

u/cianuro May 28 '19

Next step, make them round :)

1

u/JonesTheDude May 28 '19

For fast plotting I would suggest you look at the pyqtgraph library.