Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature merge results #187

Draft
wants to merge 27 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0f889f4
updated script to merge HDF5 resultfiles
LeonardSchmiester Jun 18, 2019
07c3a04
Update misc/mergeResultFiles.py
LeonardSchmiester Jun 19, 2019
db4ba48
Merge branch 'develop' into feature_mergeResults
dweindl Sep 7, 2019
452a1a2
Merge branch 'develop' into feature_mergeResults
dweindl Oct 8, 2019
d4f5a94
Merge branch 'develop' into feature_mergeResults
dweindl Oct 9, 2019
72caf06
Merge branch 'develop' into feature_mergeResults
dweindl Oct 9, 2019
27ff07d
Merge branch 'develop' into feature_mergeResults
dweindl Nov 20, 2019
8bc66d8
Merge branch 'develop' into feature_mergeResults
dweindl Dec 2, 2019
986f4e7
Merge branch 'develop' into feature_mergeResults
dweindl Dec 2, 2019
6b90925
Merge branch 'develop' into feature_mergeResults
dweindl Dec 12, 2019
192151c
Merge branch 'develop' into feature_mergeResults
dweindl Dec 14, 2019
c4485e2
Merge branch 'develop' into feature_mergeResults
dweindl Jan 8, 2020
e8f38c5
Merge branch 'develop' into feature_mergeResults
dweindl Mar 13, 2020
19b5dd1
Merge branch 'develop' into feature_mergeResults
dweindl Apr 4, 2020
d36dfb3
Merge branch 'develop' into feature_mergeResults
paulstapor Apr 21, 2020
dac15aa
Merge branch 'develop' into feature_mergeResults
dweindl Jun 16, 2020
e77f8c8
Merge branch 'develop' into feature_mergeResults
dweindl Jul 19, 2020
41ca3da
Merge branch 'develop' into feature_mergeResults
dweindl Feb 21, 2021
157cad0
Merge branch 'develop' into feature_mergeResults
dweindl Mar 13, 2021
7f569a9
SuperMUC build script: skip boost
dweindl Jun 28, 2021
eb33a10
Fix race condition with parallel HDF5 calls (#345)
dweindl Jun 28, 2021
72f29d9
Fix HDF5 generation for state reinitialization with estimated initial…
dweindl Jun 28, 2021
46589e5
Cleanup PEtab import (#346)
dweindl Jul 1, 2021
e5e4fb3
Update AMICI to develop@8ef53c88 (#347)
dweindl Jul 1, 2021
98a0746
Fixup AMICI
dweindl Jul 1, 2021
aa9db59
Merge branch 'develop' into feature_mergeResults
dweindl Jul 12, 2021
58c88bc
Merge branch 'develop' into feature_mergeResults
dweindl Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 69 additions & 40 deletions misc/mergeResultFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,83 @@

"""

import numpy as np
import h5py
import sys
import re
import os
import glob
import argparse

def printUsage():
print('Usage: %s INFILE ... OUTFILE' % __file__)

def mergeFiles(infiles, outfile):

def merge_files(in_files, out_file, save_iteration, same_input):
"""
Read final multistart optimization results from HDF5 infile and write to HDF5 outfile.
Read final multistart optimization results from HDF5 in_files and write to HDF5 out_file.
"""

fOut = h5py.File(outfile, "w")

for infile in infiles:
print(infile)
with h5py.File(infile, "r") as fIn:
copyRecursive(fIn["/"], fOut["/"])

def copyRecursive(inObj, rootOut):
if isinstance(in_files, list):
in_files_list = in_files
else:
in_files_list = glob.glob(in_files)

f_out = h5py.File(out_file, "w")

start_idx = 0
if same_input:
f_out.create_group('multistarts')
for in_file in in_files_list:
print(in_file)
with h5py.File(in_file, "r") as fIn:
if '/inputData' not in f_out:
fIn.copy('/inputData', f_out)
copy_multistarts(fIn, f_out, start_idx, save_iteration)
f_out['multistarts/' + str(start_idx)].attrs['source_file'] = in_file.split(sep='/')[-1]
start_idx += 1
else:
for in_file in in_files_list:
print(in_file)
with h5py.File(in_file, "r") as fIn:
fIn.copy('/', f_out, in_file.split(sep='/')[-1])


def copy_multistarts(f_in, f_out, start_idx, save_iteration):
"""
Recursively copy inObj to the same path under rootOut

NOTE: no attributes are copied for now
Copy all starts in fIn to fOut.
"""
print("\tCopy %s to %s" % (inObj.name, rootOut.name))
dest = rootOut.name + inObj.parent.name
if(not inObj.name in rootOut):
print("\tDestination %s does not exists: copy %s " %(dest, inObj.name))
inObj.copy(inObj.name, rootOut.file[dest])
else:
print("\tDestination %s exists: copy members of %s" %(dest, inObj.name))
for obj in inObj:
print("\t\t" + obj)
copyRecursive(inObj[obj], rootOut)
for start in f_in['/multistarts']:
if save_iteration:
f_in.copy('/multistarts/' + start, f_out, 'multistarts/' + str(start_idx))
else:
for key in f_in['/multistarts/' + start].keys():
if not (key == 'iteration'):
f_in.copy('/multistarts/' + start + '/' + key, f_out, 'multistarts/' + str(start_idx) + '/' + key)


def parse_cli_args():
"""Parse command line arguments"""

parser = argparse.ArgumentParser(
description='Merge h5 resultfiles.')

parser.add_argument('-f', '--in-files', dest='in_files',
required=True,
help='Path for files to be merged. E.g. results/*-rank00000.h5. Or list with file names.')

parser.add_argument('-o', '--out-file', dest='out_file',
required=True,
help='Name of HDF5 file to be generated')

parser.add_argument('-i', '--save-iteration', dest='save_iteration', default=False,
help='Save optimizer information for all iterations')

parser.add_argument('-s', '--same-input', dest='same_input', default=True,
help='Merges multistarts with the same inputData.')
args = parser.parse_args()

return args


def main():
numRequiredArgs = 2
if len(sys.argv) <= numRequiredArgs + 1:
printUsage()
sys.exit(1)

infiles = sys.argv[1:(len(sys.argv) - 1)]
outfile = sys.argv[-1]

mergeFiles(infiles, outfile)

args = parse_cli_args()

merge_files(args.in_files, args.out_file, args.save_iteration, args.same_input)


if __name__ == "__main__":
main()