Skip to content

Commit

Permalink
Simer support for model.runtime.paths
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Rule (VM/EMT3) <[email protected]>
  • Loading branch information
timrulebosch committed Mar 3, 2025
1 parent e19e1c5 commit 75316a7
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DSE_CLIB_VERSION ?= 1.0.24
export DSE_CLIB_URL ?= $(DSE_CLIB_REPO)/archive/refs/tags/v$(DSE_CLIB_VERSION).zip

DSE_SCHEMA_REPO ?= https://github.com/boschglobal/dse.schemas
DSE_SCHEMA_VERSION ?= 1.2.13
DSE_SCHEMA_VERSION ?= 1.2.17
export DSE_SCHEMA_URL ?= $(DSE_SCHEMA_REPO)/releases/download/v$(DSE_SCHEMA_VERSION)/dse-schemas.tar.gz

DSE_NCODEC_REPO ?= https://github.com/boschglobal/dse.standards
Expand Down
5 changes: 4 additions & 1 deletion extra/tools/simer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ module github.com/boschglobal/dse.modelc/extra/tools/simer
go 1.21.6

require (
github.com/boschglobal/dse.schemas/code/go/dse v1.2.9
github.com/boschglobal/dse.schemas/code/go/dse v1.2.17
github.com/stretchr/testify v1.8.4
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)
4 changes: 2 additions & 2 deletions extra/tools/simer/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMz
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/boschglobal/dse.schemas/code/go/dse v1.2.9 h1:hicvDIF3XrH9pQ8fSgdX0UtGx01iJHzRsQR/KETdZ6w=
github.com/boschglobal/dse.schemas/code/go/dse v1.2.9/go.mod h1:1pxTw2DGf81svt1NZrzbn7kE7l1fsOjEmDpqKdEHl2Q=
github.com/boschglobal/dse.schemas/code/go/dse v1.2.17 h1:3u0oFH3T5oolGLu2BEenbpWCshYg4Ay+80GZnKquavc=
github.com/boschglobal/dse.schemas/code/go/dse v1.2.17/go.mod h1:1pxTw2DGf81svt1NZrzbn7kE7l1fsOjEmDpqKdEHl2Q=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
25 changes: 25 additions & 0 deletions extra/tools/simer/internal/app/simer/simer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ package simer

import (
"fmt"
"io/fs"
"log/slog"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
Expand All @@ -19,6 +22,22 @@ import (
schema_kind "github.com/boschglobal/dse.schemas/code/go/dse/kind"
)

func listFiles(paths []string, exts []string) []string {
files := []string{}
for _, path := range paths {
fileSystem := os.DirFS(".")
fs.WalkDir(fileSystem, path, func(s string, d fs.DirEntry, e error) error {
slog.Debug(fmt.Sprintf("ListFiles: %s (%t, %s)", s, d.IsDir(), filepath.Ext(s)))
if !d.IsDir() && slices.Contains(exts, filepath.Ext(s)) {
files = append(files, s)
}
return nil
})
}

return files
}

func scanFiles(exts []string) []string {
files := []string{}
for _, ext := range exts {
Expand Down Expand Up @@ -195,6 +214,9 @@ func ModelCommandList(docMap map[string][]kind.KindDoc, modelcPath string, model
if model.Runtime != nil && model.Runtime.Files != nil {
yamlFiles = append(yamlFiles, *model.Runtime.Files...)
}
if model.Runtime != nil && model.Runtime.Paths != nil {
yamlFiles = append(yamlFiles, listFiles(*model.Runtime.Paths, []string{".yaml", ".yml"})...)
}
// Run as 32bit process?
progPath := modelcPath
if model.Runtime != nil && model.Runtime.X32 != nil && *model.Runtime.X32 {
Expand Down Expand Up @@ -237,6 +259,9 @@ func stackedModelCmd(stackDoc *kind.KindDoc, modelcPath string, modelcX32Path st
if model.Runtime != nil && model.Runtime.Files != nil {
yamlFiles = append(yamlFiles, *model.Runtime.Files...)
}
if model.Runtime != nil && model.Runtime.Paths != nil {
yamlFiles = append(yamlFiles, listFiles(*model.Runtime.Paths, []string{".yaml", ".yml"})...)
}
// Run as 32bit process?
if model.Runtime != nil && model.Runtime.X32 != nil && *model.Runtime.X32 {
progPath = modelcX32Path
Expand Down
20 changes: 20 additions & 0 deletions extra/tools/simer/internal/app/simer/simer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2025 Robert Bosch GmbH
//
// SPDX-License-Identifier: Apache-2.0

package simer

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestListYamlFiles(t *testing.T) {
paths := []string{"testdata/sim/model/input/data"}
exts := []string{".yaml", ".yml"}
yamlFiles := listFiles(paths, exts)
assert.Equal(t, 2, len(yamlFiles))
assert.Contains(t, yamlFiles, "testdata/sim/model/input/data/model.yaml")
assert.Contains(t, yamlFiles, "testdata/sim/model/input/data/signalgroup.yaml")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
kind: Stack
metadata:
name: default
spec:
connection:
transport:
redis:
timeout: 60
uri: redis://localhost:6379
models:
- channels:
- expectedModelCount: 2
name: physical
- expectedModelCount: 1
name: network
model:
name: simbus
name: simbus
uid: 0
- channels:
- alias: scalar_channel
name: physical
selectors:
channel: scalar_vector
model: input
model:
name: dse.modelc.csv
name: input
runtime:
env:
CSV_FILE: model/input/data/input.csv
paths:
- model/input/data
uid: 1
- channels:
- alias: scalar_channel
name: physical
selectors:
channel: scalar_vector
model: linear
- alias: network_channel
name: network
selectors:
channel: network_vector
model: linear
model:
name: dse.fmi.mcl
name: linear
runtime:
env: {}
paths:
- model/linear/data
uid: 2
---
kind: Model
metadata:
name: simbus
spec: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Timestamp;input;factor;offset
0.0000;1.0;2.0;3.0
0.0005;-1.1;2.1;3.1
0.0010;1.2;-2.2;3.2
0.0015;1.3;2.3;-3.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 Robert Bosch GmbH
#
# SPDX-License-Identifier: Apache-2.0

---
kind: Model
metadata:
name: Csv
spec:
runtime:
dynlib:
- os: linux
arch: amd64
path: sim/model/input/lib/libcsv.so
- os: linux
arch: x86
path: sim/model/input/lib/libcsv.so
- os: windows
arch: x64
path: sim/model/input/lib/libcsv.dll
- os: windows
arch: x86
path: sim/model/input/lib/libcsv.dll
channels:
- alias: scalar
selectors:
channel: scalar_channel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
kind: SignalGroup
metadata:
name: scalar_channel
labels:
model: input
channel: signal_vector
spec:
signals:
- signal: input
- signal: factor
- signal: offset
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Timestamp;A;B;C
0.0000;1.0;2.0;3.0
0.0005;-1.1;2.1;3.1
0.0010;1.2;-2.2;3.2
0.0015;1.3;2.3;-3.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
kind: Model
metadata:
annotations:
fmi_guid: '{71da084a-0998-4418-a29d-01af36a32568}'
fmi_model_cosim: "true"
fmi_model_version: ""
fmi_resource_dir: model/linear/linear_fmu/resources
fmi_stepsize: "0.0005"
mcl_adapter: fmi
mcl_version: "2.0"
name: linear
spec:
channels:
- alias: signal_channel
selectors:
channel: signal_vector
model: linear
runtime:
dynlib:
- arch: amd64
os: linux
path: model/linear/lib/libfmimcl.so
mcl:
- arch: amd64
os: linux
path: model/linear/linear_fmu/binaries/linux64/fmu2linear.so
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
kind: SignalGroup
metadata:
labels:
channel: signal_vector
model: linear
name: linear
spec:
signals:
- annotations:
fmi_variable_causality: input
fmi_variable_name: input
fmi_variable_type: Real
fmi_variable_vref: "1"
signal: input
- annotations:
fmi_variable_causality: input
fmi_variable_name: factor
fmi_variable_type: Real
fmi_variable_vref: "2"
signal: factor
- annotations:
fmi_variable_causality: input
fmi_variable_name: offset
fmi_variable_type: Real
fmi_variable_vref: "3"
signal: offset
- annotations:
fmi_variable_causality: output
fmi_variable_name: output
fmi_variable_type: Real
fmi_variable_vref: "4"
signal: output

0 comments on commit 75316a7

Please sign in to comment.