Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when the number of iterations is 0 #130

Open
koffie opened this issue Mar 13, 2023 · 3 comments
Open

Segmentation fault when the number of iterations is 0 #130

koffie opened this issue Mar 13, 2023 · 3 comments
Assignees

Comments

@koffie
Copy link

koffie commented Mar 13, 2023

We ran the complete testsuite of qxbackend with qxecelarator 0.6.2 and one testcase caused qxelarator to produce a segmentation fault. A minimal example to reproduce this is the following:

from qxelarator import QX
qx = QX()
qx.set_string("""version 1.0
qubits 2
.test
    h q[1]
""")
result_raw = qx.execute(0)

Running this gives:

Number of runs is 0
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

It would be nice if an actual python error was raised instead of a segmentation fault.

I.e. if one runs:

result_raw = qx.execute(-1)

instead one does get an error that can be caught by python and handled appriopriately

Traceback (most recent call last):
  File "/code/qutech/qx-backend/.venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3442, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-9078becc5ff9>", line 9, in <module>
    result_raw = qx.execute(-1)
  File "/code/qutech/qx-backend/.venv/lib/python3.9/site-packages/qxelarator/qxelarator.py", line 77, in execute
    return _qxelarator.QX_execute(self, iterations)
OverflowError: in method 'QX_execute', argument 2 of type 'std::size_t'

It would be nice if a similar OverflowError, or an ValueError ccould be raised when the number of iterations is 0.

@pablolh pablolh self-assigned this Mar 13, 2023
@pablolh
Copy link
Contributor

pablolh commented Mar 13, 2023

A very legit issue, I'll work on it asap. Thanks for reporting!

@koffie
Copy link
Author

koffie commented Mar 13, 2023

Actually I found another way to expose uncaught errors in the underlying c++ that are not nicely wrapped in python code so that they can be dealt with.

Example:

from qxelarator import QX
qx.execute(1)

output:

No circuit successfully loaded, call set(...) first
libc++abi: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Note that the above code for some reason seems to produce different errors when executed multiple times. I've seen SIGABRT, SIGBUS and SIGSEGV. They are probably being caused by the same underlying issue.

I've not been able to create any such uncaught exceptions using qxelarator.execute_string, so good job on this new interface.

@arcturusannamalai
Copy link

I wonder if this issue is resolved on latest main branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants