Commit 7880d080 authored by Lukas Weber's avatar Lukas Weber

support slow pyyaml again

parent d2ba8249
...@@ -3,6 +3,11 @@ import os ...@@ -3,6 +3,11 @@ import os
import subprocess import subprocess
import errno import errno
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
'''Helpers for handling loadleveller jobfiles/scripts. For lack of a better idea, the job description files of loadleveller are actually executables that output a more verbose yaml parameter file to stdout. Use the taskmaker module to write the input scripts.''' '''Helpers for handling loadleveller jobfiles/scripts. For lack of a better idea, the job description files of loadleveller are actually executables that output a more verbose yaml parameter file to stdout. Use the taskmaker module to write the input scripts.'''
class JobFileGenError(Exception): class JobFileGenError(Exception):
...@@ -19,7 +24,7 @@ class JobFile: ...@@ -19,7 +24,7 @@ class JobFile:
raise JobFileGenError('Generation script "{}" had a non-zero return code. Treating as error.'.format(filename)) raise JobFileGenError('Generation script "{}" had a non-zero return code. Treating as error.'.format(filename))
try: try:
parsed_job = yaml.load(self.raw_jobfile, Loader=yaml.CSafeLoader) parsed_job = yaml.load(self.raw_jobfile, Loader=SafeLoader)
self.__dict__.update(parsed_job) self.__dict__.update(parsed_job)
except Exception as e: except Exception as e:
raise JobFileGenError('Could not parse job generation script output: {}'.format(e)) raise JobFileGenError('Could not parse job generation script output: {}'.format(e))
......
...@@ -2,6 +2,11 @@ import yaml ...@@ -2,6 +2,11 @@ import yaml
import numpy as np import numpy as np
import itertools import itertools
try:
from yaml import CSafeLoader as SafeLoader
except ImportError:
from yaml import SafeLoader
'''This module can be used to easily extract Monte Carlo results from the *.results.yml file produced by the loadleveller library.''' '''This module can be used to easily extract Monte Carlo results from the *.results.yml file produced by the loadleveller library.'''
class Observable: class Observable:
...@@ -16,7 +21,7 @@ class Observable: ...@@ -16,7 +21,7 @@ class Observable:
class MCArchive: class MCArchive:
def __init__(self, filename): def __init__(self, filename):
with open(filename, 'r') as f: with open(filename, 'r') as f:
doc = yaml.load(f, Loader=yaml.CSafeLoader) doc = yaml.load(f, Loader=SafeLoader)
param_names = set(sum([list(task['parameters'].keys()) for task in doc], [])) param_names = set(sum([list(task['parameters'].keys()) for task in doc], []))
observable_names = set(sum([list(task['results'].keys()) for task in doc], [])) observable_names = set(sum([list(task['results'].keys()) for task in doc], []))
......
...@@ -3,12 +3,17 @@ import os ...@@ -3,12 +3,17 @@ import os
import yaml import yaml
import numpy import numpy
try:
from yaml import CSafeLoader as SafeLoader, CSafeDumper as SafeDumper
except ImportError:
from yaml import SafeLoader, SafeDumper
def _expand_path(path): def _expand_path(path):
return os.path.abspath(os.path.expandvars(os.path.expanduser(path))) return os.path.abspath(os.path.expandvars(os.path.expanduser(path)))
def JobConfig(filename): def JobConfig(filename):
with open(_expand_path(filename), 'r') as f: with open(_expand_path(filename), 'r') as f:
return yaml.load(f, Loader=yaml.CSafeLoader) return yaml.load(f, Loader=SafeLoader)
class TaskMaker: class TaskMaker:
def __init__(self, name, jobconfig): def __init__(self, name, jobconfig):
...@@ -41,4 +46,4 @@ class TaskMaker: ...@@ -41,4 +46,4 @@ class TaskMaker:
task_dict[k] = v task_dict[k] = v
jobfile_dict['tasks'][task_name] = task_dict jobfile_dict['tasks'][task_name] = task_dict
print(yaml.dump(jobfile_dict, Dumper=yaml.CSafeDumper)) print(yaml.dump(jobfile_dict, Dumper=SafeDumper))
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