I work with a set of phenisones. I am trying to find the minimum sets for each frozenset in the dictionary "output". I have 70 kg freezets, so I make a piece of this frozenset dictionary and parallelize this task. When I try to pass this dictionary as input to my function, only the key is sent, and therefore I get an error, can someone help me find something wrong with 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():
def reducer(prob,result,output):
print(output)
p = Pool(4)
func2 = partial(reduce,prob,result)
reduced_values= p.map( func2,output,chunksize=4)
p.close()
p.join()
return reduced_values
if __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 on request
from multiprocessing import Pool
from functools import partial
import itertools
output = {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 output
def reducer(prob,result,output):
print(output)
p = Pool(4)
func2 = partial(reduce,prob,result)
reduced_values= p.map( func2,output,chunksize=4)
p.close()
p.join()
return reduced_values
if __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 information 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 worker
result = (True, func(*args, **kwds))
File "F:\Python34\lib\multiprocessing\pool.py", line 44, in mapstar
return list(map(*args))
File "C:\Users\Dell\workspace\key_mining\src\variable.py", line 16, in reduce
for 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 reducer
reduced_values= p.map( func2,output,chunksize=4)
File "F:\Python34\lib\multiprocessing\pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "F:\Python34\lib\multiprocessing\pool.py", line 599, in get
raise self._value
AttributeError: 'frozenset' object has no attribute 'keys'