@@ -93,7 +93,7 @@ Next, in [Builder module] figures the **builder** module. There is no class defi
The main function of the builder module is **build**. That function builds and writes the Python representation of the model. It is called from vensim2py module after finishing the entire translation process of the Vensim model. As parameters are passed the different elements of the model that have been parsed, subscripts, namespace and the name of the file where the result of the representation in Python must be written. This function has certain lines of permanent code that always write in the created models, but then, there are certain lines of code that are completed with the translation generated before in the vensim2py model.
In image [Utils module] is found the utils module. The main purpose of utils is to join in a single module all the functions with great utility for the proyect. Many of these functions are used many times throughout the translation processs. So, as we already presented in [PySD relationships between modules], this module is used by builder, functions, external and vensim2py modules. In turn, the accesible names of the decorators, external and functions modules are imported into the utils modules to define a list with the names that hace already been used and that have a particular meaning in the model that is being translated.
In image [Utils module] is found the utils module. The main purpose of utils is to join in a single module all the functions with great utility for the project. Many of these functions are used many times throughout the translation process. So, as we already presented in [PySD relationships between modules], this module is used by builder, functions, external and vensim2py modules. In turn, the accesible names of the decorators, external and functions modules are imported into the utils modules to define a list with the names that hace already been used and that have a particular meaning in the model that is being translated.
![Utils module]
...
...
@@ -106,7 +106,7 @@ External is the main class of that module, all of the other classes inherit from
![External module]
The External class allows to store certain information, such as the name of the file being read and the data it cointains.
The External class allows to store certain information, such as the name of the file being read and the data it contains.
The Excels class is in charge of reading Excel files and storing information about them, to avoid reading these files more than once, putting the singleton pattern in to practice.
...
...
@@ -120,8 +120,16 @@ To obtain the data from statements like GET XLS DATA and GET DIRECT DATA, the Ex
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.
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 [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.
![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.