psweep.psweep.itr2params#
- psweep.psweep.itr2params(loops)[source]#
Transform the (possibly nested) result of a loop over plists (or whatever has been used to create psets) to a proper list of psets by flattening and merging dicts.
Examples
>>> a = ps.plist('a', [1,2]) >>> b = ps.plist('b', [77,88]) >>> c = ps.plist('c', ['const'])
>>> # result of loops >>> list(itertools.product(a,b,c)) [({'a': 1}, {'b': 77}, {'c': 'const'}), ({'a': 1}, {'b': 88}, {'c': 'const'}), ({'a': 2}, {'b': 77}, {'c': 'const'}), ({'a': 2}, {'b': 88}, {'c': 'const'})]
>>> # flatten into list of psets >>> ps.itr2params(itertools.product(a,b,c)) [{'a': 1, 'b': 77, 'c': 'const'}, {'a': 1, 'b': 88, 'c': 'const'}, {'a': 2, 'b': 77, 'c': 'const'}, {'a': 2, 'b': 88, 'c': 'const'}]
>>> # also more nested stuff is no problem >>> list(itertools.product(zip(a,b),c)) [(({'a': 1}, {'b': 77}), {'c': 'const'}), (({'a': 2}, {'b': 88}), {'c': 'const'})]
>>> ps.itr2params(itertools.product(zip(a,b),c)) [{'a': 1, 'b': 77, 'c': 'const'}, {'a': 2, 'b': 88, 'c': 'const'}]