Amber-MD / pytraj

Python interface of cpptraj
https://amber-md.github.io/pytraj
170 stars 38 forks source link

Limited number of LIE calls #1498

Closed RMeli closed 4 years ago

RMeli commented 4 years ago

I'm trying to compute the LIE for many different trajectories and the execution stops after 500 calls. Is there a limit on the number of LIE calls I'm not aware of?

This is the code that reproduces the problem (the trajectory contains a protein-ligand complex):

import pytraj as pt
import numpy as np

n = 0

while True:
    traj = pt.iterload("traj.nc", "traj.parm7")
    LIE = pt.analysis.energy_analysis.lie(traj, mask=":LIG",frame_indices=np.random.randint(0,5000,5))
    print(n)
    n += 1
hainm commented 4 years ago

Hi, can you please check the memory?

There is no limitation for this method. May be it’s another bug.

RMeli commented 4 years ago

Hi, thank you for the fast reply! I didn't mention the memory because it remains constant during the execution; that's why I opened a new issue instead of appending to #1495.

hainm commented 4 years ago

Thanks. I will investigate this as soon as I could. Cheers.

RMeli commented 4 years ago

FYI, this is not urgent/critical. Thanks!

hainm commented 4 years ago

hi @RMeli, it turns out that pytraj uses a function call capture_stdout to capture cpptraj stdout. That function only allows to have 500 calls (Now I know this thanks to you).

Can you please patch that function (below) and try again? thanks.

from contextlib import contextmanager
class Dummy:
    def __enter__(self):
        return self

    def __exit__(self):
        return

    def read(self):
        return ""

@contextmanager
def mock_capture():
    yield Dummy(), ""

pt.analysis.c_action.capture_stdout = mock_capture

# INSERT YOUR CODE HERE
drroe commented 4 years ago

@hainm I'll take a closer look at this tomorrow, but could you put here for posterity what info pytraj needs from stdout? Then let's add it to https://github.com/Amber-MD/cpptraj/issues/177 or create a cpptraj issue for it and I'll try to work on it tomorrow.

hainm commented 4 years ago

but could you put here for posterity what info pytraj needs from stdout?

Thanks @drroe. Currently pytraj does not have any specific need from cpptraj. The capture_stdout was added so cpptraj's stdout/stderr can be displayed in Jupyter notebook (it does not know how to display the ones from C++).

So cpptraj does not need to do anything. Cheers.

RMeli commented 4 years ago

@hainm The patch works on the simple example. I'll test it on my main pipeline soon. Thank you for the help!

RMeli commented 4 years ago

This workaround seems to work as expected, thanks.

hainm commented 4 years ago

We can close the case now. Thanks @RMeli again.

hainm commented 3 years ago

I'm trying to compute the LIE for many different trajectories and the execution stops after 500 calls. Is there a limit on the number of LIE calls I'm not aware of?

This is the code that reproduces the problem (the trajectory contains a protein-ligand complex):

import pytraj as pt
import numpy as np

n = 0

while True:
    traj = pt.iterload("traj.nc", "traj.parm7")
    LIE = pt.analysis.energy_analysis.lie(traj, mask=":LIG",frame_indices=np.random.randint(0,5000,5))
    print(n)
    n += 1

Should be fixed in #1573. I've run the code 1000 times without any issue. :D