Skip to content

Commit 9de3ae5

Browse files
authored
Merge pull request #199 from ICAMS/fix_module_command
Fix module command
2 parents 1dbb6a6 + 718d768 commit 9de3ae5

File tree

4 files changed

+115
-132
lines changed

4 files changed

+115
-132
lines changed

calphy/input.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,27 +96,27 @@ def _extract_elements_from_pair_coeff(pair_coeff_string):
9696
"""
9797
Extract element symbols from pair_coeff string.
9898
Returns None if pair_coeff doesn't contain element specifications.
99-
99+
100100
Parameters
101101
----------
102102
pair_coeff_string : str
103103
The pair_coeff command string (e.g., "* * potential.eam.fs Cu Zr")
104-
104+
105105
Returns
106106
-------
107107
list or None
108108
List of element symbols in order, or None if no elements found
109109
"""
110110
if pair_coeff_string is None:
111111
return None
112-
112+
113113
pcsplit = pair_coeff_string.strip().split()
114114
elements = []
115-
115+
116116
# Start collecting after we find element symbols
117117
# Elements are typically after the potential filename
118118
started = False
119-
119+
120120
for p in pcsplit:
121121
# Check if this looks like an element symbol
122122
# Element symbols are 1-2 characters, start with uppercase
@@ -131,7 +131,7 @@ def _extract_elements_from_pair_coeff(pair_coeff_string):
131131
if started:
132132
# We already started collecting elements and hit a non-element
133133
break
134-
134+
135135
return elements if len(elements) > 0 else None
136136

137137

@@ -208,7 +208,6 @@ class Queue(BaseModel, title="Options for configuring queue"):
208208
memory: Annotated[str, Field(default="3GB")]
209209
commands: Annotated[List, Field(default=[])]
210210
options: Annotated[List, Field(default=[])]
211-
modules: Annotated[List, Field(default=[])]
212211

213212

214213
class Tolerance(BaseModel, title="Tolerance settings for convergence"):
@@ -356,13 +355,17 @@ def _validate_all(self) -> "Input":
356355
raise ValueError("mass and elements should have same length")
357356

358357
self.n_elements = len(self.element)
359-
358+
360359
# Validate element/mass/pair_coeff ordering consistency
361360
# This is critical for multi-element systems where LAMMPS type numbers
362361
# are assigned based on element order: element[0]=Type1, element[1]=Type2, etc.
363-
if len(self.element) > 1 and self.pair_coeff is not None and len(self.pair_coeff) > 0:
362+
if (
363+
len(self.element) > 1
364+
and self.pair_coeff is not None
365+
and len(self.pair_coeff) > 0
366+
):
364367
extracted_elements = _extract_elements_from_pair_coeff(self.pair_coeff[0])
365-
368+
366369
if extracted_elements is not None:
367370
# pair_coeff specifies elements - check ordering
368371
if set(extracted_elements) != set(self.element):
@@ -372,7 +375,7 @@ def _validate_all(self) -> "Input":
372375
f" pair_coeff: {extracted_elements}\n"
373376
f"The elements specified must be the same."
374377
)
375-
378+
376379
if list(extracted_elements) != list(self.element):
377380
raise ValueError(
378381
f"Element ordering mismatch detected!\n\n"

calphy/scheduler.py

Lines changed: 100 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
energy calculations.
44
55
Copyright 2021 (c) Sarath Menon^1, Yury Lysogorskiy^2, Ralf Drautz^2
6-
^1: Max Planck Institut für Eisenforschung, Dusseldorf, Germany
6+
^1: Max Planck Institut für Eisenforschung, Dusseldorf, Germany
77
^2: Ruhr-University Bochum, Bochum, Germany
88
9-
calphy is published and distributed under the Academic Software License v1.0 (ASL).
10-
calphy is distributed in the hope that it will be useful for non-commercial academic research,
11-
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9+
calphy is published and distributed under the Academic Software License v1.0 (ASL).
10+
calphy is distributed in the hope that it will be useful for non-commercial academic research,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1212
calphy API is published and distributed under the BSD 3-Clause "New" or "Revised" License
13-
See the LICENSE FILE for more details.
13+
See the LICENSE FILE for more details.
1414
1515
More information about the program can be found in:
1616
Menon, Sarath, Yury Lysogorskiy, Jutta Rogal, and Ralf Drautz.
@@ -25,25 +25,26 @@
2525
import os
2626
import stat
2727

28+
2829
class Local:
2930
"""
3031
Local submission script
3132
"""
33+
3234
def __init__(self, options, cores=1, directory=os.getcwd()):
33-
self.queueoptions = {"scheduler": "local",
34-
"jobname": "tis",
35-
"queuename": None,
36-
"memory": None,
37-
"cores": cores,
38-
"hint": None,
39-
"directory": directory,
40-
"options": [],
41-
"commands": [],
42-
"modules": [],
43-
"header": "#!/bin/bash"
44-
45-
}
46-
for (key, val) in options.items():
35+
self.queueoptions = {
36+
"scheduler": "local",
37+
"jobname": "tis",
38+
"queuename": None,
39+
"memory": None,
40+
"cores": cores,
41+
"hint": None,
42+
"directory": directory,
43+
"options": [],
44+
"commands": [],
45+
"header": "#!/bin/bash",
46+
}
47+
for key, val in options.items():
4748
if key in self.queueoptions.keys():
4849
if val is not None:
4950
self.queueoptions[key] = val
@@ -60,14 +61,10 @@ def write_script(self, outfile):
6061
fout.write(self.queueoptions["header"])
6162
fout.write("\n")
6263

63-
#now write modules
64-
for module in self.queueoptions["modules"]:
65-
fout.write("module load %s\n" %module)
66-
67-
#now finally commands
64+
# now finally commands
6865
for command in self.queueoptions["commands"]:
69-
fout.write("%s\n" %command)
70-
fout.write("%s > %s 2> %s\n" %(self.maincommand, jobout, joberr))
66+
fout.write("%s\n" % command)
67+
fout.write("%s > %s 2> %s\n" % (self.maincommand, jobout, joberr))
7168
self.script = outfile
7269

7370
def submit(self):
@@ -77,41 +74,42 @@ def submit(self):
7774
st = os.stat(self.script)
7875
os.chmod(self.script, st.st_mode | stat.S_IEXEC)
7976
cmd = [self.script]
80-
proc = sub.Popen(cmd, stdin=sub.PIPE,stdout=sub.PIPE,stderr=sub.PIPE)
77+
proc = sub.Popen(cmd, stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE)
8178
return proc
8279

80+
8381
class SLURM:
8482
"""
8583
Slurm class for writing submission script
8684
"""
85+
8786
def __init__(self, options, cores=1, directory=os.getcwd()):
8887
"""
8988
Create class
9089
"""
91-
self.queueoptions = {"scheduler": "slurm",
92-
"jobname": "tis",
93-
"queuename": None,
94-
"walltime": "23:59:00",
95-
"memory": "3GB",
96-
"cores": cores,
97-
"hint": "nomultithread",
98-
"directory": directory,
99-
"options": [],
100-
"commands": [ "uss=$(whoami)",
101-
"find /dev/shm/ -user $uss -type f -mmin +30 -delete",
102-
],
103-
"modules": [],
104-
"header": "#!/bin/bash"
105-
106-
}
107-
for (key, val) in options.items():
90+
self.queueoptions = {
91+
"scheduler": "slurm",
92+
"jobname": "tis",
93+
"queuename": None,
94+
"walltime": "23:59:00",
95+
"memory": "3GB",
96+
"cores": cores,
97+
"hint": "nomultithread",
98+
"directory": directory,
99+
"options": [],
100+
"commands": [
101+
"uss=$(whoami)",
102+
"find /dev/shm/ -user $uss -type f -mmin +30 -delete",
103+
],
104+
"header": "#!/bin/bash",
105+
}
106+
for key, val in options.items():
108107
if key in self.queueoptions.keys():
109108
if val is not None:
110109
if val != "":
111110
self.queueoptions[key] = val
112111
self.maincommand = ""
113112

114-
115113
def write_script(self, outfile):
116114
"""
117115
Write the script file
@@ -123,69 +121,66 @@ def write_script(self, outfile):
123121
fout.write(self.queueoptions["header"])
124122
fout.write("\n")
125123

126-
#write the main header options
127-
fout.write("#SBATCH --job-name=%s\n" %self.queueoptions["jobname"])
128-
fout.write("#SBATCH --time=%s\n" %self.queueoptions["walltime"])
124+
# write the main header options
125+
fout.write("#SBATCH --job-name=%s\n" % self.queueoptions["jobname"])
126+
fout.write("#SBATCH --time=%s\n" % self.queueoptions["walltime"])
129127
if self.queueoptions["queuename"] is not None:
130-
fout.write("#SBATCH --partition=%s\n"%self.queueoptions["queuename"])
131-
fout.write("#SBATCH --ntasks=%s\n" %str(self.queueoptions["cores"]))
132-
fout.write("#SBATCH --mem-per-cpu=%s\n"%self.queueoptions["memory"])
133-
fout.write("#SBATCH --hint=%s\n" %self.queueoptions["hint"])
134-
fout.write("#SBATCH --chdir=%s\n" %self.queueoptions["directory"])
128+
fout.write("#SBATCH --partition=%s\n" % self.queueoptions["queuename"])
129+
fout.write("#SBATCH --ntasks=%s\n" % str(self.queueoptions["cores"]))
130+
fout.write("#SBATCH --mem-per-cpu=%s\n" % self.queueoptions["memory"])
131+
fout.write("#SBATCH --hint=%s\n" % self.queueoptions["hint"])
132+
fout.write("#SBATCH --chdir=%s\n" % self.queueoptions["directory"])
135133

136-
#now write extra options
134+
# now write extra options
137135
for option in self.queueoptions["options"]:
138-
fout.write("#SBATCH %s\n" %option)
136+
fout.write("#SBATCH %s\n" % option)
139137

140-
#now write modules
141-
for module in self.queueoptions["modules"]:
142-
fout.write("module load %s\n" %module)
143-
144-
#now finally commands
138+
# now finally commands
145139
for command in self.queueoptions["commands"]:
146-
fout.write("%s\n" %command)
147-
fout.write("%s > %s 2> %s\n" %(self.maincommand, jobout, joberr))
140+
fout.write("%s\n" % command)
141+
fout.write("%s > %s 2> %s\n" % (self.maincommand, jobout, joberr))
148142

149143
self.script = outfile
150144

151145
def submit(self):
152146
"""
153147
Submit the job
154148
"""
155-
cmd = ['sbatch', self.script]
156-
proc = sub.Popen(cmd, stdin=sub.PIPE,stdout=sub.PIPE,stderr=sub.PIPE)
149+
cmd = ["sbatch", self.script]
150+
proc = sub.Popen(cmd, stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE)
157151
print(f'submitting {self.queueoptions["jobname"]}')
158152
proc.communicate()
159153
return proc
160154

161155

162-
163156
class SGE:
164157
"""
165158
Slurm class for writing submission script
166159
"""
160+
167161
def __init__(self, options, cores=1, directory=os.getcwd()):
168162
"""
169163
Create class
170164
"""
171-
self.queueoptions = {"scheduler": "sge",
172-
"jobname": "tis",
173-
"walltime": "23:59:00",
174-
"queuename": None,
175-
"memory": "3GB",
176-
"system": "smp",
177-
"commands": [],
178-
"modules": [],
179-
"options": ["-j y",
180-
"-R y",
181-
"-P ams.p",
182-
],
183-
"cores": cores,
184-
"hint": None,
185-
"directory": directory,
186-
"header": "#!/bin/bash"
187-
}
188-
for (key, val) in options.items():
165+
self.queueoptions = {
166+
"scheduler": "sge",
167+
"jobname": "tis",
168+
"walltime": "23:59:00",
169+
"queuename": None,
170+
"memory": "3GB",
171+
"system": "smp",
172+
"commands": [],
173+
"options": [
174+
"-j y",
175+
"-R y",
176+
"-P ams.p",
177+
],
178+
"cores": cores,
179+
"hint": None,
180+
"directory": directory,
181+
"header": "#!/bin/bash",
182+
}
183+
for key, val in options.items():
189184
if key in self.queueoptions.keys():
190185
if val is not None:
191186
self.queueoptions[key] = val
@@ -195,40 +190,40 @@ def write_script(self, outfile):
195190
"""
196191
Write the script file
197192
"""
193+
jobout = ".".join([outfile, "out"])
194+
joberr = ".".join([outfile, "err"])
195+
198196
with open(outfile, "w") as fout:
199197
fout.write(self.queueoptions["header"])
200198
fout.write("\n")
201199

202-
#write the main header options
203-
fout.write("#$ -N %s\n" %self.queueoptions["jobname"])
204-
fout.write("#$ -l h_rt=%s\n" %self.queueoptions["walltime"])
205-
fout.write("#$ -l qname=%s\n"%self.queueoptions["queuename"])
206-
fout.write("#$ -pe %s %s\n" %( self.queueoptions["system"], str(self.queueoptions["cores"])))
207-
fout.write("#$ -l h_vmem=%s\n"%self.queueoptions["memory"])
208-
fout.write("#$ -cwd %s\n" %self.queueoptions["directory"])
209-
210-
#now write extra options
200+
# write the main header options
201+
fout.write("#$ -N %s\n" % self.queueoptions["jobname"])
202+
fout.write("#$ -l h_rt=%s\n" % self.queueoptions["walltime"])
203+
fout.write("#$ -l qname=%s\n" % self.queueoptions["queuename"])
204+
fout.write(
205+
"#$ -pe %s %s\n"
206+
% (self.queueoptions["system"], str(self.queueoptions["cores"]))
207+
)
208+
fout.write("#$ -l h_vmem=%s\n" % self.queueoptions["memory"])
209+
fout.write("#$ -cwd %s\n" % self.queueoptions["directory"])
210+
211+
# now write extra options
211212
for option in self.queueoptions["options"]:
212-
fout.write("#$ %s\n" %option)
213-
214-
#now write modules
215-
for module in self.queueoptions["modules"]:
216-
fout.write("module load %s\n" %module)
213+
fout.write("#$ %s\n" % option)
217214

218-
#now finally commands
215+
# now finally commands
219216
for command in self.queueoptions["commands"]:
220-
fout.write("%s\n" %command)
217+
fout.write("%s\n" % command)
221218

222-
fout.write("%s > %s 2> %s\n" %(self.maincommand, jobout, joberr))
223-
224-
self.script = outfile
219+
fout.write("%s > %s 2> %s\n" % (self.maincommand, jobout, joberr))
225220

221+
self.script = outfile
226222

227223
def submit(self):
228224
"""
229225
Submit the job
230226
"""
231-
cmd = ['qsub', self.script]
232-
proc = sub.Popen(cmd, stdin=sub.PIPE,stdout=sub.PIPE,stderr=sub.PIPE)
227+
cmd = ["qsub", self.script]
228+
proc = sub.Popen(cmd, stdin=sub.PIPE, stdout=sub.PIPE, stderr=sub.PIPE)
233229
return proc
234-

0 commit comments

Comments
 (0)