Skip to content
Snippets Groups Projects
Commit 236e0054 authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

mkexp/expconfig: replace deep copy of Sections by ordered dict copy

Fixes long run times for extended jobs/namelist groups
parent 19b4e6d5
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ Tools
-----
* importexp: fixed extraction of start/end date in input scripts
* mkexp: fixed long run times for extended jobs/namelist groups
Release 1.1.4
=============
......
......@@ -4,6 +4,7 @@ Generate an earth system model configuration from the given configuration file.
$Id$
'''
import collections
import io
import locale
import os
......@@ -36,6 +37,29 @@ def is_not_empty(arg):
else:
return [_f for _f in [x.rstrip() for x in arg] if _f]
def odict(self):
'''Return a deepcopy of self as an ordered dictionary.
>>> n = odict(a)
>>> n == a
1
>>> n is a
0
'''
newdict = collections.OrderedDict()
for entry in self:
this_entry = self[entry]
if isinstance(this_entry, configobj.Section):
this_entry = odict(this_entry)
elif isinstance(this_entry, list):
# create a copy rather than a reference
this_entry = list(this_entry)
elif isinstance(this_entry, tuple):
# create a copy rather than a reference
this_entry = tuple(this_entry)
newdict[entry] = this_entry
return newdict
def merge_comments(this, indict):
'''Merge comments from indict into current configuration.
......
......@@ -7,7 +7,6 @@
from __future__ import print_function
import copy
import io
import os
import re
......@@ -500,14 +499,15 @@ def extend(subjob, jobs_config, extended_jobs, job_dict=None):
# Add parent config
if extended_job:
pre_config.merge(copy.deepcopy(jobs_config[extended_job]))
pre_config.merge(expconfig.odict(jobs_config[extended_job]))
expconfig.merge_comments(pre_config, jobs_config[extended_job])
# Add actual subjob config
pre_config.merge(subconfig)
# Replace subjob config by extended config
jobs_config[subjob] = {}
jobs_config[subjob].merge(pre_config)
jobs_config[subjob].merge(expconfig.odict(pre_config))
expconfig.merge_comments(jobs_config[subjob], pre_config)
del pre_config
......@@ -564,8 +564,9 @@ for subjob, subconfig in jobs_config.items():
# Prepare namelists for inclusion in scripts
var_format = job_config['JOB'].get('.var_format', '${%s}')
var_list = set()
del job_config['jobs']
job_config['jobs'] = copy.deepcopy(jobs_config)
job_config['jobs'] = {}
job_config['jobs'].merge(expconfig.odict(jobs_config))
expconfig.merge_comments(job_config['jobs'], jobs_config)
job_config.walk(format_vars, log=var_list, fmt=var_format)
job_config['VARIABLES_'] = var_list
for namelist, groups in job_config['namelists'].items():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment