Skip to content
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

Make PySD Created Variables Private #182

Closed
JamesPHoughton opened this issue Jun 15, 2018 · 2 comments
Closed

Make PySD Created Variables Private #182

JamesPHoughton opened this issue Jun 15, 2018 · 2 comments
Labels
Milestone

Comments

@JamesPHoughton
Copy link
Collaborator

JamesPHoughton commented Jun 15, 2018

As @kaetze66 pointed out in kaetze66@c84030b, sometimes in the processing of a variable we create a new variable that didn't exist before. This may create the possibility for namespace conflicts:

For example, a stock like:

accumulation= INTEG (rate, 0)
	~	
	~		|

Has a new object created which is the stateful object, which is called each time you access a stock variable.

def accumulation():
    return integ_accumulation()

integ_accumulation = functions.Integ(lambda: rate(), lambda: 0)

Or, the INITIAL function:

StockA Initial Value=
	INITIAL(InflowA)
	~	
	~		|

Which becomes:

initial_inflowa = functions.Initial(lambda: inflowa())

def stocka_initial_value():
    return initial_inflowa()

if the model already defines a variable named initial_inflowa (which is a completely reasonable thing to do), I'm not sure if the function that creates pysafe names will properly account for this in the namespace - its been a while since I looked at that part of the code.

We need to put together a test model to try this explicitly (probably based on @kaetze66's ).

One way to fix it may be to make the created variables 'private' - by listing underscores before their names. we know no model variable will have that syntax.

@kaetze66
Copy link

Just a quick update. I have been testing for a while now the leading underscore (for delay, smooth, trend, initial) for the model database and I haven't run into any of these problems anymore. The model database is limited to .mdl files currently so xmile might be different. But based on the answer from @alexprey it seems like xmile identifiers cannot begin with an underscore which in my opinion would solve the problem or at least make it highly unlikely to occur.

@alexprey
Copy link
Collaborator

Hi, @kaetze66, solution with adding underscores is fine, I'm already done this thing in my experimental branch and it works fine.

alexprey added a commit to alexprey/pysd that referenced this issue Jul 20, 2018
@alexprey alexprey added the bug label Mar 15, 2019
@alexprey alexprey added this to the 0.10.0 milestone Mar 15, 2019
@alexprey alexprey closed this as completed Apr 2, 2019
julienmalard pushed a commit to julienmalard/pysd that referenced this issue Sep 11, 2019
julienmalard pushed a commit to julienmalard/pysd that referenced this issue Sep 25, 2019
julienmalard pushed a commit to julienmalard/pysd that referenced this issue Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants