I am handling set of frozensets. I am trying to find minimal sets for each frozenset in the dictionary 'output'. I have 70k frozensets, so i am making chunk of this frozenset dictionary and parallelizing this task. When i try to pass this dictionary as an input to my function, only key is being sent and so i am getting error, can someone help me to find what's wrong in this.
output => {frozenset({'rfid', 'zone'}): 0, frozenset({'zone'}): 0, frozenset({'zone', 'time'}): 0}def reduce(prob,result,output):print(output)for k in output.keys():#Function to do somethingdef reducer(prob,result,output):print(output)p = Pool(4) #number of processes = number of CPUsfunc2 = partial(reduce,prob,result)reduced_values= p.map( func2,output,chunksize=4)p.close() # no more tasksp.join() # wrap up current tasksreturn reduced_valuesif __name__ == '__main__':final = reducer(prob,result,output){frozenset({'rfid', 'zone'}): 0, frozenset({'zone'}): 0, frozenset({'zone', 'time'}): 0}
frozenset({'rfid', 'zone'})
Error : AttributeError: 'frozenset' object has no attribute 'keys'
Updated as requested
from multiprocessing import Pool
from functools import partial
import itertoolsoutput = {frozenset({'rfid', 'zone'}): 0, frozenset({'zone'}): 0, frozenset({'zone', 'time'}): 0}
prob = {'3': 0.3, '1': 0.15, '2': 0.5, '4': 0.05}
result = {'2': {frozenset({'time', 'zone'}), frozenset({'time', 'rfid'})}, '3': {frozenset({'time', 'rfid'}), frozenset({'rfid', 'zone'})}}def reduce(prob,result,output):print(output)for k in output.keys():for ky,values in result.items():if any(k>=l for l in values):output[k] += sum((j for i,j in prob.items() if i == ky))return outputdef reducer(prob,result,output):print(output)p = Pool(4) #number of processes = number of CPUsfunc2 = partial(reduce,prob,result)reduced_values= p.map( func2,output,chunksize=4)p.close() # no more tasksp.join() # wrap up current tasksreturn reduced_valuesif __name__ == '__main__':final = reducer(prob,result,output){frozenset({'zone', 'rfid'}): 0, frozenset({'zone'}): 0, frozenset({'time', 'zone'}): 0}for k in output.keys():
AttributeError: 'frozenset' object has no attribute 'keys'
frozenset({'zone', 'rfid'})
Full error details from the console:
{frozenset({'zone', 'time'}): 0, frozenset({'zone', 'rfid'}): 0, frozenset({'zone'}): 0}
frozenset({'zone', 'time'})
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):File "F:\Python34\lib\multiprocessing\pool.py", line 119, in workerresult = (True, func(*args, **kwds))File "F:\Python34\lib\multiprocessing\pool.py", line 44, in mapstarreturn list(map(*args))File "C:\Users\Dell\workspace\key_mining\src\variable.py", line 16, in reducefor k in output.keys():
AttributeError: 'frozenset' object has no attribute 'keys'
"""The above exception was the direct cause of the following exception:Traceback (most recent call last):File "C:\***\variable.py", line 33, in <module>final = reducer(prob,result,output)File "C:\***\variable.py", line 27, in reducerreduced_values= p.map( func2,output,chunksize=4)File "F:\Python34\lib\multiprocessing\pool.py", line 260, in mapreturn self._map_async(func, iterable, mapstar, chunksize).get()File "F:\Python34\lib\multiprocessing\pool.py", line 599, in getraise self._value
AttributeError: 'frozenset' object has no attribute 'keys'