sjtu-marl / malib

A parallel framework for population-based multi-agent reinforcement learning.
https://malib.io
MIT License
499 stars 60 forks source link

Identify the difference between data saving and no eough data #18

Closed KornbergFresnel closed 2 years ago

KornbergFresnel commented 3 years ago

OfflineDataSet cannot identify the differences between sampled data saving and no enough data at the stage of data sampling. So that trainer may be stuck at the request_data.

Proposal: use a table status to identify the differences

class Table:
    def save(self):
        self.status = Status.IN_PROCESS
        # ...
        self.status  = Status.DONE

class OfflineDataset:
    # ...
    def sample(self, *args, **kwargs):
        # ...
        try:
            if table.status == Status.IN_PROCESS:
                raise BusyError
            if table.size < self._learn_start:
                raise NoEnoughDataError
            batch = table.sample(batch_size)
        except BusyError as e:
            info = BusyError
        except NoEnoughDataError as e:
            info = NoEnoughDataError
        except Exception as e:
            info = str(e)
        return batch, info