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

Questions about subscript (Vensim function) #296

Closed
18811184907 opened this issue Sep 28, 2021 · 6 comments · Fixed by #312
Closed

Questions about subscript (Vensim function) #296

18811184907 opened this issue Sep 28, 2021 · 6 comments · Fixed by #312

Comments

@18811184907
Copy link

Dear James Houghton:
Hello, I am a postgraduate student from China, learning PySD 1.10.0. I have recently encountered a problem in the use of subscripts, and I would like to ask you for some knowledge about it.
It seems that there is no function in Lookup that can call a value with a subscript or assign a value directly. I'd like to know your solution and hope you have time to look at it and give some advice, your suggestions would be very useful to me. Thank you!
Fang zhe
This is the ‘.mdl’ file.

vensim.txt

This is simple code.

path = r"C:\Users\User\Desktop\all\pythonpysd\"
name = "T15"
typrname = ".mdl"
f = path + name + typrname
model = pysd.read_vensim(f, split_views=True)
print(model.doc())
print(model)

@enekomartinmartinez
Copy link
Collaborator

enekomartinmartinez commented Sep 30, 2021

Hi @18811184907
Unfortunately, PySD current version doesn't support that feature for hardcoded lookups
However, it is implemented for external lookups. There are two possible options here:

  1. Maybe the fastest is to move your lookup to an Excel file and read it with Vensim using GET XLS LOOKUPS or GET DIRECT LOOKUPS
  2. Implement subscript support for hardcoded lookups, this will require rewriting how hardcoded lookups are translated to pysd.

Moreover, currently any kind of lookups accept subscript as a parameter therefore you may need to define an intermediate variable, for transform the subscripts in numeric values, e. g.:

c[age]=
	a(age_values[age])
	~	
	~		|

a(
	GET DIRECT LOOKUPS('your_file.xlsx', 'tabname', 'x_series_row_or_col', 'cell'))
	~	
	~		|

age_values[age]=
	1,2,3,4,5,6,7,8,9,10
	~	
	~		|
age:
	age 1,age 2,age 3,age 4,age 5,age 6,age 7,age 8,age 9,age 10
	~	
	~		|

I hope this can help you :)

@18811184907
Copy link
Author

Hi @enekomartinmartinez
Thank you for your reply. I have made some progress.
In addition, I also found a problem. I made a modification in line 1291 of "vensim2py.py". Otherwise, an error will be reported when reading the “\”.
:

line 1291.txt

@18811184907
Copy link
Author

Hi @enekomartinmartinez
I have another question. Will the next version add VECTOR ELM MAP() to the builder? Looking forward to your reply. Thank you.

@enekomartinmartinez
Copy link
Collaborator

enekomartinmartinez commented Oct 14, 2021

Hi @18811184907
Thank you very much for notifying and correcting the bug :)
In order to implement the fix on PySD we have two options:

  1. You can download the latest source code from git and open a pull request from a fork with the corrected version. In this case, I would ask you to add some tests as well (you can provide a small test model reproducing the bug opening a PR in test_models repo and adding the test to tests/integration_tests_vensim_pathway.py, it is also recommendable that you add a test in tests/unit_tests_vensim2py.py).
  2. If you prefer it, you can provide me a small model example and I will create all the necessary tests and update PySD.

About VECTOR ELM MAP, I am not currently working on it. I give preference to the functions I need for the project I am working on, some of the functions I will add in the future have been already tracked in the issues section. In any case, I encourage you to develop this function, I can help you if you need it.

Thank you

@18811184907
Copy link
Author

18811184907 commented May 23, 2022 via email

@enekomartinmartinez
Copy link
Collaborator

You're welcome :)
Note that the PR only solves the first code you sent (running lookups with subscript variables and using subscripts as parameters).
The function VECTOR ELM MAP has not been included. I will open a new issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants