-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix Aqua's reported piracies and method ambiguities #85
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,42 @@ | ||
@testitem "Aqua" tags=[:aqua] begin | ||
using Aqua | ||
Aqua.test_all(QuantumSymbolics, | ||
ambiguities=(;broken=true), | ||
piracies=(;broken=true), | ||
) | ||
|
||
# Add any new types needed to QObj, or here if QObj if not appropriate. | ||
# Add types from elsewhere in the ecosystem here or preferably to QObj | ||
own_types = [Base.uniontypes(QObj)...,] | ||
own_types_union = Union{SymQObj,} | ||
|
||
Aqua.test_all(QuantumSymbolics, piracies=(;treat_as_own=own_types)) | ||
|
||
function normalize_arguments(method) | ||
args = Base.unwrap_unionall(method.sig).types[2:end] | ||
normalized_args = [] | ||
# handle few edge cases specific to our analysis | ||
for arg in args | ||
# mutation and order of if-conditions is intedtional here | ||
if (arg isa UnionAll) && (arg.body <: Type) arg = arg.body.parameters[1] end | ||
if (arg isa Core.TypeofVararg) arg = arg.T end | ||
if (arg isa TypeVar) arg = arg.ub end | ||
push!(normalized_args, arg) | ||
end | ||
return normalized_args | ||
end | ||
|
||
# Custom type-piracy detection, to catch uses of QuantumInterface types without a Symbolic | ||
filtered_piracies = filter(Aqua.Piracy.hunt(QuantumSymbolics)) do m | ||
!any(normalize_arguments(m) .<: own_types_union) | ||
end | ||
|
||
aqua_piracies = Aqua.Piracy.hunt(QuantumSymbolics, treat_as_own=own_types) | ||
internally_detected_piracies = setdiff(filtered_piracies, aqua_piracies) | ||
if !isempty(internally_detected_piracies) | ||
printstyled( | ||
stderr, | ||
"Internally flagged possible type-piracy:\n"; | ||
color = Base.warn_color() | ||
) | ||
show(stderr, MIME"text/plain"(), internally_detected_piracies) | ||
println(stderr, "\n") | ||
end | ||
@test isempty(internally_detected_piracies) | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Motivation here was to avoid ambiguities with other packages,
But I'm not sure if it should be
::Number
or::{Union{Number, Symbolic{Number}}}
to allowp*tr(q)
just astr(q)*p
is allowed. The test suits for QuantumSymbolics and QuantumSavory pass right now, but I wasn't sure if that is a valid operation since it was allowed before my changes.