An error occurred while loading the file. Please try again.
-
Le Roux Erwan authored
[SCM][HYPERCUBE] Add multiprocessing when loading abstract study. Refactor abstract variable and all variables accordinlgly.
d5329137
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
import datetime
import os.path as op
from cached_property import cached_property
VERSION = datetime.datetime.now()
VERSION_TIME = str(VERSION).split('.')[0]
for c in [' ', ':', '-']:
VERSION_TIME = VERSION_TIME.replace(c, '_')
NB_CORES = 7
def get_root_path() -> str:
return op.dirname(op.abspath(__file__))
def get_full_path(relative_path: str) -> str:
return op.join(get_root_path(), relative_path)
def get_display_name_from_object_type(object_type):
# assert isinstance(object_type, type), object_type
return str(object_type).split('.')[-1].split("'")[0].split(' ')[0]
def first(s):
"""Return the first element from an ordered collection
or an arbitrary element from an unordered collection.
Raise StopIteration if the collection is empty.
"""
return next(iter(s))
def float_to_str_with_only_some_significant_digits(f, nb_digits) -> str:
assert isinstance(nb_digits, int)
assert nb_digits > 0
return '%s' % float('%.{}g'.format(nb_digits) % f)
class Example(object):
@cached_property
def big_attribute(self):
print('Long loading only once...')
return 2
if __name__ == '__main__':
e = Example()
print(e.big_attribute)
print(e.big_attribute)
print(VERSION_TIME)