QuantumSavory / QuantumClifford.jl

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

naive_encoding_circuit failes when `rank(parity_checks) < length(parity_checks)` #190

Open amicciche opened 9 months ago

amicciche commented 9 months ago

When trying to generate encoding circuits for some LDPC codes, I'm getting a bounds error: Below is me trying this with three different codes:

image

I don't think the problem is with how I'm constructing the tableaux, but for thoroughness, here is my personal function stab_from_cxcz()

image

Krastanov commented 9 months ago

Could you upload the two npz files from the first two lines of the REPL screenshot?

It seems there is a problem with this line https://github.com/QuantumSavory/QuantumClifford.jl/blob/55fc8765a0ac0595768bcda47d3621b9edb28e20/src/ecc/circuits.jl#L53

Krastanov commented 9 months ago

Actually, this happens almost certainly due to redundant rows in the parity check matrix you are using. Presumably, there are 300 parity checks. However, probably only 296 of them are actually independent. That does not matter too much for the syndrome measurement circuit -- we happen to perform 4 redundant measurements, big deal. But it would matter to the encoding circuit. To verify that this is indeed the case, check what the rank(MixedDestabilizer(stab)) is. Probably it is smaller than length(stab). So, just for the encoding circuit (not for the syndrome measurement circuits) try the following modification stab = stabilizerview(MixedDestabilizer(stab)). I think that would be enough to fix the issue

Krastanov commented 9 months ago

MixedDestabilizer basically does the Gaussian elimination necessary to remove redundant rows:

julia> S"XXX ZZI IZZ ZIZ" |> MixedDestabilizer |> stabilizerview
+ XXX
+ ZZ_
+ Z_Z
amicciche commented 9 months ago

You were right about the rank being 296, but I'm now having trouble with the type of the tableau returned by that: image

Krastanov commented 9 months ago

this seems to be separate issue (I reported it just now in https://github.com/QuantumSavory/QuantumClifford.jl/issues/191)

As a temporary workaround just do reduced_checks = copy(reduced_checks) # in order to collect the array so it is not a view into another array

amicciche commented 9 months ago

I think it's working now, but the logical error versus physical error plots for LDPC codes look terrible with my way of decoding. I think this is probably due to the lookup table only working with single qubit errors, but now that the number of qubits is around 300, that almost never is going to happen. I guess it's time to talk to Krishna about us combining our work?

image
Krastanov commented 9 months ago

Yup, this is almost certainly due to the lookup table decoder. I messaged on zulip about it.

I will change the name of this issue to track more carefully the particular bug that was initially reported.

Krastanov commented 9 months ago

All we need to do here is to double check that we do not have over-determined system. Basically check length(parity_checks) (i.e. code_c = code_n - code_k) versus the rank of the MixedDestabilizer that is already constructed. If they match everything is fine, and if they do not, raise an error with a clear descriptive message (instead of the current indexing error).

S"IZZ ZZI ZIZ" can be used when adding tests.