BQSKit / bqskit

Berkeley Quantum Synthesis Toolkit
Other
106 stars 31 forks source link

Compiler Call raising an issue #213

Open mwalidcharrwi opened 5 months ago

mwalidcharrwi commented 5 months ago

Hi,

I have been calling the compiler call after passing a workflow to it and the error is as follows:

Exception ignored in: <function Compiler.del at 0x7f966cdc8430> Traceback (most recent call last): File "./conda/envs/quantum-venv/lib/python3.10/site-packages/bqskit/compiler/compiler.py", line 227, in del TypeError: 'NoneType' object is not callable

alonkukl commented 5 months ago

Hi,

Can you please share the workflow you are trying to run?, or maybe even a minimal reproducible code?

Alon

edyounis commented 5 months ago

@alonkukl Thanks for responding so quickly! This issue arose during a meeting, and I know the details. I will be looking into this shortly.

edyounis commented 5 months ago

@mwalidcharrwi Are you importing or using atexit directly in your code at all? I know you might not want to share your code publically, but can you put it in a private repo and provide access to me?

mwalidcharrwi commented 5 months ago

@edyounis @alonkukl thanks for your response no there is no atexit imported in the code. Only bqskit.passes and bqskit.compiler (compiler and compilation task) is imported. I will do that and share it with you.

mwalidcharrwi commented 5 months ago

@edyounis I sent you an invitation for the private repository with the script uploaded

edyounis commented 3 months ago

From the python docs:

__del__() can be executed during interpreter shutdown. As a consequence, the global variables it needs to access (including other modules) may already have been deleted or set to None. Python guarantees that globals whose name begins with a single underscore are deleted from their module before other globals are deleted; if no other references to such globals exist, this may help in assuring that imported modules are still available at the time when the del() method is called.

It seems like the atexit module is being deleted before the compiler is being finalized causing the atexit.register to become None. This is definitely a bug, and we should reconsider the use of __del__ in the Compiler class.

After looking at your code, @mwalidcharrwi, I see that you do not call compiler.close() or use the Compiler in a context manager. To avoid this issue currently, you should ensure to cleanup the compiler resource either with the close method, or by using it in a with block.

mwalidcharrwi commented 3 months ago

I will consider adding that to the code I shared. Thanks for the recommendation @edyounis

However, I've added the compiler.close() to the BQSKIT workflow that we had setup previously and the same issue is encountered but occasionally compared to the code shared.

Just to give you a guide for the algorithm:

compiler = compiler()

workflow = BQSKIT_workflow 

wokflow_output = compiler.compile()

compiler.close()
edyounis commented 3 months ago

Yeah there's definitely still an issue here, the __del__ finalizer can be problematic.

edyounis commented 3 months ago

@mwalidcharrwi Can you check if the commit 1004c05 fixed this issue? I am unable to reproduce locally. You may want to checkout the runtime-upgrades branch in #237 PR to test. This branch is very much active development, so I don't recommend using it other than testing if the issue is fixed.