1
$\begingroup$

I run the surface code for distance-3 with 3 round. I am now trying to decode and find the number of failures. My error probability of 0.08. Here are my syndrome results:

x_syndrome_1stround = [0, 0, 0, 1, 1, 1]
x_syndrome_2ndround = [1, 1, 0, 1, 1, 1]
x_syndrome_3rdround = [1, 1, 1, 0, 1, 0]
z_syndrome_1stround = [1, 1, 0, 0, 1, 0]
z_syndrome_2ndround = [1, 1, 1, 0, 1, 0]
z_syndrome_3rdround = [1, 1, 1, 1, 0, 0]

Here are the detector events:

first_detector_xzstab = [1,1,0,0,0,0,0,0,1,0,0,0] # first 6 elements of the list corresponds detection event for the x stabilizers, the last 6 elements of the list corresponds detection event for the z stabilizers
second_detector_xzstab = [0,0,1,1,0,1,0,0,0,1,1,0] 

The following matrices are the parity check matrix for the X and Z stabilizers:

H_d3x = csr_matrix(np.array([
[1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1]
    ]))
H_d3z= csr_matrix(np.array([
[1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1]
]))

The result of measuring data qubits after the stabilizers is here:

 data_q_meas = np.array([0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0])

This is my function for calculating the error probabilities:

import numpy as np
from pymatching import matching

    H_d3x = np.array([
        [1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0],
        [0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1]
    ])
x_syndrome_1stround = [0, 0, 0, 1, 1, 1]
x_syndrome_2ndround = [1, 1, 0, 1, 1, 1]
x_syndrome_3rdround = [1, 1, 1, 0, 1, 0]
z_syndrome_1stround = [1, 1, 0, 0, 1, 0]
z_syndrome_2ndround = [1, 1, 1, 0, 1, 0]
z_syndrome_3rdround = [1, 1, 1, 1, 0, 0]

actual_observables = np.array([0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0]) #here I am guessing that actual observables are the measurement results of the data qubits in the simulator

observables = csc_matrix([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])

def surface_code_failures(error_rate, x_syndrome_rounds, z_syndrome_rounds):
    # Parity check matrix
    num_failures = 0
    matching=Matching(H_d3x,weights=np.log((1-p)/p)) 
    print(matching)
    for x_syndrome, z_syndrome in zip(x_syndrome_rounds, z_syndrome_rounds):
        # Calculate the total syndrome (X and Z syndromes combined)
        syndrome = np.concatenate((x_syndrome, z_syndrome))
        #for i in range(syndrome.shape[0]):
        print("syndrome = ",syndrome, syndrome.shape[0])  
        predicted = matching.decode(syndrome)
        print("predicted = ",predicted)
        predicted_observables = observables@predicted % 2
           #if not matching.decode(syndrome): #syndrome
        num_failures += not np.array_equal(predicted_observables, actual_observables)

    return num_failures

# Error rate
p = 0.08

# Combine syndromes for each round
x_syndrome_rounds = [x_syndrome_1stround, x_syndrome_2ndround, x_syndrome_3rdround]
z_syndrome_rounds = [z_syndrome_1stround, z_syndrome_2ndround, z_syndrome_3rdround]

# Calculate the number of failures
num_failures = surface_code_failures(p, x_syndrome_rounds, z_syndrome_rounds)
print("Number of failures:", num_failures)

And this is how I use the function:

p = 0.08

# Combine syndromes for each round
x_syndrome_rounds = [x_syndrome_1stround, x_syndrome_2ndround, x_syndrome_3rdround]
z_syndrome_rounds = [z_syndrome_1stround, z_syndrome_2ndround, z_syndrome_3rdround]

# Calculate the number of failures
num_failures = surface_code_failures(p, x_syndrome_rounds, z_syndrome_rounds)
print("Number of failures:", num_failures)

I am having error in this line if not matching.decode(syndrome): #syndrome The error message is that: ValueError: The shape ((12,)) of the syndrome vector z is not valid. It(the program) probably did not like the dimensions, but I do not know what to give anymore. I thought I needed to give syndrome measurement results to decode the errors. Maybe I am doing wrong with syndromes? Does anyone can help me with the function?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.