Skip to content
Snippets Groups Projects
Commit 5f089eae authored by auphelia's avatar auphelia
Browse files

[notebook - trafo pass] Added explanation of transform function from ModelWrapper

parent 7f96215c
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# FINN - Transformation passes
--------------------------------------
* <font size="3">changes (transforms) the given graph</font>
* <font size="3">input: ModelWrapper</font>
* <font size="3">returns the changed model and flag `model_was_changed`</font>
* <font size="3">returns the changed model (ModelWrapper) and flag `model_was_changed`</font>
%% Cell type:markdown id: tags:
## General Information
-----------------------------
<font size="3">Transformation passes have a base class and must inherit from that. Transformations are meant to be applied using .transform function from the ModelWrapper. This function makes a deep copy of the input model by default. The next cell shows .transform of ModelWrapper. </font>
%% Cell type:markdown id: tags:
### .transform() from ModelWrapper
`def transform(self, transformation, make_deepcopy=True):
transformed_model = self
if make_deepcopy:
transformed_model = copy.deepcopy(self)
model_was_changed = True
while model_was_changed:
(transformed_model, model_was_changed) = transformation.apply(
transformed_model
)
return transformed_model`
%% Cell type:markdown id: tags:
<font size="3">When the function is called, the model, the name of the transformation and, if required, the flag make_deepcopy are passed. It is also possible not to make a copy of the model. In this case `make_deepcopy` must be set to False. Then the branch `if make_deepcopy:` would not be taken and no copy of the model would be made.
The unchanged model is first passed to the variable `transformed_model` to pass this variable on to the transformation later.
`model_was_changed` indicates whether the transformation needs to be applied more then once. Because it needs to be applied at least one time `model_was_changed` is first set to True and then depending on the return values of the transformation function the transformation can be applied more then once.
**Important**: Due to the structure of this function, `model_was_changed` must be set to False at some point. Otherwise the loop is infinite.
Each new transformation must correspond to the scheme of the base class and contain at least the function `apply(model)`, which returns the changed model and a bool value for `model_was_changed`.
</font>
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Example -
-----------------------------
<font size="3">text</font>
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment