quil-lang / qvm

The high-performance and featureful Quil simulator.
Other
411 stars 57 forks source link

Catch heap exhaustion for LISP-ALLOCATION #257

Closed notmgsk closed 4 years ago

notmgsk commented 4 years ago

Heap exhaustion errors aren't reported politely to pyquil, instead we see something like

RemoteDisconnected: Remote end closed connection without response

With this PR a more helpful error message is provided.

stylewarning commented 4 years ago

I don't think this will be very robust. I'd rather check there's enough free space before allocating the vector, and doing this as a last resort.

stylewarning commented 4 years ago

To add to my previous comment, sometimes an error is signaled, sometimes not. Running out of memory is a really tough situation. For the most part, memory will run out because a request is simply outrageous. Sometimes, there might not even be enough memory to handle the error itself.

I'm happy for an alternative viewpoint / a test of some sort.

notmgsk commented 4 years ago

It isn't robust, agreed. My original thought was also to see if enough memory was available before trying to allocate. I think I avoided doing that because I wasn't sure how to accurately calculate the memory required for a given request or how to ask SBCL how much memory is free. Please don't suggest (room) 😭

stylewarning commented 4 years ago

I'd suggest the following:

Create a function (allocation-will-likely-fail-p num-bytes)

Ask SBCL folks what the best way to implement this is.

#+sbcl the implementation

#-sbcl nil otherwise

Do a (when (allocation-... ...) (error ...))

How does that sound?