-
Notifications
You must be signed in to change notification settings - Fork 90
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
Feat: produce stack trace from python code called from JVM #960
Comments
Thanks for reporting, @Alex-K37. |
Essentially, the cause of this issue is jpype-project/jpype#1047 ; in short:
As for how I know it is from Python;
). I tried your domain in your Stack Overflow question with a valid dataset according to your typing and could not reproduce your exception. You would need to provide an actual dataset/constraints so we can reproduce it. My best guess is your old |
@triceo I made this a feature request instead of a bug for that reason. Feel free to close/postpone as you see fit. I know that multi-language inter-operation can cause all sorts of hidden trouble, which is often not easily solvable. Under the assumption that there are users with limited programming experience intending to use the python API, it would offer a way better user experience in the face of modelling errors, of course. As far as I am concerned: this is my first "serious" go at a constraint solver and I am using Python, because dealing with the data is much more flexible and interactive than doing this in Java. @Christopher-Chianelli Thank you for mentioning that this is in fact a porting issue coming from OptaPy. I think you are right with respect to copying stuff. It is however unclear to me, when Java classes are created, first. I will write another comment on SO to not pollute this issue. |
FYI: In my case, the error seems to get triggered from IMHO this supports my request for a little better debug information. The first "timefold.solver" log output is generated when solving starts, but nothing is logged before the error occurs. |
If it from |
It is similar. Maybe also related to #969. In my case the PythonString error comes from
re.search is being passed exam.teacher as PythonString. However: Exam.teacher : str in the domain.py |
What Python version are you using? It working for me locally on Python 3.12.
|
|
The intention of this particular constraint is to avoid a particular day for this particular teacher. If it was the other way round, pinning would also be counterproductive, IMHO, because there are multiple timeslots per day which can be chosen. The dataset is not perfect at all in the current state and we do not have much influence on the main database from which we have to import every couple of months. Sometimes multiple teachers surnames are assigned to an exam and if non-multiple, both forename and surname are included. We could pre-process the data and map to teacher ids, of course. Using re was a quick solution. We might translate to Java eventually, anyway. As far as I know re.search applies caching in normal CPython, so that at least the regex translation is skipped on multiple evaluations. I have to admit, I have no idea whether this caching works with jpype/jpyinterpreter. From your answer I gather, that state is probably not kept and the cache lost. What do you mean by "for_each only considers fully assigned entities, so exam.timeslot in the filter is pointless."? The constraint seems to have been effective - whether it was doing that efficiently is another issue. Or am I completely mistaken, here? |
@Alex-K37 @Christopher-Chianelli Folks, please - may I ask to continue your conversation, at this point no longer related to this issue, in another space? Perhaps our Github discussions? |
The
The cache is kept (compiling and evaluating a regex are two different things).
If you have questions related to modelling (or confusion about anything I said here), feel free to either create a question on Stack Overflow or create a discussion. If you have another issue (unrelated to this one), feel free to open a new issue. If you are able to supply a reproducer for this issue (that is, code that we can run that reproduces the exception in the issue), please put it here. |
Is your feature request related to a problem? Please describe.
I have a generate_problem function, which updates certain attributes of the domain objects. It seems, that this is an interaction issue of Python code executed from the JVM.
In my opinion, such an error could surface at any point during development leaving the developer completely clueless where to look for the error, unless he/she is following an approach of add-line/solve/add-line/solve/.... which I consider the most tedious.
Describe the solution you'd like
Produce an error message which includes a stack trace from python. This should include information that relates to the original code somehow, even if mangled by jpype or jpyinterpreter.
Describe alternatives you've considered
Follow an approach of add-line/solve/add-line/solve/.... which I consider the most tedious.
Perform type checking after generate_problem() (does that help at all with a possibly dynamic issue?)
Additional remarks
I cannot find hints to why this PythonString type is necessary and which components have to use it. There is a translation of jpype between Java strings and Python strings. Why isn't this sufficient? Or, why isn't this PythonString automatically translated to a python string, while executing in CPython or jpy*-translated python code? I do not want to deviate too much from my original feature request, however.
The text was updated successfully, but these errors were encountered: