(self, **kwargs)
| 14 | description = "Limited range TensorFlow sin approximation" |
| 15 | |
| 16 | def __init__(self, **kwargs): |
| 17 | super().__init__(**kwargs) |
| 18 | # Import Tensorflow model directory created by model.save(["stored-model"]) |
| 19 | parent_path = pathlib.Path(__file__).parent |
| 20 | # Check if building or initializing |
| 21 | if parent_path.name == "resources": |
| 22 | # __init__ called from within FMU (probably) |
| 23 | # Path relative to "resources" directory root within the FMU |
| 24 | model_dir_path = parent_path / "stored-model.keras" |
| 25 | if model_dir_path.exists(): |
| 26 | try: |
| 27 | # Fetch saved model from directory included in the FMU |
| 28 | self.model = tf.keras.models.load_model(model_dir_path) |
| 29 | except AttributeError: |
| 30 | print("Unable to load model from directory. Has TensorFlow been included in the environment?") |
| 31 | except OSError: |
| 32 | print("Unable to load model from directory. Has the correct directory been specified?") |
| 33 | else: |
| 34 | print("No model directory found. Has the directory been included in the FMU when building?") |
| 35 | |
| 36 | self.sin_input = 0. |
| 37 | self.sin_output_tf = 0. |
| 38 | self.sin_output_ref = 0. |
| 39 | |
| 40 | self.register_variable(Real("sin_input", causality=Fmi2Causality.input)) |
| 41 | self.register_variable(Real("sin_output_tf", causality=Fmi2Causality.output)) |
| 42 | self.register_variable(Real("sin_output_ref", causality=Fmi2Causality.output)) |
| 43 | |
| 44 | def do_step(self, current_time, step_size): |
| 45 | # Similar to model.predict() with less performance overhead |
nothing calls this directly
no test coverage detected