1

CONTEXT: I'm trying to perform a global sensitivity analysis for my NetLogo model using PyNetLogo on a Linux-based computing cluster. I follow closely the second example described in the PyNetLogo documentation for a Sobol' sensitivity analysis. My script is in a Jupyter Notebook and I'm using NetLogo version 6.0.4.

PROBLEM: When executing the cell that runs the simulation with the map_sync function, I get the following error message: NameError: name 'netlogo' is not defined.

enter image description here

I define 'netlogo' in a previous cell:

enter image description here

The error points to line 143 which contains 'sequence(s)' , and according to the documentation, the map_sync function takes a Python sequence as an argument. enter image description here

I'm unsure how to proceed from here and thus haven't been able to try anything, yet. I did make sure that the NetLogo model runs well itself. When I run the sensitivity analysis on my local machine following the same PyNetLogo documentation, the error doesn't occur.

Any help and suggestions would be very much appreciated - thanks a lot already!

**Update: I uninstalled PyNetLogo version 0.4.2. and tried to run the code with version 0.3, 0.4. and 0.4.1 but the error persisted, unfortunately.

Best, Marius

Marius
  • 51
  • 7
  • 1
    Where is net logo referenced? Can you include the entire context of the code that is being run? – pygeek Sep 14 '21 at 15:17
  • Hi and thanks for the reply! The line I include (netlogo = pyNetLogo.NetLogoLink(gui=False, netlogo_home='/home/users/vonessen/NetLogo-6.0.4', netlogo_version='6', jvm_home='/share/software/user/open/java/11.0.11/lib/server/libjvm.so') is the first time its mentioned, really. The previous lines follow the documentation of PyNetLogo Example 2 very closely and are just adjusted for my model (see here: https://pynetlogo.readthedocs.io/en/latest/_docs/introduction.html). Hope that helps and let me know if I missed anything! – Marius Sep 15 '21 at 21:51

1 Answers1

0

I can't comment as I don't have enough reputation. Without seeing a minimal example of your full code, and a quick check of my pynetlogo scripts (windows, multi-threaded), you are initialising each instance of netlogo within each cluster? i.e. you have netlogo = pyNetLogo.NetLogoLink(gui = False ... ) initialised within each cluster?

Lachlan
  • 360
  • 5
  • 14
  • Yes, I believe so. I'm not very familiar with Python / this type of coding, but I believe this is the line that pushes the initialization to each cluster. client = ipyparallel.Client() client.ids then direct_view = client[:] direct_view.push(dict(cwd=os.getcwd())) direct_view.push(dict(problem=problem)) and then %px import os cwd = os.getcwd() os.chdir(cwd) The next line is the instantiation itself. Hope that helps and let me know if I should include any other info. I follow Example two of the PyNetLogo documentation closely, so my code looks very similar to theirs. – Marius Sep 15 '21 at 21:55
  • If you run their example code with the netlogo example (should be in the standard install examples I think), does it work? I am not familiar with `ipyparallel`, but does the `%%px` command send the code sections to each instance? a quick look at the [docs](https://ipyparallel.readthedocs.io/en/6.2.1/magics.html) says it should be `%px`? Otherwise it seems as though their example netlogo initialisation isn't ever 'pushed' to the `client`, which might explain why you get the error saying its not defined. – Lachlan Sep 17 '21 at 03:32
  • Yes, we exactly followed Example 2, but same error. I tried both %%px and %px. %px gives the error 'NameError: name 'cwd' is not defined'; adding 'cwd = os.getcwd()' sovlces the error, but still produces the 'NameError: name 'netlogo' is not defined'. If I do %%px without cwd = os.getcwd() there is no error in that line, but eventually the same error again (NameError) when I run results = pd.DataFrame(lview.map_sync(simulation, param_values)). I agree, though, that maybe the issue is with the pushing of the initialisation, also because it produces exceptions equal to the # of runs. – Marius Sep 17 '21 at 21:41