Skip to content

Commit

Permalink
Verify Safe Rule (#150)
Browse files Browse the repository at this point in the history
* Ensure safe rrule works with value_and_pullback etc

* Bump patch
  • Loading branch information
willtebbutt authored May 14, 2024
1 parent 5872a96 commit 24404e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Tapir"
uuid = "07d77754-e150-4737-8c94-cd238a1fb45b"
authors = ["Will Tebbutt, Hong Ge, and contributors"]
version = "0.2.10"
version = "0.2.11"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
2 changes: 2 additions & 0 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ function __verify_sig(::DerivedRule{<:OpaqueClosure{sig}}, ::Tfx) where {sig, Tf
end
end

__verify_sig(rule::SafeRRule, fx) = __verify_sig(rule.rule, fx)

# rrule!! doesn't specify specific argument types which must be used, so there's nothing to
# check here.
__verify_sig(::typeof(rrule!!), fx::Tuple) = nothing
Expand Down
14 changes: 8 additions & 6 deletions test/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ end
([1.0, 1.0], x -> [sin(x), sin(2x)], 3.0),
(1.0, x -> sum(5x), [5.0, 2.0]),
]
rule = build_rrule(f, x...)
v, (df, dx...) = value_and_pullback!!(rule, ȳ, f, x...)
@test v f(x...)
@test df isa tangent_type(typeof(f))
for (_dx, _x) in zip(dx, x)
@test _dx isa tangent_type(typeof(_x))
@testset "safe_mode=$safe_mode" for safe_mode in Bool[false, true]
rule = build_rrule(f, x...; safety_on=safe_mode)
v, (df, dx...) = value_and_pullback!!(rule, ȳ, f, x...)
@test v f(x...)
@test df isa tangent_type(typeof(f))
for (_dx, _x) in zip(dx, x)
@test _dx isa tangent_type(typeof(_x))
end
end
end
@testset "sensible error when CoDuals are passed to `value_and_pullback!!" begin
Expand Down

2 comments on commit 24404e9

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/106776

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.11 -m "<description of version>" 24404e965cbe2b84966793f36a9741711cd0e553
git push origin v0.2.11

Please sign in to comment.