Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
50 views
in Technique[技术] by (71.8m points)

python - DeprecationWarning with NL4Py

I am using NL4Py and a few functions have deprecation warnings. I am able to start Nelogo, open a model, and run a model through the NL4Py python package. However, when I try to set parameter values and I get DeprecationWarning, but the function suggested is the same as the previous one used, setParamsRandom(). And the setParamsRandom() does not update parameter values in the Netlogo model. I would like to be able to set parameter values in Netlogo. I am not sure if there is an updated function or something wrong with my compatibility:

python 3.8, ipython 7.10.0, nl4py 0.7.0, jdk 15.0.2, Netlogo 6.0, MacOS Catalina 10.15.7

#start of code for nl4py
import nl4py
nl4py.initialize("/Applications/NetLogo 6.0/")
n = nl4py.netlogo_app() 
n.open_model('/Users/tracykuper/Desktop/NetLogo 6.0/models/Sample Models/Earth Science/Fire.nlogo')

n.setParamsRandom()
<ipython-input-10-50e53e085382>:1: DeprecationWarning: Call to deprecated function setParamsRandom (Alias left for backward compatibility. Use setParamsRandom() since version 1.0.0.).
  n.setParamsRandom()
---------------------------------------------------------------------------
Py4JJavaError                             Traceback (most recent call last)
<ipython-input-10-50e53e085382> in <module>
----> 1 n.setParamsRandom()
      2 #n.getParamList()

~/opt/anaconda3/envs/netpy/lib/python3.8/site-packages/nl4py/NL4PyException.py in new_func1(*args, **kwargs)
     57                 )
     58                 warnings.simplefilter('default', DeprecationWarning)
---> 59                 return func1(*args, **kwargs)
     60 
     61             return new_func1

~/opt/anaconda3/envs/netpy/lib/python3.8/site-packages/nl4py/NetLogoGUI.py in setParamsRandom(self)
    185     @deprecated('Alias left for backward compatibility. Use setParamsRandom() since version 1.0.0.')
    186     def setParamsRandom(self):
--> 187         self.set_params_random()
    188 
    189     @deprecated('Alias left for backward compatibility. Use getParamNames() since version 1.0.0.')

~/opt/anaconda3/envs/netpy/lib/python3.8/site-packages/nl4py/NetLogoGUI.py in set_params_random(self)
     97 
     98         '''    
---> 99         paramSpecs = self.app.getParamList(self.path).getParamSpecs()
    100 
    101         ##Using some bsearch code here thanks to Forrest Stonedahl

~/opt/anaconda3/envs/netpy/lib/python3.8/site-packages/py4j/java_gateway.py in __call__(self, *args)
   1302 
   1303         answer = self.gateway_client.send_command(command)
-> 1304         return_value = get_return_value(
   1305             answer, self.gateway_client, self.target_id, self.name)
   1306 

~/opt/anaconda3/envs/netpy/lib/python3.8/site-packages/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    324             value = OUTPUT_CONVERTER[type](answer[2:], gateway_client)
    325             if answer[1] == REFERENCE_TYPE:
--> 326                 raise Py4JJavaError(
    327                     "An error occurred while calling {0}{1}{2}.
".
    328                     format(target_id, ".", name), value)

Py4JJavaError: An error occurred while calling o0.getParamList.
: java.lang.NoSuchMethodError: 'org.nlogo.api.ValueConstraint org.nlogo.agent.Observer.constraint(int)'
    at bsearch.nlogolink.Utils.getDefaultConstraintsText(Utils.java:68)
    at nl4py.server.NetLogoAppController.getParamList(NetLogoAppController.java:169)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)

    at java.base/java.lang.Thread.run(Thread.java:832)
question from:https://stackoverflow.com/questions/65888938/deprecationwarning-with-nl4py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Turns out nlpy0.5.0 works much better and will follow the documentation: https://arxiv.org/pdf/1808.03292.pdf.

I was able to install the nlpy0.5.0 with the following code:

pip install install nl4py==0.5.0 

Hopefully whoever updated the nlpy0.7.0 will update the documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...