Issue1777

classification
Title: Help getting SymPy working with Jython
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stefan.richthofer Nosy List: amak, asmeurer, fwierzbicki, stefan.richthofer, zyasoft
Priority: normal Keywords:

Created on 2011-07-22.20:34:51 by asmeurer, last changed 2017-03-28.05:25:43 by zyasoft.

Messages
msg6578 (view) Author: Aaron Meurer (asmeurer) Date: 2011-07-22.20:34:50
I asked about this on the mailing list.  SymPy (sympy.org) does not import in Jython because of the following problem:

Traceback (most recent call last):
 File "./bin/test", line 17, in <module>
   from sympy.utilities.runtests import test
 File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/__init__.py",
line 30, in <module>
   from sympy.core import *
 File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/__init__.py",
line 8, in <module>
   from expr import Expr, AtomicExpr
 File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/expr.py",
line 1826, in <module>
   class AtomicExpr(Atom, Expr):
TypeError: Error when calling the metaclass bases
   multiple bases have instance lay-out conflict

See the issue in our issue tracker for more information (http://code.google.com/p/sympy/issues/detail?id=1233).  You can also see there the git commit that first caused this problem, which adds __slots__ to some Mixin class and a class that inherits from it.

We'd of course be willing to change the SymPy code to fix this, though we'd like to continue using __slots__ if possible.

By the way, git clone git://github.com/sympy/sympy.git will get you the latest dev version of SymPy.
msg6628 (view) Author: Alan Kennedy (amak) Date: 2011-09-03.01:54:28
__slots__ is an cpython optimization hack, whereby certain metadata overhead is eliminated for variables that are declared in the __slots__ list/tuple. It also affects inheritance, particularly multiple inheritance.

http://stackoverflow.com/questions/472000/python-slots
http://dev.svetlyak.ru/using-slots-for-optimisation-in-python-en/

Having an empty __slots__ variable is a dirtier hack for modifying the readability of class attributes.

You need to 

A: Contact the original committer of the __slots__ optimisation and *make* them justify their commit. They need to rationalize *why* their commit is a benefit to a code base that is expected to run on multiple python versions, e.g. cpython, jython, ironpython, pypy, etc. Have they tested on all of the target platforms? If not, the change should be rejected.

B: Hack around it (jythonistas have to do this all the time: cpython developers seem to have an attitude that cpython running on their favourite operating system is the only python on the world).

This should work

try:
    import java
except ImportError:
    __slots__ = []
msg6631 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-03.19:39:20
Well, I don't really see any problem with option B.  It gives the best of both worlds: it works in Jython, but we still get the optimization in CPython.  It would be a little better if we could test against the behavior itself rather than against if we are in Jython or not, but I have no idea what is going on here, so I wouldn't know how to do that.

See the SymPy issue for a patch that fixes this.  Unfortunately, now that we can import sympy in jython, there are a ton of test failures, so we still may require assistance in fixing things (which is much appreaciated, by the way).
msg6632 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-03.20:50:03
So now that this is working, there are a lot of test failures, as I mentioned, but there is also what appears to be a jython bug:

Traceback (most recent call last):
  File "bin/test", line 55, in <module>
    ok = sympy.test(*args, **{"verbose": options.verbose, "kw": options.kw,
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 191, in test
    return t.test(sort=sort)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 512, in test
    self.test_file(f)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 512, in test
    self.test_file(f)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 526, in test_file
    execfile(filename, gl)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 526, in test_file
    execfile(filename, gl)
java.lang.ClassFormatError: Invalid method Code length 116077 in class file org/python/pycode/_pyx6285
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
	at org.python.core.BytecodeLoader$Loader.loadClassFromBytes(BytecodeLoader.java:119)
	at org.python.core.BytecodeLoader.makeClass(BytecodeLoader.java:37)
	at org.python.core.BytecodeLoader.makeCode(BytecodeLoader.java:67)
	at org.python.compiler.LegacyCompiler$LazyLegacyBundle.loadCode(LegacyCompiler.java:43)
	at org.python.core.CompilerFacade.compile(CompilerFacade.java:34)
	at org.python.core.Py.compile_flags(Py.java:1703)
	at org.python.core.Py.compile_flags(Py.java:1708)
	at org.python.core.Py.compile_flags(Py.java:1718)
	at org.python.core.__builtin__.execfile_flags(__builtin__.java:514)
	at org.python.core.__builtin__.execfile(__builtin__.java:499)
	at org.python.core.__builtin__.execfile(__builtin__.java:526)
	at org.python.core.BuiltinFunctions.__call__(__builtin__.java:155)
	at org.python.core.PyObject.__call__(PyObject.java:408)
	at sympy.utilities.runtests$py.test_file$16(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py:591)
	at sympy.utilities.runtests$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
	at org.python.core.PyFunction.__call__(PyFunction.java:327)
	at org.python.core.PyMethod.__call__(PyMethod.java:124)
	at sympy.utilities.runtests$py.test$15(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py:516)
	at sympy.utilities.runtests$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:194)
	at org.python.core.PyFunction.__call__(PyFunction.java:387)
	at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:220)
	at org.python.core.PyMethod.__call__(PyMethod.java:211)
	at sympy.utilities.runtests$py.test$7(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py:191)
	at sympy.utilities.runtests$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyObject._callextra(PyObject.java:527)
	at org.python.pycode._pyx0.f$0(bin/test:62)
	at org.python.pycode._pyx0.call_function(bin/test)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1261)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235)
	at org.python.util.jython.run(jython.java:247)
	at org.python.util.jython.main(jython.java:129)

java.lang.ClassFormatError: java.lang.ClassFormatError: Invalid method Code length 116077 in class file org/python/pycode/_pyx6285

You can reproduce by using my jython-slots branch (see https://github.com/sympy/sympy/pull/586) and running "jython bin/test sympy/mpmath/tests/test_fp.py".  This is using the most recent version of Jython (2.5.2).
msg6633 (view) Author: Alan Kennedy (amak) Date: 2011-09-04.00:45:15
> "java.lang.ClassFormatError: java.lang.ClassFormatError: Invalid method Code length 116077 in class file org/python/pycode/_pyx6285"

Not a bug, unfortunately, but a limitation of java class files, which cannot be more then 64K long.

http://grinder.sourceforge.net/faq.html#faq-N10544

Your test_fp.py module is too long needs to be broken up if it's going to work under jython.
msg6634 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-04.00:55:59
From my understanding of that FAQ, rather the function inside the module needs to be broken up.  There are several files that are much longer than that, but this particular test file has a single test function that is 1300 lines long.

Thanks for the help.  I'll ask here if I have any more difficulties with the rest of the failures.

By the way, you might try to make the error message a little nicer for this error :)
msg6635 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-04.01:30:33
So you were actually right that they do have to go in separate files.  Maybe I'm misreading something, but I think that FAQ you linked to is a little misleading in that.  

Also, apparently you can have more characters than that if they are commented, which was throwing me off for a bit. :)
msg6636 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-04.02:36:42
OK, so I missed a very important part of that FAQ (emphasis added): "The short answer is that a function in your script is too long and is tripping over a Java limitation on the length of a method inherited by Jython. **Java** methods are limited to 65535 characters or less."

I was counting the number of characters in the Python function, but I guess that is completely unrelated.  So splitting it into three parts does the trick.  Sorry for the noise.
msg6637 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-04.03:07:13
OK, new Jython error:

$~/jython2.5.2/jython bin/test sympy/physics/quantum/tests/test_anticommutator.py 
============================= test process starts ==============================
executable:   /Users/aaronmeurer/jython2.5.2/jython  (2.5.2-final-0)
architecture: 32-bit
cache:        yes
ground types: python
random seed:  98235021

Traceback (most recent call last):
  File "bin/test", line 55, in <module>
    ok = sympy.test(*args, **{"verbose": options.verbose, "kw": options.kw,
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 191, in test
    return t.test(sort=sort)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 512, in test
    self.test_file(f)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 512, in test
    self.test_file(f)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 526, in test_file
    execfile(filename, gl)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py", line 526, in test_file
    execfile(filename, gl)
  File "/users/aaronmeurer/documents/python/sympy/sympy/sympy/physics/quantum/tests/test_anticommutator.py", line 3, in <module>
    from sympy.physics.quantum.dagger import Dagger
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py", line 46, in <module>
    import represent as repmod
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py", line 21, in <module>
    from sympy.physics.quantum.operatorset import operators_to_state, state_to_operators
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py", line 27, in <module>
    from sympy.physics.quantum.spin import (
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py", line 871, in <module>
    Jx = JxOp('J')
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py", line 120, in __new__
    inst = Expr.__new__(cls, *args, **{'commutative':False})
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py", line 85, in __new__
    obj._init_assumptions(assumptions)
  File "/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/assumptions.py", line 237, in _init_assumptions
    self._assumptions  = self.default_assumptions
java.lang.ArrayIndexOutOfBoundsException: 2
	at org.python.core.PyObjectDerived.setSlot(PyObjectDerived.java:13)
	at org.python.core.PySlot.member_descriptor___set__(PySlot.java:50)
	at org.python.core.PySlot.__set__(PySlot.java:44)
	at org.python.core.PyObject.object___setattr__(PyObject.java:3742)
	at org.python.core.PyObject.object___setattr__(PyObject.java:3732)
	at org.python.core.PyObject$object___setattr___exposer.__call__(Unknown Source)
	at org.python.core.PyObjectDerived.__setattr__(PyObjectDerived.java:990)
	at sympy.core.assumptions$py._init_assumptions$10(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/assumptions.py:257)
	at sympy.core.assumptions$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/assumptions.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
	at org.python.core.PyFunction.__call__(PyFunction.java:327)
	at org.python.core.PyMethod.__call__(PyMethod.java:124)
	at sympy.core.basic$py.__new__$3(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py:89)
	at sympy.core.basic$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyObject._callextra(PyObject.java:527)
	at sympy.physics.quantum.qexpr$py.__new__$5(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py:123)
	at sympy.physics.quantum.qexpr$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyType.invokeNew(PyType.java:472)
	at org.python.core.PyType.type___call__(PyType.java:1558)
	at org.python.core.PyType$type___call___exposer.__call__(Unknown Source)
	at org.python.core.PyTypeDerived.__call__(PyTypeDerived.java:951)
	at org.python.core.PyObject.__call__(PyObject.java:387)
	at org.python.core.PyObject.__call__(PyObject.java:391)
	at sympy.physics.quantum.spin$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py:1456)
	at sympy.physics.quantum.spin$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at sympy.physics.quantum.operatorset$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py:275)
	at sympy.physics.quantum.operatorset$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at sympy.physics.quantum.represent$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py:486)
	at sympy.physics.quantum.represent$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_name(imp.java:824)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importOneAs(imp.java:921)
	at sympy.physics.quantum$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py:60)
	at sympy.physics.quantum$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at org.python.pycode._pyx22.f$0(/users/aaronmeurer/documents/python/sympy/sympy/sympy/physics/quantum/tests/test_anticommutator.py:46)
	at org.python.pycode._pyx22.call_function(/users/aaronmeurer/documents/python/sympy/sympy/sympy/physics/quantum/tests/test_anticommutator.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1261)
	at org.python.core.__builtin__.execfile_flags(__builtin__.java:522)
	at org.python.core.__builtin__.execfile(__builtin__.java:499)
	at org.python.core.__builtin__.execfile(__builtin__.java:526)
	at org.python.core.BuiltinFunctions.__call__(__builtin__.java:155)
	at org.python.core.PyObject.__call__(PyObject.java:408)
	at sympy.utilities.runtests$py.test_file$16(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py:591)
	at sympy.utilities.runtests$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
	at org.python.core.PyFunction.__call__(PyFunction.java:327)
	at org.python.core.PyMethod.__call__(PyMethod.java:124)
	at sympy.utilities.runtests$py.test$15(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py:516)
	at sympy.utilities.runtests$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:194)
	at org.python.core.PyFunction.__call__(PyFunction.java:387)
	at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:220)
	at org.python.core.PyMethod.__call__(PyMethod.java:211)
	at sympy.utilities.runtests$py.test$7(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py:191)
	at sympy.utilities.runtests$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/utilities/runtests.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyObject._callextra(PyObject.java:527)
	at org.python.pycode._pyx0.f$0(bin/test:62)
	at org.python.pycode._pyx0.call_function(bin/test)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1261)
	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235)
	at org.python.util.jython.run(jython.java:247)
	at org.python.util.jython.main(jython.java:129)

java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 2
msg6643 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2011-09-09.21:48:04
Do you have a pointer to the code that causes the ArrayIndexOutOfBoundsException?
msg6645 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-11.20:22:19
This is not very easy to track down, as it seems to again be caused by some class inheritance stuff.  It might also be caused by some of the strange things that this particular module does with imports (e.g., it's the only module in SymPy that uses __all__ pretty heavily).

So far, all I've figured out is that a better way to reproduce the problem is to call

import sympy.physics.quantum.spin

You need to run this in my jython-slots branch (https://github.com/asmeurer/sympy/tree/jython-slots) because otherwise you will get the original error (btw, you can also browse the code from there).  If you don't know how to use git, the following will get you up and running:

git clone git://github.com/sympy/sympy.git
cd sympy
git remote add asmeurer git://github.com/asmeurer/sympy.git
git fetch asmeurer
git checkout asmeurer/jython-slots

Then you can run jython from that directory and run the above import, and it should reproduce it.

The actual line that causes the problem is shown in the traceback.  But this line is called hundreds of times without any problems (stuff inside of sympy/core is used basically everywhere).  It's just this particular class (JxOp) that causes problems for it.  

I will keep digging to see if I can make a smaller reproducible example. But any advice on what you think might be the problem on your part would be much appreciated.  In particular, I have no idea how to interpret the Java traceback or error message.

Here's the traceback from just running the import (instead of the tests, as I did originally):

>>> import sympy.physics.quantum.spin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/physics/quantum/__init__.py", line 46, in <module>
    import represent as repmod
  File "sympy/physics/quantum/represent.py", line 21, in <module>
    from sympy.physics.quantum.operatorset import operators_to_state, state_to_operators
  File "sympy/physics/quantum/operatorset.py", line 27, in <module>
    from sympy.physics.quantum.spin import (
  File "sympy/physics/quantum/spin.py", line 871, in <module>
    Jx = JxOp('J')
  File "sympy/physics/quantum/qexpr.py", line 120, in __new__
    inst = Expr.__new__(cls, *args, **{'commutative':False})
  File "sympy/core/basic.py", line 85, in __new__
    obj._init_assumptions(assumptions)
  File "sympy/core/assumptions.py", line 238, in _init_assumptions
    print getattr(self,'_assumptions', None)
java.lang.ArrayIndexOutOfBoundsException: 2
	at org.python.core.PyObjectDerived.getSlot(PyObjectDerived.java:9)
	at org.python.core.PySlot.member_descriptor___get__(PySlot.java:37)
	at org.python.core.PySlot.__get__(PySlot.java:30)
	at org.python.core.PyObject.object___findattr__(PyObject.java:3706)
	at org.python.core.Deriveds.__findattr_ex__(Deriveds.java:42)
	at org.python.core.PyObjectDerived.__findattr_ex__(PyObjectDerived.java:983)
	at org.python.core.__builtin__.getattr(__builtin__.java:620)
	at org.python.core.BuiltinFunctions.__call__(__builtin__.java:208)
	at org.python.core.PyObject.__call__(PyObject.java:426)
	at sympy.core.assumptions$py._init_assumptions$10(sympy/core/assumptions.py:260)
	at sympy.core.assumptions$py.call_function(sympy/core/assumptions.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
	at org.python.core.PyFunction.__call__(PyFunction.java:327)
	at org.python.core.PyMethod.__call__(PyMethod.java:124)
	at sympy.core.basic$py.__new__$3(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py:89)
	at sympy.core.basic$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyObject._callextra(PyObject.java:527)
	at sympy.physics.quantum.qexpr$py.__new__$5(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py:123)
	at sympy.physics.quantum.qexpr$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyType.invokeNew(PyType.java:472)
	at org.python.core.PyType.type___call__(PyType.java:1558)
	at org.python.core.PyType$type___call___exposer.__call__(Unknown Source)
	at org.python.core.PyTypeDerived.__call__(PyTypeDerived.java:951)
	at org.python.core.PyObject.__call__(PyObject.java:387)
	at org.python.core.PyObject.__call__(PyObject.java:391)
	at sympy.physics.quantum.spin$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py:1456)
	at sympy.physics.quantum.spin$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at sympy.physics.quantum.operatorset$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py:275)
	at sympy.physics.quantum.operatorset$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at sympy.physics.quantum.represent$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py:486)
	at sympy.physics.quantum.represent$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_name(imp.java:824)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importOneAs(imp.java:921)
	at sympy.physics.quantum$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py:60)
	at sympy.physics.quantum$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importOne(imp.java:903)
	at org.python.pycode._pyx23.f$0(<stdin>:1)
	at org.python.pycode._pyx23.call_function(<stdin>)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1261)
	at org.python.core.Py.exec(Py.java:1305)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
	at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
	at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:46)
	at org.python.util.InteractiveConsole.push(InteractiveConsole.java:110)
	at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:90)
	at org.python.util.jython.run(jython.java:317)
	at org.python.util.jython.main(jython.java:129)

java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 2

By the way, at first glance, this appears to me to be a Jython bug.  Would you agree with that?  Or is it common to get Java tracebacks from non-Jython problems?
msg6646 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-11.20:25:03
Sorry, that traceback actually came from a print statement that I had put in there.  That at least shows that both trying to set self._assumptions and trying to read it cause the problem.  Here is the actual traceback:

>>> import sympy.physics.quantum.spin
sympy/external/importtools.py:104: UserWarning: Python version is too old to use numpy (2.6 or newer required)
  warnings.warn("Python version is too old to use %s "
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sympy/physics/quantum/__init__.py", line 46, in <module>
    import represent as repmod
  File "sympy/physics/quantum/represent.py", line 21, in <module>
    from sympy.physics.quantum.operatorset import operators_to_state, state_to_operators
  File "sympy/physics/quantum/operatorset.py", line 27, in <module>
    from sympy.physics.quantum.spin import (
  File "sympy/physics/quantum/spin.py", line 871, in <module>
    Jx = JxOp('J')
  File "sympy/physics/quantum/qexpr.py", line 120, in __new__
    inst = Expr.__new__(cls, *args, **{'commutative':False})
  File "sympy/core/basic.py", line 85, in __new__
    obj._init_assumptions(assumptions)
  File "sympy/core/assumptions.py", line 237, in _init_assumptions
    self._assumptions  = self.default_assumptions
java.lang.ArrayIndexOutOfBoundsException: 2
	at org.python.core.PyObjectDerived.setSlot(PyObjectDerived.java:13)
	at org.python.core.PySlot.member_descriptor___set__(PySlot.java:50)
	at org.python.core.PySlot.__set__(PySlot.java:44)
	at org.python.core.PyObject.object___setattr__(PyObject.java:3742)
	at org.python.core.PyObject.object___setattr__(PyObject.java:3732)
	at org.python.core.PyObject$object___setattr___exposer.__call__(Unknown Source)
	at org.python.core.PyObjectDerived.__setattr__(PyObjectDerived.java:990)
	at sympy.core.assumptions$py._init_assumptions$10(sympy/core/assumptions.py:257)
	at sympy.core.assumptions$py.call_function(sympy/core/assumptions.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:149)
	at org.python.core.PyFunction.__call__(PyFunction.java:327)
	at org.python.core.PyMethod.__call__(PyMethod.java:124)
	at sympy.core.basic$py.__new__$3(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py:89)
	at sympy.core.basic$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/core/basic.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyObject._callextra(PyObject.java:527)
	at sympy.physics.quantum.qexpr$py.__new__$5(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py:123)
	at sympy.physics.quantum.qexpr$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/qexpr.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
	at org.python.core.PyFunction.function___call__(PyFunction.java:376)
	at org.python.core.PyFunction.__call__(PyFunction.java:371)
	at org.python.core.PyFunction.__call__(PyFunction.java:366)
	at org.python.core.PyType.invokeNew(PyType.java:472)
	at org.python.core.PyType.type___call__(PyType.java:1558)
	at org.python.core.PyType$type___call___exposer.__call__(Unknown Source)
	at org.python.core.PyTypeDerived.__call__(PyTypeDerived.java:951)
	at org.python.core.PyObject.__call__(PyObject.java:387)
	at org.python.core.PyObject.__call__(PyObject.java:391)
	at sympy.physics.quantum.spin$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py:1456)
	at sympy.physics.quantum.spin$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/spin.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at sympy.physics.quantum.operatorset$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py:275)
	at sympy.physics.quantum.operatorset$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/operatorset.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importFromAs(imp.java:978)
	at org.python.core.imp.importFrom(imp.java:954)
	at sympy.physics.quantum.represent$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py:486)
	at sympy.physics.quantum.represent$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/represent.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_name(imp.java:824)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importOneAs(imp.java:921)
	at sympy.physics.quantum$py.f$0(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py:60)
	at sympy.physics.quantum$py.call_function(/Users/aaronmeurer/Documents/Python/sympy/sympy/sympy/physics/quantum/__init__.py)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.imp.createFromCode(imp.java:386)
	at org.python.core.imp.createFromPyClass(imp.java:204)
	at org.python.core.imp.loadFromSource(imp.java:567)
	at org.python.core.imp.find_module(imp.java:473)
	at org.python.core.PyModule.impAttr(PyModule.java:100)
	at org.python.core.imp.import_next(imp.java:715)
	at org.python.core.imp.import_logic(imp.java:777)
	at org.python.core.imp.import_name(imp.java:839)
	at org.python.core.imp.importName(imp.java:884)
	at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
	at org.python.core.PyObject.__call__(PyObject.java:357)
	at org.python.core.__builtin__.__import__(__builtin__.java:1173)
	at org.python.core.imp.importOne(imp.java:903)
	at org.python.pycode._pyx1.f$0(<stdin>:1)
	at org.python.pycode._pyx1.call_function(<stdin>)
	at org.python.core.PyTableCode.call(PyTableCode.java:165)
	at org.python.core.PyCode.call(PyCode.java:18)
	at org.python.core.Py.runCode(Py.java:1261)
	at org.python.core.Py.exec(Py.java:1305)
	at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215)
	at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)
	at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)
	at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:46)
	at org.python.util.InteractiveConsole.push(InteractiveConsole.java:110)
	at org.python.util.InteractiveConsole.interact(InteractiveConsole.java:90)
	at org.python.util.jython.run(jython.java:317)
	at org.python.util.jython.main(jython.java:129)

java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 2
msg6647 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2011-09-12.16:45:16
> java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 2
>
> By the way, at first glance, this appears to me to be a Jython bug.  Would you agree with that?  Or is it common to get Java tracebacks from non-Jython problems?
>
This does indeed look like a problem in Jython - in principle pure Python code (that is no Java, Java inheritance or ctypes, etc) should not produce Java exceptions, and if they do this indicates a bug in Jython.  Looking at the stack trace it appears to still be something wrong with our slots implementation... but I'm not sure what yet. This is a busy work week for me, but I will try to have a look before the week is out.

-Frank
msg6655 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-28.17:35:02
I don't know how much help this will be to the Jython developers.  Maybe a SymPy developer could gain some insight from it. If you run this from within the isympy script, which is a script that runs "from sympy import *" and defines some default symbols for you to use (sympy.physics is not included in import *), it doesn't generate the Java traceback:


$~/jython2.5.2/jython bin/isympy 
Couldn't locate IPython. Having IPython installed is greatly recommended.
See http://ipython.scipy.org for more details. If you use Debian/Ubuntu,
just install the 'ipython' package and start isympy again.

Reading history: /Users/aaronmeurer/.sympy-history
ValueError: symbol arg must be either single or eval
Python console for SymPy 0.7.1-git (Python 2.5.2-32-bit) (ground types: python)

These commands were executed:
>>> from __future__ import division
>>> from sympy import *
>>> x, y, z, t = symbols('x y z t')
>>> k, m, n = symbols('k m n', integer=True)
>>> f, g, h = symbols('f g h', cls=Function)

Documentation can be found at http://www.sympy.org

>>> import sympy.physics.quantum.spin
/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/external/importtools.py:104: UserWarning: Python version is too old to use numpy (2.6 or newer required)
  warnings.warn("Python version is too old to use %s "
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/physics/quantum/__init__.py", line 46, in <module>
    import represent as repmod
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/physics/quantum/represent.py", line 21, in <module>
    from sympy.physics.quantum.operatorset import operators_to_state, state_to_operators
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/physics/quantum/operatorset.py", line 27, in <module>
    from sympy.physics.quantum.spin import (
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/physics/quantum/spin.py", line 871, in <module>
    Jx = JxOp('J')
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/physics/quantum/qexpr.py", line 120, in __new__
    inst = Expr.__new__(cls, *args, **{'commutative':False})
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/core/basic.py", line 85, in __new__
    obj._init_assumptions(assumptions)
  File "/Users/aaronmeurer/Documents/python/sympy/sympy/sympy/core/assumptions.py", line 237, in _init_assumptions
    self._assumptions  = self.default_assumptions
ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 2

Another note: my branch should be merged soon, so you should be able to test this against the SymPy git master.
msg6656 (view) Author: Aaron Meurer (asmeurer) Date: 2011-09-28.17:35:55
> Another note: my branch should be merged soon, so you should be able to test this against the SymPy git master.

I just merged it.  You can now test this against the git master of SymPy.
msg7841 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-27.17:54:52
Hi Aaron, sorry this got dropped on the floor. Are you still around and do you still see this problem?
msg7842 (view) Author: Aaron Meurer (asmeurer) Date: 2013-02-27.18:00:14
We are still tracking this at http://code.google.com/p/sympy/issues/detail?id=1233. See the latest comments (starting at comment 28). We are hitting some import issue. The tracebacks are long, so I refer you to the SymPy issue for full details.
msg7844 (view) Author: Aaron Meurer (asmeurer) Date: 2013-02-27.18:05:03
To be clear, we also have the metaclass thing with __slots__. Removing __slots__ from Basic fixes that, but then we get the import issue. Most of the SymPy issue discussion is me unsuccessfully trying to figure out how to fix the import thing. 

It would be great if __slots__ worked, but we can always work around it using the import java thing as before. The import issue I have no idea about, though. That seems like a genuine jython bug.
msg7854 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-27.18:56:56
FYI the NullPointerException from dict_pop is fixed in the latest Jython default (2.7) -- so this one should be fixed: http://code.google.com/p/sympy/issues/detail?id=1233#c31

I have no doubt that other trouble will happen after that. The ast inheritance troubles are still an issue for example.
msg7856 (view) Author: Aaron Meurer (asmeurer) Date: 2013-02-27.19:37:30
Right. That was Jython issue 1676. I was just noting a similarity in the traceback, which may or may not be meaningful. For now, we are dealing just with Python tracebacks, one about metaclasses, and if you work around that, an ImportError.
msg7857 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-27.19:44:23
Ah ok - could you point me to the comment number that has the import stack trace? Or is it the same as msg6655 ?
msg7858 (view) Author: Aaron Meurer (asmeurer) Date: 2013-02-27.19:52:06
Comment out Basic.__slots__. You will get the stack trace from comment 28 (the second one, the ImportError). If you attempt to fix that by commenting out the import of ask in sympy/core/sets.py (apply the diff from comment 33, and also remove the import of ask at the top of the file), you get the traceback from comment 37.  Removing the ask import that that point is not as easy, so I haven't attempted it yet.

It seems like it is hitting a circular import, but according to CPython, it should be able to import everything just fine.

If it will help, I can create branches in my GitHub fork that replicate the various tracebacks.
msg8523 (view) Author: Jim Baker (zyasoft) Date: 2014-05-22.00:41:01
Linked to https://github.com/sympy/sympy/issues/4332

Fixing test_import so that all tests pass is of course something we MUST fix for beta 4.
msg9334 (view) Author: Jim Baker (zyasoft) Date: 2015-01-07.07:05:56
Imports now pass test_import, but when

byte-compiling build/bdist.java1.7.0_21/egg/sympy/physics/quantum/tests/test_spin.py to test_spin$py.class

I get java.lang.RuntimeException: java.lang.RuntimeException: Method code too large!

sympy is clearly a tough project for us!

I'm going to mark this priority normal since I don't see what we can do for beta 4 or rc1 of 2.7.0, but something to look at afterwards for sure.
msg10017 (view) Author: Jim Baker (zyasoft) Date: 2015-05-04.16:12:45
Currently depends on #527524
msg10025 (view) Author: Jim Baker (zyasoft) Date: 2015-05-05.05:34:56
Discounting large methods, recent updates in https://hg.python.org/jython/rev/9483b3252bd5 has also improved compatibility. Newly exposed bug:

$ ~/jythondev/jython27/dist/bin/jython setup.py test
/Users/jbaker/jythondev/jython27/dist/Lib/site-packages/setuptools/dist.py:279: UserWarning: Normalizing '0.7.7.dev' to '0.7.7.dev0'
  warnings.warn(
running test
Traceback (most recent call last):
  File "setup.py", line 316, in <module>
    setup(name='sympy',
  File "/Users/jbaker/jythondev/jython27/dist/Lib/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/Users/jbaker/jythondev/jython27/dist/Lib/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/Users/jbaker/jythondev/jython27/dist/Lib/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/Users/jbaker/jythondev/jython27/dist/Lib/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "setup.py", line 221, in run
    from sympy.utilities import runtests
  File "/Users/jbaker/opensource/sympy/sympy/__init__.py", line 37, in <module>
    from .core import *
  File "/Users/jbaker/opensource/sympy/sympy/core/__init__.py", line 8, in <module>
    from .expr import Expr, AtomicExpr
  File "/Users/jbaker/opensource/sympy/sympy/core/expr.py", line 3127, in <module>
    class AtomicExpr(Atom, Expr):
TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict
msg10988 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2016-11-24.05:48:47
I just skimmed this thread again and noticed that the latest exposed bug is the same as in the initial message:

TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict

So was this a regression in sympy? It was once fixed; maybe this fix can be restored...
msg10989 (view) Author: Aaron Meurer (asmeurer) Date: 2016-11-24.06:02:04
The most recent SymPy commit to reference Jython is https://github.com/sympy/sympy/pull/586. The fix from that PR was removed with the class at https://github.com/sympy/sympy/pull/1162. Probably a similar fix on the most recent metaclasses would fix things again.
msg10997 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2016-12-02.00:47:16
Aaron, great that you pinned it!

I am curious to hear whether you could restore the old fix. Also what the next hurdle will be. I hope we can finally move on with this long-standing issue.
msg10998 (view) Author: Aaron Meurer (asmeurer) Date: 2016-12-02.02:11:09
I didn't attempt the old fix. I don't have Jython installed on my computer. The next step would be to apply the fix and see if SymPy imports, and if it does, run the tests in Jython. I definitely would accept a pull request that makes SymPy work in Jython.
msg11065 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-02.16:28:18
Aaron, you got a PR on this front: https://github.com/sympy/sympy/pull/12120

With these changes I was able to make sympy 1.0 work with Jython. However current dev-version doesn't (yet) work, because of #2548.

If you try this with sympy 1.0, Jython will prompt you with

java.lang.RuntimeException: java.lang.RuntimeException: Encountered too large method code in 
/data/workspace/linux/Jython/packages/sympy-sympy-1.0/sympy/polys/polyquinticconst.py
Please provide a CPython 2.7 bytecode file (.pyc) to proceed, e.g. run
python -m py_compile /some_path/sympy-sympy-1.0/sympy/polys/polyquinticconst.py
and try again.

Just do as it tells you, call
python -m py_compile /some_path/sympy-sympy-1.0/sympy/polys/polyquinticconst.py
(assuming python refers to CPython 2.7)
After that it should work. See my note in #527524 regarding this.
msg11073 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-03.18:35:24
#2548 was fixed as of https://github.com/jythontools/jython/commit/ebb7f49b47290fe20b1d72991b7a2d37f256fd92 and SymPy is working now, provided that one uses a version with https://github.com/sympy/sympy/pull/12120#issuecomment-277042966 incorporated.

However it is very slow. Much slower than I would expect even for Jython, so we should profile and investigate here. I was bale to run stuff from https://github.com/sympy/sympy/wiki/Quick-examples, specificially I am able to run this test-script:

from sympy import *
x, y, z, t = symbols('x y z t')
k, m, n = symbols('k m n', integer=True)
f, g, h = map(Function, 'fgh')
print Rational(3,2)*pi + exp(I*x) / (x**2 + y)
print exp(I*x).subs(x,pi).evalf()
print exp(pi * sqrt(163)).evalf(50)
print latex(S('2*4+10',evaluate=False))
print ((x+y)**2 * (x+1)).expand()
a = 1/x + (x*sin(x) - 1)/x
print simplify(a)
print solve(Eq(x**3 + 2*x**2 + 4*x + 8, 0), x)
print solve(x**3 + 2*x**2 + 4*x + 8, x)
print solve([Eq(x + 5*y, 2), Eq(-3*x + 6*y, 15)], [x, y])
print solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])
a, b = symbols('a b')
print product(n*(n+1), (n, 1, b))
print (1/cos(x)).series(x, 0, 6)
print diff(cos(x**2)**2 / (1+x), x)
print integrate(x**2 * cos(x), x)
f = Function('f')
print dsolve(Eq(Derivative(f(x),x,x) + 9*f(x), 1), f(x))
print 'done'

I started SymPy tests, but didn't yet have the patience to complete them, because it is so very slow :(
However no error yet as long as I let it run (maybe a hang-up, cannot tell because I had to cancel for now).
msg11088 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-08.16:31:40
Also see #2551.
msg11093 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-08.22:46:19
With #2551 fixed, I claim this one is fixed as it can be.

- oversized method-issue still makes the setup a bit unhandy, but isn't a real problem.

- speed issue should be investigated via profiling, but IMO that should be a new issue - a fresh thread scoped on SymPy/Jython performance and current state.
msg11094 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-08.22:51:53
Aaron:
I would appreciate if you could include Jython into your testing landscape once 2.7.1 is released, so we will directly notice if things for SymPy break again. (Due to speed issue I'd suggest to apply only basic tests on Jython so far; mainly assert that import works and some basic operations like those from https://github.com/sympy/sympy/wiki/Quick-examples.)
msg11095 (view) Author: Aaron Meurer (asmeurer) Date: 2017-02-09.02:05:11
Can Jython be installed in Travis? That's the only way it will reasonably get tested. Doing the whole suite sounds about impossible, but a reduced suite sounds fine.
History
Date User Action Args
2017-03-28 05:25:43zyasoftsetstatus: pending -> closed
2017-02-09 02:05:12asmeurersetmessages: + msg11095
2017-02-08 22:51:53stefan.richthofersetmessages: + msg11094
2017-02-08 22:46:19stefan.richthofersetstatus: open -> pending
assignee: stefan.richthofer
type: behaviour
components: + Core
versions: + Jython 2.7
messages: + msg11093
milestone: Jython 2.7.1
resolution: fixed
2017-02-08 16:31:40stefan.richthofersetmessages: + msg11088
2017-02-03 18:35:25stefan.richthofersetmessages: + msg11073
2017-02-02 16:28:18stefan.richthofersetmessages: + msg11065
2016-12-02 02:11:10asmeurersetmessages: + msg10998
2016-12-02 00:47:16stefan.richthofersetmessages: + msg10997
2016-11-24 06:02:04asmeurersetmessages: + msg10989
2016-11-24 05:48:48stefan.richthofersetmessages: + msg10988
2016-11-20 15:59:24stefan.richthofersetnosy: + stefan.richthofer
2015-05-05 05:34:57zyasoftsetmessages: + msg10025
2015-05-04 16:12:45zyasoftsetmessages: + msg10017
2015-01-07 07:05:57zyasoftsetpriority: high -> normal
messages: + msg9334
2014-09-26 04:52:01zyasoftsetassignee: fwierzbicki -> (no value)
2014-05-22 00:41:01zyasoftsetnosy: + zyasoft
messages: + msg8523
2013-02-27 19:52:07asmeurersetmessages: + msg7858
2013-02-27 19:44:23fwierzbickisetmessages: + msg7857
2013-02-27 19:37:31asmeurersetmessages: + msg7856
2013-02-27 18:56:56fwierzbickisetmessages: + msg7854
2013-02-27 18:05:03asmeurersetmessages: + msg7844
2013-02-27 18:00:15asmeurersetmessages: + msg7842
2013-02-27 17:55:08fwierzbickisetpriority: high
assignee: fwierzbicki
2013-02-27 17:54:52fwierzbickisetmessages: + msg7841
2011-09-28 17:35:55asmeurersetmessages: + msg6656
2011-09-28 17:35:03asmeurersetmessages: + msg6655
2011-09-12 16:45:16fwierzbickisetmessages: + msg6647
2011-09-11 20:25:03asmeurersetmessages: + msg6646
2011-09-11 20:22:20asmeurersetmessages: + msg6645
2011-09-09 21:48:04fwierzbickisetnosy: + fwierzbicki
messages: + msg6643
2011-09-04 03:07:13asmeurersetmessages: + msg6637
2011-09-04 02:36:42asmeurersetmessages: + msg6636
2011-09-04 01:30:33asmeurersetmessages: + msg6635
2011-09-04 00:56:00asmeurersetmessages: + msg6634
2011-09-04 00:45:15amaksetmessages: + msg6633
2011-09-03 20:50:04asmeurersetmessages: + msg6632
2011-09-03 19:39:20asmeurersetmessages: + msg6631
2011-09-03 01:54:28amaksetmessages: + msg6628
2011-07-23 13:45:14amaksetnosy: + amak
2011-07-22 20:34:51asmeurercreate