diff --git a/README.md b/README.md index 8b5d772e..96e5591c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PEtab SciML test suite -[![Build Status](https://https://github.com/PEtab-dev/petab_sciml_testsuite/actions/workflows/CI.yml/badge.svg?branch=main)](https://https://github.com/PEtab-dev/petab_sciml_testsuite/actions/workflows/CI.yml?query=branch%3Amain) +[![Build Status](https://github.com/PEtab-dev/petab_sciml_testsuite/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/PEtab-dev/petab_sciml_testsuite/actions/workflows/CI.yml?query=branch%3Amain) [![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl) [![code style: runic](https://img.shields.io/badge/code_style-%E1%9A%B1%E1%9A%A2%E1%9A%BE%E1%9B%81%E1%9A%B2-black)](https://github.com/fredrikekre/Runic.jl) @@ -60,9 +60,9 @@ Currently, supported and tested layers and activation functions are: - **Layers**: `Conv1-3d`, `ConvTranspose1-3d`, `AvgPool1-3d`, `MaxPool1-3d`, `LPPool1-3d`, `AdaptiveMaxPool1-3d`, `AdaptiveMeanPool1-3d`, `BatchNorm1-3d`, `InstanceNorm1-3d`, `LayerNorm`, `Dropout1-3d`, `Dropout`, `AlphaDropout`, `Linear`, `Bilinear` and `Flatten`. -- **Activation**: `relu`, `relu6`, `hardtanh`, `hardswish`, `selu`, `leaky_relu`, `gelu`, - `logsigmoid`, `tanhshrink`, `softsign`, `softplus`, `tanh`, `sigmoid`, `hardsigmoid`, - `mish`, `elu`, `celu`, `softmax` and `log_softmax`. +- **Activation**: `relu`, `relu6`, `hardtanh`, `hardswish`, `selu`, `silu` `leaky_relu`, + `gelu`, `logsigmoid`, `tanhshrink`, `softsign`, `softplus`, `tanh`, `sigmoid`, + `hardsigmoid`, `mish`, `elu`, `celu`, `softmax` and `log_softmax`. A list of supported layers and activation functions for each tool supporting PEtab SciML can be found in the PEtab SciML diff --git a/test_cases/ml_model_import/054/README.md b/test_cases/ml_model_import/054/README.md new file mode 100644 index 00000000..c3ad1704 --- /dev/null +++ b/test_cases/ml_model_import/054/README.md @@ -0,0 +1,7 @@ +# Net Test Case 054 + +Test case for testing neural network import only. + +## Neural-net + +A simple feed-forward network testing `silu` (often called `swish`) activation function. diff --git a/test_cases/ml_model_import/054/create_testdata/net.jl b/test_cases/ml_model_import/054/create_testdata/net.jl new file mode 100644 index 00000000..e1212b01 --- /dev/null +++ b/test_cases/ml_model_import/054/create_testdata/net.jl @@ -0,0 +1,27 @@ +using Lux, StableRNGs +using PEtabSciMLTestsuite: save_ps, save_io, write_yaml + +# runic: off +nn_model = @compact( + layer1 = Dense(2, 5, Lux.swish), + layer2 = Dense(5, 1), +) do x + embed = layer1(x) + out = layer2(embed) + @return out +end +# runic: on + +input_order_jl, input_order_py = ["W"], ["W"] +output_order_jl, output_order_py = ["W"], ["W"] +dirsave = joinpath(@__DIR__, "..") +for i in 1:3 + rng = StableRNG(i) + ps, st = Lux.setup(rng, nn_model) + input = rand(rng, Float32, 2) + output = nn_model(input, ps, st)[1] + save_ps(dirsave, i, nn_model, :net0, ps) + save_io(dirsave, i, input, input_order_jl, input_order_py, :input) + save_io(dirsave, i, output, output_order_jl, output_order_py, :output) +end +write_yaml(dirsave, input_order_jl, input_order_py, output_order_jl, output_order_py) diff --git a/test_cases/ml_model_import/054/create_testdata/net.py b/test_cases/ml_model_import/054/create_testdata/net.py new file mode 100644 index 00000000..6d366b20 --- /dev/null +++ b/test_cases/ml_model_import/054/create_testdata/net.py @@ -0,0 +1,26 @@ +"""Neural network import test generation""" + +import torch +from torch import nn +from torch.nn import functional as F +from pysrc.ml_import_helper import make_yaml, test_nn + + +class Net(nn.Module): + def __init__(self) -> None: + super().__init__() + self.layer1 = nn.Linear(2, 5) + self.layer2 = nn.Linear(5, 1) + + def forward(self, net_input: torch.Tensor) -> torch.Tensor: + x = self.layer1(net_input) + x = F.silu(x) + out = self.layer2(x) + return out + + +def ml_model_import_054(dir_save): + net = Net() + make_yaml(net, dir_save) + test_nn(net, dir_save, ["layer1", "layer2"]) + return 0 diff --git a/test_cases/ml_model_import/054/net.yaml b/test_cases/ml_model_import/054/net.yaml new file mode 100644 index 00000000..d56ed5f7 --- /dev/null +++ b/test_cases/ml_model_import/054/net.yaml @@ -0,0 +1,47 @@ +nn_model_id: net0 +inputs: +- input_id: input0 +layers: +- layer_id: layer1 + layer_type: Linear + args: + in_features: 2 + out_features: 5 + bias: true +- layer_id: layer2 + layer_type: Linear + args: + in_features: 5 + out_features: 1 + bias: true +forward: +- name: net_input + op: placeholder + target: net_input + args: [] + kwargs: {} +- name: layer1 + op: call_module + target: layer1 + args: + - net_input + kwargs: {} +- name: silu + op: call_function + target: silu + args: + - layer1 + kwargs: + inplace: false +- name: layer2 + op: call_module + target: layer2 + args: + - silu + kwargs: {} +- name: output + op: output + target: output + args: + - layer2 + kwargs: {} diff --git a/test_cases/ml_model_import/054/net_input_1.hdf5 b/test_cases/ml_model_import/054/net_input_1.hdf5 new file mode 100644 index 00000000..595273ea Binary files /dev/null and b/test_cases/ml_model_import/054/net_input_1.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_input_2.hdf5 b/test_cases/ml_model_import/054/net_input_2.hdf5 new file mode 100644 index 00000000..b88fe32c Binary files /dev/null and b/test_cases/ml_model_import/054/net_input_2.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_input_3.hdf5 b/test_cases/ml_model_import/054/net_input_3.hdf5 new file mode 100644 index 00000000..27b6f97e Binary files /dev/null and b/test_cases/ml_model_import/054/net_input_3.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_output_1.hdf5 b/test_cases/ml_model_import/054/net_output_1.hdf5 new file mode 100644 index 00000000..6daaafc7 Binary files /dev/null and b/test_cases/ml_model_import/054/net_output_1.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_output_2.hdf5 b/test_cases/ml_model_import/054/net_output_2.hdf5 new file mode 100644 index 00000000..a586adb0 Binary files /dev/null and b/test_cases/ml_model_import/054/net_output_2.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_output_3.hdf5 b/test_cases/ml_model_import/054/net_output_3.hdf5 new file mode 100644 index 00000000..01d8a209 Binary files /dev/null and b/test_cases/ml_model_import/054/net_output_3.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_ps_1.hdf5 b/test_cases/ml_model_import/054/net_ps_1.hdf5 new file mode 100644 index 00000000..4c61d22b Binary files /dev/null and b/test_cases/ml_model_import/054/net_ps_1.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_ps_2.hdf5 b/test_cases/ml_model_import/054/net_ps_2.hdf5 new file mode 100644 index 00000000..055a6683 Binary files /dev/null and b/test_cases/ml_model_import/054/net_ps_2.hdf5 differ diff --git a/test_cases/ml_model_import/054/net_ps_3.hdf5 b/test_cases/ml_model_import/054/net_ps_3.hdf5 new file mode 100644 index 00000000..a3be365c Binary files /dev/null and b/test_cases/ml_model_import/054/net_ps_3.hdf5 differ diff --git a/test_cases/ml_model_import/054/solutions.yaml b/test_cases/ml_model_import/054/solutions.yaml new file mode 100644 index 00000000..5da6addb --- /dev/null +++ b/test_cases/ml_model_import/054/solutions.yaml @@ -0,0 +1,21 @@ +input_order_py: + - "W" +net_input: + - "net_input_1.hdf5" + - "net_input_2.hdf5" + - "net_input_3.hdf5" +input_order_jl: + - "W" +output_order_jl: + - "W" +net_ps: + - "net_ps_1.hdf5" + - "net_ps_2.hdf5" + - "net_ps_3.hdf5" +net_file: "net.yaml" +output_order_py: + - "W" +net_output: + - "net_output_1.hdf5" + - "net_output_2.hdf5" + - "net_output_3.hdf5"