Skip to content

Modification of pyrms import when debugging #2363

@calvinp0

Description

@calvinp0

Motivation or Problem

When VSCode/PyCharm are being used to debug RMG-Py, the execution of the code during the debug process will suddenly stop without reporting the exception. The exception will only be reported if the user ticks the 'User Uncaught Exceptions'/'Raise Exceptions' in the 'BREAKPOINTS' section. The issue is that during the debugging process there is a few lines of code it fails

File: reactors.py

try:
    from pyrms import rms
    from diffeqpy import de
    from julia import Main
except:
    pass

The reported error is 'ModuleNotFoundError' for 'pyrms'

Desired Solution

This error can be rectified a couple of ways:

  1. Modify the except statement to include 'ModuleNotFoundError'
  2. Check if in debug mode
import sys

gettrace = getattr(sys, 'gettrace', None)

if gettrace is None:
    try:
        from pyrms import rms
        from diffeqpy import de
        from julia import Main
   except:
        pass
elif gettrace():
        ###Run Alternative pyrms/diffeqpy load as explained in point 3
  1. Import pyrms and diffeqpy modification
elif gettrace():
        from julia.api import Julia
        jl=Julia(compiled_modules=False)
        from pyrms import rms
        from diffeqpy import de
        from julia import Main
  1. Improve the loading of RMS - PyJulia has the ability to create a system image as *.sys file. This will improve the load time of RMS. However, it will require updating PyJulia to version 0.6.0 (right now RMG uses PyJulia - 0.5.3)
python -m julia.sysimage sys.so

Now assuming the system image, named sys.so (can be changed of course), has been created - then changes to importing Jula from julia.api will be required.

        from julia.api import Julia
        jl=Julia(sysimage="sys.so") #This may need modification to also include the path
  1. If point four is followed through, then creating of the system image can be part of the installation of RMG-Py for the Source instructions.

Full Solution

import sys
gettrace=getattr(sys, 'gettrace', None)

if gettrace is None:
    try:
        from pyrms import rms
        from diffeqpy import de
        from julia import Main
    except ModuleNotFoundError:
        pass
elif gettrace():
    try:
        from os.path import dirname, abspath, join
        path_rms = dirname(dirname(dirname(abspath(__file__))))
        from julia.api import Julia
        jl = Julia(sysimage=join(path_rms,"sys.so"))
        from pyrms import rms
        from diffeqpy import de
        from julia import Main
    except:
        from julia.api import Julia
        jl = Julia(compiled_modules=False)
        from pyrms import rms
        from diffeqpy import de
        from julia import Main

Metadata

Metadata

Assignees

No one assigned

    Labels

    stalestale issue/PR as determined by actions bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions