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

fix #191: too restrictive typeassert for MixedDestabilizer #366

Merged
merged 6 commits into from
Nov 3, 2024

Conversation

Fe-r-oz
Copy link
Contributor

@Fe-r-oz Fe-r-oz commented Sep 22, 2024

This now works and all the test passes as well:

julia> random_destabilizer(5,6) |> stabilizerview |> MixedDestabilizer
๐’Ÿโ„ฏ๐“ˆ๐“‰๐’ถ๐’ทโ”โ”
+ Z_____
+ _Z____
+ __Z___
+ ___Z__
+ _____X
๐’ณโ‚—โ”โ”โ”โ”โ”โ”
+ ZZZZX_
๐’ฎ๐“‰๐’ถ๐’ทโ”โ”โ”โ”
+ XZ_ZZ_
- ZX__Z_
+ __YZZ_
+ Z_ZXZ_
+ _____Z
๐’ตโ‚—โ”โ”โ”โ”โ”โ”
+ ____Z_

The JET errors does not increase as well. Hopefully, this is plausible.

  • The code is properly formatted and commented.
  • Substantial new functionality is documented within the docs.
  • All new functionality is tested.
  • All of the automated tests on github pass.

@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Sep 23, 2024

The PR is ready for review. Thank you!

P.S. My bad for the rebase. Initially, I had used : after 191 in commit message which didn't pushed the issue to appear in Development. However, I noticed simply using #issue can make the issue appear in Development. So, I did the rebase using reword to remove : in hash191: . But the issue still didn't appear in Development...

@Krastanov Krastanov self-requested a review September 26, 2024 21:13
Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

Could you elaborate why this is necessary? Maybe add tests that would have failed without this change?

@Krastanov
Copy link
Member

The proper fix for this probably requires better parameterization of the input argument. The issue is that the following T is not what is preserved:

MixedDestabilizer(::Stabilizer{T}) where {T}

Rather what is preserved is the T in here:

MixedDestabilizer(::Stabilizer{Tableau{P, <:AbstractMatrix{T}}}) where {P, T}

Maybe we should define eltype for these guys.

eltype(::Stabilizer{Tableau{P, <:AbstractMatrix{T}}}) where {P, T} = T

@Krastanov Krastanov marked this pull request as draft September 26, 2024 21:23
Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests โœ…

Project coverage is 83.97%. Comparing base (f3eb7cd) to head (0122d72).
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #366      +/-   ##
==========================================
+ Coverage   82.42%   83.97%   +1.55%     
==========================================
  Files          70       70              
  Lines        4580     4918     +338     
==========================================
+ Hits         3775     4130     +355     
+ Misses        805      788      -17     

โ˜” View full report in Codecov by Sentry.
๐Ÿ“ข Have feedback on the report? Share it here.

@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Oct 28, 2024

I attempted the suggested approach by defining the following method:

Base.eltype(::Stabilizer{Tableau{P, <:AbstractMatrix{T}}}) where {P, T} = T

Afterward, I initialized a variable t using:

t = zeros(eltype(stab), n * 2, n)

However, when executing random_destabilizer(5, 6) |> stabilizerview |> MixedDestabilizer, I encountered the following warning and error messages:

INFO: Given QuantumClifford was explicitly requested, output will be shown live.
WARNING: Method definition eltype(QuantumClifford.Stabilizer{QuantumClifford.Tableau{P, var"#s37"} where var"#s37" <: AbstractArray{T, 2}}) where {P, T} in module QuantumClifford at /home/Desktop/191/QuantumClifford.jl/src/QuantumClifford.jl:408 overwritten at /home/Desktop/191/QuantumClifford.jl/src/QuantumClifford.jl:940.
ERROR: Method overwriting is not permitted during Module precompilation. Use `__precompile__(false)` to opt-out of precompilation.

I have followed your suggestions from #366 (review) by including a comment to elaborate the changes.

I hope this is reasonable.

@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Oct 28, 2024

Maybe add tests that would have failed without this change?

Thank you! I have added tests that fail on the master branch, which reproduce the error without the need for fancy expressions like random_destabilizer(5, 6) |> stabilizerview |> MixedDestabilizer.

ERROR: TypeError: in typeassert, expected QuantumClifford.Tableau{SubArray{UInt8, 1, Vector{UInt8}, Tuple{UnitRange{Int64}}, true}, SubArray{UInt64, 2, Matrix{UInt64}, Tuple{Base.Slice{Base.OneTo{Int64}}, UnitRange{Int64}}, true}}, got a value of type QuantumClifford.Tableau{Vector{UInt8}, Matrix{UInt64}}
Stacktrace:
 [1] MixedDestabilizer(stab::Stabilizer{QuantumClifford.Tableau{SubArray{โ€ฆ}, SubArray{โ€ฆ}}}; undoperm::Bool, reportperm::Bool)
   @ QuantumClifford ~/Desktop/hnEW/QuantumClifford.jl/src/QuantumClifford.jl:574
 [2] top-level scope

Consequently, the suggestions from #366 (review) have been fully incorporated. Thus, this PR resolves #191

  • comment elaborating the change
  • tests that would have failed (on master branch) without this change

@Fe-r-oz Fe-r-oz marked this pull request as ready for review October 28, 2024 08:09
@Fe-r-oz Fe-r-oz requested a review from Krastanov October 28, 2024 08:18
Krastanov and others added 2 commits November 2, 2024 11:04
โ€ฆimproved since this was necessary; also simplified the tests
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Nov 2, 2024

Yup, the JET and compiler have improved as previously removing ::T caused some tests to fail.

Thank you for the simplification.

@Krastanov
Copy link
Member

Great! Thanks for the fix!

@Krastanov Krastanov merged commit 56acb6e into QuantumSavory:master Nov 3, 2024
16 of 18 checks passed
@Fe-r-oz Fe-r-oz deleted the i191 branch November 8, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants