pyRDDLGym icon indicating copy to clipboard operation
pyRDDLGym copied to clipboard

RDDLSimServer data.json file truncated

Open GMMDMDIDEMS opened this issue 11 months ago • 3 comments

With large instances (many objects and states) and correspondingly large data.json files, it very often happens that the data.json files are cut off, i.e. a part is missing and is not formatted correctly.

I cannot exactly identify the cause of the problem, but it is not due to the implementation. I can rule out that it is due to a lack of disk space, and it shouldn't be due to memory either, as a Docker container has no resource constraints by default. No error is thrown if a file is saved incorrectly formatted/truncated and it is also not possible to say that a file is no longer written correctly above a certain size. Some files with 13MB were written correctly and some whose correct size is 8MB were only written up to 2.4MB.

However, switching from json to orjson, a faster and more memory-efficient alternative, eliminates all problems.

Fix

https://github.com/pyrddlgym-project/pyRDDLGym/blob/ad21a92772035017785fc044014cb45596eaea0b/pyRDDLGym/core/server.py#L154

with

import orjson

def dump_data(self, fn):
   """Dumps the data to a json file."""
   json_content = orjson.dumps(self.logs)
   with open(fn, mode="wb") as f:
      f.write(json_content)

GMMDMDIDEMS avatar Mar 11 '24 10:03 GMMDMDIDEMS