Skip to content
Snippets Groups Projects
Commit 01f0c6ea authored by marrobl's avatar marrobl
Browse files

Updated

parent fb14f11e
No related branches found
No related tags found
No related merge requests found
...@@ -120,25 +120,25 @@ In Vensim there are different statements that allow to obtain data from external ...@@ -120,25 +120,25 @@ In Vensim there are different statements that allow to obtain data from external
To obtain data from statements like GET XLS DATA and GET DIRECT DATA, there is the ExtData class. In turn, for the GET XLS LOOKUPS and GET DIRECT LOOKUPS statements, the ExtLookup class. For the GET XLS CONSTANT and GET DIRECT CONSTANT functions, the ExtConstant class and, finally, to implement the GET XLS SUBSCRIPT and GET DIRECT SUBSCRIPT function, the ExtSubscript class. To obtain data from statements like GET XLS DATA and GET DIRECT DATA, there is the ExtData class. In turn, for the GET XLS LOOKUPS and GET DIRECT LOOKUPS statements, the ExtLookup class. For the GET XLS CONSTANT and GET DIRECT CONSTANT functions, the ExtConstant class and, finally, to implement the GET XLS SUBSCRIPT and GET DIRECT SUBSCRIPT function, the ExtSubscript class.
These expressions create a new instance of the External class where information is stored to represent the necessary data structures. These instances of the External class are initialized before stateful objects. These expressions create a new instance of the External class where the information to represent the necessary data structures is stored. These instances of the External class are initialized before the stateful objects.
To better understand the functionality and the reason for the next module presented called decorator, it would be advisable to know the [Decorator pattern](https://refactoring.guru/design-patterns/decorator). To better understand the functionality and the reason for the next module presented, called decorator, it would be advisable to know the [Decorator pattern](https://refactoring.guru/design-patterns/decorator).
A kind of two-level cache is implemented in PySD to speed up the execution of the model as much as possible. The cache is implemented by decorators. In the translation process, each translated statement or function is tagged with one of two cache types. The @cache.run decorator is used for functions whose value is constant during model execution. In this way, only once is its value calculated throughout the execution of the model. On the other hand, functions whose values need to change with each execution step are labeled with the @cache.step decorator. In PySD, a kind of two-level cache is implemented to speed up model execution as much as possible. The cache is implemented using decorators. In the translation process, each translated statement or function is tagged with one of two types of caches. The @cache.run decorator is used for functions whose value is constant during model execution. In this way, their value is only calculated once throughout the execution of the model. On the other hand, functions whose values must change with each execution step are labeled with the @cache.step decorator.
In [Decorators module] figure the decorators module is detailed where the functions to develop and decorate the functions of the model in the translation step are found. In [Decorators module] figure the decorators module is detailed where the functions to develop and decorate the functions of the model in the translation step are located.
![Decorators module] ![Decorators module]
The Cache class allows to define the functionality of these decorators. The run and step functions define the two-level cache functionality used in PySD. The reset function resets the time entered as a parameter and clears the cache of the values that are labeled as step. The clean function cleans the cache whose name is passed as a parameter. The Cache class allows to define the functionality of these decorators. The run and step functions define the functionality of the two-level cache used in PySD. The reset function resets the time entered as a parameter and clears the cache of values tagged as step. The clean function clears the cache whose name is passed as a parameter.
## The process view of PySD ## The process view of PySD
Activity diagrams are used to represent the PySD process view. The [Main process view] is the main activity diagram of PySD, the other diagrams presented in the next figures are a breakdown of this one. Activity diagrams are used to represent the PySD process view. The [Main process view] is the main activity diagram of PySD, the other diagrams presented in the next figures are a breakdown of this.
![Main process view] ![Main process view]
The translation process begins when the user indicate the Vensim model (with .mdl extension) to be translated, using the read\_vensim function of the pysd module. In this function, internally the translate\_vensim function is called, which is passed as a parameter the Vensim model and is found in the vensim2py module. This is when the file path extension is modified, changing the extension from mdl to py, so the translated model in Python will be saved in the same path as the Vensim model. Then, the sections that make up the model are split and, subsequently, from these obtained sections, a list is created with all macros in the model. Also, each section is organized and translated resulting in translation to complete the Python file. The subsystems that make up the [Main process view] diagram are explained in more detail bellow. The translation process begins when the user indicates the Vensim model (.mdl extension) to be translated, using the read\_vensim function of the pysd module. In this function, the translate\_vensim function is called internally, which is passed as a parameter the Vensim model and is found in the vensim2py module. This is when the file path extension is modified, changing the extension from mdl to py, so the translated model in Python will be saved in the same path as the Vensim model. Then, the sections that make up the model are split and, subsequently, from these obtained sections, a list is created with all macros in the model. Also, each section is organized and translated resulting in translation to complete the Python file. The subsystems that make up the [Main process view] diagram are explained in more detail bellow.
The figure [Divide into sections] shows the first subsystem. Inside the translate\_vensim function, the Vensim model is read in text mode and the grammar file\_structure\_grammar is responsible for separating the macros and the main code. This grammar is defined in the get\_file\_sections function, in vensim2py module. In turn, in this function defines the class that has the visitor methods associated with the grammar rules, called FileParser. As result of this function and grammar, the text of the model is divided into a list with the different sections that compose it, and a section is obtained for each macro of the model and other section with the main code. The figure [Divide into sections] shows the first subsystem. Inside the translate\_vensim function, the Vensim model is read in text mode and the grammar file\_structure\_grammar is responsible for separating the macros and the main code. This grammar is defined in the get\_file\_sections function, in vensim2py module. In turn, in this function defines the class that has the visitor methods associated with the grammar rules, called FileParser. As result of this function and grammar, the text of the model is divided into a list with the different sections that compose it, and a section is obtained for each macro of the model and other section with the main code.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment