23
23
logger = logging .getLogger (__name__ )
24
24
25
25
26
- def display_number (x ):
27
- ret = "n/a"
28
- if math .isfinite (x ):
29
- ret = f"{ x : 0.2g} "
30
- return ret
31
-
32
-
33
- def display_size (n ):
34
- return humanfriendly .format_size (n , binary = True )
35
-
36
-
37
26
@dataclasses .dataclass
38
27
class VcfFieldSummary (core .JsonDataclass ):
39
28
num_chunks : int = 0
@@ -874,11 +863,11 @@ def summary_table(self):
874
863
"name" : name ,
875
864
"type" : col .vcf_field .vcf_type ,
876
865
"chunks" : summary .num_chunks ,
877
- "size" : display_size (summary .uncompressed_size ),
878
- "compressed" : display_size (summary .compressed_size ),
866
+ "size" : core . display_size (summary .uncompressed_size ),
867
+ "compressed" : core . display_size (summary .compressed_size ),
879
868
"max_n" : summary .max_number ,
880
- "min_val" : display_number (summary .min_value ),
881
- "max_val" : display_number (summary .max_value ),
869
+ "min_val" : core . display_number (summary .min_value ),
870
+ "max_val" : core . display_number (summary .max_value ),
882
871
}
883
872
884
873
data .append (d )
@@ -1546,12 +1535,12 @@ def summary_table(self):
1546
1535
d = {
1547
1536
"name" : array .name ,
1548
1537
"dtype" : str (array .dtype ),
1549
- "stored" : display_size (stored ),
1550
- "size" : display_size (array .nbytes ),
1551
- "ratio" : display_number (array .nbytes / stored ),
1538
+ "stored" : core . display_size (stored ),
1539
+ "size" : core . display_size (array .nbytes ),
1540
+ "ratio" : core . display_number (array .nbytes / stored ),
1552
1541
"nchunks" : str (array .nchunks ),
1553
- "chunk_size" : display_size (array .nbytes / array .nchunks ),
1554
- "avg_chunk_stored" : display_size (int (stored / array .nchunks )),
1542
+ "chunk_size" : core . display_size (array .nbytes / array .nchunks ),
1543
+ "avg_chunk_stored" : core . display_size (int (stored / array .nchunks )),
1555
1544
"shape" : str (array .shape ),
1556
1545
"chunk_shape" : str (array .chunks ),
1557
1546
"compressor" : str (array .compressor ),
@@ -1567,7 +1556,7 @@ def parse_max_memory(max_memory):
1567
1556
return 2 ** 63
1568
1557
if isinstance (max_memory , str ):
1569
1558
max_memory = humanfriendly .parse_size (max_memory )
1570
- logger .info (f"Set memory budget to { display_size (max_memory )} " )
1559
+ logger .info (f"Set memory budget to { core . display_size (max_memory )} " )
1571
1560
return max_memory
1572
1561
1573
1562
@@ -1721,7 +1710,7 @@ def init(
1721
1710
num_samples = self .icf .num_samples ,
1722
1711
num_partitions = self .num_partitions ,
1723
1712
num_chunks = total_chunks ,
1724
- max_encoding_memory = display_size (self .get_max_encoding_memory ()),
1713
+ max_encoding_memory = core . display_size (self .get_max_encoding_memory ()),
1725
1714
)
1726
1715
1727
1716
def encode_samples (self , root ):
@@ -2082,7 +2071,7 @@ def encode_all_partitions(
2082
2071
per_worker_memory = self .get_max_encoding_memory ()
2083
2072
logger .info (
2084
2073
f"Encoding Zarr over { num_partitions } partitions with "
2085
- f"{ worker_processes } workers and { display_size (per_worker_memory )} "
2074
+ f"{ worker_processes } workers and { core . display_size (per_worker_memory )} "
2086
2075
"per worker"
2087
2076
)
2088
2077
# Each partition requires per_worker_memory bytes, so to prevent more that
@@ -2091,12 +2080,14 @@ def encode_all_partitions(
2091
2080
if max_num_workers < worker_processes :
2092
2081
logger .warning (
2093
2082
f"Limiting number of workers to { max_num_workers } to "
2094
- f"keep within specified memory budget of { display_size (max_memory )} "
2083
+ "keep within specified memory budget of "
2084
+ f"{ core .display_size (max_memory )} "
2095
2085
)
2096
2086
if max_num_workers <= 0 :
2097
2087
raise ValueError (
2098
2088
f"Insufficient memory to encode a partition:"
2099
- f"{ display_size (per_worker_memory )} > { display_size (max_memory )} "
2089
+ f"{ core .display_size (per_worker_memory )} > "
2090
+ f"{ core .display_size (max_memory )} "
2100
2091
)
2101
2092
num_workers = min (max_num_workers , worker_processes )
2102
2093
0 commit comments