wmayner / pyphi

A toolbox for integrated information theory.
https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006343
Other
368 stars 98 forks source link

The PyPhi package may have CPU leaking #28

Open Zhangyanbo opened 5 years ago

Zhangyanbo commented 5 years ago

When repeatly run pyphi.compute.phi(subsystem), the CPU using is continue growing and the program speed is contiune slowing down.

Zhangyanbo commented 5 years ago

I run the pyphi.compute.phi(subsystem) about 2000 times and the program slowed down.

wmayner commented 5 years ago

Hello,

Can you give more details? The information in your issue is not sufficient to address the problem.

Please provide your:

  1. Python version
  2. Operating system and version
  3. PyPhi version
  4. A minimal working example

Also, just to be clear: are you sure you mean CPU leakage and not memory leakage? I've never heard of CPU leakage.

Zhangyanbo commented 5 years ago

I will provide more information soon. And yes, I mean CPU leakage not memory leakage.

wmayner commented 5 years ago

Thanks. In that case, could you please also clarify what you mean by that term?

Zhangyanbo commented 5 years ago

It seems the PyPhi is using multiple threads to do computation. But when you finished a Phi computing, some threads may not stoped and still using CPU.

Zhangyanbo commented 5 years ago

You can try this program and you will see the time cost is growing. While I'm always doing the same computing:

from sympy.combinatorics.graycode import GrayCode
from itertools import permutations
import numpy as np
import warnings
import pyphi
import pandas as pd
import time

ntimes = 10
each_time_compute = 20

warnings.filterwarnings('ignore')

labels = ('A', 'B', 'C')
m = [[0, 0, 0],
     [0, 0, 1],
     [1, 0, 1],
     [1, 0, 0],
     [1, 1, 0],
     [1, 1, 1],
     [1, 1, 1],
     [1, 1, 0]]

def is_in(state, tpm):
    for astate in tpm:
        if state == astate.tolist():
            return True
    return False

def getphi(tpm):
    network = pyphi.Network(tpm, node_labels=labels)
    phis = []
    for i in range(2):
        for j in range(2):
            for k in range(2):
                state = (i, j, k)
                node_indices = (0, 1, 2)
                if is_in(list(state), tpm):
                    subsystem = pyphi.Subsystem(network, state, node_indices)
                    phis += [pyphi.compute.phi(subsystem)]
    return phis

# Show CPU Leakage

for i in range(ntimes):
    start = time.time()
    for j in range(each_time_compute):
        temp = getphi(np.array(m))
    end = time.time()
    print('epco', i, 'time cost:', end-start, 's')
Zhangyanbo commented 5 years ago
  1. Python version: 3.7
  2. Operating system and version: Ubuntu 18.04.2 LTS
  3. PyPhi version: 1.1.0
wmayner commented 5 years ago

Thank you. It appears that this is related to parallel cut evaluation. Can you please confirm that there is no increase in computation time when you set pyphi.config.PARALLEL_CUT_EVALUATION = False?

Zhangyanbo commented 5 years ago

Yes! The time cost does not grow after setting pyphi.config.PARALLEL_CUT_EVALUATION = False. Do you know why it happens?