Package: pydy
PyDy, short for Python Dynamics, is a tool kit written in the Python
programming language that utilizes an array of scientific programs to enable
the study of multibody dynamics. The goal is to have a modular framework that
can provide the user with their desired workflow, including:Model specificationEquation of motion generationSimulationVisualizationBenchmarkingPublicationWe started by building theSymPymechanics packagewhich provides an API
for building models and generating the symbolic equations of motion for complex
multibody systems. More recently we developed two packages,pydy.codegenandpydy.viz, for simulation and visualization of the models, respectively.  This
Python package contains these two packages and other tools for working with
mathematical models generated from SymPy mechanics. The remaining tools
currently used in the PyDy workflow are popular scientific Python packages such
asNumPy,SciPy,IPython,Jupyter,ipywidgets,pythreejs, andmatplotlibwhich provide additional code for numerical analyses, simulation, and
visualization.InstallationWe recommend thecondapackage manager and theAnacondaorMinicondadistributions for easy cross platform installation.Once Anaconda (or Miniconda) is installed type:$ conda install -c conda-forge pydyAlso, a simple way to install all of the optional dependencies is to install
thepydy-optionalmetapackage using conda:$ conda install -c conda-forge pydy-optionalNote thatpydy-optionalcurrently enforces the use of Jupyter 4.0, so you
may not want to install into your root environment. Create a new environment
for working with PyDy examples that use the embedded Jupyter visualizations:$ conda create -n pydy -c conda-forge pydy-optional
$ conda activate pydy
(pydy)$ python -c "import pydy; print(pydy.__version__)"Other installation optionsIf you have the pip package manager installed you can type:$ pip install pydyInstalling from source is also supported. The latest stable version of the
package can be downloaded from PyPi[1]:$ wget https://pypi.python.org/packages/source/p/pydy/pydy-X.X.X.tar.gz[1]ChangeX.X.Xto the latest version number.and extracted and installed[2]:$ tar -zxvf pydy-X.X.X.tar.gz
$ cd pydy-X.X.X
$ python setup.py install[2]For system wide installs you may need root permissions (perhaps prepend
commands withsudo).DependenciesPyDy has hard dependencies on the following software[3]:[3]We only test PyDy with these minimum dependencies; these module versions
are provided in the Ubuntu 20.04 packages. Previous versions may work.Python >= 3.7setuptools >= 44.0.0NumPy>= 1.16.5SciPy>= 1.3.3SymPy>= 1.5.1PyWin32 >= 219 (Windows Only)PyDy has optional dependencies for extended code generation on:Cython>= 0.29.14Theano>= 1.0.4and animated visualizations withScene.display_jupyter()on:Jupyter Notebook>= 6.0.0 orJupyter Lab>= 1.0.0ipywidgets>= 6.0.0pythreejs>= 2.1.1or interactive animated visualizations withScene.display_ipython()on:4.0.0 <=Jupyter Notebook< 5.0.04.0.0 <=ipywidgets< 5.0.0The examples may require these dependencies:matplotlib>= 3.1.2version_informationUsageThis is an example of a simple one degree of freedom system: a mass under the
influence of a spring, damper, gravity and an external force:/ / / / / / / / /
-----------------
  |    |     |   | g
  \   | |    |   V
k /   --- c  |
  |    |     | x, v
 --------    V
 |  m   | -----
 --------
    | F
    VDerive the system:fromsympyimportsymbolsimportsympy.physics.mechanicsasmemass,stiffness,damping,gravity=symbols('m, k, c, g')position,speed=me.dynamicsymbols('x v')positiond=me.dynamicsymbols('x',1)force=me.dynamicsymbols('F')ceiling=me.ReferenceFrame('N')origin=me.Point('origin')origin.set_vel(ceiling,0)center=origin.locatenew('center',position*ceiling.x)center.set_vel(ceiling,speed*ceiling.x)block=me.Particle('block',center,mass)kinematic_equations=[speed-positiond]force_magnitude=mass*gravity-stiffness*position-damping*speed+forceforces=[(center,force_magnitude*ceiling.x)]particles=[block]kane=me.KanesMethod(ceiling,q_ind=[position],u_ind=[speed],kd_eqs=kinematic_equations)kane.kanes_equations(particles,loads=forces)Create a system to manage integration and specify numerical values for the
constants and specified quantities. Here, we specify sinusoidal forcing:fromnumpyimportarray,linspace,sinfrompydy.systemimportSystemsys=System(kane,constants={mass:1.0,stiffness:10.0,damping:0.4,gravity:9.8},specifieds={force:lambdax,t:sin(t)},initial_conditions={position:0.1,speed:-1.0},times=linspace(0.0,10.0,1000))Integrate the equations of motion to get the state trajectories:y=sys.integrate()Plot the results:importmatplotlib.pyplotaspltplt.plot(sys.times,y)plt.legend((str(position),str(speed)))plt.xlabel('Time [s]')plt.show()DocumentationThe documentation for this package is hosted athttp://pydy.readthedocs.orgbut
you can also build them from source using the following instructions.To build the documentation you must install the dependencies:Sphinxnumpydocjupyter-sphinxTo build the HTML docs, run Make from within thedocsdirectory:$ cd docs
$ make htmlYou can then view the documentation from your preferred web browser, for
example:$ firefox _build/html/index.htmlModules and PackagesCode Generation (codegen)This package provides code generation facilities. It generates functions that
can numerically evaluate the right hand side of the ordinary differential
equations generated withsympy.physics.mechanicswith three different
backends: SymPy’slambdify, Theano, and Cython.Models (models.py)The models module provides some canned models of classic systems.Systems (system.py)The System module provides aSystemclass to manage simulation of a single
system.Visualization (viz)This package provides tools to create 3D animated visualizations of the
systems. The visualizations utilize WebGL and run in a web browser. They can
also be embedded into an IPython notebook for added interactivity.Development EnvironmentThe source code is managed with the Git version control system. To get the
latest development version and access to the full repository, clone the
repository from Github with:$ git clone https://github.com/pydy/pydy.gitYou should then install the dependencies for running the tests:nose: 1.3.7phantomjs: 1.9.0Isolated EnvironmentsIt is typically advantageous to setup a virtual environment to isolate the
development code from other versions on your system. There are two popular
environment managers that work well with Python packages: virtualenv andconda.The following installation assumes you havevirtualenvwrapperin addition to
virtualenv and all the dependencies needed to build the various packages:$ mkvirtualenv pydy-dev
(pydy-dev)$ pip install numpy scipy cython nose theano sympy ipython "notebook<5.0" "ipywidgets<5.0" version_information
(pydy-dev)$ pip install matplotlib # make sure to do this after numpy
(pydy-dev)$ git clone git@github.com:pydy/pydy.git
(pydy-dev)$ cd pydy
(pydy-dev)$ python setup.py developOr withconda:$ conda create -c pydy -n pydy-dev setuptools numpy scipy ipython "notebook<5.0" "ipywidgets<5.0" cython nose theano sympy matplotlib version_information
$ source activate pydy-dev
(pydy-dev)$ git clone git@github.com:pydy/pydy.git
(pydy-dev)$ cd pydy
(pydy-dev)$ conda develop .The full Python test suite can be run with:(pydy-dev)$ nosetestsFor the JavaScript tests the Jasmine and blanket.js libraries are used. Both
of these libraries are included in pydy.viz with the source. To run the
JavaScript tests:cd pydy/viz/static/js/tests && phantomjs run-jasmine.js SpecRunner.html && cd ../../../../../BenchmarkRun the benchmark to test the n-link pendulum problem with the various backends:$ python bin/benchmark_pydy_code_gen.py <max # of links> <# of time steps>CitationIf you make use of PyDy in your work or research, please cite us in your
publications or on the web. This citation can be used:Gilbert Gede, Dale L Peterson, Angadh S Nanjangud, Jason K Moore, and Mont
Hubbard, “Constrained Multibody Dynamics With Python: From Symbolic Equation
Generation to Publication”, ASME 2013 International Design Engineering
Technical Conferences and Computers and Information in Engineering
Conference, 2013,10.1115/DETC2013-13470.Questions, Bugs, Feature RequestsIf you have any question about installation, usage, etc, feel free send a
message to our publicmailing list.If you think there’s a bug or you would like to request a feature, please open
anissueon Github.Related PackagesThese are various related and similar Python packages:https://github.com/cdsousa/sympyboticshttps://pypi.python.org/pypi/ARShttps://pypi.python.org/pypi/Hamiltonhttps://pypi.python.org/pypi/PyODEhttps://pypi.python.org/pypi/arborishttps://pypi.python.org/pypi/odeVizhttps://pypi.python.org/pypi/pymunk