build.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import sys
  2. import os
  3. global gmax
  4. def byte(x):
  5. return x.to_bytes(1,sys.byteorder)
  6. class SemiGroup:
  7. def __init__(self,parent=None,x=None):
  8. if parent==None and x==None:
  9. self.m=1
  10. self.c=1
  11. self.g=0
  12. self.d=bytearray(3*gmax+1)
  13. for i in range(3*gmax+1):
  14. self.d[i]=1+int(i/2)
  15. elif parent!=None and x==None:
  16. self.m=parent
  17. self.c=self.m
  18. self.g=self.m-1
  19. self.d=bytearray(3*gmax+1)
  20. self.d[0]=1
  21. for i in range(1,2*self.m):
  22. self.d[i]=int(i/self.m)
  23. for i in range(3*gmax+1-2*self.m):
  24. self.d[i+2*self.m]=2+int(i/2)
  25. elif parent!=None and x!=None:
  26. if not parent.is_valid_irreductible(x):
  27. raise AttributeError("x is not irreducible")
  28. if x<parent.c:
  29. raise AttributeError("x is not effective")
  30. if parent.m==x:
  31. self.delta=1
  32. self.m=x+1
  33. else:
  34. if parent.d[x+parent.m]==2:
  35. self.delta=0
  36. else:
  37. self.delta=-1
  38. self.g=parent.g+1
  39. self.m=parent.m
  40. self.c=x+1
  41. self.d=bytearray(3*gmax+1)
  42. for y in range(x):
  43. self.d[y]=parent.d[y]
  44. self.d[x]=0
  45. for y in range(x+1,3*gmax+1):
  46. self.d[y]=parent.d[y]-min(1,parent.d[y-x])
  47. def __repr__(self):
  48. res='<'
  49. first=True
  50. for i in range(self.m,self.m+self.c+1):
  51. if self.d[i]==1:
  52. if not first:
  53. res+=','
  54. res+=repr(i)
  55. first=False
  56. return res+'>'+' g='+repr(self.g)
  57. def is_valid_irreductible(self,x):
  58. if x<0 or x>3*gmax:
  59. raise AttributeError("x is out of range")
  60. return self.d[x]==1 and x!=self.m
  61. def split_sons(self):
  62. first=None
  63. other=[]
  64. for x in range(self.c,self.c+self.m):
  65. if self.is_valid_irreductible(x):
  66. if first==None:
  67. first=SemiGroup(self,x)
  68. else:
  69. other.append(SemiGroup(self,x))
  70. return (first,other)
  71. def record(self,file):
  72. file.write(byte(self.c))
  73. file.write(byte(S.g))
  74. file.write(byte(S.m))
  75. file.write(self.d)
  76. if __name__=="__main__":
  77. file=open("genus","r")
  78. gmax=int(file.readline())
  79. file.close()
  80. print("Generate wilf program ...")
  81. os.system("cd c++;make;cd ..")
  82. print("Generate OAR tasks for cutted explorations of numerical semigroup up to genus",gmax,"...")
  83. mmax=int((3*(gmax+2))/5)
  84. param_file=open("oar/param","w")
  85. for m in range(3,mmax+1):
  86. S=SemiGroup(m)
  87. for k in range(gmax-m+1):
  88. (S,Others)=S.split_sons()
  89. task_filename="task_"+repr(m)+"_"+repr(k)
  90. task_file=open("tasks/"+task_filename,"wb")
  91. task_file.write(len(Others).to_bytes(8,sys.byteorder))
  92. task_file.write(byte(S.g))
  93. task_file.write(byte(S.m))
  94. for T in Others:
  95. T.record(task_file)
  96. task_file.close()
  97. param_file.write(task_filename+"\n")
  98. param_file.close()
  99. print("Generate OAR script ...")
  100. file=open("oar_wilf.sh",'w')
  101. file.write("#!/bin/sh\n")
  102. file.write("#OAR -l core=1,walltime=1:00:00\n")
  103. file.write("#OAR -t idempotent\n")
  104. file.write("#OAR -q besteffort\n")
  105. file.write("#OAR -t besteffort\n")
  106. file.write("#OAR --checkpoint 60\n")
  107. file.write("#OAR --signal 12\n")
  108. file.write("#OAR --array-param-file oar/param\n")
  109. file.write("#OAR -O oar/output/j%jobid%\n")
  110. file.write("#OAR -E oar/error/j%jobid%\n")
  111. file.write("cd /nfs/home/lmpa/jfromentin/wilf\n")
  112. file.write("./wilf tasks/$*\n")
  113. file.write("mv tasks/$* tasks/done")
  114. file.write("mv tasks/$*-out tasks/out")
  115. file.close()