build.py~ 3.8 KB

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