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

ci: standardize workflows using SciML's reusable workflows #255

Closed
wants to merge 8 commits into from
47 changes: 0 additions & 47 deletions .github/workflows/CI.yml

This file was deleted.

28 changes: 9 additions & 19 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Documentation
name: "Documentation"

on:
push:
Expand All @@ -7,22 +7,12 @@ on:
tags: '*'
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch || github.ref != 'refs/tags/v*' }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ --code-coverage=user docs/make.jl
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
with:
file: lcov.info
build-and-deploy-docs:
name: "Documentation"
uses: "SciML/.github/.github/workflows/documentation.yml@v1"
secrets: "inherit"
37 changes: 4 additions & 33 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
name: format-check
name: "Format Check"

on:
push:
branches:
- 'master'
- 'release-'
tags: '*'
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
format-check:
name: "Format Check"
uses: "SciML/.github/.github/workflows/format-suggestions-on-pr.yml@v1"
33 changes: 4 additions & 29 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Invalidations
name: "Invalidations"

on:
pull_request:
Expand All @@ -10,31 +10,6 @@ concurrency:
cancel-in-progress: true

jobs:
evaluate:
# Only run on PRs to the default branch.
# In the PR trigger above branches can be specified only explicitly whereas this check should work for master, main, or any other default branch
if: github.base_ref == github.event.repository.default_branch
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- uses: actions/checkout@v4
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_pr

- uses: actions/checkout@v4
with:
ref: ${{ github.event.repository.default_branch }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-invalidations@v1
id: invs_default

- name: Report invalidation counts
run: |
echo "Invalidations on default branch: ${{ steps.invs_default.outputs.total }} (${{ steps.invs_default.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
echo "This branch: ${{ steps.invs_pr.outputs.total }} (${{ steps.invs_pr.outputs.deps }} via deps)" >> $GITHUB_STEP_SUMMARY
- name: Check if the PR does increase number of invalidations
if: steps.invs_pr.outputs.total > steps.invs_default.outputs.total
run: exit 1
evaluate-invalidations:
name: "Evaluate Invalidations"
uses: "SciML/.github/.github/workflows/invalidations.yml@v1"
31 changes: 31 additions & 0 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "Tests"

on:
pull_request:
branches:
- master
paths-ignore:
- 'docs/**'
push:
branches:
- master
paths-ignore:
- 'docs/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch || github.ref != 'refs/tags/v*' }}

jobs:
tests:
name: "Tests"
strategy:
fail-fast: false
matrix:
version:
- "1"
- "1.6"
uses: "SciML/.github/.github/workflows/tests.yml@v1"
with:
julia-version: "${{ matrix.version }}"
secrets: "inherit"
18 changes: 9 additions & 9 deletions src/cost_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ function (f::L2Loss)(sol::DiffEqBase.AbstractNoTimeSolution)

if weight == nothing
@inbounds for i in 1:length(sol)
sumsq += (data[i] - sol[i])^2
sumsq += (data[i] - sol.u[i])^2
end
else
@inbounds for i in 1:length(sol)
if weight isa Real
sumsq = sumsq + ((data[i] - sol[i])^2) * weight
sumsq = sumsq + ((data[i] - sol.u[i])^2) * weight
else
sumsq = sumsq + ((data[i] - sol[i])^2) * weight[i]
sumsq = sumsq + ((data[i] - sol.u[i])^2) * weight[i]
end
end
end
Expand All @@ -82,11 +82,11 @@ function (f::L2Loss)(sol::SciMLBase.AbstractSciMLSolution)

if weight == nothing
@inbounds for i in 1:length(sol)
for j in 1:length(sol[i])
for j in 1:length(sol.u[i])
sumsq += (data[j, i] - sol[j, i])^2
end
if diff_weight != nothing && i != 1
for j in 1:length(sol[i])
for j in 1:length(sol.u[i])
if diff_weight isa Real
sumsq += diff_weight *
((data[j, i] - data[j, i - 1] - sol[j, i] +
Expand All @@ -102,16 +102,16 @@ function (f::L2Loss)(sol::SciMLBase.AbstractSciMLSolution)
else
@inbounds for i in 1:length(sol)
if weight isa Real
for j in 1:length(sol[i])
for j in 1:length(sol.u[i])
sumsq = sumsq + ((data[j, i] - sol[j, i])^2) * weight
end
else
for j in 1:length(sol[i])
for j in 1:length(sol.u[i])
sumsq = sumsq + ((data[j, i] - sol[j, i])^2) * weight[j, i]
end
end
if diff_weight != nothing && i != 1
for j in 1:length(sol[i])
for j in 1:length(sol.u[i])
if diff_weight isa Real
sumsq += diff_weight *
((data[j, i] - data[j, i - 1] - sol[j, i] +
Expand Down Expand Up @@ -194,7 +194,7 @@ function (f::LogLikeLoss)(sol::SciMLBase.AbstractSciMLSolution)
# i is the number of time points
# j is the size of the system
# corresponds to distributions[i,j]
ll -= logpdf(distributions[i], sol[i])
ll -= logpdf(distributions[i], sol.u[i])
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/tests_on_odes/regularization_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ result = solve(optprob, Optim.BFGS())

optprob = Optimization.OptimizationProblem(cost_function_2, [1.2, 2.7])
result = solve(optprob, Optim.BFGS())
@test result.minimizer≈[1.5; 3.0] atol=3e-1
@test result.u≈[1.5; 3.0] atol=3e-1

optprob = Optimization.OptimizationProblem(cost_function_3, [1.3, 0.8, 2.8, 1.2])
result = solve(optprob, Optim.BFGS())
@test result.minimizer≈[1.5; 1.0; 3.0; 1.0] atol=5e-1
@test result.u≈[1.5; 1.0; 3.0; 1.0] atol=5e-1
8 changes: 4 additions & 4 deletions test/tests_on_odes/two_stage_method_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ println("Use Two Stage Method to fit the parameter")

cost_function = two_stage_objective(prob1, t, data)
result = Optim.optimize(cost_function, 0.0, 10.0)
@test result.minimizer[1]≈1.5 atol=3e-1
@test result.u[1]≈1.5 atol=3e-1
cost_function = two_stage_objective(prob2, t, data)
result = Optim.optimize(cost_function, [1.0, 2.5], Optim.BFGS())
@test result.minimizer≈[1.5; 3.0] atol=3e-1
@test result.u≈[1.5; 3.0] atol=3e-1
cost_function = two_stage_objective(prob3, t, data)
result = Optim.optimize(cost_function, [1.3, 0.8, 2.8, 1.2], Optim.BFGS())
@test result.minimizer≈[1.5; 1.0; 3.0; 1.0] atol=5e-1
@test result.u≈[1.5; 1.0; 3.0; 1.0] atol=5e-1
# test differentiation
obj = two_stage_objective(prob2, t, data, Optimization.AutoForwardDiff())
optprob = OptimizationNLopt.OptimizationProblem(obj, [1.3, 0.8])
result = solve(optprob, Optim.ConjugateGradient())
@test result.minimizer≈[1.5; 3.0] atol=3e-1
@test result.u≈[1.5; 3.0] atol=3e-1

obj = two_stage_objective(prob2, t, data, Optimization.AutoForwardDiff())
opt = Opt(:LD_LBFGS, 2)
Expand Down
Loading