Skip to main content

A framework for modeling and simulating dynamical systems.

Project description

PyPI Package latest release Documentation Status Travis-CI Build Status Coverage Status

SimuPy is a framework for simulating interconnected dynamical system models and provides an open source, python-based tool that can be used in model- and system- based design and simulation workflows. Dynamical system models can be specified as an object with the interface described in the API Documentation. Models can also be constructed using symbolic expressions, as in

from sympy.physics.mechanics import dynamicsymbols
from sympy.tensor.array import Array
from simupy.systems.symbolic import DynamicalSystem

x = x1, x2, x3 = Array(dynamicsymbols('x1:4'))
u = dynamicsymbols('u')
sys = DynamicalSystem(Array([-x1+x2-x3, -x1*x2-x2+u, -x1+u]), x, u)

which will automatically create callable functions for the state equations, output equations, and jacobians. By default, the code generator uses a wrapper for sympy.lambdify. You can change it by passing the system initialization arguments code_generator (the function) and additional keyword arguments to the generator in a dictionary code_generator_args. You can change the defaults for future systems by changing the module variables

import simupy.systems.symbolic
simupy.systems.symbolic.DEFAULT_CODE_GENERATOR = your_code_generator_function
simupy.systems.symbolic.DEFAULT_CODE_GENERATOR_ARGS = {'extra_arg': value}

A number of helper classes/functions exist to simplify the construction of models. For example, a linear feedback controller can be defined as

from simupy.systems import LTISystem
ctrl = LTISystem([[1.73992128, 0.99212953,  -2.98819041]])

The gains in the example come from the infinite horizon LQR based on the system linearized about the origin. A block diagram of the system under feedback control can be constructed

from simupy.block_diagram import BlockDiagram
BD = BlockDiagram(sys, ctrl)
BD.connect(sys, ctrl) # connect the current state to the feedback controller
BD.connect(ctrl, sys) # connect the controlled input to the system

Initial conditions for systems with non-zero dimensional state can be defined (it defaults to zeros of the appropriate dimension) and the interconnected systems can be simulated with the BlockDiagram’s simulate method,

sys.initial_condition = [5, -3, 1]
res = BD.simulate(10)

which uses scipy.integrate.ode as the default solver for the initial-valued problem. The results are an instance of the SimulationResult class, with array attributes t, x, y, and e, holding time, state, output, and event values for each integrator time step. The first axis indexes the time step. For x, y, and e, the second axis indexes the individual signal components, ordered first by the order each system was added to the block diagram then according to the system state and output specification. The simulation defaults to the dopri5 solver with dense output, but a different integrator_class and integrator_options options can be used as long as it supports a subset of the scipy.integrate.ode API. The default values used for future simulations can be changed following the pattern for the symbolic code generator options.

A number of utilities for constructing and manipulating systems and the simulation results are also included:

  • process_vector_args and lambdify_with_vector_args from simupy.utils.symbolic are helpers for code generation using sympy.lambdify

  • simupy.utils.callable_from_trajectory is a simple wrapper for making polynomial spline interpolators using scipy.interpolate.splprep

  • simupy.matrices includes tools for constructing (vector) systems using matrix expressions and re-wrapping the results into matrix form

  • simupy.systems.SystemFromCallable is a helper for converting a function to a state-less system (typically a controller) to simulate

  • MemorylessSystem and LTISystem are subclasses to more quickly create these types of systems

  • SwitchedSystem is used to construct systems with discontinuities, defined by zero-crossings of the event_equation_function output.

The examples subdirectory includes a number of worked problems. The documentation and docstrings are also available for reference.

Installation

Version 1.0 of SimuPy is pip installable

$ pip install simupy

However, the latest features and examples are only available in the development version. To install,

$ git clone https://github.com/simupy/simupy.git
$ pip install -e simupy

SimuPy has been tested locally against

but tests on Travis may run with newer versions. Much of the functionality works without SymPy, so installation does not require it. The examples use matplotlib to visualize the results. Testing uses pytest. The documents are built with Sphinx == 1.6.3.

Contributing

  1. To discuss problems or feature requests, file an issue. For bugs, please include as much information as possible, including operating system, python version, and version of all dependencies.

  2. To contribute, make a pull request. Contributions should include tests for any new features/bug fixes and follow best practices including PEP8, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simupy-1.1.2.tar.gz (195.7 kB view details)

Uploaded Source

Built Distribution

simupy-1.1.2-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

Details for the file simupy-1.1.2.tar.gz.

File metadata

  • Download URL: simupy-1.1.2.tar.gz
  • Upload date:
  • Size: 195.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for simupy-1.1.2.tar.gz
Algorithm Hash digest
SHA256 aecafc1ed728fb69b82b3fa43cfcb66c1edf70352c282a1eab31816ffe6cd33e
MD5 40416b6dcfaf2a7fabae5d6db8ca80b1
BLAKE2b-256 217c1287faaf5b93b4f514b25df00fbc11b6ac8149067988444e1e2fe5333df6

See more details on using hashes here.

File details

Details for the file simupy-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: simupy-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 42.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for simupy-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7a6bed0ce7dc4e043b9ceb3ee823b7e4692afe56e1b6c2d63d008c63fc9878ae
MD5 ee869d5aed10eab21edca3a060a4c977
BLAKE2b-256 ac6fa09d6939e94a5e0dd9ae639ee5884496da42a087cd2caee92ab6a09818f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page