• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Question How do you develop python classes that contains computationally expensive code?

yhelothar

Lifer
So I'm writing a class that contains a couple of methods that need to be run in succession. Some of the earlier methods are computationally expensive and can take 5+ minutes to run.
If I want to test code in the later methods, I need to re-instantiate the object with the modified code, then re-run all of the methods, and thus taking a long time.
If the methods were in functions instead of being within a class, the outputs of each function would be stored in memory so I can just input those outputs to the function I'm developing. It makes rapid prototyping really quick and easy. What's the best way to develop classes to afford that same prototyping-testing feedback loop ability?
 
I suggest you get pickled! :beercheers: Wait, that didn't come out right.

I suggest you get your class pickled! Wait, that sounds worse. 😱

I suggest you pickle your class. Hm, still sounds weird, but I'll go with it. 😉

What I mean to suggest is that you set up your class, pickle it, and save it to be used as test data later.

Note that this could also be an opportunity to set up your code to have a checkpoint - a point where the current state of the computation is saved into a file. You can then use that file to restart computation from that point if something unexpected happens, like Windows crashing.
 
I suggest you get pickled! :beercheers: Wait, that didn't come out right.

I suggest you get your class pickled! Wait, that sounds worse. 😱

I suggest you pickle your class. Hm, still sounds weird, but I'll go with it. 😉

What I mean to suggest is that you set up your class, pickle it, and save it to be used as test data later.

Note that this could also be an opportunity to set up your code to have a checkpoint - a point where the current state of the computation is saved into a file. You can then use that file to restart computation from that point if something unexpected happens, like Windows crashing.
Great idea. You got me out of this pickle with the pickle!
 
Back
Top