-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord_atoms.py
41 lines (27 loc) · 1.01 KB
/
record_atoms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
###Script for writing atoms in Pfin(N) with fixed maximum to local directory
from PfinN import * #Need functions for Pfin(N) subset arithmetic
from time import time
import multiprocessing as mp
atom_ref_path = 'atoms/atoms_max'
def ret_if_atom(X): #returns X if X is an atom, otherwise None
if is_atom(X):
return X
else:
pass
def atoms(n): #returns the list of atoms which have max n
p = mp.Pool()
return [a for a in p.map(ret_if_atom,interval_subsets(n)) if a != None]
#Uses synchronous multiprocessing for the sake of keeping atom list "in order"
#Future improvements:
#**try async for better speed
#**avoid list implementation
def write_atoms(list_of_atoms,file): #for our purposes, list_of_atoms = atoms(n)
for a in list_of_atoms:
file.write(str(a)+'\n')
file.close()
#### The following will record all atoms in Pfin(N) with max=n
#### to a file named 'atoms_maxn
import sys
n = int(sys.argv[1])
file = open('atoms/atoms_max'+str(n),'w')
write_atoms(atoms(n),file)