Skip to content

Commit

Permalink
revamp CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoStrouwen committed Jan 14, 2024
1 parent ca6633f commit 7b1b369
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 91 deletions.
32 changes: 19 additions & 13 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,34 @@ on:
- main
paths-ignore:
- 'docs/**'
schedule:
- cron: '41 0 * * 5'
jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
group:
- Core
version:
- '1'
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: 1
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
version: ${{ matrix.version }}
- uses: julia-actions/cache@v1
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 }}-
token: ${{ secrets.GITHUB_TOKEN }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
GROUP: ${{ matrix.group }}
with:
depwarn: error
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ on:
- main
tags: '*'
pull_request:

schedule:
- cron: '41 0 * * 5'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
version: '1'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
19 changes: 15 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@ version = "1.2.1"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
Aqua = "0.8"
CUDA = "3, 5"
DiffEqBase = "6"
DocStringExtensions = "0.8, 0.9"
ExprTools = "0.1"
Flux = "0.13, 0.14"
Functors = "0.2, 0.3, 0.4"
LinearAlgebra = "1"
Random = "1"
Reexport = "1"
SafeTestsets = "0.1"
SparseArrays = "1"
Statistics = "1"
Test = "1"
Zygote = "0.6"
julia = "1.6,1.7"
julia = "1.10"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "SafeTestsets"]
12 changes: 6 additions & 6 deletions src/DeepBSDE.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
"""
```julia
NNPDENS(u0,σᵀ∇u;opt=Flux.ADAM(0.1))
NNPDENS(u0,σᵀ∇u;opt=Flux.Optimise.Adam(0.1))
```
Uses a neural stochastic differential equation, which is then solved by the methods available in DifferentialEquations.jl.
The alg keyword is required for specifying the SDE solver algorithm that will be used on the internal SDE. All of the other
Uses a neural stochastic differential equation, which is then solved by the methods available in DifferentialEquations.jl.
The alg keyword is required for specifying the SDE solver algorithm that will be used on the internal SDE. All of the other
keyword arguments are passed to the SDE solver.
## Arguments
- `u0`: a Flux.jl `Chain` for the initial condition guess.
- `σᵀ∇u`: a Flux.jl `Chain` for the BSDE value guess.
- `opt`: the optimization algorithm to be used to optimize the neural networks. Defaults to `ADAM`.
- `opt`: the optimization algorithm to be used to optimize the neural networks. Defaults to `Flux.Optimise.Adam`.
"""
struct NNPDENS{C1,C2,O} <: NeuralPDEAlgorithm
u0::C1
σᵀ∇u::C2
opt::O
end

NNPDENS(u0,σᵀ∇u;opt=Flux.ADAM(0.1)) = NNPDENS(u0,σᵀ∇u,opt)
NNPDENS(u0,σᵀ∇u;opt=Flux.Optimise.Adam(0.1)) = NNPDENS(u0,σᵀ∇u,opt)

function DiffEqBase.solve(
prob::TerminalPDEProblem,
Expand Down Expand Up @@ -165,7 +165,7 @@ function DiffEqBase.solve(
l < 1e-6 && Flux.stop()
end
dataS = Iterators.repeated((), maxiters_upper)
Flux.train!(loss_, ps, dataS, ADAM(0.01); cb = cb)
Flux.train!(loss_, ps, dataS, Flux.Optimise.Adam(0.01); cb = cb)
u_high = loss_()
# Function to precalculate the f values over the domain
function give_f_matrix(X,urange,σᵀ∇u,p,t)
Expand Down
17 changes: 9 additions & 8 deletions src/DeepSplitting.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
Base.copy(t::Tuple) = t # required for below
function Base.copy(opt::O) where O<:Flux.Optimise.AbstractOptimiser
return O([copy(getfield(opt,f)) for f in fieldnames(typeof(opt))]...)
_copy(t::Tuple) = t
_copy(t) = t
function _copy(opt::O) where O<:Flux.Optimise.AbstractOptimiser
return O([_copy(getfield(opt,f)) for f in fieldnames(typeof(opt))]...)
end

"""
DeepSplitting(nn, K=1, opt = ADAM(0.01), λs = nothing, mc_sample = NoSampling())
DeepSplitting(nn, K=1, opt = Flux.Optimise.Adam(0.01), λs = nothing, mc_sample = NoSampling())
Deep splitting algorithm.
# Arguments
* `nn`: a [Flux.Chain](https://fluxml.ai/Flux.jl/stable/models/layers/#Flux.Chain), or more generally a [functor](https://github.com/FluxML/Functors.jl).
* `K`: the number of Monte Carlo integrations.
* `opt`: optimizer to be used. By default, `Flux.ADAM(0.01)`.
* `opt`: optimizer to be used. By default, `Flux.Optimise.Adam(0.01)`.
* `λs`: the learning rates, used sequentially. Defaults to a single value taken from `opt`.
* `mc_sample::MCSampling` : sampling method for Monte Carlo integrations of the non-local term. Can be `UniformSampling(a,b)`, `NormalSampling(σ_sampling, shifted)`, or `NoSampling` (by default).
Expand All @@ -25,7 +26,7 @@ nn = Flux.Chain(Dense(d, hls, tanh),
Dense(hls,hls,tanh),
Dense(hls, 1, x->x^2))
alg = DeepSplitting(nn, K=10, opt = ADAM(), λs = [5e-3,1e-3],
alg = DeepSplitting(nn, K=10, opt = Flux.Optimise.Adam(), λs = [5e-3,1e-3],
mc_sample = UniformSampling(zeros(d), ones(d)) )
```
"""
Expand All @@ -39,7 +40,7 @@ end

function DeepSplitting(nn;
K=1,
opt::O = ADAM(0.01),
opt::O = Flux.Optimise.Adam(0.01),
λs::L = nothing,
mc_sample::MCSampling = NoSampling()) where {O <: Flux.Optimise.AbstractOptimiser, L <: Union{Nothing,Vector{N}} where N <: Number}
isnothing(λs) ? λs = [opt.eta] : nothing
Expand Down Expand Up @@ -175,7 +176,7 @@ function solve(
_maxiters = length(maxiters) > 1 ? maxiters[min(net,2)] : maxiters[]

for λ in λs
opt_net = copy(opt) # starting with a new optimiser state at each time step
opt_net = _copy(opt) # starting with a new optimiser state at each time step
opt_net.eta = λ
verbose && println("Training started with ", typeof(opt_net), " and λ :", opt_net.eta)
for epoch in 1:_maxiters
Expand Down
Loading

0 comments on commit 7b1b369

Please sign in to comment.