ngnrsaa / qflex

Flexible Quantum Circuit Simulator (qFlex) implements an efficient tensor network, CPU-based simulator of large quantum circuits.
Apache License 2.0
97 stars 24 forks source link

Temp file usage causing exceptions and disk storage leaks - Patch attached #289

Closed kkissell closed 4 years ago

kkissell commented 4 years ago

The Cirq bindings and python tests used python tempfile constructs incorrectly, causing exceptions when the deconstructor tries to use the os bindings after the global os object is freed, and one of the test modules simply leaked files. Fixing this cleanly touches several files, though mostly with a simple substiution once the data_storage_interface fix is done. Zipped patch file attached. 0001-Changes-to-temporary-storage-management-to-fix-error.patch.zip

alexandrupaler commented 4 years ago

Thank you. Can you please create a pull request with the patch? Is the core of the solution to use a directory for the file?

self._tdir = tempfile.TemporaryDirectory()
self.storage = tempfile.NamedTemporaryFile(mode='w',dir=self._tdir.name, delete=False)
kkissell commented 4 years ago

Not sure what the actual mechanics are to "create a pull request with the patch". I'm doing my work on Linux instances in Google Cloud, starting with an anonymous git clone onto the system, doing the commit to the local repository, generating a patch from that, then scping it to my Mac where I can log directly into github. Most of my work with git as a maintainer was for the kernel, where we lobbed patch files up the line.

I mucked with this for quite a while looking for a clean fix. The key was, as you say, to use a self-deleting TemporaryDirectory populated with non-self-deleting temporary files.

/K.

On Sun, Apr 12, 2020 at 2:08 PM alexandrupaler notifications@github.com wrote:

Thank you. Can you please create a pull request with the patch? Is the core of the solution to use a directory for the file?

self._tdir = tempfile.TemporaryDirectory() self.storage = tempfile.NamedTemporaryFile(mode='w',dir=self._tdir.name, delete=False)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ngnrsaa/qflex/issues/289#issuecomment-612676192, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNZVF5QP6YWTMLXQOSXQNDRMIUVRANCNFSM4MGRYMLQ .

-- Kevin D. KISSELL Technical Director, HPC and Quantum Google Cloud Office of the CTO

alexandrupaler commented 4 years ago

No problem. Thank you again. I created #290 where I applied your patch.

alexandrupaler commented 4 years ago

290 merge should have solved this issue