Package: simupy
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 theAPI Documentation. Models can also be constructed using symbolic
expressions, as infromsympy.physics.mechanicsimportdynamicsymbolsfromsympy.tensor.arrayimportArrayfromsimupy.systems.symbolicimportDynamicalSystemx=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
forsympy.lambdify. You can change it by passing the system initialization
argumentscode_generator(the function) and additional keyword arguments
to the generator in a dictionarycode_generator_args. You can change the
defaults for future systems by changing the module variablesimportsimupy.systems.symbolicsimupy.systems.symbolic.DEFAULT_CODE_GENERATOR=your_code_generator_functionsimupy.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 asfromsimupy.systemsimportLTISystemctrl=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 constructedfromsimupy.block_diagramimportBlockDiagramBD=BlockDiagram(sys,ctrl)BD.connect(sys,ctrl)# connect the current state to the feedback controllerBD.connect(ctrl,sys)# connect the controlled input to the systemInitial 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 theBlockDiagram’ssimulatemethod,sys.initial_condition=[5,-3,1]res=BD.simulate(10)which usesscipy.integrate.odeas the default solver for the initial-valued
problem. The results are an instance of theSimulationResultclass, with
array attributest,x,y, ande, holding time, state, output,
and event values for each integrator time step. The first axis indexes the time
step. Forx,y, ande, 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 thedopri5solver with dense output, but a differentintegrator_classandintegrator_optionsoptions can be used as long as
it supports a subset of thescipy.integrate.odeAPI. 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_argsandlambdify_with_vector_argsfromsimupy.utils.symbolicare helpers for code generation usingsympy.lambdifysimupy.utils.callable_from_trajectoryis a simple wrapper for making
polynomial spline interpolators usingscipy.interpolate.splprepsimupy.matricesincludes tools for constructing (vector) systems using
matrix expressions and re-wrapping the results into matrix formsimupy.systems.SystemFromCallableis a helper for converting a function
to a state-less system (typically a controller) to simulateMemorylessSystemandLTISystemare subclasses to more quickly create
these types of systemsSwitchedSystemis used to construct systems with discontinuities,
defined by zero-crossings of theevent_equation_functionoutput.The examples subdirectory includes a number of worked problems. The
documentation and docstrings are also available for reference.InstallationVersion 1.0 of SimuPy ispipinstallable$pipinstallsimupyHowever, the latest features and examples are only available in the development
version. To install,$gitclonehttps://github.com/simupy/simupy.git$pipinstall-esimupySimuPy has been tested locally againstPython >= 3.6NumPy>= 1.11SciPy>= 0.18SymPy>= 1.0but tests on Travis may run with newer versions. Much of the functionality
works without SymPy, so installation does not require it. The examples usematplotlibto visualize the results. Testing usespytest. The documents are
built withSphinx== 1.6.3.ContributingTo 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.To contribute, make a pull request. Contributions should include tests for
any new features/bug fixes and follow best practices including PEP8, etc.