File size: 1,348 Bytes
5ac1897
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from .basic import bsb
from .adaptable.v1 import asb

# The batch manager is used to quickly initialize a batched task.
# The Usage of the batch manager is as follows:


def eg_bbm():
    ''' Basic version of the batch manager. '''
    task_len = 1e6
    task_things = [i for i in range(int(task_len))]

    for bw in bsb(total=task_len, batch_size=300, enable_tqdm=True):
        sid = bw.sid
        eid = bw.eid
        round_things = task_things[sid:eid]
        # Do something with `round_things`.


def eg_asb():
    ''' Basic version of the batch manager. '''
    task_len = 1024
    task_things = [i for i in range(int(task_len))]

    lb, ub = 1, 300  # lower & upper bound of batch size
    for bw in asb(total=task_len, bs_scope=(lb, ub), enable_tqdm=True):
        sid = bw.sid
        eid = bw.eid
        round_things = task_things[sid:eid]
        # Do something with `round_things`.

        try:
            # Do something with `round_things`.
            pass
        except Exception as e:
            if not bw.shrink():
                # In this case, it means task_things[sid:sid+lb] is still too large to handle.
                # So you need to do something to handle this situation.
                pass
            continue  #! DO NOT FORGET CONTINUE

        # Do something with `round_things` if no exception is raised.