masfaraud / bmspy Goto Github PK
View Code? Open in Web Editor NEWPython Block-Model Simulator. An alternative to simulink in python.
License: GNU Lesser General Public License v3.0
Python Block-Model Simulator. An alternative to simulink in python.
License: GNU Lesser General Public License v3.0
Hi,
I'm playing with your library and I'm lost in ODE.Evaluate and in DynamicSystem.Simulate.
I guess the main reason is that we were doing it differently in our school.
Could you please give me some link where I could read more about the method you used?
Or at least give me the name of your solution.
Where am I aiming to:
My favourite method of testing ODEs is solving move on a circle.
dx/dt = -y
dy/dt = x
x[0] = 1
y[0] = 0
Ideal result should be:
x = cos(t)
y = sin(t)
And the real result depends on size of time-step and also on the method used.
With better method you can use longer time-step.
In our school we were forced to use Runge-Kutta: https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
I'm building Blocks with multiple outputs and I think I found a few issues (see #25)
class CountBlock(Block):
def __init__(self, inputs, outputs):
super(CountBlock, self).__init__(inputs, outputs, 1, 0)
self.last_it = -1
self.cnt = 0
def Evaluate(self, it, ts):
if it != self.last_it:
# first time we see this 'it', reset counter
self.cnt = 0
self.last_it = it
else:
self.cnt += 1
outputs = [self.cnt for _ in range(self.n_outputs)]
return outputs
def Label(self):
return 'identity'
def test_count():
input_1 = SignalFunction('input_1', lambda x: np.random.randn())
input_2 = SignalFunction('input_2', lambda x: np.random.randn())
output_1 = Variable('output_1')
output_2 = Variable('output_2')
output_3 = Variable('output_3')
output_4 = Variable('output_4')
output_5 = Variable('output_5')
output_6 = Variable('output_6')
counter_1 = CountBlock([input_1, input_2], [output_1])
counter_2 = CountBlock([input_1, input_2], [output_2, output_3])
counter_3 = CountBlock([input_1, input_2], [output_4, output_5, output_6])
te = 10
ns = 10
model_1 = bms.DynamicSystem(te, ns, [counter_1])
model_1.Simulate()
model_2 = bms.DynamicSystem(te, ns, [counter_2])
model_2.Simulate()
model_3 = bms.DynamicSystem(te, ns, [counter_3])
model_3.Simulate()
print output_1.values
print output_2.values
print output_3.values
print output_4.values
print output_5.values
print output_6.values
after a "pip install bms" and trying one example I get:
Traceback (most recent call last):
File "bms_ex1.py", line 9, in
from bms.signals.functions import Ramp
ImportError: No module named signals.functions
could you please check on a fresh install if the pypi package install works? I suspect the init.py files for the submodules need more content.
I am on ubuntu 16.04lts with python 2.7.11
Wow, great work!
Models I want to run make use of differentiation and integration blocks, and I couldn't find them. Adding them would be very interesting. I made a fork of the project and plan to work on it when I have a better understanding of your code.
Hello. First of all, you are doing an incredible job here! I hope we can have a fully functional Python "Simulink" one day! I'm an electrical engineering student and also a Python fan.
So, talking about my issue, I've read all the documentation, but I haven't found a way to access the Drag & Drop Model drawer. Can you help me?
Cheers,
Douglas
Hi, I just discovered BMS and I'm trying to figure out if this (which looks great) will be useful to me as is.
I would need a 'delay' block. For example if I have signal A and B, I want to sum them but the 'sum' is actually summarizing a real process that actually tokes some time (is not like adding two electrical currents but actually doing some work). Therefore I would like to 'delay' the sum.
As I see it one option is to add a 'delay' block. Another approach is to just add a 'delay' option to some basic blocks (which might default to 0). What are your ideas? Maybe I'm missing something and this is already implemented? If not, if you suggest best approach that fits your philosophy I might be able to submit a PR.
Thanks
Hey man - great work!
If you ever go into a GUI thing here's an awesome project with a beautiful GUI that you can use - Orange Data Mining https://orange.biolab.si/
Keep up the good work!
Branko
Hi @masfaraud
I love your project. Is there a way to combine multiple blocks into a new block?
The Pypi package (python 2.7) seems to be "broken"?
The dependencies are not auto-installing and the bms/physical
folder do not exist.
You can check it here: https://pypi.python.org/pypi/bms
Isn't it because of the install script?
Lines 14 to 26 in ddc4ce9
The packages line should be:
packages=['bms','bms.blocks','bms.signals','bms.physical'],
Thanks a lot for this exciting project! It really looks very promising. Especially for my own control systems library I really needed something like this for a long time. Please let me know if you need a hand on the Dynamic System model parts.
I have to ask though, would you please include the license information or could you clarify which license you have in mind and add it to the repository?
A minor dependency issue : When I run the electric_motor.py example I received the missing module cma
error. I see that it is missing from the dependency list in the setup.py
Hey, this is a great job!!!
I found some problems, however:
LookupError: setuptools-scm was unable to detect version for 'c:\BMSpy-master'.
Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the
.git folder) don't contain the necessary metadata and will not work.
For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
Thanks a lot, and again, great job!
The documentation hosted on pythonhosted is a bit dated.
And I'm not sure if it's best practice to keep the built documentation on the git repository. At least, that's what a gitignore template for Python indicates.
Thanks for created this package!
I think it would be nice to distribute via conda or other distribution system.
Nice work! Really appreciated.
Any way you guys will consider pep8ing the code? The whole codebase would benefit from use of pep8 linter. Just to mention a few:
Networkx 2.0 removed the reverse argument to the topological sorting.
Hey there, back again!
Seeing as there are at least three different contributors to the project, it would be nice if there was a guideline for contributing to the project, such as docstring styles, formatting, and other stuff. Seeing as you are the owner of the project, I believe it would be best if you decided on it. If you want, I can write one based on what you decide. Making the project follow a certain standard makes it easier for new contributors to get used to the code.
Things like spacing between operators and values, tabs-vs-spaces, maximum number of characters per line, could be included.
Regarding docstrings, I'm partial to the following style, using Google docstring formatting and .. math
for displaying formulas:
class Saturation(Block):
"""Defines a saturation block.
.. math::
output =
\\begin{cases}
min\_value, & \\textrm{if } input < min\_value
max\_value, & \\textrm{if } input > max\_value
input, & \\textrm{if } min\_value \leq input \leq max\_value
\\end{cases}
Args:
input_variable (Variable): This is the input of the block.
output_variable (Variable): This is the output of the block.
min_value: This is the lower bound for the output.
max_value: This is the upper bound for the output.
"""
Traceback (most recent call last):
File "bms_ex1.py", line 23, in
ds.Simulate()
File "build/bdist.linux-x86_64/egg/bms/core.py", line 343, in Simulate
File "build/bdist.linux-x86_64/egg/bms/blocks/continuous.py", line 145, in Solve
File "build/bdist.linux-x86_64/egg/bms/blocks/continuous.py", line 140, in OutputMatrices
File "build/bdist.linux-x86_64/egg/bms/blocks/continuous.py", line 128, in _get_M
ZeroDivisionError: float division by zero
I'm submitting a ...
What is the current behavior?
Indexing error in line 505 and 510 of "bms/core.py" (VariablesValues method)
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem Avoid reference to other packages
import bms
from bms.signals.functions import Step
from bms.blocks.continuous import Gain
te = 10
ns = 500
R = Step(('In', 'R'))
Y = bms.Variable(('Out', 'Y'))
G = Gain(R, Y, 1)
system = bms.DynamicSystem(te, ns, [G])
simulation = system.Simulate()
system.VariablesValues(Y, t=1)
1 (Print a number)
What is the motivation / use case for changing the behavior?
The function dont work
Possible fixes
cast "i" variable in line 505 and 510 like "int(i)"
variables.values[int(i)]*((ti-t)/self.ts+1)+variables.values[i+1]*(t-ti)/self.ts)
Please tell us about your environment:
The package 'dill' seems to be required, but it is not listed as a requirement in setup.py.
After a 'git clone' of the repo and 'sudo python setup.py install' I get:
import dill
ImportError: No module named dill
Bonjour
je suis tombé sur ton package sur la modélisation des systèmes.
j'essaie de construire une documentation simple et progressive pour mes élèves de prépa.
j'ai commencé mais j'ai quelques soucis,
as-tu déja une ébauche de DOC/TP .
L'idée c'est de construire pas à pas une modélisation python du robot Maxpid (je présume que tu connais)
Cordialement
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.