0

I am running an ensemble of netlogo models through pynetlogo. Every few steps i export the world to file, perform some minor incantations and then import those worlds from file again and keep running the model.
Works like a charm, very happy.

I wanted however to cut down on the write/read operations on disc and I realized that the extensions export-the and import-a would output the world string. So I want to:

  1. save the export-the:world call to the string saved_world
  2. then re import it through import-a:world

Unfortunately when I try do to this, and more specifically:

saved_world = netlogo.report('export-the:world')
netlogo.command('import-a:world '+ str(saved_world))

I get hit by a torrent of Scala exceptions, the legible few related to illegal characters. My guess is that the conversion netlogo string to java string object to python string and back to command, some escape parameters are lost or added in a way that is illegal.

Has anybody gone through something similar? I tried encoding/decoding the saved_world string in many different ways (raw, non-raw, utf8, etc...) but with no success.

CarrKnight
  • 2,768
  • 2
  • 23
  • 25
  • 1
    Can you print out what `saved_world` looks like on the Python side? And then instead of directly running `import-a:world`, `show` the value on the NetLogo side as well? That might give a clue as to what's going wrong. Also, what does the `str()` call do? – Jasper Jun 10 '21 at 12:57
  • 1
    Unfortunately a well known problem of `export-the` extension is that the output string is so big that it crashes the netlogo console (at least for wolf-sheep-grass which I am using as example). So I can't compare this manually. `str()` in python forces an object to be string. The `pynetlogo` library is not returning a python string, but a Java string object (through `jpype`) so you need to explicitly cast it – CarrKnight Jun 10 '21 at 14:18
  • Understood about the console crash for printing the `export-the`. How about sending it to a file instead and then checking the results there? – Jasper Jun 10 '21 at 15:46
  • Have you ever figured out how to get around these illegal character errors? I face a similar problem at the moment – DeMelkbroer Aug 31 '22 at 09:28
  • @DeMelkbroer I am sorry but no luck. Had switched to a MESA implementation of that model. – CarrKnight Aug 31 '22 at 10:30

0 Answers0