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

Support Python 3 #229

Merged
merged 14 commits into from
Jun 16, 2015
Merged

Support Python 3 #229

merged 14 commits into from
Jun 16, 2015

Conversation

oliverlee
Copy link
Contributor

Addresses #38
I got 2 of the examples (mass_spring_damper, three_link_conical_pendulum) to run with Python 3.4.2.

  • There are no merge conflicts.
  • If there is a related issue, a reference to that issue is in the
    commit message.
  • Unit tests have been added for the new feature.
  • The PR passes tests both locally (run nosetests) and on Travis CI.
  • All public methods and classes have docstrings. (We use the numpydoc
    format
    .)
  • An explanation has been added to the online documentation. (docs
    directory)
  • The code follows PEP8 guidelines. (use a linter, e.g.
    pylint, to check your code)
  • The new feature is documented in the Release
    Notes
    .
  • The code is backwards compatible. (All public methods/classes must
    follow deprecation cycles.)
  • All reviewer comments have been addressed.

@oliverlee
Copy link
Contributor Author

Also I don't know if Python3' or 'Python 3' is more correct.

@moorepants
Copy link
Member

This is great. I'm sure it will take some testing tweaking. We'll see if it passes all of the Python 2.7 tests.

I'd also like to get Travis running Python 3 but we may need to switch to using miniconda as the testing backend so that we can easily pull in the dependencies.

Do you think we should support Python 3.3+? Or just Python 3.4+?

@pydy/pydy-developers This needs review. All help is welcome.

@moorepants moorepants added this to the 0.3.0 Release milestone Jun 13, 2015
@oliverlee
Copy link
Contributor Author

3.4

@oliverlee
Copy link
Contributor Author

I also looked through all the sources after using 2to3 and it seems okay to me.

@moorepants
Copy link
Member

I just got a bunch of test failures locally testing with Python 3.4:

======================================================================
ERROR: pydy.viz.tests.test_scene.TestScene.test_create_static_html
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/viz/tests/test_scene.py", line 247, in test_create_static_html
    outfile_prefix="test")
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 364, in generate_visualization_json_system
    system.constants.values(), **kwargs)
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 208, in generate_visualization_json
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 312, in generate_simulation_dict
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/visualization_frame.py", line 290, in evaluate_transformation_matrix
    new[i, :, :] = self._numeric_transform(*args)
TypeError: <lambda>() missing 3 required positional arguments: '_Dummy_6742', '_Dummy_6743', and '_Dummy_6744'

======================================================================
ERROR: pydy.viz.tests.test_scene.TestScene.test_custom_camera
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/viz/tests/test_scene.py", line 230, in test_custom_camera
    self.sys.constants.values())
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 312, in generate_simulation_dict
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/visualization_frame.py", line 290, in evaluate_transformation_matrix
    new[i, :, :] = self._numeric_transform(*args)
TypeError: <lambda>() missing 3 required positional arguments: '_Dummy_6771', '_Dummy_6772', and '_Dummy_6773'

======================================================================
ERROR: pydy.viz.tests.test_scene.TestScene.test_generate_scene_dict
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/viz/tests/test_scene.py", line 156, in test_generate_scene_dict
    self.sys.constants.values())
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 312, in generate_simulation_dict
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/visualization_frame.py", line 290, in evaluate_transformation_matrix
    new[i, :, :] = self._numeric_transform(*args)
TypeError: <lambda>() missing 3 required positional arguments: '_Dummy_6787', '_Dummy_6788', and '_Dummy_6789'

======================================================================
ERROR: pydy.viz.tests.test_scene.TestScene.test_generate_simulation_dict
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/viz/tests/test_scene.py", line 111, in test_generate_simulation_dict
    self.sys.constants.values())
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 312, in generate_simulation_dict
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/visualization_frame.py", line 290, in evaluate_transformation_matrix
    new[i, :, :] = self._numeric_transform(*args)
TypeError: <lambda>() missing 3 required positional arguments: '_Dummy_6803', '_Dummy_6804', and '_Dummy_6805'

======================================================================
ERROR: pydy.viz.tests.test_scene.TestScene.test_generate_visualization_json_system
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/viz/tests/test_scene.py", line 263, in test_generate_visualization_json_system
    scene.generate_visualization_json_system(self.sys)
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 364, in generate_visualization_json_system
    system.constants.values(), **kwargs)
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 208, in generate_visualization_json
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/scene.py", line 312, in generate_simulation_dict
    constant_values)
  File "/home/moorepants/src/pydy/pydy/viz/visualization_frame.py", line 290, in evaluate_transformation_matrix
    new[i, :, :] = self._numeric_transform(*args)
TypeError: <lambda>() missing 3 required positional arguments: '_Dummy_6819', '_Dummy_6820', and '_Dummy_6821'

======================================================================
ERROR: pydy.tests.test_system.TestSystem.test_constants
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/tests/test_system.py", line 110, in test_constants
    testing.assert_allclose(sys.constants.values(), constants.values())
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/testing/utils.py", line 1297, in assert_allclose
    verbose=verbose, header=header)
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/testing/utils.py", line 648, in assert_array_compare
    val = comparison(x, y)
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/testing/utils.py", line 1292, in compare
    return np.allclose(x, y, rtol=rtol, atol=atol)
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/core/numeric.py", line 2219, in allclose
    xinf = isinf(x)
TypeError: ufunc 'isinf' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

======================================================================
ERROR: pydy.tests.test_system.TestSystem.test_initial_conditions
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/tests/test_system.py", line 277, in test_initial_conditions
    testing.assert_allclose(sys.initial_conditions.values(), ic.values())
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/testing/utils.py", line 1297, in assert_allclose
    verbose=verbose, header=header)
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/testing/utils.py", line 648, in assert_array_compare
    val = comparison(x, y)
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/testing/utils.py", line 1292, in compare
    return np.allclose(x, y, rtol=rtol, atol=atol)
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/numpy/core/numeric.py", line 2219, in allclose
    xinf = isinf(x)
TypeError: ufunc 'isinf' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_doprint
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/codegen/tests/test_c_code.py", line 319, in test_doprint
    assert header == expected_header
AssertionError

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_generate_code_blocks
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/codegen/tests/test_c_code.py", line 212, in test_generate_code_blocks
    assert v == expected[k]
AssertionError

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_generate_comma_lists
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/codegen/tests/test_c_code.py", line 108, in test_generate_comma_lists
    assert self.generator.comma_lists() == expected
AssertionError

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_generate_cse
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/codegen/tests/test_c_code.py", line 86, in test_generate_cse
    assert self.generator.subexprs == expected_subexprs
AssertionError

======================================================================
FAIL: pydy.tests.test_models.test_multi_mass_spring_damper_double
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/tests/test_models.py", line 71, in test_multi_mass_spring_damper_double
    assert sys.specifieds_symbols == [f0, f1]
AssertionError

======================================================================
FAIL: pydy.tests.test_system.TestSystem.test_init
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/tests/test_system.py", line 63, in test_init
    assert sys.specifieds.keys() == [dynamicsymbols('f0')]
AssertionError

======================================================================
FAIL: pydy.tests.test_system.TestSystem.test_specifieds
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/moorepants/anaconda/envs/pydy-dev-py3/lib/python3.4/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/moorepants/src/pydy/pydy/tests/test_system.py", line 150, in test_specifieds
    assert sys.specifieds.keys() == [dynamicsymbols('f0')]
AssertionError

----------------------------------------------------------------------
Ran 67 tests in 123.297s

FAILED (errors=7, failures=7)
(pydy-dev-py3)moorepants@moorepants-2170p:pydy(pr-229)$ conda list
# packages in environment at /home/moorepants/anaconda/envs/pydy-dev-py3:
#
alabaster                 0.7.3                    py34_0  
babel                     1.3                      py34_0  
certifi                   14.05.14                 py34_0  
cython                    0.22                     py34_0  
dateutil                  2.1                      py34_2  
docutils                  0.12                     py34_0  
fontconfig                2.11.1                        4  
freetype                  2.5.2                         2  
ipython                   3.1.0                    py34_1  
ipython-notebook          3.1.0                    py34_1  
jinja2                    2.7.3                    py34_1  
jsonschema                2.4.0                    py34_0  
libpng                    1.6.17                        0  
libsodium                 0.4.5                         0  
libxml2                   2.9.0                         0  
markupsafe                0.23                     py34_0  
matplotlib                1.4.3                np19py34_2  
mistune                   0.5.1                    py34_1  
modernize                 0.4                       <pip>
mpmath                    0.19                     py34_0  
nose                      1.3.7                    py34_0  
numpy                     1.9.2                    py34_0  
openssl                   1.0.1k                        1  
pip                       7.0.3                    py34_0  
ptyprocess                0.4                      py34_0  
pygments                  2.0.2                    py34_0  
pyparsing                 2.0.3                    py34_0  
pyqt                      4.11.3                   py34_1  
python                    3.4.3                         1  
python-dateutil           2.4.2                    py34_0  
pytz                      2015.4                   py34_0  
pyzmq                     14.6.0                   py34_0  
qt                        4.8.6                         3  
readline                  6.2                           2  
scipy                     0.15.1               np19py34_0  
setuptools                17.0                     py34_0  
sip                       4.16.5                   py34_0  
six                       1.9.0                    py34_0  
snowballstemmer           1.2.0                    py34_0  
sphinx                    1.3.1                    py34_0  
sphinx-rtd-theme          0.1.7                     <pip>
sphinx_rtd_theme          0.1.7                    py34_0  
sqlite                    3.8.4.1                       1  
sympy (/home/moorepants/src/sympy) 0.7.7.dev0                <pip>
system                    5.8                           2  
terminado                 0.5                      py34_0  
theano                    0.7.0                np19py34_0  
tk                        8.5.18                        0  
tornado                   4.2                      py34_0  
xz                        5.0.5                         0  
zeromq                    4.0.5                         0  
zlib                      1.2.8                         0  

@oliverlee
Copy link
Contributor Author

Oh I didn't run the tests correctly.

@moorepants
Copy link
Member

I do nosetests -v from the top level directory.

@oliverlee
Copy link
Contributor Author

$ nosetests -v
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/init.py", line 651, in _build_master
ws.require(requires)
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/init.py", line 952, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.4/dist-packages/pkg_resources/init.py", line 844, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (nose 1.3.7 (/usr/local/lib/python3.4/dist-packages), Requirement.parse('nose==1.3.4'))

@moorepants
Copy link
Member

I can't work on this today, but I'll help setup Travis for Python 2 and 3 testing so we can merge that in with this PR (unless you want to do it). I think we should switch Travis to using miniconda, bump the minimum dep versions for numpy/scipy/etc up to the whatever the oldest versions are in the anaconda repos, and then test on 2.7, maybe 3.3 (sympy supports 3.3), and 3.4.

@moorepants
Copy link
Member

Do you have nose installed?

@oliverlee
Copy link
Contributor Author

oliver@arcturus:~$ nose
No command 'nose' found, did you mean:

Probably don't have time to setup Travis.

@moorepants
Copy link
Member

The command is nosetests and the package name is nose, i.e. pip install nose.

@oliverlee
Copy link
Contributor Author

Oh yeah, that was already installed. I thought you meant some other tool called nose.

@oliverlee
Copy link
Contributor Author

Nvm I figured it out.

@oliverlee oliverlee force-pushed the enh-update-to-python3 branch 3 times, most recently from 9fa48a4 to d959ea6 Compare June 13, 2015 22:22
@oliverlee
Copy link
Contributor Author

Some tests fail on my computer:

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_doprint
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/oliver/repos/math/pydy/pydy/codegen/tests/test_c_code.py", line 319, in test_doprint
    assert header == expected_header
AssertionError

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_generate_code_blocks
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/oliver/repos/math/pydy/pydy/codegen/tests/test_c_code.py", line 212, in test_generate_code_blocks
    assert v == expected[k]
AssertionError

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_generate_comma_lists
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/oliver/repos/math/pydy/pydy/codegen/tests/test_c_code.py", line 108, in test_generate_comma_lists
    assert self.generator.comma_lists() == expected
AssertionError

======================================================================
FAIL: pydy.codegen.tests.test_c_code.TestCMatrixGenerator.test_generate_cse
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/oliver/repos/math/pydy/pydy/codegen/tests/test_c_code.py", line 86, in test_generate_cse
    assert self.generator.subexprs == expected_subexprs
AssertionError

======================================================================
FAIL: pydy.tests.test_models.test_multi_mass_spring_damper_double
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/home/oliver/repos/math/pydy/pydy/tests/test_models.py", line 71, in test_multi_mass_spring_damper_double
    assert sys.specifieds_symbols == [f0, f1]
AssertionError

----------------------------------------------------------------------
Ran 67 tests in 61.212s

But pydy.tests.test_models.test_multi_mass_spring_damper_double will pass sometimes.

@moorepants
Copy link
Member

I wonder if cse is generating slightly different values for python 2 and 3 and that is causing those remaining failures.

@oliverlee
Copy link
Contributor Author

In System, the properties constants_symbols and specifieds_symbols are returned as lists but have no inherent order as they are created from set operations.

@oliverlee
Copy link
Contributor Author

Ran 67 tests in 65.083s

OK

@oliverlee oliverlee force-pushed the enh-update-to-python3 branch 7 times, most recently from 73aa6ee to 579bdf7 Compare June 14, 2015 09:28
@oliverlee
Copy link
Contributor Author

To be clear I'm fine with System.constants_symbols and System.specifieds_symbols being sets. Is that even what you've changed?

Yes

But I think you changed ODEFunctionGenerator.specifieds to a set too.

I'll take a look. I didn't realize there was another specifieds field.

@moorepants
Copy link
Member

Are you on giitter, it is easier to chat there?

@moorepants
Copy link
Member

@oliverlee oliverlee force-pushed the enh-update-to-python3 branch from 7583904 to e67af10 Compare June 16, 2015 09:58
@oliverlee oliverlee force-pushed the enh-update-to-python3 branch 3 times, most recently from 51bd530 to 084ce19 Compare June 16, 2015 11:27
@oliverlee
Copy link
Contributor Author

I had increase SciPy to 0.14.0 after changing NumPy to 1.9.

The absolute import commit was removed and I changed oliverlee@10bd4cd to use relative imports as well.

I think this has now addressed all of your points.

@oliverlee oliverlee force-pushed the enh-update-to-python3 branch 3 times, most recently from 245abc5 to aea2baa Compare June 16, 2015 12:06
Change System.constants_symbols and System.specifieds_symbols properties
from lists to sets as the collections have no inherent order. Tests have
been modified to set the order of the symbols when necessary for
comparison.
Print only the first occurance of each DeprecationWarning.
Bump mininmum version of require and optional dependencies to use
binaries available with conda for Python 3.4. Python 2 requirements are
unchanged. Minimum dependencies for Python 3 are:
  - NumPy 1.8.1
  - SciPy 0.14.0
  - SymPy 0.7.5
  - Theano 0.7.0
  - Cython 0.20.1
This topic branch resolves pydy#38.
@oliverlee oliverlee force-pushed the enh-update-to-python3 branch from aea2baa to 96e76b2 Compare June 16, 2015 13:18
@moorepants
Copy link
Member

Thanks for this heroic PR! Merging!

moorepants added a commit that referenced this pull request Jun 16, 2015
@moorepants moorepants merged commit 4084422 into pydy:master Jun 16, 2015
@oliverlee oliverlee deleted the enh-update-to-python3 branch June 16, 2015 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants