Exemplo n.º 1
0
 def test_graph_construction(self):
     """Check that single errors create a pair of nodes for all types of code."""
     for d in [2, 3]:
         for T in [1, 2]:
             for xbasis in [False, True]:
                 code = RepetitionCode(d, T, xbasis=xbasis)
                 self.single_error_test(code)
Exemplo n.º 2
0
 def test_weight(self):
     """Error weighting code test."""
     error = ("Error: Calculated error probability not correct for " +
              "test result '0 0  11 00' in d=3, T=1 repetition code.")
     code = RepetitionCode(3, 1)
     dec = GraphDecoder(code)
     test_results = {"0": {"0 0  00 00": 1024, "0 0  11 00": 512}}
     p = dec.get_error_probs(test_results)
     self.assertTrue(round(p[(1, 0, 0), (1, 0, 1)], 2) == 0.33, error)
Exemplo n.º 3
0
 def test_string2nodes(self):
     """Test string2nodes with different logical values."""
     code = RepetitionCode(3, 2)
     dec = GraphDecoder(code)
     s0 = '0 0  01 00 01'
     s1 = '1 1  01 00 01'
     self.assertTrue(
         dec._string2nodes(s0,
                           logical='0') == dec._string2nodes(s1,
                                                             logical='1'),
         'Error: Incorrect nodes from results string')
Exemplo n.º 4
0
 def test_string2nodes(self):
     """Test string2nodes with different logical values."""
     code = RepetitionCode(3, 2)
     dec = GraphDecoder(code)
     s0 = "0 0  01 00 01"
     s1 = "1 1  01 00 01"
     self.assertTrue(
         dec._string2nodes(s0,
                           logical="0") == dec._string2nodes(s1,
                                                             logical="1"),
         "Error: Incorrect nodes from results string",
     )
Exemplo n.º 5
0
 def test_graph(self):
     """Test if analytically derived SyndromeGraph is correct."""
     error = (
         "Error: The analytical SyndromeGraph does not coincide " +
         "with the brute force SyndromeGraph in d=7, T=2 RepetitionCode.")
     code = RepetitionCode(7, 2)
     graph_new = GraphDecoder(code, brute=False).S
     graph_old = GraphDecoder(code, brute=True).S
     test_passed = True
     for node in graph_new.nodes():
         test_passed &= node in graph_old.nodes()
     for node in graph_old.nodes():
         test_passed &= node in graph_new.nodes()
     test_passed &= rx.is_isomorphic(graph_new, graph_old,
                                     lambda x, y: x == y)
     self.assertTrue(test_passed, error)
Exemplo n.º 6
0
 def test_graph_construction(self):
     """Check that single errors create a pair of nodes for all types of code."""
     for d in [2, 3]:
         for T in [1, 2]:
             for xbasis in [False, True]:
                 for resets in [False, True]:
                     for delay in [0, 16]:
                         code = RepetitionCode(d,
                                               T,
                                               xbasis=xbasis,
                                               resets=resets,
                                               delay=delay)
                         self.single_error_test(code)
                         if delay > 0 and T > 1:
                             num_delays = code.circuit['0'].count_ops(
                             )['delay']
                             self.assertTrue(
                                 num_delays == (d - 1) * (T - 1),
                                 "Error: wrong number of delay gates.")
Exemplo n.º 7
0
    def test_rep(self):
        """
        Repetition code test.
        """
        matching_probs = {}
        lookup_probs = {}
        post_probs = {}

        max_dist = 5

        noise_model = get_noise(0.02, 0.02)

        for d in range(3, max_dist + 1, 2):

            code = RepetitionCode(d, 2)

            results = get_syndrome(code, noise_model=noise_model, shots=8192)

            dec = GraphDecoder(code)

            logical_prob_match = dec.get_logical_prob(results)
            logical_prob_lookup = lookuptable_decoding(results, results)
            logical_prob_post = postselection_decoding(results)

            for log in ['0', '1']:
                matching_probs[(d, log)] = logical_prob_match[log]
                lookup_probs[(d, log)] = logical_prob_lookup[log]
                post_probs[(d, log)] = logical_prob_post[log]

        for d in range(3, max_dist - 1, 2):
            for log in ['0', '1']:
                m_down = matching_probs[(d, log)] \
                    > matching_probs[(d + 2, log)]
                l_down = lookup_probs[(d, log)] \
                    > lookup_probs[(d + 2, log)]
                p_down = post_probs[(d, log)] \
                    > post_probs[(d + 2, log)]

                m_error = "Error: Matching decoder does not improve "\
                    + "logical error rate between repetition codes"\
                    + " of distance " + str(d) + " and " + str(d + 2) + ".\n"\
                    + "For d="+str(d)+": " + str(matching_probs[(d, log)])\
                    + ".\n"\
                    + "For d="+str(d+2)+": " + str(matching_probs[(d+2, log)])\
                    + "."
                l_error = "Error: Lookup decoder does not improve "\
                    + "logical error rate between repetition codes"\
                    + " of distance " + str(d) + " and " + str(d + 2) + ".\n"\
                    + "For d="+str(d)+": " + str(lookup_probs[(d, log)])\
                    + ".\n"\
                    + "For d="+str(d+2)+": " + str(lookup_probs[(d+2, log)])\
                    + "."
                p_error = "Error: Postselection decoder does not improve "\
                    + "logical error rate between repetition codes"\
                    + " of distance " + str(d) + " and " + str(d + 2) + ".\n"\
                    + "For d="+str(d)+": " + str(post_probs[(d, log)])\
                    + ".\n"\
                    + "For d="+str(d+2)+": " + str(post_probs[(d+2, log)])\
                    + "."

                self.assertTrue(m_down or matching_probs[(d, log)] == 0.0,
                                m_error)
                self.assertTrue(l_down or lookup_probs[(d, log)] == 0.0,
                                l_error)
                self.assertTrue(p_down or post_probs[(d, log)] == 0.0, p_error)