optapy / optapy

OptaPy is an AI constraint solver for Python to optimize planning and scheduling problems.

Home Page:https://www.optapy.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@optapy.problem_fact => java.lang.VerifyError: Bad type on operand stack

AndrewMullin01 opened this issue · comments

I'm modifying the Employee Scheduling quickstart, however I'm running into an error with the @problem_fact decorator.

Some context: my goal is to create a pilot rostering tool for already scheduled flights. The complexity comes in that I have a Pilot problem_fact Class and Duty planning_entity Class. Pilots get assigned to duties, but I also want to keep track of the duties assigned to a pilot to ensure they aren't flying too many hours per day, among other constraints. The Pilot class therefore has get/set_duties planning_list_variable functions. This causes a circular reference problem. The classes rely on each other being instantiated first before they can reference them in their own instantiation. I solved this by taking those function definitions out of the class and assigning them after all classes have been instantiated. I suspect this might be causing the problem in some way.

Anyways, @optapy.problem_fact is throwing java.lang.VerifyError: Bad type on operand stack when a problem_fact class that references Pilot is instantiated.

See my stackoverflow question for more details.

Any assistance would be much appreciated.

While debugging I ran an untouched version of the Employee Scheduling quickstart. Despite making no changes, it crashes as well. However, I can run the school timetabling quickstart without error.

Here is the debug logs of Employee Scheduling quickstart:

python : Traceback (most recent call last):
At line:1 char:1
+ python main.py 2> debug.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
  File "PythonClassTranslator.java", line 292, in 
org.optaplanner.jpyinterpreter.PythonClassTranslator.translatePythonClass
Exception: Java Exception

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

Traceback (most recent call last):
  File "C:\Users\andre\Desktop\PySandbox\pilot-roster\optapy-quickstarts-stable\employee-scheduling\main.py", line 1, 
in <module>
    from services import app, generate_demo_data
  File "C:\Users\andre\Desktop\PySandbox\pilot-roster\optapy-quickstarts-stable\employee-scheduling\services.py", 
line 1, in <module>
    from domain import Employee, Shift, Availability, AvailabilityType, ScheduleState, EmployeeSchedule
  File "C:\Users\andre\Desktop\PySandbox\pilot-roster\optapy-quickstarts-stable\employee-scheduling\domain.py", line 
38, in <module>
    class Availability:
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\optapy\annotations.py", line 585, in 
problem_fact
    out.__optapy_java_class = _generate_problem_fact_class(fact_class)
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\optapy\optaplanner_java_interop.py", 
line 1063, in _generate_problem_fact_class
    parent_class = compile_and_get_class(python_class)
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\optapy\optaplanner_java_interop.py", 
line 1050, in compile_and_get_class
    parent_class = translate_python_class_to_java_class(python_class).getJavaClass()
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\jpyinterpreter\python_to_java_bytecode_
translator.py", line 1193, in translate_python_class_to_java_class
    static_attributes_map.put(attribute[0], convert_to_java_python_like_object(attribute[1]))
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\jpyinterpreter\python_to_java_bytecode_
translator.py", line 399, in convert_to_java_python_like_object
    convert_to_java_python_like_object(map_value, instance_map))
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\jpyinterpreter\python_to_java_bytecode_
translator.py", line 422, in convert_to_java_python_like_object
    out = translate_python_class_to_java_class(raw_type)
  File "C:\Users\andre\AppData\Local\Programs\Python\Python39\lib\site-packages\jpyinterpreter\python_to_java_bytecode_
translator.py", line 1220, in translate_python_class_to_java_class
    out = PythonClassTranslator.translatePythonClass(python_compiled_class)
java.lang.VerifyError: java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    org/jpyinterpreter/user/enum/Enum/__new__$$2.invoke(Lorg/jpyinterpreter/user/domain/AvailabilityType;Lorg/optaplann
er/jpyinterpreter/PythonLikeObject;)Lorg/optaplanner/jpyinterpreter/PythonLikeObject; @897: invokestatic
  Reason:
    Type 'org/optaplanner/jpyinterpreter/PythonLikeObject' (current frame, stack[1]) is not assignable to 
'org/optaplanner/jpyinterpreter/types/PythonLikeType'
  Current Frame:
    bci: @897
    flags: { }
    locals: { 'org/jpyinterpreter/user/enum/Enum/__new__$$2', 'org/jpyinterpreter/user/domain/AvailabilityType', 
'org/optaplanner/jpyinterpreter/PythonLikeObject', 'org/jpyinterpreter/user/domain/AvailabilityType', 
'org/optaplanner/jpyinterpreter/PythonLikeObject', top, 'org/optaplanner/jpyinterpreter/types/PythonNone', top, top, 
top, null, 'org/optaplanner/jpyinterpreter/types/collections/PythonLikeTuple', top, top, top, top, top, 
'java/lang/Object', 'org/optaplanner/jpyinterpreter/PythonLikeObject' }
    stack: { 'org/optaplanner/jpyinterpreter/PythonLikeObject', 'org/optaplanner/jpyinterpreter/PythonLikeObject', 
'org/optaplanner/jpyinterpreter/PythonLikeObject' }
  Bytecode:
    0000000: b200 5a3a 0b2b 4e2c 3a04 2ac0 0002 b400
    0000010: 4eb2 005c 125e b900 6203 00c0 0064 1904
    0000020: bb00 2259 1265 b700 265a 5fb6 0069 b800
    0000030: 6f2d b900 7504 002d a500 09b2 007b a700
    0000040: 06b2 007e b200 7ba5 0009 1904 c000 64b0
    0000050: 2dc0 0080 b400 8419 045c 5f59 b900 8801
    0000060: 0012 8ab9 008e 0200 5901 a500 2f5b 57bb
    0000070: 0090 59b7 0091 5a5f b900 9702 0057 5a5f
    0000080: b900 9702 0057 b800 6f01 b900 7504 0059
    0000090: b200 9da5 0007 a700 1a58 575f 3a0d 3a0c
    00000a0: bb00 9f59 bb00 a159 b700 a257 b700 a3bf
    00000b0: 5b57 58c0 0064 b03a 0ab2 00a8 1223 b800
    00000c0: adb2 00a8 2ac0 0002 b400 4eb9 00b1 0100
    00000d0: 190a 59b9 0088 0100 592a c000 02b4 004e
    00000e0: b200 5c12 b3b9 0062 0300 c000 64c0 00b5
    00000f0: 5fb6 00b9 9900 0f57 5757 013a 0a57 5757
    0000100: a702 3359 2ac0 0002 b400 4eb2 005c 12bb
    0000110: b900 6203 00c0 0064 c000 b55f b600 b999
    0000120: 01f3 5757 572d c000 80b4 00be 59b9 0088
    0000130: 0100 12c0 b600 c359 01a6 001d 57b2 00c5
    0000140: 12c6 b900 ca02 005f c000 645f c000 35b9
    0000150: 00ce 0200 015f 5fbb 0022 5912 23b7 0026
    0000160: 5f59 01a5 0014 3a0c 5919 0c5f 5f03 5fb9
    0000170: 00d1 0300 a700 0457 b800 6f2d b900 7504
    0000180: 0059 b900 8801 0012 d3b9 00d6 0200 5a57
    0000190: bb00 9059 b700 915a 5fb9 0097 0200 57b8
    00001a0: 006f 01b9 0075 0400 3a0c 3a0d 3a0e 3a0f
    00001b0: 190f 190e 190d 190c 5959 b900 8801 0012
    00001c0: d8b9 00d6 0200 5a57 bb00 9059 b700 915a
    00001d0: 5fb9 0097 0200 57b8 006f 01b9 0075 0400
    00001e0: a700 0757 a701 1c3a 0519 05b2 00c5 12d9
    00001f0: b900 ca02 005f c000 645f c000 35b9 00ce
    0000200: 0200 1904 5f5a b900 8801 0012 dbb6 00df
    0000210: b200 e4a6 0004 5f5c 5c5f 59b9 0088 0100
    0000220: 12db b900 8e02 0059 01a5 0032 5b57 bb00
    0000230: 9059 b700 915a 5fb9 0097 0200 575a 5fb9
    0000240: 0097 0200 57b8 006f 01b9 0075 0400 59b2
    0000250: 009d a500 0a5b 5758 a700 8658 5759 b900
    0000260: 8801 0012 dbb9 008e 0200 5901 a500 305b
    0000270: 57bb 0090 59b7 0091 5a5f b900 9702 0057
    0000280: 5a5f b900 9702 0057 b800 6f01 b900 7504
    0000290: 0059 b200 9da6 0049 57a7 0005 5758 5f3a
    00002a0: 113a 10bb 009f 59bb 00a1 59b7 00a2 12e6
    00002b0: b600 ea19 11b9 0088 0100 b600 eeb6 00ea
    00002c0: 12f0 b600 ea19 10b9 0088 0100 b600 eeb6
    00002d0: 00ea 12f2 b600 eab6 00f5 b700 f8bf 5b57
    00002e0: 58b2 007b a5fe c419 055f 575b 573a 103a
    00002f0: 115f 1911 1910 013a 0a57 5757 c000 64b0
    0000300: 190f 190e 190d 190c 5701 3a0a 5757 57a7
    0000310: 0024 59c1 00fa 9900 07c0 00fa bfbb 0022
    0000320: 5912 23b7 0026 b800 6f01 b900 7504 00c0
    0000330: 00fa bfb2 00fc 1223 b900 ca02 00c0 00a5
    0000340: 3a06 2d59 b900 8801 0012 feb9 008e 0200
    0000350: 5f19 043a 123a 1119 1159 c101 009a 0012
    0000360: 59c1 00b5 9a00 11b9 0088 0100 a700 09c0
    0000370: 0100 b601 043a 1119 11c0 0064 1912 c000
    0000380: 64b8 010a 5f57 3a07 a700 fe3a 0ab2 00a8
    0000390: 1223 b800 adb2 00a8 2ac0 0002 b400 4eb9
    00003a0: 00b1 0100 190a 59b9 0088 0100 592a c000
    00003b0: 02b4 004e b200 5c13 010c b900 6203 00c0
    00003c0: 0064 c000 b55f b600 b999 009c 573a 0857
    00003d0: 3a10 3a11 3a12 1912 1911 1910 1908 3a06
    00003e0: b200 fc12 23b9 00ca 0200 c000 a53a 0701
    00003f0: 3a0a 5757 57b2 00fc 1223 b900 ca02 00c0
    0000400: 00a5 3a08 013a 08a7 007f 3a0a 1912 1911
    0000410: 1910 b200 a813 010d b800 adb2 00a8 2ac0
    0000420: 0002 b400 4eb9 00b1 0100 190a 59b9 0088
    0000430: 0100 b200 fc12 23b9 00ca 0200 c000 a53a
    0000440: 0801 3a08 59c1 00fa 9900 07c0 00fa bfbb
    0000450: 0022 5912 23b7 0026 b800 6f01 b900 7504
    0000460: 00c0 00fa bf59 c100 fa99 0007 c000 fabf
    0000470: bb00 2259 1223 b700 26b8 006f 01b9 0075
    0000480: 0400 c000 fabf 2ac0 0002 b400 4eb2 005c
    0000490: 1301 0fb9 0062 0300 c000 6419 072d bb00
    00004a0: 2259 1301 10b7 0026 5a5f b600 695a 5fb6
    00004b0: 0069 b800 6f2d b900 7504 0059 b900 8801
    00004c0: 0013 0112 b900 d602 005a 57bb 0090 59b7
    00004d0: 0091 5a5f b900 9702 0057 b800 6f01 b900
    00004e0: 7504 00b2 007b a500 0919 07c0 0064 b02a
    00004f0: c000 02b4 004e b200 5c13 0114 b900 6203
    0000500: 00c0 0064 b200 fc12 65b9 00ca 0200 c000
    0000510: 3519 042d c000 80b4 0117 bb00 2259 1301
    0000520: 10b7 0026 5a5f b600 695a 5fb6 0069 5fc0
    0000530: 0035 5fc0 0022 b601 1bbb 0022 5912 65b7
    0000540: 0026 5a5f b600 69b8 006f 2db9 0075 0400
    0000550: 3a09 1907 b200 fc12 23b9 00ca 0200 c000
    0000560: a5a5 0009 b200 7ba7 0006 b200 7eb2 007b
    0000570: a500 4719 06b2 00fc 1223 b900 ca02 00c0
    0000580: 00a5 a500 09b2 007b a700 06b2 007e b200
    0000590: 7ba5 0026 1909 59c1 00fa 9900 07c0 00fa
    00005a0: bfbb 0022 5912 23b7 0026 b800 6f01 b900
    00005b0: 7504 00c0 00fa bf19 06b2 00fc 1223 b900
    00005c0: ca02 00c0 00a5 a500 09b2 007b a700 06b2
    00005d0: 007e b200 7ba5 0066 2ac0 0002 b400 4eb2
    00005e0: 005c 12bb b900 6203 00c0 0064 b200 fc13
    00005f0: 0110 b900 ca02 00c0 0035 2dc0 0080 b401
    0000600: 1e19 07bb 0022 5913 0110 b700 265a 5fb6
    0000610: 0069 5a5f b600 695f c000 355f c000 22b6
    0000620: 011b bb00 2259 1265 b700 265a 5fb6 0069
    0000630: b800 6f2d b900 7504 003a 0619 0919 065f
    0000640: b200 c513 011f b900 ca02 005f 5b57 5f59
    0000650: b900 8801 0013 0121 b900 d602 005b 573a
    0000660: 133a 145f 1914 1913 bb00 9059 b700 915a
    0000670: 5fb9 0097 0200 575a 5fb9 0097 0200 575a
    0000680: 5fb9 0097 0200 57b8 006f 01b9 0075 0400
    0000690: 1906 59c1 00fa 9900 07c0 00fa bfbb 0022
    00006a0: 5912 23b7 0026 b800 6f01 b900 7504 00c0
    00006b0: 00fa bf                                
  Exception Handler Table:
    bci [440, 480] => handler: 483
    bci [988, 1034] => handler: 1034
    bci [819, 907] => handler: 907
    bci [80, 183] => handler: 183
  Stackmap Table:
    
full_frame(@65,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Top,Object[#34]},{})
    same_locals_1_stack_item_frame(@68,Object[#119])
    same_frame(@80)
    full_frame(@153,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Top,Object[#34]
},{Object[#100],Object[#100],Object[#100],Object[#100],Object[#100]})
    full_frame(@154,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Top,Object[#34]
},{Object[#100],Object[#100],Object[#100]})
    full_frame(@176,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Top,Object[#34]
},{Object[#100],Object[#100],Object[#100]})
    same_locals_1_stack_item_frame(@183,Object[#87])
    full_frame(@259,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#296],Object[#87],Object[#181]})
    full_frame(@342,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#100],Object[#100]})
    full_frame(@375,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#100],Object[#34],Object[#100]})
    full_frame(@376,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#100],Object[#34]})
    full_frame(@424,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#100]})
    full_frame(@483,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#85]})
    full_frame(@487,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#100],Obje
ct[#100]})
    full_frame(@535,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Object[#100],Top,Top,Top,Top,Object
[#87],Object[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#
100],Object[#100],Object[#100]})
    full_frame(@603,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Object[#100],Top,Top,Top,Top,Object
[#87],Object[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#
100],Object[#100],Object[#100],Object[#100],Object[#100],Object[#100],Object[#100],Object[#100]})
    full_frame(@604,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Object[#100],Top,Top,Top,Top,Object
[#87],Object[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#
100],Object[#100],Object[#100],Object[#100],Object[#100],Object[#100]})
    full_frame(@668,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Object[#100],Top,Top,Top,Top,Object
[#87],Object[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#
100],Object[#100],Object[#100],Object[#100],Object[#100],Object[#100]})
    full_frame(@670,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Object[#100],Top,Top,Top,Top,Object
[#87],Object[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#
100],Object[#100],Object[#100]})
    full_frame(@734,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Object[#100],Top,Top,Top,Top,Object
[#87],Object[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#
100],Object[#100],Object[#100],Object[#100]})
    full_frame(@768,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34],Object[#100],Object[#165],Object[#170],Object[#165]},{})
    full_frame(@786,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#296],Object[#87],Object[#181]})
    full_frame(@797,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Obj
ect[#34]},{Object[#165],Object[#170],Object[#165],Object[#296],Object[#87],Object[#181]})
    full_frame(@819,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Null,Object[#34
]},{})
    full_frame(@879,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Object[#165],Top,Top,Top,Null,O
bject[#34],Top,Top,Top,Top,Top,Object[#128],Object[#100]},{Object[#100],Object[#128]})
    full_frame(@885,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Object[#165],Top,Top,Top,Null,O
bject[#34],Top,Top,Top,Top,Top,Object[#128],Object[#100]},{Object[#100],Object[#4]})
    full_frame(@907,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Null,Object[#34
]},{Object[#87]})
    full_frame(@1034,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Object[#4],Top,Object[
#87],Object[#34],Top,Top,Top,Top,Object[#165],Object[#170],Object[#165]},{Object[#87]})
    full_frame(@1103,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Null,Top,Object[#87],O
bject[#34],Top,Top,Top,Top,Object[#165],Object[#170],Object[#165]},{Object[#165],Object[#170],Object[#165],Object[#165]
,Object[#170],Object[#165],Object[#296],Object[#87],Object[#181]})
    full_frame(@1125,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Ob
ject[#34]},{Object[#165],Object[#170],Object[#165],Object[#296],Object[#87],Object[#181]})
    full_frame(@1136,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Top,Top,Top,Top,Object[#87],Ob
ject[#34]},{Object[#165],Object[#170],Object[#165],Object[#296],Object[#87],Object[#181]})
    full_frame(@1158,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Object[#4],Object[#165],Top,To
p,Null,Object[#34],Top,Top,Top,Top,Top,Object[#4],Object[#100]},{})
    same_frame_extended(@1263)
    full_frame(@1386,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Object[#4],Object[#165],Top,Ob
ject[#100],Null,Object[#34],Top,Top,Top,Top,Top,Object[#4],Object[#100]},{})
    same_locals_1_stack_item_frame(@1389,Object[#119])
    same_frame(@1419)
    same_locals_1_stack_item_frame(@1422,Object[#119])
    same_locals_1_stack_item_frame(@1441,Object[#100])
    same_frame(@1463)
    same_frame(@1487)
    same_locals_1_stack_item_frame(@1490,Object[#119])
    same_frame_extended(@1595)
    full_frame(@1693,{Object[#2],Object[#128],Object[#100],Object[#128],Object[#100],Top,Object[#4],Object[#165],Top,Ob
ject[#100],Null,Object[#34],Top,Top,Top,Top,Top,Object[#4],Object[#100],Object[#4],Object[#4]},{Object[#100],Object[#4]
})

removing the AvailabilityType reference from the Availability class seems to resolve the issue in the Employee Scheduling quickstart. Will keep investigating

Looking at the error, I think it is caused because AvailabilityType is an Enum. I recall enums working previously; what is your Python version (this is relevant, since we translate CPython bytecode to Java bytecode, and the error is a result of a mistranslation).

Pyhon 3.9.0

I now have it working fine on Python 3.11.1