Skip to content

Commit

Permalink
initial actions (#3)
Browse files Browse the repository at this point in the history
* initial actions

* fixed test

* fixed test

* typo
  • Loading branch information
ThummeTo committed Oct 23, 2023
1 parent f97e7cb commit 0eb4b97
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 70 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Install CompatHelper
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: Run CompatHelper
run: julia -e 'using CompatHelper; CompatHelper.main()'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}

84 changes: 84 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Creation of the SSH deploy key for the CompatHelper

## 1. Create an ssh key pair.
This command is avaible for Windows (`cmd`) and Linux (`bash`).
```
ssh-keygen -N "" -f compathelper_key -t ed25519 -C compathelper
```

## 2. Copy the **private** key.
Copy the output to your clipboard.
1. Windows

```
type compathelper_key
```

1. Linux

```
cat compathelper_key
```


## 3. Create a GitHub secret.
1. Open the repository on the GitHub page.

1. Click on the **Settings** tab.

1. Click on **Secrets**.

1. Click on **Actions**.

1. Click on the **New repository secret** button.

1. Name the secret `COMPATHELPER_PRIV`.

1. Paste the **private** key as content.

## 4. Copy the **public** key.
Copy the output to your clipboard.

1. Windows

```
type compathelper_key.pub
```

1. Linux

```
cat compathelper_key.pub
```


## 5. Create a GitHub deploy key.
1. Open the repository on the GitHub page.

1. Click on the **Settings** tab.

1. Click on **Deploy keys**.

1. Click on the **Add deploy key** button.

1. Name the deploy key `COMPATHELPER_PUB`.

1. Paste the **public** key as content.

1. Enable the write access for the deploy key.

## 6. Delete the ssh key pair.
1. Windows

```
del compathelper_key compathelper_key.pub
```

1. Linux

```
rm -f compathelper_key compathelper_key.pub
```

For more Information click [here](https://docs.juliahub.com/CompatHelper/GCWpz/2.0.1/#Instructions-for-setting-up-the-SSH-deploy-key).

15 changes: 15 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
61 changes: 61 additions & 0 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Run tests

on:
workflow_dispatch:
push:
pull_request:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
# Don't cancel in-progress jobs if any matrix job fails
fail-fast: false
matrix:
julia-version: ['1.6', '1'] # "1" automatically expands to the latest stable 1.x release of Julia
julia-arch: [x64]
os: [ubuntu-latest, windows-latest]
experimental: [false]

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Check out repository
uses: actions/checkout@v2

# Set up Julia
- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}

# Set up cache
- name: "Set up cache"
uses: actions/cache@v2
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
# Build package
- name: "Build package"
uses: julia-actions/julia-buildpkg@v1

# Run the tests
- name: "Run tests"
uses: julia-actions/julia-runtest@v1

# Preprocess Coverage
- name: "Preprocess Coverage"
uses: julia-actions/julia-processcoverage@v1

# Run codecov
- name: "Run CodeCov"
uses: codecov/codecov-action@v2
with:
file: lcov.info
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FMISensitivity"
uuid = "3e748fe5-cd7f-4615-8419-3159287187d2"
authors = ["TT <[email protected]>", "LM <[email protected]>"]
version = "0.1.0"
version = "0.1.1"

[deps]
FMICore = "8af89139-c281-408e-bce2-3005eb87462f"
Expand All @@ -11,5 +11,5 @@ SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
[compat]
FMICore = "0.18.0"
ForwardDiffChainRules = "0.2.0"
SciMLSensitivity = "7.40.0"
SciMLSensitivity = "7.41.0"
julia = "1.6"
140 changes: 72 additions & 68 deletions test/FMI2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,71 +426,75 @@ fmi2Unload(fmu)

########## Event Indicators Check ###########

# load demo FMU
fmu = fmi2Load("VLDM", EXPORTINGTOOL, "2020x"; type=:ME)
data = FMIZoo.VLDM(:train)

# enable time gradient evaluation (disabled by default for performance reasons)
fmu.executionConfig.eval_t_gradients = true

# prepare (allocate) an FMU instance
c, x0 = FMIImport.prepareSolveFMU(fmu, nothing, fmu.type, nothing, nothing, nothing, nothing, nothing, data.params, 0.0, 0.0, nothing)

x_refs = fmu.modelDescription.stateValueReferences
x = fmi2GetContinuousStates(c)
dx = fmi2GetReal(c, c.fmu.modelDescription.derivativeValueReferences)
u_refs = fmu.modelDescription.inputValueReferences
u = zeros(fmi2Real, 0)
y_refs = fmu.modelDescription.outputValueReferences
y = zeros(fmi2Real, 0)
p_refs = copy(fmu.modelDescription.parameterValueReferences)

# remove some parameters
deleteat!(p_refs, findall(x -> (x >= UInt32(134217728) && x <= UInt32(134217737)), p_refs))
p = fmi2GetReal(c, p_refs)
e = fmi2GetEventIndicators(c)
t = 0.0

# Jacobian ∂e/∂x
_f = function(_x)
ec_idcs = collect(UInt32(i) for i in 1:fmu.modelDescription.numberOfEventIndicators)
ret = fmu(;ec=e, ec_idcs=ec_idcs, x=_x)
ret.ec
end
_f(x)
j_fwd = ForwardDiff.jacobian(_f, x)
j_rwd = ReverseDiff.jacobian(_f, x)
j_fid = FiniteDiff.finite_difference_jacobian(_f, x)
# j_smp = fmi2SampleJacobian(c, :indicators, fmu.modelDescription.parameterValueReferences)
# no option to get sensitivitities directly in FMI2...

# ToDo: Improve test, test again ground truth
@test isapprox(j_fwd, j_fid; atol=atol)
@test isapprox(j_rwd, j_fid; atol=atol)

if CHECK_ZYGOTE
j_zyg = Zygote.jacobian(_f, x)[1]
@test isapprox(j_zyg, j_rwd; atol=atol)

@test c.solution.evals_∂e_∂x == 62
else
@test c.solution.evals_∂e_∂x == 34
end

@test c.solution.evals_∂ẋ_∂x == 0
@test c.solution.evals_∂ẋ_∂u == 0
@test c.solution.evals_∂ẋ_∂p == 0
@test c.solution.evals_∂ẋ_∂t == 0

@test c.solution.evals_∂y_∂x == 0
@test c.solution.evals_∂y_∂u == 0
@test c.solution.evals_∂y_∂p == 0
@test c.solution.evals_∂y_∂t == 0

@test c.solution.evals_∂e_∂u == 0
@test c.solution.evals_∂e_∂p == 0
@test c.solution.evals_∂e_∂t == 0
reset!(c)

# clean up
fmi2Unload(fmu)
# [ToDo] Enable Test for Linux too (by providing a FMU)

if Sys.iswindows()
# load demo FMU
fmu = fmi2Load("VLDM", EXPORTINGTOOL, "2020x"; type=:ME)
data = FMIZoo.VLDM(:train)

# enable time gradient evaluation (disabled by default for performance reasons)
fmu.executionConfig.eval_t_gradients = true

# prepare (allocate) an FMU instance
c, x0 = FMIImport.prepareSolveFMU(fmu, nothing, fmu.type, nothing, nothing, nothing, nothing, nothing, data.params, 0.0, 0.0, nothing)

x_refs = fmu.modelDescription.stateValueReferences
x = fmi2GetContinuousStates(c)
dx = fmi2GetReal(c, c.fmu.modelDescription.derivativeValueReferences)
u_refs = fmu.modelDescription.inputValueReferences
u = zeros(fmi2Real, 0)
y_refs = fmu.modelDescription.outputValueReferences
y = zeros(fmi2Real, 0)
p_refs = copy(fmu.modelDescription.parameterValueReferences)

# remove some parameters
deleteat!(p_refs, findall(x -> (x >= UInt32(134217728) && x <= UInt32(134217737)), p_refs))
p = fmi2GetReal(c, p_refs)
e = fmi2GetEventIndicators(c)
t = 0.0

# Jacobian ∂e/∂x
_f = function(_x)
ec_idcs = collect(UInt32(i) for i in 1:fmu.modelDescription.numberOfEventIndicators)
ret = fmu(;ec=e, ec_idcs=ec_idcs, x=_x)
ret.ec
end
_f(x)
j_fwd = ForwardDiff.jacobian(_f, x)
j_rwd = ReverseDiff.jacobian(_f, x)
j_fid = FiniteDiff.finite_difference_jacobian(_f, x)
# j_smp = fmi2SampleJacobian(c, :indicators, fmu.modelDescription.parameterValueReferences)
# no option to get sensitivitities directly in FMI2...

# ToDo: Improve test, test again ground truth
@test isapprox(j_fwd, j_fid; atol=atol)
@test isapprox(j_rwd, j_fid; atol=atol)

if CHECK_ZYGOTE
j_zyg = Zygote.jacobian(_f, x)[1]
@test isapprox(j_zyg, j_rwd; atol=atol)

@test c.solution.evals_∂e_∂x == 62
else
@test c.solution.evals_∂e_∂x == 34
end

@test c.solution.evals_∂ẋ_∂x == 0
@test c.solution.evals_∂ẋ_∂u == 0
@test c.solution.evals_∂ẋ_∂p == 0
@test c.solution.evals_∂ẋ_∂t == 0

@test c.solution.evals_∂y_∂x == 0
@test c.solution.evals_∂y_∂u == 0
@test c.solution.evals_∂y_∂p == 0
@test c.solution.evals_∂y_∂t == 0

@test c.solution.evals_∂e_∂u == 0
@test c.solution.evals_∂e_∂p == 0
@test c.solution.evals_∂e_∂t == 0
reset!(c)

# clean up
fmi2Unload(fmu)
end

0 comments on commit 0eb4b97

Please sign in to comment.