Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some test scripts from matHELICS #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test matHELICS

on:
push:
pull_request:
branches:
- main
workflow_dispatch:
#schedule:
# - cron: "35 10 * * 1,3,5 # running early in the morning (UTC)

jobs:
ci-test:
strategy:
fail-fast: false
matrix:
os: [windows-2019,macos-11,ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Install latest HELICS release
uses: gmlc-tdc/helics-action/install@main
- name: Set up MATLAB
uses: matlab-actions/[email protected]
with:
release: R2021a
- name: Set up MEX
uses: matlab-actions/run-command@v1
with:
command: mex -setup
- name: Build matHELICS
uses: matlab-actions/run-command@v1
with:
command: buildHelicsInterface('helics',true)
- name: store package
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}-matHELICS
path: matHELICS.*
- name: run startup
uses: matlab-actions/run-command@v1
with:
command: addpath('helics'), helicsStartup
- name: run tests
uses: matlab-actions/run-command@v1
with:
command: addpath('tests'),addpath('helics'),runAllTests

51 changes: 51 additions & 0 deletions .github/workflows/update-helics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Update HELICS Version

on:
workflow_dispatch:
inputs:
version:
description: 'HELICS version number'
required: true
type: string
dryrun:
description: 'Do a dry run of the update process, without making the commit'
required: false
type: boolean


jobs:
update-helics-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set git config for commits
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"

- name: Update HELICS version number
run: |
# Update lines in the package file
version_line="HelicsVersion='${{ inputs.version }}';"
echo "::group::buildHelicsInterface.m version line"
echo "$version_line"
echo "::endgroup::"
sed -i "/HelicsVersion=/c ${version_line}" buildHelicsInterface.m

git add buildHelicsInterface.m

echo "::group::git diff --staged"
git diff --staged
echo "::endgroup::"

git commit -m "Bump HELICS download version to ${{ inputs.version }}"

echo "::group::git show"
git show
echo "::endgroup::"

if [ "${{ inputs.dryrun }}" = "false" ]; then
echo "Pushing changes"
git push
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ venv*
.LSOverride

# Icon must end with two \r
Icon
Icon


# Thumbnails
._*
Expand Down
28 changes: 14 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: ^(ThirdParty/|test/files/|.github/workflows/|.github/actions/)
repos:
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 2.1.6
rev: 3.0.0
hooks:
- id: markdownlint
args: [-s, ./config/.markdownlintrc]
Expand All @@ -11,20 +11,27 @@ repos:
hooks:
- id: cmake-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.1
rev: v4.0.0-alpha.8
hooks:
- id: prettier
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.13
rev: v1.5.5
hooks:
- id: remove-tabs
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.3.0
hooks:
- id: codespell
exclude: ^(test/)
args:
[
"-w",
"--skip=*.csv",
"--ignore-words=./config/spelling_whitelist.txt",
"--exclude-file=./config/spelling_ignorelines.txt",
]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.6.0
hooks:
- id: mixed-line-ending
- id: trailing-whitespace
Expand All @@ -35,15 +42,8 @@ repos:
- id: end-of-file-fixer
- id: check-shebang-scripts-are-executable
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1
rev: v19.1.0
hooks:
- id: clang-format
types:
- c++
- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|PyTest|Github
exclude: .pre-commit-config.yaml
- c
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ For HELICS documentation see [HELICS.org](www.helics.org)

For other platforms the installation is as simple as downloading this repository and inside matlab executing the `buildSimHELICS` Matlab script.

This should download the required HELICS binary files and compile the platform specific mex file. This does require a compiler be installed on the system and executing inside matlab
This should download the required HELICS binary files and compile the platform specific mex file. This does require a compiler be installed on the system and executing inside matlab

``` matlab
```matlab
>> mex -setup
```

Expand All @@ -20,21 +20,21 @@ This setup is only once on any given Matlab installation and does not need to be
>> buildSimHELICS('../helics');
```

this will generate the helics interface in a folder 1 level above the simHELICS directory. If desired it can also be built in the simHELICS directory for example:
this will generate the helics interface in a folder 1 level above the simHELICS directory. If desired it can also be built in the simHELICS directory for example:

```matlabs
>> cd simHELICS
>> buildSimHELICS();
```

The `buildSimHELICS` function also has an option to generate the package file. This can be used to generate a package that can be transfered to a similar system.
The `buildSimHELICS` function also has an option to generate the package file. This can be used to generate a package that can be transferred to a similar system.

This is a new process for building a simulink interface, it is tested but not extensively and not on a large variety of platforms if you run into issues please let us know.

### Requirements

Matlab 2018a or greater.
intalled compatible compiler to build the mex file
installed compatible compiler to build the mex file

### building with custom HELICS version

Expand All @@ -53,40 +53,44 @@ These simulink blocks are in a simHELICS.slx library object and can be loaded or

### federate block

The federate block takes 1 parameter which is the name of a config file. This config file is typically json, but other formats including a direct string input is allowed. This configuration json is the only means of configuring the federate in simulink. All interfaces should be specified in this configuraiton file.
The federate block takes 1 parameter which is the name of a config file. This config file is typically json, but other formats including a direct string input is allowed. This configuration json is the only means of configuring the federate in simulink. All interfaces should be specified in this configuration file.

### input block

The input block is used to retreive data from HELICS. It takes two parameters. The first is an integer or string with the input index(zero based) or name resepectively, and some arguments as a string as the second argument. Allowed arguments are 'output_size=X', and 'output_type=XXXX'. These define the size and type of the simulink output on the block. Default for an empty string is 1, and double. 'double','int', 'bool', and 'complex' are supported along with 'vector' and 'complex_vector'. The HELICS interface type is defined in the configuration. This is defining the desired output type in simulink.
The input block is used to retrieve data from HELICS. It takes two parameters. The first is an integer or string with the input index(zero based) or name respectively, and some arguments as a string as the second argument. Allowed arguments are 'output_size=X', and 'output_type=XXXX'. These define the size and type of the simulink output on the block. Default for an empty string is 1, and double. 'double','int', 'bool', and 'complex' are supported along with 'vector' and 'complex_vector'. The HELICS interface type is defined in the configuration. This is defining the desired output type in simulink.

The input_block is wired to the helics_federate block.
The input_block is wired to the helics_federate block.

### Publication block

The publication block is used to send data via HELICS. The first is an integer or string with the publication index(zero based) or name resepectively, and some arguments as a string as the second argument. Allowed arguments are 'input_size=X', and 'input_type=XXXX'. These define the size and type of the second simulink input on the block. Default for an empty string argument is 1, and double. 'double','int', 'bool', and 'complex' are supported along with 'vector' and 'complex_vector'. The HELICS interface type is defined in the configuration. This is defining the desired input type and size in simulink.
The publication block is used to send data via HELICS. The first is an integer or string with the publication index(zero based) or name respectively, and some arguments as a string as the second argument. Allowed arguments are 'input_size=X', and 'input_type=XXXX'. These define the size and type of the second simulink input on the block. Default for an empty string argument is 1, and double. 'double','int', 'bool', and 'complex' are supported along with 'vector' and 'complex_vector'. The HELICS interface type is defined in the configuration. This is defining the desired input type and size in simulink.

The publication is block is wired to the helics_federate block and the data wishing to be published.

### Example

A trivial example federate (test_fed.slx) is located in the example folder, along with a simple config file. This federate sends data to itself using a inproc federate and plots the result.
A trivial example federate (test_fed.slx) is located in the example folder, along with a simple config file. This federate sends data to itself using a inproc federate and plots the result.

## Building with older versions of Matlab

If it is necessary to run on an older version of Matlab prior to 2018a, some minor modifications to the helicsMex.cpp may be possible to allow things to work fine, please contact the developers for specific instructions.

Versions prior to Matlab 2015 will require more extensive modifications. And may be better served by using the Swig based matlab build from Helics version 3.2 which should be compatible with other HELICS versions in the 3.X series.
Versions prior to Matlab 2015 will require more extensive modifications. And may be better served by using the Swig based matlab build from Helics version 3.2 which should be compatible with other HELICS versions in the 3.X series.

## Source Repo

The simHelics source code is hosted on GitHub: [https://github.com/GMLC-TDC/simHelics](https://github.com/GMLC-TDC/simHELICS) \[This may not be accurate\]
The simHELICS source code is hosted on GitHub: [https://github.com/GMLC-TDC/simHelics](https://github.com/GMLC-TDC/simHELICS)

## Citation

General citation for HELICS:
T. Hardy, B. Palmintier, P. Top, D. Krishnamurthy and J. Fuller, "HELICS: A Co-Simulation Framework for Scalable Multi-Domain Modeling and Analysis," in IEEE Access, doi: 10.1109/ACCESS.2024.3363615, available at [https://ieeexplore.ieee.org/document/10424422](https://ieeexplore.ieee.org/document/10424422/
T. Hardy, B. Palmintier, P. Top, D. Krishnamurthy and J. Fuller, "HELICS: A Co-Simulation Framework for Scalable Multi-Domain Modeling and Analysis," in IEEE Access, doi: 10.1109/ACCESS.2024.3363615, available at [<https://ieeexplore.ieee.org/document/10424422>](https://ieeexplore.ieee.org/document/10424422/)

## Release

HELICS, simHELICS and many associated repositories are distributed under the terms of the BSD-3 clause license. All new
contributions must be made under this license. [LICENSE](LICENSE)
contributions must be made under this license. [LICENSE](LICENSE)

SPDC-License-Identifier: BSD-3-Clause

Portions of the code written by LLNL with release number LLNL-CODE-866414
11 changes: 4 additions & 7 deletions buildSimHELICS.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function buildSimHELICS(targetPath,makePackage)
end
%actually build the mex file
fprintf('building helics mex target\n');

mex('-lhelics','-R2018a',['-I',basePath,'/include/'],['-L',basePath,'/lib'],['LDFLAGS=$LDFLAGS -Wl,-rpath,$ORIGIN/lib,-rpath,',basePath,'/lib',',-rpath,',basePath,'/lib64'],fullfile(inputPath,'helics_federate.c'),'-outdir',targetPath);
mex('-lhelics','-R2018a',['-I',basePath,'/include/'],['-L',basePath,'/lib'],['LDFLAGS=$LDFLAGS -Wl,-rpath,$ORIGIN/lib,-rpath,',basePath,'/lib',',-rpath,',basePath,'/lib64'],fullfile(inputPath,'helics_input.c'),'-outdir',targetPath);
mex('-lhelics','-R2018a',['-I',basePath,'/include/'],['-L',basePath,'/lib'],['LDFLAGS=$LDFLAGS -Wl,-rpath,$ORIGIN/lib,-rpath,',basePath,'/lib',',-rpath,',basePath,'/lib64'],fullfile(inputPath,'helics_publication.c'),'-outdir',targetPath);
Expand Down Expand Up @@ -108,7 +108,7 @@ function buildSimHELICS(targetPath,makePackage)
%copy the needed dll file if on windows
if ispc
if (~exist(fullfile(targetPath,targetFile),'file'))

copyfile(fullfile(basePath,'bin',targetFile),fullfile(targetPath,targetFile));
copyfile(fullfile(basePath,'bin','*.dll'),targetPath);
end
Expand All @@ -118,7 +118,7 @@ function buildSimHELICS(targetPath,makePackage)
end
%% now build the interface directory and copy files
fprintf('copying required files\n');

% copy the include directory with the C headers
if (~exist(fullfile(targetPath,'include'),'dir'))
mkdir(fullfile(targetPath,'include'));
Expand All @@ -137,7 +137,7 @@ function buildSimHELICS(targetPath,makePackage)
else
copyfile(fullfile(basePath,'bin'),fullfile(targetPath,'bin'));
end

if (makePackage)
fprintf('generating helics simulink binary package file\n');
rmdir(basePath,'s');
Expand All @@ -150,6 +150,3 @@ function buildSimHELICS(targetPath,makePackage)
warning('unrecognized platform for making package');
end
end



27 changes: 27 additions & 0 deletions config/.markdownlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
rule "MD001" # header levels increment by 1
rule "MD003", :style => :atx # header style - atx
rule "MD004", :style => :dash # unordered list style - dash
#rule "MD005" # don't allow inconsistent indentation for list items managed by prettier
#rule "MD007", :indent => 2 # unordered list indentation should be 4 spaces managed by prettier
rule "MD009" # trailing spaces not allowed
rule "MD010" # hard tabs not allowed
rule "MD011" # alert on reversed link syntax
rule "MD012" # alert on multiple consecutive blank lines
#rule "MD013" # line length should be no more than 80 characters
#rule "MD014" # dollars signs not before commands w/o showing output
rule "MD018" # must have space after header style
rule "MD019" # no multiple spaces after header style
rule "MD022" # headers should be surrounded by blank lines
rule "MD023" # headers must start at the beginning of the line
rule "MD024", :allow_different_nesting => true # no multiple same level headers with same content
rule "MD025" # only 1 level 1 header
rule "MD026", :punctuation => '.,;:' # no trailing punctuation in headers
rule "MD027" # no multiple spaces after blockquote symbol
rule "MD028" # no blank lines within blockquote
#rule "MD029", :style => :ordered # ordered list item prefix, shoulded be ordered
#rule "MD030", :ul_single => 1, :ol_single => 1, :ul_multi => 1, :ol_multi => 3 # spaces after list markers, controlled by prettier
rule "MD031" # fenced code blocks need line surrounding
#rule "MD032" # lists should be surrounded by line # handled by prettier markdown formatting
rule "MD034" # no raw url
rule "MD040" # Fenced code blocks should have a language specified
rule "MD046", :style => :fenced # code block style - fenced
1 change: 1 addition & 0 deletions config/spelling_ignorelines.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Parth Bansal](https://github.com/parthb83)
9 changes: 9 additions & 0 deletions config/spelling_whitelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ans
te
stoll
endwhile
fo
emiss
ist
copyable
dur
Loading
Loading