def test_timelike_weights(t_weights, expected_edges): H = np.array([[1, 1, 0], [0, 1, 1]]) m = Matching() m.load_from_check_matrix(H, spacelike_weights=np.array([0.3, 0.7, 0.9]), timelike_weights=t_weights, repetitions=3) es = set((tuple(sorted([u, v])), d["weight"]) for u, v, d in m.edges()) assert es == expected_edges
def test_measurement_error_probabilities(p_meas, expected_edges, repetitions): m = Matching( [[1, 1, 0], [0, 1, 1]], error_probabilities=[0.1, 0.2, 0.3], measurement_error_probabilities=p_meas, repetitions=repetitions ) es = set((tuple(sorted([u, v])), d["error_probability"]) for u, v, d in m.edges()) assert es == expected_edges # Check measurement_error_probability also accepted m = Matching( [[1, 1, 0], [0, 1, 1]], error_probabilities=[0.1, 0.2, 0.3], measurement_error_probability=p_meas, repetitions=repetitions ) es = set((tuple(sorted([u, v])), d["error_probability"]) for u, v, d in m.edges()) assert es == expected_edges
def test_qubit_id_accepted_using_add_edge(): m = Matching() m.add_edge(0, 1, qubit_id=0) m.add_edge(1, 2, qubit_id={1, 2}) es = list(m.edges()) expected_edges = [ (0, 1, {'fault_ids': {0}, 'weight': 1.0, 'error_probability': -1.0}), (1, 2, {'fault_ids': {1, 2}, 'weight': 1.0, 'error_probability': -1.0}) ] assert es == expected_edges
def test_add_edge(): m = Matching() m.add_edge(0, 1) m.add_edge(1, 2) assert m.num_nodes == 3 assert m.num_edges == 2 m = Matching() m.add_edge(0, 1, weight=0.123, error_probability=0.6) m.add_edge(1, 2, weight=0.6, error_probability=0.3, fault_ids=0) m.add_edge(2, 3, weight=0.01, error_probability=0.5, fault_ids={1, 2}) expected = [(0, 1, {'fault_ids': set(), 'weight': 0.123, 'error_probability': 0.6}), (1, 2, {'fault_ids': {0}, 'weight': 0.6, 'error_probability': 0.3}), (2, 3, {'fault_ids': {1, 2}, 'weight': 0.01, 'error_probability': 0.5})] assert m.edges() == expected
def test_matching_edges(): g = nx.Graph() g.add_edge(0, 1, qubit_id=0, weight=1.1, error_probability=0.1) g.add_edge(1, 2, qubit_id=1, weight=2.1, error_probability=0.2) g.add_edge(2, 3, qubit_id={2,3}, weight=0.9, error_probability=0.3) g.nodes[0]['is_boundary'] = True g.nodes[3]['is_boundary'] = True g.add_edge(0, 3, weight=0.0) m = Matching(g) es = list(m.edges()) expected_edges = [ (0,1,{'qubit_id': {0}, 'weight': 1.1, 'error_probability': 0.1}), (0,3,{'qubit_id': set(), 'weight': 0.0, 'error_probability': -1.0}), (1,2,{'qubit_id': {1}, 'weight': 2.1, 'error_probability': 0.2}), (2,3,{'qubit_id': {2,3}, 'weight': 0.9, 'error_probability': 0.3}) ] assert es == expected_edges
def test_negative_weight_edge_returned(): m = Matching() m.add_edge(0, 1, weight=0.5, error_probability=0.3) m.add_edge(1, 2, weight=0.5, error_probability=0.3, fault_ids=0) m.add_edge(2, 3, weight=-0.5, error_probability=0.7, fault_ids={1, 2}) expected = [(0, 1, { 'fault_ids': set(), 'weight': 0.5, 'error_probability': 0.3 }), (1, 2, { 'fault_ids': {0}, 'weight': 0.5, 'error_probability': 0.3 }), (2, 3, { 'fault_ids': {1, 2}, 'weight': -0.5, 'error_probability': 0.7 })] assert m.edges() == expected