/
datamining.py
840 lines (725 loc) · 27.2 KB
/
datamining.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
import codecs
from collections import OrderedDict
from datetime import datetime
import dill as pickle
import inspect
import json
import numpy as np
import os
import pandas
from pandas.errors import EmptyDataError
from tqdm import tqdm
import types
from pyiron_base import GenericJob, FileHDFio, get_function_from_string
from pyiron.table.funct import (
get_incar,
get_sigma,
get_total_number_of_atoms,
get_elements,
get_convergence_check,
get_number_of_species,
get_number_of_ionic_steps,
get_ismear,
get_encut,
get_n_kpts,
get_n_equ_kpts,
get_number_of_final_electronic_steps,
get_majority_species,
get_job_name,
get_job_id,
get_energy_tot,
get_energy_free,
get_energy_int,
get_energy_tot_per_atom,
get_energy_free_per_atom,
get_energy_int_per_atom,
get_e_conv_level,
get_f_states,
get_e_band,
get_majority_crystal_structure,
get_equilibrium_parameters,
get_structure,
get_forces,
get_magnetic_structure,
get_average_waves,
get_plane_waves,
get_ekin_error,
get_volume,
get_volume_per_atom,
)
__author__ = "Uday Gajera, Jan Janssen, Joerg Neugebauer"
__copyright__ = (
"Copyright 2020, Max-Planck-Institut für Eisenforschung GmbH - "
"Computational Materials Design (CM) Department"
)
__version__ = "0.0.1"
__maintainer__ = "Jan Janssen"
__email__ = "janssen@mpie.de"
__status__ = "development"
__date__ = "Sep 1, 2018"
class FunctionContainer(object):
"""
Class which is able to append, store and retreive a set of functions.
"""
def __init__(self):
self._user_function_dict = {}
self._system_function_lst = [
get_incar,
get_sigma,
get_total_number_of_atoms,
get_elements,
get_convergence_check,
get_number_of_species,
get_number_of_ionic_steps,
get_ismear,
get_encut,
get_n_kpts,
get_n_equ_kpts,
get_number_of_final_electronic_steps,
get_majority_species,
get_job_name,
get_job_id,
get_energy_tot,
get_energy_free,
get_energy_int,
get_energy_tot_per_atom,
get_energy_free_per_atom,
get_energy_int_per_atom,
get_e_conv_level,
get_f_states,
get_e_band,
get_majority_crystal_structure,
get_equilibrium_parameters,
get_structure,
get_forces,
get_magnetic_structure,
get_average_waves,
get_plane_waves,
get_ekin_error,
get_volume,
get_volume_per_atom,
]
self._system_function_dict = {
func.__name__: False for func in self._system_function_lst
}
self._system_function_dict["get_job_id"] = True
@property
def _function_lst(self):
return [
funct
for funct in self._system_function_lst
if funct.__name__ in self._system_function_dict.keys()
and self._system_function_dict[funct.__name__]
] + list(self._user_function_dict.values())
def _to_hdf(self, hdf):
self._to_pickle(
hdf=hdf, key="user_function_dict", value=self._user_function_dict
)
self._to_pickle(
hdf=hdf, key="system_function_dict", value=self._system_function_dict
)
def _from_hdf(self, hdf):
self._user_function_dict = self._from_pickle(hdf=hdf, key="user_function_dict")
self._system_function_dict = self._from_pickle(
hdf=hdf, key="system_function_dict"
)
def __setitem__(self, key, item):
if isinstance(item, str):
self._user_function_dict[key] = eval(
'lambda job: {"' + key + '":' + item + "}"
)
elif isinstance(item, types.FunctionType):
self._user_function_dict[key] = lambda job: {key: item(job)}
else:
raise TypeError("unsupported function type!")
def __getitem__(self, key):
return self._user_function_dict[key]
def __getattr__(self, name):
if name in list(self._system_function_dict.keys()):
self._system_function_dict[name] = True
return self._system_function_dict[name]
else:
super(FunctionContainer, self).__getattr__(name)
def __dir__(self):
return list(self._system_function_dict.keys())
@staticmethod
def _to_pickle(hdf, key, value):
hdf[key] = codecs.encode(pickle.dumps(value), "base64").decode()
@staticmethod
def _from_pickle(hdf, key):
return pickle.loads(codecs.decode(hdf[key].encode(), "base64"))
class JobFilters(object):
"""
Certain predefined job filters
"""
@staticmethod
def job_type(job_type):
def filter_job_type(job):
return job.__name__ == job_type
return filter_job_type
@staticmethod
def job_name_contains(job_name_segment):
def filter_job_name_segment(job):
return job_name_segment in job.job_name
return filter_job_name_segment
class PyironTable(object):
"""
Class for easy, efficient, and pythonic analysis of data from pyiron projects
Args:
project (pyiron.project.Project/None): The project to analyze
name (str): Name of the pyiron table
"""
def __init__(self, project, name=None):
self._project = project
self._df = pandas.DataFrame({})
self.convert_to_object = False
self._name = name
self._db_filter_function = always_true_pandas
self._db_filter_function_str = inspect.getsource(always_true_pandas)
self._filter_function = always_true
self._filter_function_str = inspect.getsource(always_true)
self._filter = JobFilters()
self.add = FunctionContainer()
self._csv_file = None
if self._is_file():
self.load()
self.EMPTY_STR = "-"
@property
def filter(self):
"""
Object containing pre-defined filter functions
Returns:
pyiron.table.datamining.JobFilters: The object containing the filters
"""
return self._filter
@property
def _file_name_csv(self):
if self._csv_file is None:
return self._project.path + self.name + ".csv"
else:
return self._csv_file
@property
def _file_name_txt(self):
return self._project.path + self.name + ".txt"
@property
def name(self):
"""
Name of the table. Takes the project name if not specified
Returns:
str: Name of the table
"""
if self._name is None:
return self._project.name
return self._name
@property
def db_filter_function(self):
"""
Function to filter the a project database table before job specific functions are applied.
The function must take a pyiron project table in the pandas.DataFrame format (project.job_table()) and return a
boolean pandas.DataSeries with the same number of rows as the project table
Example:
def function(df):
return (df["chemicalformula"=="H2"]) & (df["hamilton"=="Vasp"])
"""
return self._db_filter_function
@db_filter_function.setter
def db_filter_function(self, funct):
self._db_filter_function = funct
try:
self._db_filter_function_str = inspect.getsource(funct)
except (OSError, IOError):
pass
@property
def filter_function(self):
"""
Function to filter each job before more expensive functions are applied
"""
return self._filter_function
@filter_function.setter
def filter_function(self, funct):
self._filter_function = funct
try:
self._filter_function_str = inspect.getsource(funct)
except (OSError, IOError):
pass
def to_hdf(self):
file = FileHDFio(file_name=self._project.path + self.name + ".h5", h5_path="/")
self.add._to_hdf(file)
def from_hdf(self):
file = FileHDFio(file_name=self._project.path + self.name + ".h5", h5_path="/")
self.add._from_hdf(file)
def save(self, name=None):
self._name = name
self.to_hdf()
self._save_csv()
def load(self, name=None):
self._name = name
self.from_hdf()
self._load_csv()
def create_table(self, enforce_update=False, level=3, file=None, job_status_list=None):
skip_table_update = False
filter_funct = self.filter_function
if job_status_list is None:
job_status_list = ["finished"]
if self._is_file():
if file is None:
file = FileHDFio(
file_name=self._project.path + self.name + ".h5", h5_path="/"
)
temp_user_function_dict, temp_system_function_dict = self._get_data_from_hdf5(
hdf=file
)
job_update_lst = self._collect_job_update_lst(
job_status_list=job_status_list,
filter_funct=filter_funct,
job_stored_ids=self._get_job_ids()
)
keys_update_user_lst = [
key
for key in self.add._user_function_dict.keys()
if key not in temp_user_function_dict.keys()
]
keys_update_system_lst = [
k
for k, v in self.add._system_function_dict.items()
if v and not temp_system_function_dict[k]
]
if (
len(job_update_lst) == 0
and len(keys_update_user_lst) == 0
and keys_update_system_lst == 0
and not enforce_update
):
skip_table_update = True
else:
job_update_lst = self._collect_job_update_lst(
job_status_list=job_status_list,
filter_funct=filter_funct,
job_stored_ids=None
)
keys_update_user_lst, keys_update_system_lst = [], []
if not skip_table_update and len(job_update_lst) != 0:
df_new_ids = self._iterate_over_job_lst(
job_lst=job_update_lst, function_lst=self.add._function_lst, level=level
)
else:
df_new_ids = pandas.DataFrame({})
if not skip_table_update and (
len(keys_update_user_lst) != 0 or len(keys_update_system_lst) != 0
):
job_update_lst = self._collect_job_update_lst(
job_status_list=job_status_list,
filter_funct=filter_funct,
job_stored_ids=None
)
function_lst = [
v
for k, v in self.add._user_function_dict.items()
if k in keys_update_system_lst
] + [
funct
for funct in self.add._system_function_lst
if funct.__name__ in keys_update_system_lst
]
df_new_keys = self._iterate_over_job_lst(
job_lst=job_update_lst, function_lst=function_lst, level=level
)
else:
df_new_keys = pandas.DataFrame({})
if len(self._df) > 0 and len(df_new_keys) > 0:
self._df = pandas.concat(
[self._df, df_new_keys], axis=1, sort=False
).reset_index(drop=True)
if len(self._df) > 0 and len(df_new_ids) > 0:
self._df = pandas.concat([self._df, df_new_ids], sort=False).reset_index(
drop=True
)
elif len(df_new_ids) > 0:
self._df = df_new_ids
def convert_dict(self, input_dict):
return {key: self.str_to_value(value) for key, value in input_dict.items()}
def refill_dict(self, diff_dict_lst):
total_key_lst = self.total_lst_of_keys(diff_dict_lst)
for ind, sub_dict in enumerate(diff_dict_lst):
for key in total_key_lst:
if key not in sub_dict.keys():
sub_dict[key] = self.EMPTY_STR
else:
sub_dict[key] = self.str_to_value(sub_dict[key])
def col_to_value(self, col_name):
val_lst, key_lst, ind_lst = [], [], []
for ind, name in enumerate(self._df[col_name]):
# print ('name: ', ind, name)
# if name == self.EMPTY_STR:
# continue
name = name.split("_")
ind_lst.append(ind)
key_lst.append(name[0])
val_lst.append(eval(".".join(name[1:])))
if len(set(key_lst)) == 1:
key = key_lst[0]
self._df[key] = val_lst
else:
raise ValueError("key not unique: {}".format(set(key_lst)))
def get_dataframe(self):
return self._df
def list_nodes(self):
return list(self._df.columns)
def list_groups(self):
return list(set(self._df["col_0"]))
@staticmethod
def str_to_value(input_val):
if not isinstance(input_val, str):
return input_val
else:
try:
return eval(input_val)
except (TypeError, SyntaxError, NameError):
return input_val
@staticmethod
def _apply_function_on_job(funct, job):
try:
return funct(job)
except ValueError:
return {}
@staticmethod
def total_lst_of_keys(diff_dict_lst):
total_key_lst = []
for sub_dict in diff_dict_lst:
for key in sub_dict.keys():
total_key_lst.append(key)
return set(total_key_lst)
def __getitem__(self, item, max_level=5):
rename_dict = OrderedDict()
if item in self.list_groups():
for i in range(1, max_level):
rename_dict["col_{}".format(i)] = "col_{}".format(i - 1)
new_table = PyironTable(self._project[item])
new_table._df = self._df.drop("col_0", axis=1)
new_table._df.rename(index=str, columns=rename_dict, inplace=True)
return new_table
if item in self.list_nodes():
return np.array(self._df[item])
return None
def __str__(self):
return self._df.__str__()
def __repr__(self):
"""
Human readable string representation
Returns:
str: pandas Dataframe structure as string
"""
return self._df.__repr__()
def _is_file(self):
return self._project is not None and os.path.isfile(self._file_name_csv)
def _save_csv(self):
self._df.to_csv(self._file_name_csv, index=False)
def _load_csv(self):
self._df = pandas.read_csv(self._file_name_csv)
def _get_project_list(self, name, pr_len, level=3):
lst = [self.EMPTY_STR for _ in range(level)]
for i, p in enumerate(name.split("/")[pr_len - 1 : -1]):
if len(lst) > i:
lst[i] = p
return lst
def _get_data_from_hdf5(self, hdf):
temp_user_function_dict = self.add._from_pickle(
hdf=hdf, key="user_function_dict"
)
temp_system_function_dict = self.add._from_pickle(
hdf=hdf, key="system_function_dict"
)
return temp_user_function_dict, temp_system_function_dict
def _get_job_ids(self):
if len(self._df) > 0:
return self._df.job_id.values
else:
return np.array([])
def _get_filtered_job_ids_from_project(self, recursive=True):
project_table = self._project.job_table(recursive=recursive)
filter_funct = self.db_filter_function
return project_table[filter_funct(project_table)]["id"].tolist()
def _apply_list_of_functions_on_job(self, job, fucntion_lst):
diff_dict = {}
for funct in fucntion_lst:
funct_dict = self._apply_function_on_job(funct, job)
for key, value in funct_dict.items():
diff_dict[key] = value
return diff_dict
def _iterate_over_job_lst(self, job_lst, function_lst, level):
pr_len = len(self._project.project_path.split("/"))
diff_dict_lst = []
for job_inspect in tqdm(job_lst):
if self.convert_to_object:
job = job_inspect.load_object()
else:
job = job_inspect
diff_dict = self._apply_list_of_functions_on_job(
job=job, fucntion_lst=function_lst
)
pr_lst = self._get_project_list(job.project.project_path, pr_len, level)
for ic, col in enumerate(pr_lst):
diff_dict["col_{}".format(ic)] = col
diff_dict_lst.append(diff_dict)
self.refill_dict(diff_dict_lst)
return pandas.DataFrame(diff_dict_lst)
def _collect_job_update_lst(self, job_status_list, filter_funct, job_stored_ids=None):
"""
Collect jobs to update the pyiron table
Args:
job_status_list (list): List of job status to consider
filter_funct (function): Filter function
job_stored_ids (list/ None): List of already analysed job ids
Returns:
list: List of JobCore objects
"""
if job_stored_ids is not None:
job_id_lst = [
job_id
for job_id in self._get_filtered_job_ids_from_project()
if job_id not in job_stored_ids
]
else:
job_id_lst = self._get_filtered_job_ids_from_project()
job_update_lst = []
for job_id in tqdm(job_id_lst):
try:
job = self._project.inspect(job_id)
except IndexError: # In case the job was deleted while the pyiron table is running
job = None
if job is not None and job.status in job_status_list and filter_funct(job):
job_update_lst.append(job)
return job_update_lst
def _repr_html_(self):
"""
Internal helper function to represent the GenericParameters object within the Jupyter Framework
Returns:
HTML: Jupyter HTML object
"""
return self._df._repr_html_()
class TableJob(GenericJob):
def __init__(self, project, job_name):
super(TableJob, self).__init__(project, job_name)
self.__version__ = "0.1"
self.__name__ = "TableJob"
self._analysis_project = None
self._pyiron_table = PyironTable(project=None)
self._enforce_update = False
self._project_level = 0
self.analysis_project = project.project
@property
def filter(self):
return self._pyiron_table.filter
@property
def project_level(self):
return self._project_level
@project_level.setter
def project_level(self, level):
self._project_level = level
@property
def db_filter_function(self):
return self._pyiron_table.db_filter_function
@db_filter_function.setter
def db_filter_function(self, funct):
self._pyiron_table.db_filter_function = funct
@property
def filter_function(self):
return self._pyiron_table.filter_function
@filter_function.setter
def filter_function(self, funct):
self._pyiron_table.filter_function = funct
@property
def pyiron_table(self):
return self._pyiron_table
@property
def ref_project(self):
return self.analysis_project
@ref_project.setter
def ref_project(self, project):
self.analysis_project = project
@property
def analysis_project(self):
return self._analysis_project
@analysis_project.setter
def analysis_project(self, project):
self._analysis_project = project
self._pyiron_table = PyironTable(project=self._analysis_project)
@property
def add(self):
return self._pyiron_table.add
@property
def convert_to_object(self):
return self._pyiron_table.convert_to_object
@convert_to_object.setter
def convert_to_object(self, conv_to_obj):
self._pyiron_table.convert_to_object = conv_to_obj
@property
def enforce_update(self):
return self._enforce_update
@enforce_update.setter
def enforce_update(self, enforce):
if isinstance(enforce, bool):
if enforce:
self._enforce_update = True
if self.status.finished:
self.status.created = True
else:
self._enforce_update = False
else:
raise TypeError()
@staticmethod
def convert_numpy_to_list(table_dict):
for k,v in table_dict.items():
for k1,v1 in v.items():
if isinstance(v1,np.ndarray):
v[k1] = v1.tolist()
return table_dict
def to_hdf(self, hdf=None, group_name=None):
"""
Store pyiron table job in HDF5
Args:
hdf:
group_name:
"""
super(TableJob, self).to_hdf(hdf=hdf, group_name=group_name)
with self.project_hdf5.open("input") as hdf5_input:
hdf5_input["bool_dict"] = {
"enforce_update": self._enforce_update,
"convert_to_object": self._pyiron_table.convert_to_object,
}
self._pyiron_table.add._to_hdf(hdf5_input)
if self._analysis_project is not None:
hdf5_input["project"] = {
"path": self._analysis_project.path,
"user": self._analysis_project.user,
"sql_query": self._analysis_project.sql_query,
"filter": self._analysis_project._filter,
"inspect_mode": self._analysis_project._inspect_mode,
}
if self.pyiron_table._filter_function is not None:
try:
hdf5_input["filter"] = inspect.getsource(
self.pyiron_table._filter_function
)
except (OSError, IOError):
if self.pyiron_table._filter_function_str is not None:
hdf5_input["filter"] = self.pyiron_table._filter_function_str
if self.pyiron_table._db_filter_function is not None:
try:
hdf5_input["db_filter"] = inspect.getsource(
self.pyiron_table._db_filter_function
)
except (OSError, IOError):
if self.pyiron_table._db_filter_function_str is not None:
hdf5_input["db_filter"] = self.pyiron_table._db_filter_function_str
if len(self.pyiron_table._df) != 0:
with self.project_hdf5.open("output") as hdf5_output:
table_dict = self.convert_numpy_to_list(self.pyiron_table._df.to_dict())
hdf5_output["table"] = json.dumps(table_dict)
def from_hdf(self, hdf=None, group_name=None):
"""
Restore pyiron table job from HDF5
Args:
hdf:
group_name:
"""
super(TableJob, self).from_hdf(hdf=hdf, group_name=group_name)
with self.project_hdf5.open("input") as hdf5_input:
if "project" in hdf5_input.list_nodes():
project_dict = hdf5_input["project"]
project = self.project.__class__(
path=project_dict["path"],
user=project_dict["user"],
sql_query=project_dict["sql_query"],
)
project._filter = project_dict["filter"]
project._inspect_mode = project_dict["inspect_mode"]
self.analysis_project = project
if "filter" in hdf5_input.list_nodes():
self.pyiron_table._filter_function_str = hdf5_input["filter"]
self.pyiron_table.filter_function = get_function_from_string(
hdf5_input["filter"]
)
if "db_filter" in hdf5_input.list_nodes():
self.pyiron_table._db_filter_function_str = hdf5_input["db_filter"]
self.pyiron_table.db_filter_function = get_function_from_string(
hdf5_input["db_filter"]
)
bool_dict = hdf5_input["bool_dict"]
self._enforce_update = bool_dict["enforce_update"]
self._pyiron_table.convert_to_object = bool_dict["convert_to_object"]
self._pyiron_table.add._from_hdf(hdf5_input)
pyiron_table = os.path.join(self.working_directory, "pyirontable.csv")
if os.path.exists(pyiron_table):
try:
self._pyiron_table._df = pandas.read_csv(pyiron_table)
self._pyiron_table._csv_file = pyiron_table
except EmptyDataError:
pass
else:
with self.project_hdf5.open("output") as hdf5_output:
if "table" in hdf5_output.list_nodes():
self._pyiron_table._df = pandas.DataFrame(
json.loads(hdf5_output["table"])
)
def validate_ready_to_run(self):
if self._analysis_project is None:
raise ValueError("Analysis project not defined!")
def run_static(self):
self._create_working_directory()
self.status.running = True
self.update_table()
self.status.finished = True
self.run()
def update_table(self, job_status_list=None):
"""
Update the pyiron table object, add new columns if a new function was added or add new rows for new jobs
Args:
job_status_list (list/None): List of job status which are added to the table by default ["finished"]
"""
if job_status_list is None:
job_status_list = ["finished"]
self.project.db.item_update({"timestart": datetime.now()}, self.job_id)
with self.project_hdf5.open("input") as hdf5_input:
self._pyiron_table.create_table(
enforce_update=self._enforce_update,
file=hdf5_input,
level=self._project_level,
job_status_list=job_status_list,
)
self.to_hdf()
self._pyiron_table._df.to_csv(
os.path.join(self.working_directory, "pyirontable.csv"), index=False
)
with self.project_hdf5.open("output") as hdf5_output:
table_dict = self.convert_numpy_to_list(self.pyiron_table._df.to_dict())
hdf5_output["table"] = json.dumps(table_dict)
self.project.db.item_update(self._runtime(), self.job_id)
def write_input(self):
pass
def get_dataframe(self):
"""
Returns:
pandas.Dataframe
"""
return self.pyiron_table._df
def always_true_pandas(job_table):
"""
A function which returns a pandas Series with all True values based on the size of the input pandas dataframe
Args:
job_table (pandas.DataFrame): Input dataframe
Returns:
pandas.Series: A series of True values
"""
from pandas import Series
return Series([True] * len(job_table), index=job_table.index)
def always_true(_):
"""
A function that always returns True no matter what!
Returns:
bool: True
"""
return True