-
Notifications
You must be signed in to change notification settings - Fork 89
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
Improve supporting for XMILE specification #144
Improve supporting for XMILE specification #144
Conversation
@JamesPHoughton need small help from you. I can't understand how works the imports in python. On my local setup import on this line |
@JamesPHoughton also I want to say that xmile parser works fine, but model execution is not works, because it is depends on specific definitions in vensim models. F.ex. after run I have the next error |
@alexprey - I haven't figured out how to do imports on this package in a way that works for both python2 and python3. Its a problem. Right now, should be working with py3 - I see on travis that that build at least runs most of the tests. The last issue is because of the |
@JamesPHoughton can I try to change logic with it and use something abstract for computation steps? |
Hey @alexprey, if you want to merge my recent changes into your branch, i'll complete this PR and we'll be on the same page. Otherwise, I'm happy to pull pieces into my branch. |
…on/pysd into structuring_readers # Conflicts: # pysd/py_backend/functions.py
@JamesPHoughton of course, I'll merge your branch and solve conflicts. |
@JamesPHoughton can you check |
Good call, looks like scipy is an issue for others as well:
|
# http://docs.oasis-open.org/xmile/xmile/v1.0/csprd01/xmile-v1.0-csprd01.html#_Toc398039982 | ||
# ==== | ||
|
||
# "delay" !TODO! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The delay functions create additional structure in the model, so they'll eventually be part of a dictionary called builders
. Then what happens is when the parser encounters a delay call, it'll run the builder function that makes delays, using the appropriate arguments, add the new structure to the list of model elements, and then substitute into the equation a reference to that new structure. As an example, in the translation from vensim, the INTEG
call triggers the parser to call the builder.add_stock()
function, which adds this line as new structure, and inserts a call to that object in the original function. It may not be the best way to do it, but it makes it more straightforward to keep track of documentation and function names, without adding too much complexity.
I've created an empty dictionary in this file builders = {}
just as a placeholder. Lets put these delay and smooth and trend functions in there.
# http://docs.oasis-open.org/xmile/xmile/v1.0/csprd01/xmile-v1.0-csprd01.html#_Toc398039980 | ||
# === | ||
|
||
"abs": "abs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like the way you've cleaned this up. Much more readable. Thanks!
pysd/py_backend/xmile/SMILE2Py.py
Outdated
# === | ||
|
||
# !TODO! | ||
# This function works with wrong way for XMILE specification: http://docs.oasis-open.org/xmile/xmile/v1.0/csprd01/xmile-v1.0-csprd01.html#_Toc398039983 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that vensim's pulse
behaves differently from XMILE's? If that's the case, we should have both in the functions
file and just make sure we call the right one in the translator.
# === | ||
# 3.5.6 Miscellaneous Functions | ||
# http://docs.oasis-open.org/xmile/xmile/v1.0/csprd01/xmile-v1.0-csprd01.html#_Toc398039985 | ||
# === | ||
"if_then_else": "functions.if_then_else", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be able to get away with replacing if/then/else individually with their python safe equivalents. If not, we'll have to add a special line to the grammar to handle and translate them. I agree, lets get the other bits working and come back to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean using the native python if then else
construction instead the buildin function?
@@ -79,6 +168,8 @@ def parse(self, text, context='eqn'): | |||
If context is set to equation, lone identifiers will be parsed as calls to elements | |||
If context is set to definition, lone identifiers will be cleaned and returned. | |||
""" | |||
# !TODO! Should remove the inline comments from `text` before parsing the grammar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline comments - good point. I have a hunch that it would be cleanest to pull these out using the grammar and parser, as opposed to preprocessing with a regex, but open to trying it each way.
Is there a sample model that includes comments? If not, we'll need to make one and add it to the test-models repo before tackling this.
Thanks for all your work on this! I really appreciate the collaboration. =) If you've got the appetite for it, would you mind adding a test of the XMILE syntax pulse/ramp etc. input functions to the test repository? It would be good to have a test for your |
Hi @JamesPHoughton, thanks :) I try to figure out how write additional test cases and continue work with you on xmike supporting in pysd. When it will be realesed we want to update it into sdcloud solution, because old version have many issue that you already fixed sinse 032 version! I hope that we can write quality execution engine for xmile. And this expirience is very helpfully for me in my future reserches about
…-----
Regards, Alexey
From sdCloud.io development team.
|
I'm check the XMILE specification and try to mention the possible issues that should to implement.
I not mention in this file problem with parsing the
IF ... THEN ... ELSE
statement, but it should be also supported by grammar. In nearest future I want to continue improve specification supporting.The first I want to fix small, but where important issues:
PULSE
functionRegards,
Alexey from sdCloud.io development team.