QuantumSavory / QuantumClifford.jl

Clifford circuits, graph states, and other quantum Stabilizer formalism tools.
MIT License
113 stars 45 forks source link

beginning of biased pauli noise for PF sim #295

Closed amicciche closed 2 months ago

amicciche commented 3 months ago

This is the code that was mentioned in our Zulip messages. One note, it seemed to be that line 41 in the noise.jl, n = nqubits(s) wasn't doing anything, so I went ahead and deleted that in addition to the functions I added.

As mentioned over Zulip, because of the error, this code is untested, aside from being able to generate the object from the Julia REPL.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 2.77778% with 35 lines in your changes missing coverage. Please review.

Project coverage is 82.24%. Comparing base (1fb1783) to head (e6548f9).

Files Patch % Lines
src/noise.jl 0.00% 18 Missing :warning:
src/pauli_frames.jl 0.00% 17 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #295 +/- ## ========================================== - Coverage 83.01% 82.24% -0.77% ========================================== Files 61 61 Lines 4033 4067 +34 ========================================== - Hits 3348 3345 -3 - Misses 685 722 +37 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

amicciche commented 3 months ago

I'm now having this error when I try to use QuantumClifford:

image

Krastanov commented 3 months ago

yeah, tests fail, so I have definitely done something silly. Should have waited for tests to pass before pinging you

Krastanov commented 3 months ago

it is fixed now

amicciche commented 3 months ago

The applynoise!() that takes a PauliFrame seems to work correctly, however with the way the constructors are written for PauliError, one can't do something like the following (which will probably a common enough case to warrant fixing): image I tried to fix this by changing Integer to Real on line 37 of noise.jl, but this caused an error. Here: image

Krastanov commented 3 months ago

What error did the change to Real cause?

Krastanov commented 3 months ago

marking this as a draft just to make my review queue a bit more manageable. Mark it as finished when ready for review.

amicciche commented 3 months ago

What error did the change to Real cause?

When I change it to Real: image

I get this error: image

Krastanov commented 3 months ago

Float is a Real so when you do PauliNoise(x::Real, y::Real, z::Real) = PauliNoise(float(x), float(y), float(z)) you end up with infinite recursion.

A cleaner solution than both what I have written and what you have written is to specify the type for the constructor:

julia> struct A{T} a::T end

julia> A(a::Real) = A{Float64}(a)
A

julia> A(1)
A{Float64}(1.0)

Or even better, something that does not hardcode Float64

julia> struct A{T} a::T end

julia> function A(a::Real) 
           a = float(a)
           return A{typeof(a)}(a)
       end
A

julia> A(1)
A{Float64}(1.0)

julia> A(BigInt(1))
A{BigFloat}(1.0)

So the cleanest solution should be something along the lines of

function PauliNoise(px::Real, py::Real, pz::Real)
    px, py, pz = float.((px, py, pz))
    px, py, pz = promote(px, py, pz)
    T = typeof(px)
    return PauliNoise{T}(px, py, pz)
end
amicciche commented 3 months ago

Ah, I see! I'll try to fix this later today, using what you suggested, thanks!

amicciche commented 3 months ago

Your code worked as provided! Thanks! With that, I think everything works. I checked for a few codes that doing PauliError(qubit, p) after decoding results in the same logical vs physical error rate plots as PauliError(qubit, p/3, p/3, p/3). For some CSS codes, I also checked that the X and Z logical error corresponding to those simulations also matches doing PauliError(qubit, p*2/3, 0, 0) and PauliError(qubit, 0, 0, p*2/3) correspondingly (and the other X/Z logical error is 0). Similarly, PauliError(qubit, 0, p*2/3, 0) gives the same performance as PauliError(qubit, p).