Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pynetlogo calling a model which uses py extension #79

Open
SebasMeza opened this issue Jun 22, 2023 · 11 comments
Open

pynetlogo calling a model which uses py extension #79

SebasMeza opened this issue Jun 22, 2023 · 11 comments

Comments

@SebasMeza
Copy link

SebasMeza commented Jun 22, 2023

Hi,

I hope to receive any help here.

I'm trying to run an old model that I initialized in Python through pynetlogo and that model has inside as well usage of the py extension. I know it is a strange usage to call a NetLogo model from Python and then use Python from the model but it is something I did some years ago and worked properly.

Nowadays I'm trying to set up again the model (for research purposes) but I'm getting the error shown in the image and the following message:

`java.lang.RuntimeException
at netLogoLink.NetLogoLink.loadModel(NetLogoLink.java:121)

Traceback (most recent call last):

  File NetLogoLink.java:121 in netLogoLink.NetLogoLink.loadModel

Exception: Java Exception


The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File ~\anaconda3\lib\site-packages\pynetlogo\core.py:246 in load_model
    self.link.loadModel(path)

java.lang.RuntimeException: java.lang.RuntimeException


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  Cell In[4], line 1
    model.load_model('C:/Users/sebas/Downloads/AGuerra/Artículo/models/simulation.nlogo')

  File ~\anaconda3\lib\site-packages\pynetlogo\core.py:249 in load_model
    raise NetLogoException(str(ex))

NetLogoException: java.lang.RuntimeException`

I guess the error raises because I'm also calling Python from the models called by Python. I guess it is because I call other models without the Python extension and it works fine.

Let me know please what the cause could be and if I making any mistake or I'm guessing well. Just trying to find a solution but I'm still not there.

@quaquel

image

@bussayii
Copy link

Hi!

I have been trying to fix this problem for weeks too.
I have this exact error and my model also uses py extension.

At first, my environment was like this ...

  • python 3.8
  • netlogo 6.2.2
  • jpype1 1.4.1
  • pynetlogo 0.5.1
    This environment generate the error for both a simple CCL's example model and my model with lots of extensions.

I have used pynetlogo in 2021 successfully. Thus, I tried downgrading everything to older versions as follows...

  • python 3.8
  • netlogo 6.0.4 and netlogo 6.1.1
  • jpype1 1.2.1
  • pynetlogo 0.3
    With this environment netlogo 6.0.4 can run CCL's simple model without errors but it yields that exact error with my model.
    And netlogo 6.1.1 yields that exact error for both the simple model and my model.

Both of my ubuntu 22.04 and windows 10 face this same problem.

Please let me know if i had done anything wrong or if there is a solution. Thank you in advance.

@bussayii
Copy link

I have tried this too. Running my model gives the same error. I didn't run the simple model though.

  • python 3.8
  • netlogo 6.3.0
  • jpype latest
  • pynetlogo 0.5.1

And I have been alternating between openjdk 11 and openjdk 8 too.

@quaquel
Copy link
Owner

quaquel commented Jun 24, 2023

There is no immediate recent change in pynetlogo that comes to mind that might explain this problem. Can either of you test a model with some other extension?

@bussayii
Copy link

Hello! Thank you for the answer!

I have tried opting in one extension at a time and opting out one at a time to this simple model. The model with that exact list of extensions works fine on NetLogo 6.3 standalone, but gives error when loading though pynetlogo.

The model

extensions [ cf csv gis matrix py table vid]

to setup
clear-all
file-close-all ; Close any files open from last run
reset-ticks
end

; procedure to generate 100 random turtles
to generate-turtles
create-turtles 100 [
set xcor random-xcor
set ycor random-ycor
set size 1 + random 5
]
end

I have ruled out that only the py extension is a part of this problem. The error for my windows 10 looks like this.

The error


Exception Traceback (most recent call last)
File NetLogoLink.java:121, in netLogoLink.NetLogoLink.loadModel()

Exception: Java Exception

The above exception was the direct cause of the following exception:

java.lang.RuntimeException Traceback (most recent call last)
File ~.conda\envs\pynl051-env38\lib\site-packages\pynetlogo\core.py:246, in NetLogoLink.load_model(self, path)
245 try:
--> 246 self.link.loadModel(path)
247 except jpype.JException as ex:

java.lang.RuntimeException: java.lang.RuntimeException

During handling of the above exception, another exception occurred:

NetLogoException Traceback (most recent call last)
Cell In[2], line 1
----> 1 netlogo.load_model('C:\yiyi\CSVExample.nlogo')

File ~.conda\envs\pynl051-env38\lib\site-packages\pynetlogo\core.py:249, in NetLogoLink.load_model(self, path)
247 except jpype.JException as ex:
248 print(ex.stacktrace())
--> 249 raise NetLogoException(str(ex))

NetLogoException: java.lang.RuntimeException

image

My environment is like this ...

python 3.8, netlogo 6.3.0, pynetlogo 0.5.1 & 0.5, jpype1 1.4.1 & 1.4.0, netlogo's py extension 0.5.3 & 0.5.4

all of the version combinations yield similar results (the errors when loading the py extension through pynetlogo)

What can I do next to help?

@quaquel
Copy link
Owner

quaquel commented Jun 26, 2023

Sorry, but I am not sure I fully understand. To be clear: do all extensions fail, or just the py extension?

@bussayii
Copy link

Oh, it is just the py extension that raises the error.

@quaquel
Copy link
Owner

quaquel commented Jun 27, 2023

Thanks for the clarification and the provided simple example. Since all other extensions work, this rules out anything with search paths and the loading of the various jars associated with each extension. Unfortunately, the Java InvocationTargetException is not a really clear exception which makes it harder to figure out what is going on. I presently, unfortunately, don't have the time to dig into this more deeply.

I tried to reproduce the error, but I am on an m1 mac and have so far failed to replicate it. I do get a slightly different error (java.lang.ClassCastException: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')). I'll try once I have time on linux or windows.

@bussayii
Copy link

bussayii commented Jul 1, 2023

Thanks again for the support :) I am new here and super happy to help. Please take your time.

@imantha-das
Copy link

Just curious has anyone managed to find work around for this problem or fixed it?
I am also getting the same issue (Netlogo py extension). I am using an M1 Mac.

java.lang.ExceptionInInitializerError
        at org.nlogo.extensions.py.PythonExtension.runOnce(PythonExtension.scala:69)
        at org.nlogo.workspace.ExtensionManager.initializedClassManager(ExtensionManager.scala:198)

@quaquel
Copy link
Owner

quaquel commented Aug 26, 2024

To my knowledge, there has been no further work on this issue. I would need a minimum example to start taking a look myself.

@imantha-das
Copy link

imantha-das commented Sep 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants