diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 2893aedef..ee85be538 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -8,4 +8,4 @@ steps: agents: queue: "juliagpu" cuda: "*" - timeout_in_minutes: 60 \ No newline at end of file + timeout_in_minutes: 60 diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index d6cf9b637..bd9a98157 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -42,4 +42,4 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COMPATHELPER_PRIV: ${{ secrets.DOCUMENTER_KEY }} - # COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }} \ No newline at end of file + # COMPATHELPER_PRIV: ${{ secrets.COMPATHELPER_PRIV }} diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml index 3d22d7dca..48f803c46 100644 --- a/.github/workflows/Documentation.yml +++ b/.github/workflows/Documentation.yml @@ -15,7 +15,7 @@ concurrency: cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} jobs: - + docs: name: ${{ matrix.pkg.shortcut }} runs-on: ubuntu-latest @@ -33,7 +33,7 @@ jobs: - name: DifferentiationInterfaceTest shortcut: DIT dir: './DifferentiationInterfaceTest' - + steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 diff --git a/.github/workflows/PreCommit.yml b/.github/workflows/PreCommit.yml new file mode 100644 index 000000000..973b79567 --- /dev/null +++ b/.github/workflows/PreCommit.yml @@ -0,0 +1,27 @@ +name: Pre-Commit + +# needed to allow julia-actions/cache to delete old caches that it has created +permissions: + actions: write + contents: read + +on: + push: + branches: + - main + tags: ["*"] + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + workflow_dispatch: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + - uses: julia-actions/cache@v2 + - run: julia -e 'using Pkg; Pkg.add("JuliaFormatter")' + - uses: astral-sh/setup-uv@v6 + - run: uv tool install pre-commit + - run: pre-commit run --all-files --show-diff-on-failure --color always diff --git a/.github/workflows/Register.yml b/.github/workflows/Register.yml index 1cd7f515b..8993e12a2 100644 --- a/.github/workflows/Register.yml +++ b/.github/workflows/Register.yml @@ -13,4 +13,4 @@ jobs: steps: - uses: julia-actions/RegisterAction@latest with: - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml index 236c5e7cc..4b5204195 100644 --- a/.github/workflows/TagBot.yml +++ b/.github/workflows/TagBot.yml @@ -36,4 +36,4 @@ jobs: with: token: ${{ secrets.GITHUB_TOKEN }} ssh: ${{ secrets.DOCUMENTER_KEY }} - subdir: DifferentiationInterfaceTest \ No newline at end of file + subdir: DifferentiationInterfaceTest diff --git a/.gitignore b/.gitignore index 024591613..3e2063221 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ *.csv playground.jl -.vscode \ No newline at end of file +.vscode diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..bfa4f3a3e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-merge-conflict + - id: no-commit-to-branch +- repo: "https://github.com/domluna/JuliaFormatter.jl" + rev: "v2.1.6" # or whatever the desired release is + hooks: + - id: "julia-formatter" +fail_fast: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a7bef8a60..d3aad94fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,5 +9,7 @@ _Only the two maintainers are allowed to approve and merge pull requests._ Feel free to ping them if they do not answer within a week or so. Apart from the conditions above, this repository follows the [ColPrac](https://github.com/SciML/ColPrac) best practices and [Conventional Commits](https://www.conventionalcommits.org/en/). -Its code is formatted using [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) with [BlueStyle](https://github.com/JuliaDiff/BlueStyle) -- please format any modified code before opening a pull request, otherwise CI will fail. +Its code is formatted using [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) with [BlueStyle](https://github.com/JuliaDiff/BlueStyle). +As part of continuous integration, a set of formal tests is run using [pre-commit](https://pre-commit.com/). +We invite you to install pre-commit so that these checks are performed locally before you open or update a pull request. You can refer to the [dev guide](https://juliadiff.org/DifferentiationInterface.jl/DifferentiationInterface/dev/dev_guide/) for details on the package structure and the testing pipeline. diff --git a/DifferentiationInterface/CHANGELOG.md b/DifferentiationInterface/CHANGELOG.md index 07423260d..a40a9a1fa 100644 --- a/DifferentiationInterface/CHANGELOG.md +++ b/DifferentiationInterface/CHANGELOG.md @@ -93,4 +93,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#790]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/790 [#788]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/788 [#782]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/782 -[#768]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/768 \ No newline at end of file +[#768]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/768 diff --git a/DifferentiationInterface/Project.toml b/DifferentiationInterface/Project.toml index cef7316e7..aae70a9d6 100644 --- a/DifferentiationInterface/Project.toml +++ b/DifferentiationInterface/Project.toml @@ -75,7 +75,6 @@ GPUArraysCore = "0.2" GTPSA = "1.4.0" JET = "0.9" JLArrays = "0.2.0" -JuliaFormatter = "1,2" LinearAlgebra = "1" Mooncake = "0.4.147" Pkg = "1" @@ -110,7 +109,6 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" GTPSA = "b27dd330-f138-47c5-815b-40db9dd9b6e8" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" -JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PolyesterForwardDiff = "98d1487c-24ca-40b6-b7ab-df2af84e126b" @@ -136,7 +134,6 @@ test = [ "ExplicitImports", "JET", "JLArrays", - "JuliaFormatter", "Pkg", "Random", "SparseArrays", diff --git a/DifferentiationInterface/README.md b/DifferentiationInterface/README.md index 81b4919cb..a82202fe5 100644 --- a/DifferentiationInterface/README.md +++ b/DifferentiationInterface/README.md @@ -73,7 +73,7 @@ Pkg.add( ```julia using DifferentiationInterface -import ForwardDiff, Enzyme, Zygote # AD backends you want to use +import ForwardDiff, Enzyme, Zygote # AD backends you want to use f(x) = sum(abs2, x) @@ -97,23 +97,23 @@ You can use the provided [`CITATION.cff`](https://github.com/JuliaDiff/Different ```bibtex @misc{dalle2025commoninterfaceautomaticdifferentiation, - title={A Common Interface for Automatic Differentiation}, + title={A Common Interface for Automatic Differentiation}, author={Guillaume Dalle and Adrian Hill}, year={2025}, eprint={2505.05542}, archivePrefix={arXiv}, primaryClass={cs.MS}, - url={https://arxiv.org/abs/2505.05542}, + url={https://arxiv.org/abs/2505.05542}, } @misc{schäfer2022abstractdifferentiationjlbackendagnosticdifferentiableprogramming, - title={AbstractDifferentiation.jl: Backend-Agnostic Differentiable Programming in Julia}, + title={AbstractDifferentiation.jl: Backend-Agnostic Differentiable Programming in Julia}, author={Frank Schäfer and Mohamed Tarek and Lyndon White and Chris Rackauckas}, year={2022}, eprint={2109.12449}, archivePrefix={arXiv}, primaryClass={cs.MS}, - url={https://arxiv.org/abs/2109.12449}, + url={https://arxiv.org/abs/2109.12449}, } ``` diff --git a/DifferentiationInterface/docs/src/assets/logo.jl b/DifferentiationInterface/docs/src/assets/logo.jl index 610627c14..ef4609669 100644 --- a/DifferentiationInterface/docs/src/assets/logo.jl +++ b/DifferentiationInterface/docs/src/assets/logo.jl @@ -47,7 +47,7 @@ end # ╔═╡ 69d0fa4d-2585-42a0-981f-99d43f7e2c1f md"## Creating Favicons -Using Imagemagick, run +Using Imagemagick, run ```bash convert -background transparent logo.svg -define icon:auto-resize=256,128,48,32,16 favicon.ico ``` diff --git a/DifferentiationInterface/docs/src/faq/differentiability.md b/DifferentiationInterface/docs/src/faq/differentiability.md index 5845e80f5..1fd3be287 100644 --- a/DifferentiationInterface/docs/src/faq/differentiability.md +++ b/DifferentiationInterface/docs/src/faq/differentiability.md @@ -51,7 +51,7 @@ In some situations, manually writing overloads for `x::Dual` or `x::AbstractArra ### ReverseDiff [ReverseDiff.jl](https://github.com/JuliaDiff/ReverseDiff.jl) relies on operator overloading for scalars, but also for arrays. -The relevant types are called `TrackedReal` and `TrackedArray`, they have a set of [limitations](https://juliadiff.org/ReverseDiff.jl/stable/limits/) very similar to that of ForwardDiff.jl's `Dual` and will cause similar errors. +The relevant types are called `TrackedReal` and `TrackedArray`, they have a set of [limitations](https://juliadiff.org/ReverseDiff.jl/stable/limits/) very similar to that of ForwardDiff.jl's `Dual` and will cause similar errors. ### Symbolic backends @@ -112,4 +112,4 @@ There are, however, translation utilities: Also note the existence of [`DifferentiationInterface.DifferentiateWith`](@ref), which allows the user to wrap a function that should be differentiated with a specific backend. -Right now, it only targets [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl), [Mooncake.jl](), [ChainRules.jl](https://juliadiff.org/ChainRulesCore.jl/stable/)-compatible backends (e.g., [Zygote.jl](https://github.com/FluxML/Zygote.jl)), but PRs are welcome to define Enzyme.jl rules for this object. \ No newline at end of file +Right now, it only targets [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl), [Mooncake.jl](), [ChainRules.jl](https://juliadiff.org/ChainRulesCore.jl/stable/)-compatible backends (e.g., [Zygote.jl](https://github.com/FluxML/Zygote.jl)), but PRs are welcome to define Enzyme.jl rules for this object. diff --git a/DifferentiationInterface/ext/DifferentiationInterfaceGTPSAExt/onearg.jl b/DifferentiationInterface/ext/DifferentiationInterfaceGTPSAExt/onearg.jl index 58baad569..45257d21c 100644 --- a/DifferentiationInterface/ext/DifferentiationInterfaceGTPSAExt/onearg.jl +++ b/DifferentiationInterface/ext/DifferentiationInterfaceGTPSAExt/onearg.jl @@ -114,7 +114,7 @@ struct GTPSAOneArgGradientPrep{SIG,X} <: DI.GradientPrep{SIG} xt::X end -# Unlike JVP, this requires us to use all variables +# Unlike JVP, this requires us to use all variables function DI.prepare_gradient_nokwarg( strict::Val, f, backend::AutoGTPSA{D}, x, contexts::Vararg{DI.Constant,C} ) where {D,C} @@ -197,7 +197,7 @@ struct GTPSAOneArgJacobianPrep{SIG,X} <: DI.JacobianPrep{SIG} xt::X end -# To materialize the entire Jacobian we use all variables +# To materialize the entire Jacobian we use all variables function DI.prepare_jacobian_nokwarg( strict::Val, f, backend::AutoGTPSA{D}, x, contexts::Vararg{DI.Constant,C} ) where {D,C} @@ -406,7 +406,7 @@ function DI.value_derivative_and_second_derivative!( end ## Hessian -# Stores allocated array of TPS and an array for the monomial coefficient +# Stores allocated array of TPS and an array for the monomial coefficient # indexing in GTPSA.cycle! (which is used if a Descriptor is specified) struct GTPSAOneArgHessianPrep{SIG,X,M} <: DI.HessianPrep{SIG} _sig::Val{SIG} @@ -424,14 +424,14 @@ function DI.prepare_hessian_nokwarg( else nn = length(x) d = Descriptor(nn, 2) - # If all variables/variable+parameters have truncation order > 2, then + # If all variables/variable+parameters have truncation order > 2, then # the indexing is known beforehand and we can do it (very slightly) faster m = nothing end xt = similar(x, TPS{promote_type(eltype(x), Float64)}) # xt and x have same indexing because of similar - # Setting the first derivatives must be 1-based + # Setting the first derivatives must be 1-based # linear with the variables. j = 1 for i in eachindex(xt) diff --git a/DifferentiationInterface/test/Back/GTPSA/test.jl b/DifferentiationInterface/test/Back/GTPSA/test.jl index 68b66918e..c0541406f 100644 --- a/DifferentiationInterface/test/Back/GTPSA/test.jl +++ b/DifferentiationInterface/test/Back/GTPSA/test.jl @@ -27,7 +27,7 @@ test_differentiation( d1 = GTPSA.Descriptor(20, 2) # 20 variables to 2nd order test_differentiation(AutoGTPSA(d1); type_stability=:full, logging=LOGGING); -# Test with Descriptor using varying orders +# Test with Descriptor using varying orders vos = 2 * ones(Int, 20) vos[1] = 3 d2 = GTPSA.Descriptor(vos, 3) diff --git a/DifferentiationInterface/test/Core/Internals/_formalities.jl b/DifferentiationInterface/test/Core/Internals/_formalities.jl index aa1050c9d..475676702 100644 --- a/DifferentiationInterface/test/Core/Internals/_formalities.jl +++ b/DifferentiationInterface/test/Core/Internals/_formalities.jl @@ -4,7 +4,6 @@ using Aqua: Aqua using DifferentiationInterface using ExplicitImports using JET: JET -using JuliaFormatter: JuliaFormatter using Test using SparseMatrixColorings using SparseArrays @@ -17,10 +16,6 @@ end JET.test_package(DifferentiationInterface; target_defined_modules=true) end -@testset "JuliaFormatter" begin - @test JuliaFormatter.format(DifferentiationInterface; verbose=false, overwrite=false) -end - @testset "Documentation" begin if VERSION >= v"1.11" @test isempty(Docs.undocumented_names(DifferentiationInterface)) diff --git a/DifferentiationInterfaceTest/CHANGELOG.md b/DifferentiationInterfaceTest/CHANGELOG.md index c0eca7a37..569fbe0ab 100644 --- a/DifferentiationInterfaceTest/CHANGELOG.md +++ b/DifferentiationInterfaceTest/CHANGELOG.md @@ -38,4 +38,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#786]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/786 [#749]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/749 [#748]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/748 -[#745]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/745 \ No newline at end of file +[#745]: https://github.com/JuliaDiff/DifferentiationInterface.jl/pull/745 diff --git a/DifferentiationInterfaceTest/Project.toml b/DifferentiationInterfaceTest/Project.toml index 5b98aed4c..e0fb1e147 100644 --- a/DifferentiationInterfaceTest/Project.toml +++ b/DifferentiationInterfaceTest/Project.toml @@ -59,7 +59,6 @@ ForwardDiff = "0.10.36,1" Functors = "0.4, 0.5" JET = "0.4 - 0.8, 0.9" JLArrays = "0.1, 0.2" -JuliaFormatter = "1,2" LinearAlgebra = "1" Lux = "1.1.0" LuxTestUtils = "1.3.1" @@ -88,7 +87,6 @@ Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b" JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb" -JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" Lux = "b2108857-7c20-44ae-9111-449ecde12c47" LuxTestUtils = "ac9de150-d08f-4546-94fb-7472b5760531" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -114,7 +112,6 @@ test = [ "ForwardDiff", "JET", "JLArrays", - "JuliaFormatter", "Pkg", "Random", "SparseArrays", diff --git a/DifferentiationInterfaceTest/README.md b/DifferentiationInterfaceTest/README.md index 54090ed5d..f3036cf32 100644 --- a/DifferentiationInterfaceTest/README.md +++ b/DifferentiationInterfaceTest/README.md @@ -47,7 +47,7 @@ Pkg.add( url="https://github.com/JuliaDiff/DifferentiationInterface.jl", subdir="DifferentiationInterface" ) - + Pkg.add( url="https://github.com/JuliaDiff/DifferentiationInterface.jl", subdir="DifferentiationInterfaceTest" diff --git a/DifferentiationInterfaceTest/test/formalities.jl b/DifferentiationInterfaceTest/test/formalities.jl index 37a8e39d6..5f827e8f4 100644 --- a/DifferentiationInterfaceTest/test/formalities.jl +++ b/DifferentiationInterfaceTest/test/formalities.jl @@ -3,18 +3,12 @@ using DifferentiationInterfaceTest using Aqua: Aqua using ExplicitImports using JET: JET -using JuliaFormatter: JuliaFormatter using SparseMatrixColorings: SparseMatrixColorings using Test @testset "Aqua" begin Aqua.test_all(DifferentiationInterfaceTest; ambiguities=false, undocumented_names=true) end -@testset "JuliaFormatter" begin - @test JuliaFormatter.format( - DifferentiationInterfaceTest; verbose=false, overwrite=false - ) -end @testset verbose = true "JET" begin JET.test_package(DifferentiationInterfaceTest; target_defined_modules=true) end