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

Format SciML Style #74

Merged
merged 1 commit into from
Jun 23, 2022
Merged
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
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
42 changes: 42 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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@v1
- 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'
24 changes: 10 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ using Documenter, NonlinearSolve

include("pages.jl")

makedocs(
sitename="NonlinearSolve.jl",
authors="Chris Rackauckas",
modules=[NonlinearSolve,NonlinearSolve.SciMLBase],
clean=true,doctest=false,
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical="https://nonlinearsolve.sciml.ai/stable/"),
pages=pages
)
makedocs(sitename = "NonlinearSolve.jl",
authors = "Chris Rackauckas",
modules = [NonlinearSolve, NonlinearSolve.SciMLBase],
clean = true, doctest = false,
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical = "https://nonlinearsolve.sciml.ai/stable/"),
pages = pages)

deploydocs(
repo = "github.com/SciML/NonlinearSolve.jl.git";
push_preview = true
)
deploydocs(repo = "github.com/SciML/NonlinearSolve.jl.git";
push_preview = true)
24 changes: 9 additions & 15 deletions docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# Put in a separate page so it can be used by SciMLDocs.jl

pages=[
pages = [
"Home" => "index.md",
"Tutorials" => Any[
"tutorials/nonlinear.md",
"tutorials/iterator_interface.md"
],
"Basics" => Any[
"basics/NonlinearProblem.md",
"basics/NonlinearFunctions.md",
"basics/FAQ.md"
],
"Solvers" => Any[
"solvers/NonlinearSystemSolvers.md",
"solvers/BracketingSolvers.md"
]
]
"Tutorials" => Any["tutorials/nonlinear.md",
"tutorials/iterator_interface.md"],
"Basics" => Any["basics/NonlinearProblem.md",
"basics/NonlinearFunctions.md",
"basics/FAQ.md"],
"Solvers" => Any["solvers/NonlinearSystemSolvers.md",
"solvers/BracketingSolvers.md"],
]
2 changes: 1 addition & 1 deletion src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import RecursiveFactorization

abstract type AbstractNonlinearSolveAlgorithm <: SciMLBase.AbstractNonlinearAlgorithm end
abstract type AbstractBracketingAlgorithm <: AbstractNonlinearSolveAlgorithm end
abstract type AbstractNewtonAlgorithm{CS,AD} <: AbstractNonlinearSolveAlgorithm end
abstract type AbstractNewtonAlgorithm{CS, AD} <: AbstractNonlinearSolveAlgorithm end
abstract type AbstractImmutableNonlinearSolver <: AbstractNonlinearSolveAlgorithm end

include("utils.jl")
Expand Down
190 changes: 96 additions & 94 deletions src/bisection.jl
Original file line number Diff line number Diff line change
@@ -1,114 +1,116 @@
struct Bisection <: AbstractBracketingAlgorithm
exact_left::Bool
exact_right::Bool
exact_left::Bool
exact_right::Bool
end

function Bisection(;exact_left=false, exact_right=false)
Bisection(exact_left, exact_right)
function Bisection(; exact_left = false, exact_right = false)
Bisection(exact_left, exact_right)
end

struct BisectionCache{uType}
state::Int
left::uType
right::uType
state::Int
left::uType
right::uType
end

function alg_cache(alg::Bisection, left, right, p, ::Val{true})
BisectionCache(0, left, right)
BisectionCache(0, left, right)
end

function alg_cache(alg::Bisection, left, right, p, ::Val{false})
BisectionCache(0, left, right)
BisectionCache(0, left, right)
end

function perform_step(solver::BracketingImmutableSolver, alg::Bisection, cache)
@unpack f, p, left, right, fl, fr, cache = solver

if cache.state == 0
fzero = zero(fl)
fl * fr > fzero && error("Bracket became non-containing in between iterations. This could mean that "
* "input function crosses the x axis multiple times. Bisection is not the right method to solve this.")

mid = (left + right) / 2

if left == mid || right == mid
@set! solver.force_stop = true
@set! solver.retcode = FLOATING_POINT_LIMIT
return solver
end

fm = f(mid, p)

if iszero(fm)
if alg.exact_left
@set! cache.state = 1
@set! cache.right = mid
@set! cache.left = mid
@set! solver.cache = cache
elseif alg.exact_right
@set! solver.left = prevfloat_tdir(mid, left, right)
solver = sync_residuals!(solver)
@set! cache.state = 2
@set! cache.left = mid
@set! solver.cache = cache
else
@set! solver.left = prevfloat_tdir(mid, left, right)
@set! solver.right = nextfloat_tdir(mid, left, right)
solver = sync_residuals!(solver)
@set! solver.force_stop = true
return solver
end
else
if sign(fm) == sign(fl)
@set! solver.left = mid
@set! solver.fl = fm
else
@set! solver.right = mid
@set! solver.fr = fm
end
end
elseif cache.state == 1
mid = (left + cache.right) / 2

if cache.right == mid || left == mid
if alg.exact_right
@set! cache.state = 2
@set! solver.cache = cache
return solver
else
@set! solver.right = nextfloat_tdir(mid, left, right)
solver = sync_residuals!(solver)
@set! solver.force_stop = true
return solver
end
end

fm = f(mid, p)
@unpack f, p, left, right, fl, fr, cache = solver

if iszero(fm)
@set! cache.right = mid
@set! solver.cache = cache
else
@set! solver.left = mid
@set! solver.fl = fm
end
else
mid = (cache.left + right) / 2

if right == mid || cache.left == mid
@set! solver.force_stop = true
return solver
end

fm = f(mid, p)
if cache.state == 0
fzero = zero(fl)
fl * fr > fzero &&
error("Bracket became non-containing in between iterations. This could mean that "
*
"input function crosses the x axis multiple times. Bisection is not the right method to solve this.")

mid = (left + right) / 2

if iszero(fm)
@set! cache.left = mid
@set! solver.cache = cache
if left == mid || right == mid
@set! solver.force_stop = true
@set! solver.retcode = FLOATING_POINT_LIMIT
return solver
end

fm = f(mid, p)

if iszero(fm)
if alg.exact_left
@set! cache.state = 1
@set! cache.right = mid
@set! cache.left = mid
@set! solver.cache = cache
elseif alg.exact_right
@set! solver.left = prevfloat_tdir(mid, left, right)
solver = sync_residuals!(solver)
@set! cache.state = 2
@set! cache.left = mid
@set! solver.cache = cache
else
@set! solver.left = prevfloat_tdir(mid, left, right)
@set! solver.right = nextfloat_tdir(mid, left, right)
solver = sync_residuals!(solver)
@set! solver.force_stop = true
return solver
end
else
if sign(fm) == sign(fl)
@set! solver.left = mid
@set! solver.fl = fm
else
@set! solver.right = mid
@set! solver.fr = fm
end
end
elseif cache.state == 1
mid = (left + cache.right) / 2

if cache.right == mid || left == mid
if alg.exact_right
@set! cache.state = 2
@set! solver.cache = cache
return solver
else
@set! solver.right = nextfloat_tdir(mid, left, right)
solver = sync_residuals!(solver)
@set! solver.force_stop = true
return solver
end
end

fm = f(mid, p)

if iszero(fm)
@set! cache.right = mid
@set! solver.cache = cache
else
@set! solver.left = mid
@set! solver.fl = fm
end
else
@set! solver.right = mid
@set! solver.fr = fm
mid = (cache.left + right) / 2

if right == mid || cache.left == mid
@set! solver.force_stop = true
return solver
end

fm = f(mid, p)

if iszero(fm)
@set! cache.left = mid
@set! solver.cache = cache
else
@set! solver.right = mid
@set! solver.fr = fm
end
end
end
solver
solver
end
Loading