Commit c219b520 authored by Lukas Weber's avatar Lukas Weber
Browse files

add jobfile python module and .clang-format

parent b99f88ce
---
BasedOnStyle: LLVM
AccessModifierOffset: '-4'
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlines: DontAlign
AlignOperands: 'true'
AlignTrailingComments: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'true'
AlwaysBreakTemplateDeclarations: 'true'
BreakBeforeBraces: Attach
BreakConstructorInitializers: BeforeColon
ColumnLimit: '100'
Cpp11BracedListStyle: 'true'
FixNamespaceComments: 'false'
IndentCaseLabels: 'false'
IndentWidth: '4'
IndentWrappedFunctionNames: 'true'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '1'
NamespaceIndentation: None
PointerAlignment: Right
ReflowComments: 'true'
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: Never
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
SpacesInSquareBrackets: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: ForIndentation
...
import yaml
import os
'''Helpers for handling loadleveller jobfiles.'''
class JobFile:
def __init__(self, filename):
with open(filename, 'r') as f:
jobfile = yaml.safe_load(f)
self.tasks = jobfile['tasks']
cwd = os.getcwd()
try:
jobpath = os.path.dirname(filename)
if jobpath != '':
os.chdir(os.path.dirname(filename))
jobconfig_path = os.path.expandvars(os.path.expanduser(jobfile['jobconfig']))
with open(jobconfig_path) as f:
self.jobconfig = yaml.safe_load(f)
self.mc_binary = os.path.abspath(os.path.expandvars(os.path.expanduser(self.jobconfig['mc_binary'])))
finally:
os.chdir(cwd)
......@@ -98,7 +98,8 @@ def ystatus():
return False
for task, tp in zip(job_prog.tasks, job_prog.progress):
print('{t}: {tp.num_runs} runs, {tp.sweeps}/{tp.target_sweeps} sweeps, {tp.therm_sweeps/tp.num_runs}/{tp.target_therm} thermalization'.format(t=task,tp=tp))
therm_per_run = tp.therm_sweeps/tp.num_runs if tp.num_runs > 0 else 0
print('{t}: {tp.num_runs} runs, {tp.sweeps}/{tp.target_sweeps} sweeps, {therm_per_run}/{tp.target_therm} thermalization'.format(t=task,tp=tp,therm_per_run=int(round(therm_per_run))))
except FileNotFoundError as e:
print("Error: jobfile '{}' not found.".format(args.jobfile))
......@@ -3,7 +3,7 @@
import yaml
import argparse
import subprocess
from loadleveller import clusterutils
from loadleveller import clusterutils, jobfile
import glob
import sys
import os
......@@ -27,17 +27,10 @@ if args.single and args.merge:
print('Error: cannot merge and run in single mode at the same time.')
sys.exit(1)
with open(jobfile_name, 'r') as f:
jobfile = yaml.safe_load(f)
jobconfig_path = os.path.expandvars(os.path.expanduser(jobfile['jobconfig']))
with open(jobconfig_path) as f:
jobconfig = yaml.safe_load(f)
mcbinary = os.path.expandvars(os.path.expanduser(jobconfig['mc_binary']))
job = jobfile.JobFile(jobfile_name)
# check age of the different files
binary_modtime = os.stat(mcbinary).st_mtime
binary_modtime = os.stat(job.mc_binary).st_mtime
jobfile_modtime = os.stat(jobfile_name).st_mtime
try:
......@@ -47,7 +40,7 @@ try:
error = False
label = 'Warning' if args.force else 'Error'
if binary_modtime > data_modtime:
print('{}: binary \'{}\' is newer than the checkpoint files.'.format(label, mcbinary))
print('{}: binary \'{}\' is newer than the checkpoint files.'.format(label, job.mc_binary))
error = True
if jobfile_modtime > data_modtime:
print('{}: jobfile \'{}\' is newer than the checkpoint files.'.format(label, jobfile_name))
......@@ -59,10 +52,10 @@ except StopIteration:
pass
if args.single:
cmd = [mcbinary, 'single', jobfile_name]
cmd = [job.mc_binary, 'single', jobfile_name]
print('$ '+' '.join(cmd))
subprocess.run(cmd)
elif args.merge:
subprocess.run([mcbinary, 'merge', jobfile_name])
subprocess.run([job.mc_binary, 'merge', jobfile_name])
else:
clusterutils.run(jobfile_name, jobconfig, [mcbinary, jobfile_name])
clusterutils.run(jobfile_name, job.jobconfig, [job.mc_binary, jobfile_name])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment