[netlogo] output as a list/array



Stupid question but is it possible to return a netlogo list to the oms script? I guess yes as I saw some issues (#319 and #323) about it. But I have no idea how I should do it. I tried various things and no success so far.
Val[Array[Double]] gives me:

 Error when fetching netlogo output talents in variable (talents: Array[Double])

Maybe I haven’t looked at the good place and there is a doc with the different type/cast possible? …


Hi Simon,

it is possible. Could you provide your OpenMOLE script here, so I can look at it ?



Here is the oms script (nothing much more than what the wizard created):

val seed = Val[Int]
val numberOfIndividuals = Val[Double]
val ppOfLuckyEvents = Val[Double]
val numberOfEvents = Val[Double]
val meanTalent = Val[Double]
val stdevTalent = Val[Double]
val sizeOfIndividuals = Val[Double]
val initialSuccess = Val[Double]
val simulationTime = Val[Double]
val time = Val[Double]
val talents = Val[List[Double]]
val successes = Val[List[Double]]

val launch = List("setup","go;;You should set your stopping criteria here instead")
val tvlmodelTask = NetLogo6Task(workDirectory / "TvLmodel.nlogo", launch, embedWorkspace = false, seed=seed) set(
  inputs += (seed),
  inputs += numberOfIndividuals mapped "number-of-individuals",
  inputs += ppOfLuckyEvents mapped "pp-of-lucky-events",
  inputs += numberOfEvents mapped "number-of-events",
  inputs += meanTalent mapped "mean-talent",
  inputs += stdevTalent mapped "stdev-talent",
  inputs += sizeOfIndividuals mapped "size-of-individuals",
  inputs += initialSuccess mapped "initial-success",
  inputs += simulationTime mapped "simulation-time",
  outputs += talents mapped "talents",
  outputs += successes mapped "successes",
  //Default values. Can be removed if OpenMOLE Vals are set by values coming from the workflow
  seed := 0,
  numberOfIndividuals := 1000.0,
  ppOfLuckyEvents := 50.0,
  numberOfEvents := 1000.0,
  meanTalent := 0.54,
  stdevTalent := 0.17,
  sizeOfIndividuals := 7.0,
  initialSuccess := 5.0,
  simulationTime := 35.0)

tvlmodelTask hook ToStringHook()

Thank you very much for your help btw :smiley: reactive community we have here :wink: :


(Juste Raimbault) #4

Hi Simon,
The Val[List[Double]] prototype will fail with netlogolists, but a Val[Array[Double]] should work with a level 1 logo list ; (if you have nested list you should use a Array[Array[Double]])


Ok I tried that but it was returning error too. I guess maybe the problem comes from the Netlogo script.

(Juste Raimbault) #6

Strange ; could you provide the rest of the exception ?


ok I got it :smile: :tada:

The problem was from the way I was launching the model so this:

val launch = List("setup","go;;You should set your stopping criteria here instead")

As the model was using the loop from the “run button” of netlogo I didn’t get that I should do the loop by myself in the launch command. Thus the run was only one loop of the model, the if-condition where the lists were filled was never entered. I guess that by default global variable in NetLogo are Double, thus a Double was returned in my outputs which were defined as Array. That was generating the Java error. Solved by doing that:

val launch = List("setup","while[conditionthatwasingobefore == 1][go];;You should set your stopping criteria here instead")

I gess the comment “You should set your stopping criteria here instead” was not clear enough for me :frowning:

Sorry for disturbing and thanks for the help!


(Juste Raimbault) #8

Indeed, if the global output was never set it is by default at 0 in NetLogo, so it was failing trying to fetch an array to a double.

For what is run in the model, indeed you need to write yourself the full procedure inside netlogo, OpenMole won’t for example loop your go ; it is supposed to be explained in the doc https://openmole.org/NetLogo.html (section Headless Netlogo Model)
If you have feedback on the doc do not hesitate, maybe it is still a bit confused !


It may be just my fault as I haven’t wrote anything in netlogo is 6-7 years and I forget about those tricky netlogo stuff of where to handle the mainloop/stop conditions. And it’s true there is even a comment added by the wizard to remind it.
Any maybe a clear sentence to remind it to people like me may help. I opened a pull request if someone think it’s worth it! cf pr #385