pyphi icon indicating copy to clipboard operation
pyphi copied to clipboard

The PyPhi package may have CPU leaking

Open Zhangyanbo opened this issue 6 years ago • 9 comments

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

Zhangyanbo avatar Mar 14 '19 18:03 Zhangyanbo

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

Zhangyanbo avatar Mar 14 '19 18:03 Zhangyanbo

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.

wmayner avatar Mar 14 '19 18:03 wmayner

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

Zhangyanbo avatar Mar 14 '19 18:03 Zhangyanbo

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

wmayner avatar Mar 14 '19 18:03 wmayner

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 avatar Mar 14 '19 18:03 Zhangyanbo

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 avatar Mar 14 '19 18:03 Zhangyanbo

  1. Python version: 3.7
  2. Operating system and version: Ubuntu 18.04.2 LTS
  3. PyPhi version: 1.1.0

Zhangyanbo avatar Mar 14 '19 18:03 Zhangyanbo

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?

wmayner avatar Mar 15 '19 20:03 wmayner

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

Zhangyanbo avatar Mar 15 '19 22:03 Zhangyanbo