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

Update for julia 1.x #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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: 0 additions & 1 deletion .codecov.yml

This file was deleted.

39 changes: 39 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI
on:
push:
branches:
aurelio-amerio marked this conversation as resolved.
Show resolved Hide resolved
tags: ['*']
pull_request:
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 }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1.6'
- '1.8'
aurelio-amerio marked this conversation as resolved.
Show resolved Hide resolved
- 'nightly'
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
files: lcov.info
16 changes: 16 additions & 0 deletions .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CompatHelper
on:
schedule:
- cron: 0 0 * * *
workflow_dispatch:
jobs:
CompatHelper:
runs-on: ubuntu-latest
steps:
- 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 }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure this package has a DOCUMENTER_KEY, since it doesn’t have any documentation. I guess we’ll see what this does in that case. In my opinion, we don’t really need CompatHelper.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

run: julia -e 'using CompatHelper; CompatHelper.main()'
8 changes: 6 additions & 2 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: TagBot
on:
schedule:
- cron: 0 * * * *
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, I guess we’ll see whether this works or not. TagBot would be really good to have.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
Manifest.toml
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this file do?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I forgot to add the folder to gitignore, I will remove it

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The UnitfulIntegration.jl package was authored by Andrew Keller and is licensed under the MIT "Expat" License:

> Copyright (c) 2017, California Institute of Technology. All rights reserved.
> Copyright (c) 2022, California Institute of Technology. All rights reserved.
aurelio-amerio marked this conversation as resolved.
Show resolved Hide resolved
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 19 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name = "UnitfulIntegration"
uuid = "d000b014-1cca-4823-a42a-b615c320b663"
aurelio-amerio marked this conversation as resolved.
Show resolved Hide resolved
authors = ["contributors"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
authors = ["contributors"]

IMO, just writing "contributors" doesn’t add much value. I would just remove the line (the authors field is not required, Unitful doesn’t have one either).

version = "0.2.0"

[deps]
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
julia = "1"
QuadGK = "2.6"
Unitful = "^1.12"
aurelio-amerio marked this conversation as resolved.
Show resolved Hide resolved

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# UnitfulIntegration

[![Build Status](https://travis-ci.org/ajkeller34/UnitfulIntegration.jl.svg?branch=master)](https://travis-ci.org/ajkeller34/UnitfulIntegration.jl)
[![Coverage Status](https://coveralls.io/repos/ajkeller34/UnitfulIntegration.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/ajkeller34/UnitfulIntegration.jl?branch=master)
[![codecov.io](http://codecov.io/github/ajkeller34/UnitfulIntegration.jl/coverage.svg?branch=master)](http://codecov.io/github/ajkeller34/UnitfulIntegration.jl?branch=master)
[![CI](https://github.com/PainterQubits/UnitfulIntegration.jl/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/PainterQubits/UnitfulIntegration.jl/actions/workflows/CI.yml)
[![codecov.io](https://codecov.io/github/PainterQubits/UnitfulIntegration.jl/coverage.svg?branch=master)](https://codecov.io/github/PainterQubits/UnitfulIntegration.jl?branch=master)

This package enables integration of physical quantity-valued functions, using
the Quantity types implemented in [Unitful.jl](https://github.com/ajkeller34/Unitful.jl).

This package currently supports [QuadGK.jl](https://github.com/JuliaMath/QuadGK.jl),
which was originally in Julia Base. We do not support QuadGK as implemented in Julia 0.5.
To use this package with Julia 0.5, you need to install the QuadGK package and
qualify all invocations of QuadGK functions with the module name (e.g.
`import QuadGK; QuadGK.quadgk(...)`).
This package currently supports [QuadGK.jl](https://github.com/JuliaMath/QuadGK.jl).
aurelio-amerio marked this conversation as resolved.
Show resolved Hide resolved



PRs for other integration packages are welcome.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this? Do you think that they shouldn’t be welcome any more?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my mistake, I intended to remove the part concearning the old julia version and ended up removing the PR part too

3 changes: 0 additions & 3 deletions REQUIRE

This file was deleted.

43 changes: 0 additions & 43 deletions appveyor.yml

This file was deleted.

69 changes: 7 additions & 62 deletions src/UnitfulIntegration.jl
Original file line number Diff line number Diff line change
@@ -1,71 +1,16 @@
__precompile__(true)
module UnitfulIntegration

using Unitful
import Unitful: DimensionError
import QuadGK
import LinearAlgebra
import Unitful: AbstractQuantity
import QuadGK: cachedrule, rulecache

function QuadGK.quadgk(f, a::Quantity, b::Quantity, c::Quantity...; kws...)
d = dimension(a)
d != dimension(b) && throw(DimensionError(a,b))
for x in c
d != dimension(x) && throw(DimensionError(a,x))
end
QuadGK.quadgk(f, promote(a,b,c...)...; kws...)
end

function QuadGK.quadgk(f, a::Quantity{T,D,U}, b::Quantity{T,D,U}, c::Quantity{T,D,U}...;
atol=missing, rtol=sqrt(eps(T)), maxevals=10^7, order=7, norm=LinearAlgebra.norm) where
{T<:AbstractFloat,D,U}
if ismissing(atol)
error("must provide an explicit atol keyword argument, e.g. ",
"`zero(f(a)*a)` supposing f is defined at a.")
end
_do_quadgk(f, [a, b, c...], order, T, atol, rtol, maxevals, norm)
end

function QuadGK.quadgk(f, a::Quantity{Complex{T},D,U}, b::Quantity{Complex{T},D,U},
c::Quantity{Complex{T},D,U}...; atol=missing, rtol=sqrt(eps(T)), maxevals=10^7,
order=7, norm=LinearAlgebra.norm) where {T<:AbstractFloat,D,U}
if ismissing(atol)
error("must provide an explicit atol keyword argument, e.g. ",
"`zero(f(a)*a)` supposing f is defined at a.")
end
_do_quadgk(f, [a, b, c...], order, T, atol, rtol, maxevals, norm)
end

# Necessary with infinite or semi-infinite intervals since quantities !<: Real
function _do_quadgk(f, s::Array{Quantity{T,D,U},1}, n, ::Type{Tw}, atol, rtol,
maxevals, nrm) where {Tw,T<:Real,D,U}
# fix `cachedrule` until it is possible to extend Unitful with package extension https://github.com/JuliaLang/julia/pull/47695 (julia >= 1.10)

s_no_u = reinterpret(T, s)
s1 = s_no_u[1]; s2 = s_no_u[end]; inf1 = isinf(s1); inf2 = isinf(s2)
if inf1 || inf2
if inf1 && inf2 # x = t/(1-t^2) coordinate transformation
return QuadGK.do_quadgk(t -> begin t2 = t*t; den = 1 / (1 - t2);
f(t*den*U())*U() * (1+t2)*den*den; end,
map(x -> isinf(x) ? copysign(one(x), x) :
2x / (1+hypot(1,2x)), s_no_u),
n, T, atol, rtol, maxevals, nrm)
end
s0,si = inf1 ? (s2,s1) : (s1,s2)
if si < 0 # x = s0 - t/(1-t)
return QuadGK.do_quadgk(t -> begin den = 1 / (1 - t);
f((s0 - t*den)*U())*U() * den*den; end,
reverse!(map(x -> 1 / (1 + 1 / (s0 - x)), s_no_u)),
n, T, atol, rtol, maxevals, nrm)
else # x = s0 + t/(1-t)
return QuadGK.do_quadgk(t -> begin den = 1 / (1 - t);
f((s0 + t*den)*U())*U() * den*den; end,
map(x -> 1 / (1 + 1 / (x - s0)), s_no_u),
n, T, atol, rtol, maxevals, nrm)
end
end
QuadGK.do_quadgk(f, s, n, Tw, atol, rtol, maxevals, nrm)
@generated function cachedrule(::Type{T}, n::Integer) where {T<:AbstractQuantity}
TF = typeof(float(real(one(T))))
cache = haskey(rulecache, TF) ? rulecache[TF] : (rulecache[TF] = Dict{Int,NTuple{3,Vector{TF}}}())
:(haskey($cache, n) ? $cache[n] : ($cache[n] = kronrod($T, n)))
end

_do_quadgk(f, s, n, ::Type{Tw}, atol, rtol, maxevals, nrm) where {Tw} =
QuadGK.do_quadgk(f, s, n, Tw, atol, rtol, maxevals, nrm)

end # module
32 changes: 6 additions & 26 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
using UnitfulIntegration
using Test
using UnitfulIntegration, Test, QuadGK, Unitful

import QuadGK
using Unitful
import Unitful: m, s, DimensionError

# Test physical quantity-valued functions
@test QuadGK.quadgk(x->x*m, 0.0, 1.0, atol=0.0m)[1] ≈ 0.5m
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this test?

@testset "quad" begin
f(x) = x^2
res = quadgk(f, 1u"m", 2u"m")[1]
@test isapprox(res, 7//3 *u"m^3")
end

# Test integration over an axis with units
@test QuadGK.quadgk(ustrip, 0.0m, 1.0m, atol=0.0m)[1] ≈ 0.5m

# Test integration where the unitful domain is infinite or semi-infinite
@test QuadGK.quadgk(x->exp(-x/(1.0m)), 0.0m, Inf*m, atol=0.0m)[1] ≈ 1.0m
@test QuadGK.quadgk(x->exp(x/(1.0m)), -Inf*m, 0.0m, atol=0.0m)[1] ≈ 1.0m
@test QuadGK.quadgk(x->exp(-abs(x/(1.0m))),
-Inf*m, Inf*m, atol=0.0m)[1] ≈ 2.0m

# Test mixed case (physical quantity-valued f and unitful domain)
@test QuadGK.quadgk(t->ustrip(t)*m/s, 0.0s, 2.0s, atol=0.0m)[1] ≈ 2.0m

# Test that errors are thrown when dimensionally unsound
@test_throws DimensionError QuadGK.quadgk(ustrip, 0.0m, 1.0s)[1]
@test_throws DimensionError QuadGK.quadgk(ustrip, 0.0, 1.0m)[1]

# Test that we throw an error when atol is not specified (at present
# I believe it is only possible to check when the domain is unitful)
@test_throws ErrorException QuadGK.quadgk(ustrip, 0.0m, 1.0m)
Comment on lines -11 to -29
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove these tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerning the test, are they all still relevant? I don't have any particular reason against more tests, I'm just not sure if all the old test are necessary. I guess it's better to have more tests than lesser though, I'll amend my commit

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit: it seems they were, as there are issues with the infinites handling (more broken stuff), I'm working on it