Skip to content

Commit

Permalink
support for 1.9
Browse files Browse the repository at this point in the history
support for 1.9
try compatibility with julia 1.8
update test.yml to v4
support for julia < 1.9
add OrdinaryDiffEq still as [deps] such that it can be used in 1.8
  • Loading branch information
oameye committed Feb 22, 2024
1 parent 3812383 commit b006f4a
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 103 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
54 changes: 54 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI
on:
push:
tags:
- '*'
branches:
- 'master'
pull_request:
branches:
- 'master'
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
actions: write
contents: read
strategy:
matrix:
version:
- '1.10'
- '1.9'
# - 'nightly'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: julia-actions/setup-julia@v1
with:
show-versioninfo: true
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
# - uses: julia-actions/julia-processcoverage@v1
# - uses: codecov/codecov-action@v4
# with:
# files: lcov.info
# token: ${{ secrets.CODECOV_TOKEN }}
# fail_ci_if_error: false
# - uses: julia-actions/julia-uploadcoveralls@v1
# env:
# COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
37 changes: 4 additions & 33 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,14 @@ on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- name: Check if Julia is already available in the PATH
id: julia_in_path
run: which julia
continue-on-error: true
- name: Install Julia, but only if it is not already available in the PATH
uses: julia-actions/setup-julia@v1
with:
version: '1'
arch: ${{ runner.arch }}
if: steps.julia_in_path.outcome != 'success'
- name: "Add the General registry via Git"
run: |
import Pkg
ENV["JULIA_PKG_SERVER"] = ""
Pkg.Registry.add("General")
shell: julia --color=yes {0}
- name: "Install CompatHelper"
run: |
import Pkg
name = "CompatHelper"
uuid = "aa819f21-2bde-4658-8897-bab36330d9b7"
version = "3"
Pkg.add(; name, uuid, version)
shell: julia --color=yes {0}
- name: "Run CompatHelper"
run: |
import CompatHelper
CompatHelper.main()
shell: julia --color=yes {0}
- name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }}
# COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }}
run: julia -e 'using CompatHelper; CompatHelper.main()'
36 changes: 0 additions & 36 deletions .github/workflows/test.yml

This file was deleted.

23 changes: 12 additions & 11 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"

[weakdeps]
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"

[extensions]
ModelingToolkitExt = "ModelingToolkit"
SteadyStateDiffEqExt = "SteadyStateDiffEq"
TimeEvolution = "OrdinaryDiffEq"

[compat]
ModelingToolkit = "< 9"
BijectiveHilbert = "0.3.0"
DSP = "0.7.4"
DelimitedFiles = "1"
Expand All @@ -43,20 +49,15 @@ Peaks = "0.4.0"
Plots = "1.35.0"
ProgressMeter = "1.7.2"
Symbolics = "5.0.0"
julia = "1.8.2"

[extensions]
TimeEvolution = "OrdinaryDiffEq"
ModelingToolkitExt = "ModelingToolkit"
SteadyStateDiffEqExt = "SteadyStateDiffEq"
julia = "1.9.0"

[extras]
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SteadyStateDiffEq = "9672c7b4-1e72-59bd-8a11-6ac3964bc41f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Pkg", "Test", "OrdinaryDiffEq", "ModelingToolkit", "SteadyStateDiffEq", "NonlinearSolve"]
2 changes: 1 addition & 1 deletion ext/ModelingToolkitExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ODESystem(eom::HarmonicEquation)
eqs = simplify.(expand.(eqs))

# compute jacobian for performance
@named sys = ODESystem(eqs, slow_time, vars, par_names)
@named sys = ODESystem(eqs, slow_time, vars, par_names) #mtk v9 need @mtkbuild
return sys
end

Expand Down
16 changes: 12 additions & 4 deletions src/HarmonicBalance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using Random
import HomotopyContinuation
const HC = HomotopyContinuation
import Distances
# using Requires
# using SnoopPrecompile

import Base: show, display
Expand Down Expand Up @@ -72,10 +73,17 @@ export first_order_transform!, is_rearranged_standard, rearrange_standard!, get_
export get_krylov_equations

# support for julia < 1.9
if !isdefined(Base, :get_extension)
include("ext/TimeEvolution.jl")
using .TimeEvolution
end
# function __init__()
# @static if !isdefined(Base, :get_extension)
# @require OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" begin
# include("../ext/TimeEvolution/TimeEvolution.jl")
# end
# end
# end
# if !isdefined(Base, :get_extension)
# include("../ext/TimeEvolution/TimeEvolution.jl")
# using .TimeEvolution
# end
export ParameterSweep, ODEProblem, solve, ODESystem, steady_state_sweep
export plot_1D_solutions_branch, follow_branch

Expand Down
15 changes: 10 additions & 5 deletions test/ModelingToolkitExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@ using HarmonicBalance
using ModelingToolkit
using Test

@variables α ω ω0 F γ t x(t);
diff_eq = DifferentialEquation(d(x, t, 2) + ω0^2*x + α * x^3 + γ * d(x, t) ~ F*cos*t), x)
@variables α ω ω0 F γ t x(t)
diff_eq = DifferentialEquation(
d(x, t, 2) + ω0^2 * x + α * x^3 + γ * d(x, t) ~ F * cos* t), x)
add_harmonic!(diff_eq, x, ω) #
harmonic_eq = get_harmonic_equations(diff_eq)

ODESystem(harmonic_eq)

force = 0.01; omega0 = 1.1; alpha = 1.0; gamma = 0.01;
force = 0.01
omega0 = 1.1
alpha = 1.0
gamma = 0.01
fixed_nonlin ==> alpha, ω0 => omega0, F => force, γ => gamma)
ω_span = (0.9, 1.5); ω_range = range(ω_span..., 100)
ω_span = (0.9, 1.5)
ω_range = range(ω_span..., 100)
varied = ω => ω_range

param = ParameterList(merge(Dict(fixed_nonlin), Dict=> 1.1)))
varied = 1 => ω_range
x0 = [1.0, 0.0];
x0 = [1.0, 0.0]

ODEProblem(harmonic_eq, x0, (0, 100), param)
39 changes: 27 additions & 12 deletions test/SteadyStateDiffEqExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

using ModelingToolkit, SteadyStateDiffEq, OrdinaryDiffEq, LinearAlgebra, NonlinearSolve

@testset "Steady state sweeps" begin

@testset "one variable ODE" begin
@variables t v(t)=0
@parameters g=9.8 k=0.2
Expand All @@ -16,30 +16,46 @@ using ModelingToolkit, SteadyStateDiffEq, OrdinaryDiffEq, LinearAlgebra, Nonline

varied = 2 => range(0, 1, 100)

swept = steady_state_sweep(prob_np, prob_ss, NewtonRaphson(), DynamicSS(Rodas5()); varied=varied)
swept = steady_state_sweep(
prob_np, prob_ss, NewtonRaphson(), DynamicSS(Rodas5()); varied = varied)
end

@testset "two variable ODE (duffing)" begin
@variables t u1(t) v1(t);
@variables t u1(t) v1(t)
@parameters α ω ω0 F γ

eqs = [
Differential(t)(u1) ~ (F*γ - u1*γ*^2) - u1*γ*(ω0^2) - v1*^2)*ω - 2*v1*^3) + 2*v1*ω*(ω0^2) - (3//4)*(u1^3)*α*γ + (3//2)*(u1^2)*v1*α*ω - (3//4)*u1*(v1^2)*α*γ + (3//2)*(v1^3)*α*ω) /^2 + (4)*^2)),
Differential(t)(v1) ~ (-2*F*ω - u1*^2)*ω - (2)*u1*^3) + 2*u1*ω*(ω0^2) + v1*γ*^2) + v1*γ*(ω0^2) + (3//2)*(u1^3)*α*ω + (3//4)*(u1^2)*v1*α*γ + (3//2)*u1*(v1^2)*α*ω + (3//4)*(v1^3)*α*γ) / (-^2) - (4)*^2))
]
Differential(t)(u1) ~ (F * γ - u1 * γ *^2) - u1 * γ * (ω0^2) -
v1 *^2) * ω - 2 * v1 *^3) +
2 * v1 * ω * (ω0^2) - (3 // 4) * (u1^3) * α * γ +
(3 // 2) * (u1^2) * v1 * α * ω -
(3 // 4) * u1 * (v1^2) * α * γ +
(3 // 2) * (v1^3) * α * ω) /^2 + (4) *^2)),
Differential(t)(v1) ~ (-2 * F * ω - u1 *^2) * ω - (2) * u1 *^3) +
2 * u1 * ω * (ω0^2) + v1 * γ *^2) +
v1 * γ * (ω0^2) + (3 // 2) * (u1^3) * α * ω +
(3 // 4) * (u1^2) * v1 * α * γ +
(3 // 2) * u1 * (v1^2) * α * ω +
(3 // 4) * (v1^3) * α * γ) / (-^2) - (4) *^2))
]

@named model = ODESystem(eqs, t, [u1, v1], [α, ω, ω0, F, γ])
model = structural_simplify(model)

force = 0.01; omega0 = 1.1; alpha = 1.0; gamma = 0.01;
force = 0.01
omega0 = 1.1
alpha = 1.0
gamma = 0.01
param = [alpha, omega0, omega0, force, gamma]
x0 = [1.0, 0.0];
x0 = [1.0, 0.0]
prob_ss = SteadyStateProblem{true}(model, x0, param, jac = true)
prob_np = NonlinearProblem(prob_ss)

ω_span = (0.9, 1.5); ω_range = range(ω_span..., 100)
ω_span = (0.9, 1.5)
ω_range = range(ω_span..., 100)
varied = 2 => ω_range
swept = steady_state_sweep(prob_np, prob_ss, NewtonRaphson(), DynamicSS(Rodas5()); varied=varied)
swept = steady_state_sweep(
prob_np, prob_ss, NewtonRaphson(), DynamicSS(Rodas5()); varied = varied)

@test length(swept) == 100
@test length(swept[1]) == 2
Expand All @@ -49,12 +65,11 @@ using ModelingToolkit, SteadyStateDiffEq, OrdinaryDiffEq, LinearAlgebra, Nonline
function has_discontinuity(v::Vector{Float64})
threshold = 1.0e-1 # Define a threshold for the discontinuity
for i in 2:length(v)
abs(v[i] - v[i-1]) > threshold && return true
abs(v[i] - v[i - 1]) > threshold && return true
end
return false
end

@test has_discontinuity(norm.(swept))
end

end # Steady state sweeps
11 changes: 10 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ files = [
"linear_response.jl",
"limit_cycle.jl",
"time_evolution.jl",
"hysteresis_sweep.jl",
"hysteresis_sweep.jl"
]

files_ext = [
"ModelingToolkitExt.jl",
"SteadyStateDiffEqExt.jl"
]
Expand All @@ -30,4 +33,10 @@ for file in files
printstyled(file * ": OK\n"; color=:green)
end

if isdefined(Base, :get_extension) && VERSION >= v"1.9.0"
for file in files_ext
include(file)
printstyled(file * ": OK\n"; color=:green)
end
end
printstyled("\nALL TESTS PASSED!\n"; color=:green)

0 comments on commit b006f4a

Please sign in to comment.