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

SystemError when handling KeyboardInterrupt #1483

Closed
jaimergp opened this issue May 10, 2016 · 4 comments
Closed

SystemError when handling KeyboardInterrupt #1483

jaimergp opened this issue May 10, 2016 · 4 comments

Comments

@jaimergp
Copy link
Contributor

Hello.

I am using a custom script to run MD simulations with OpenMM. This script has the following code in it:

try:
    simulation.step(steps)
except (Exception, KeyboardInterrupt) as ex:
    if isinstance(ex, KeyboardInterrupt):
        report = input('\nCtr+C detected. Save current state? (y/N): ')
        if report not in ('Y', 'y', 'yes', 'YES'):
            sys.exit('Ok, bye!')
    else:
        print('An error occurred. Attempting emergency report...')
    try:
        backup_simulation(simulation)
    except Exception:
        print('FAILED!')
    else:
        print('SUCCESS!')
    finally:
        raise ex

This was working with OpenMM 6.3, but it fails with OpenMM 7.0:

^CKeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/XXX/.local/anaconda/envs/openmm/bin/ommprotocol", line 9, in <module>
    load_entry_point('ommprotocol', 'console_scripts', 'ommprotocol')()
  File "/home/XXX/dev/ommprotocol/ommprotocol/ommprotocol.py", line 357, in run_protocol
    loaded_input, positions=pos, velocities=vel, box_vectors=box, **options)
  File "/home/XXX/dev/ommprotocol/ommprotocol/ommprotocol.py", line 237, in stage
    simulation = app.Simulation(input_top.topology, system, _integrator, **platform_kwargs)
  File "/home/XXX/.local/anaconda/envs/openmm/lib/python3.5/site-packages/simtk/openmm/app/simulation.py", line 101, in __init__
    self.context = mm.Context(self.system, self.integrator)
SystemError: <built-in function delete_Context> returned a result with an error set

How can I handle Ctrl+C inputs in OpenMM 7.0?

@peastman
Copy link
Member

What is ommprotocol? Is that something you've developed?

@jchodera
Copy link
Member

Looks like the source is here: https://github.com/insilichem/ommprotocol

@peastman
Copy link
Member

It looks to me like this may be related: https://bugs.python.org/issue23571. Python 3.5 changed how exceptions are handled. But still, this shouldn't be happening. If an OpenMM function is throwing an exception, the SWIG wrapper should catch it and translate it to a Python exception. It shouldn't let the C++ except propagate up to the Python level.

Are you using a precompiled OpenMM library, or did you build it yourself? If the latter, here are a couple of things I would try. First, make sure you're using the latest version of SWIG. If this behavior just recently changed in Python, it's possible older versions would cause problems. Second, try deleting the "wrappers" and "python" folders inside your build directory. Then run CMake to regenerate them and rebuild. It's possible something in those folders has just gotten out of sync or something.

@jaimergp
Copy link
Contributor Author

Hi guys, thanks for the prompt answer.

Yes, @jchodera is right. That's the source code, but I am rewriting most of it in OO style (dev branch). Anyways, the error is the same in both versions. I have observed that the error does not always happen - it is more likely to happen when the simulation has been running for very little time (10-100 fs).

My environment is Arch Linux, Python 3.5, latest OpenMM from conda binaries, so no, I am not compiling it myself. I'll have a look at that patch you are referencing, @peastman, and also different Python versions.

I'll keep you informed. Thanks again!

@peastman peastman closed this as completed Dec 1, 2020
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