mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-10-24 22:57:42 -05:00
Remove tensorflow dependency of hybrid newton test
This commit is contained in:
1 parent
6a41fe4060
commit
372be6832c
3 files changed
+26
-5
No files matched your search
@@ -3,4 +3,3 @@ future
|
||||
decorator
|
||||
opm
|
||||
numpy
|
||||
tensorflow-cpu
|
||||
@@ -4,10 +4,10 @@ from pathlib import Path
|
||||
import numpy as np
|
||||
import subprocess
|
||||
|
||||
from .utils import Dense, Sequential
|
||||
from .utils import collect_input_features, compute_output_vars, write_config, extract_newtit_from_file, extract_unrst_variables
|
||||
from .utils import (ABSOLUTE_CASES, RELATIVE_CASES, FEATURE_ENGINEERING_CASES, SCALING_CASES, MULTI_MODEL_CASES, ZERO_NEWTON_CASES, ALL_CASES)
|
||||
|
||||
import tensorflow as tf
|
||||
from kerasify import export_model
|
||||
|
||||
|
||||
@@ -89,9 +89,8 @@ class TestHybridNewton(unittest.TestCase):
|
||||
input_flat = input_flat.reshape(-1)
|
||||
output_flat = output_flat.reshape(-1)
|
||||
|
||||
model = tf.keras.Sequential([
|
||||
tf.keras.Input(shape=(input_flat.shape[0],)),
|
||||
tf.keras.layers.Dense(output_flat.shape[0], use_bias=True)
|
||||
model = Sequential([
|
||||
Dense(input_dim=input_flat.shape[0], output_dim=output_flat.shape[0])
|
||||
])
|
||||
model.layers[0].set_weights([np.zeros((input_flat.shape[0], output_flat.shape[0])), output_flat])
|
||||
apply_time = self.times[start_idx]
|
||||
@@ -197,3 +196,5 @@ class TestHybridNewton(unittest.TestCase):
|
||||
f"got {h}, expected <= {b}"
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -5,6 +5,27 @@ from pathlib import Path
|
||||
|
||||
from opm.io.ecl import ERst, ESmry
|
||||
|
||||
# Avoid tensorflow dependency but maintain compability with kerasify export_model method
|
||||
class Dense:
|
||||
def __init__(self, input_dim, output_dim, activation='linear'):
|
||||
self.weights = np.zeros((input_dim, output_dim), dtype=np.float32)
|
||||
self.biases = np.zeros((output_dim,), dtype=np.float32)
|
||||
self.activation = activation
|
||||
|
||||
def set_weights(self, w_b):
|
||||
self.weights = w_b[0].astype(np.float32)
|
||||
self.biases = w_b[1].astype(np.float32)
|
||||
|
||||
def get_weights(self):
|
||||
return [self.weights, self.biases]
|
||||
|
||||
def get_config(self):
|
||||
return {'activation': self.activation}
|
||||
|
||||
class Sequential:
|
||||
def __init__(self, layers):
|
||||
self.layers = layers
|
||||
|
||||
|
||||
def extract_unrst_variables(data_dir, deck_file):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user