Skip to content

Commit 4e2cb01

Browse files
authored
update abitimer (#4319)
1 parent afa6652 commit 4e2cb01

File tree

3 files changed

+931
-7
lines changed

3 files changed

+931
-7
lines changed

src/pymatgen/io/abinit/abitimer.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import collections
99
import logging
1010
import os
11+
import re
1112
import sys
1213

1314
import matplotlib.pyplot as plt
@@ -141,7 +142,16 @@ def _read(self, fh, fname):
141142

142143
def parse_line(line):
143144
"""Parse single line."""
144-
name, vals = line[:25], line[25:].split()
145+
# Assume the first element of the values is a float. Use the first
146+
# float appearing as a split between the name and the values.
147+
# Also only digits, "." and spaces can be present after the fist float.
148+
match = re.search(r"\s(\d+\.\d+[-\d.\s]*)$", line)
149+
if not match:
150+
raise self.Error(f"Cannot properly split line in label and values: {line}")
151+
split_index = match.start()
152+
name = line[:split_index].rstrip()
153+
vals = line[split_index:].strip().split()
154+
145155
try:
146156
ctime, cfract, wtime, wfract, ncalls, gflops = vals
147157
except ValueError:
@@ -712,15 +722,11 @@ def to_table(self, sort_key="wall_time", stop=None):
712722

713723
def get_dataframe(self, sort_key="wall_time", **kwargs):
714724
"""Return a pandas DataFrame with entries sorted according to `sort_key`."""
715-
frame = pd.DataFrame(columns=AbinitTimerSection.FIELDS)
716-
717-
for osect in self.order_sections(sort_key):
718-
frame = frame.append(osect.to_dict(), ignore_index=True)
725+
data = [osect.to_dict() for osect in self.order_sections(sort_key)]
726+
frame = pd.DataFrame(data, columns=AbinitTimerSection.FIELDS)
719727

720728
# Monkey patch
721729
frame.info = self.info
722-
frame.cpu_time = self.cpu_time
723-
frame.wall_time = self.wall_time
724730
frame.mpi_nprocs = self.mpi_nprocs
725731
frame.omp_nthreads = self.omp_nthreads
726732
frame.mpi_rank = self.mpi_rank

0 commit comments

Comments
 (0)