# Path: src/common.py
# def removekey(d, key):
# def colinear(p0, p1, p2):
# def manhattan_dist(A,B):
# def euclidean_dist(A,B):
# def Charge(X_charge = 0, Z_charge = 0):
# def Sign(count, num_sides):
#     def __init__(self, depth, dimension = 2):
#     def Syndrome(self, type, charge_type):
#     def PhysicalErrors(self):
#     def distance(self, type, node1, node2):
#     def Assessment(self):
# class Code:


from decoders import *
from matplotlib import path
from math import floor
from src import common
import sys
import networkx as nx
import numpy as np


    center = CentralNode(UnclusteredGraph, cluster)
    for mate in cluster:
        if mate != center:
            BoundTransport(code, center, mate, dim, type, charge_type)

def BoundTransport(code, fixed_node, mobile_node, dim, type, charge_type):
    if 'external' in mobile_node[1]:
        charge = mobile_node[1]['charge']
        first_link = code.External[type][mobile_node[0]]['measure']
        shared = code.External[type][mobile_node[0]]['data']

        count = code.External[type][mobile_node[0]]['order']
        num_sides = code.External[type][mobile_node[0]]['sides']
        sign = common.Sign(count, num_sides)
        delta_charge = sign * charge
        first_link_charge = code.Primal.node[shared]['charge'][charge_type]
        code.Primal.node[shared]['charge'][charge_type] = (first_link_charge - delta_charge)%dim
        
        mobile_node = first_link
        chain = nx.shortest_path(code.Dual[type], mobile_node, fixed_node[0])
        chain_length = len(chain) - 1
        for link in range(chain_length):
            previous, next = chain[link], chain[link + 1]
            for shared in code.Stabilizers[type][previous]['data']:
                if shared in code.Stabilizers[type][next]['data']:

                    num_sides = code.Stabilizers[type][previous]['sides']
                    count = code.Stabilizers[type][previous]['data'][shared]

# Path: src/common.py
# def removekey(d, key):
# def colinear(p0, p1, p2):
# def manhattan_dist(A,B):
# def euclidean_dist(A,B):
# def Charge(X_charge = 0, Z_charge = 0):
# def Sign(count, num_sides):
#     def __init__(self, depth, dimension = 2):
#     def Syndrome(self, type, charge_type):
#     def PhysicalErrors(self):
#     def distance(self, type, node1, node2):
#     def Assessment(self):
# class Code:


# Path: src/decoders/rg.py
from decoders import *
from matplotlib import path
from math import floor
from src import common
import sys
import networkx as nx
import numpy as np



    center = CentralNode(UnclusteredGraph, cluster)
    for mate in cluster:
        if mate != center:
            BoundTransport(code, center, mate, dim, type, charge_type)

def BoundTransport(code, fixed_node, mobile_node, dim, type, charge_type):
    if 'external' in mobile_node[1]:
        charge = mobile_node[1]['charge']
        first_link = code.External[type][mobile_node[0]]['measure']
        shared = code.External[type][mobile_node[0]]['data']

        count = code.External[type][mobile_node[0]]['order']
        num_sides = code.External[type][mobile_node[0]]['sides']
        sign = common.Sign(count, num_sides)
        delta_charge = sign * charge
        first_link_charge = code.Primal.node[shared]['charge'][charge_type]
        code.Primal.node[shared]['charge'][charge_type] = (first_link_charge - delta_charge)%dim
        
        mobile_node = first_link
        chain = nx.shortest_path(code.Dual[type], mobile_node, fixed_node[0])
        chain_length = len(chain) - 1
        for link in range(chain_length):
            previous, next = chain[link], chain[link + 1]
            for shared in code.Stabilizers[type][previous]['data']:
                if shared in code.Stabilizers[type][next]['data']:

                    num_sides = code.Stabilizers[type][previous]['sides']
                    count = code.Stabilizers[type][previous]['data'][shared]

                    sign = common.Sign(count, num_sides)