# 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 time
import networkx as nx
import numpy as np
		cc[t2].append((ext2,{'charge':c,'type':t2}))

		cc, uc, code = GCC_Two_Color_Simplify(cc, uc, code, ct, cntr)
	return cc, uc, code 

def GCC_Boundary_Two_Color_Simplify(ints, cc, uc, code, ct, scale, cntr):
	cc, uc, code = clean_clusters(cc, uc, code)
	d = code.dimension
	[m0, m1] = ints
	c0, c1 = m0[1]['charge'], m1[1]['charge']
	t0, t1 = m0[1]['type'], m1[1]['type']
	t2 = code.complementaryType([t0,t1])
	if c0 == c1:
		if any((common.euclidean_dist(ext, m0[0]) < scale and common.euclidean_dist(ext, m1[0]) < scale) for ext in code.External[t2]):
			if any((ext in code.Dual[t1].neighbors(m0[0]) and ext in code.Dual[t0].neighbors(m1[0])) for ext in code.External[t2]):
				for ext in code.External[t2]:
					if ext in code.Dual[t1].neighbors(m0[0]) and ext in code.Dual[t0].neighbors(m1[0]):
						break
			else:
				ext = closest_to_point(code.External[t2],m0[0])

			uc.add_node(ext, charge = c0, type = t2)
			cc[t2].append((ext,{'charge':c0,'type':t2}))
			code.Stabilizers[t2][ext]['charge'][ct] = c0
			cc, uc, code = GCC_Two_Color_Simplify(cc, uc, code, ct, cntr)

		elif any(common.euclidean_dist(ext, m0[0]) < scale for ext in code.External[t0]) and any(common.euclidean_dist(ext, m1[0]) < scale for ext in code.External[t1]):
			cc, uc, code = GCC_Boundary_One_Color_Simplify(m0[0], cc, uc, code, t0, ct, scale, cntr)
			cc, uc, code = GCC_Boundary_One_Color_Simplify(m1[0], cc, uc, code, t1, ct, scale, cntr)


# 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/gcc.py
from decoders import *
from matplotlib import path
from math import floor
from src import common
import sys
import time
import networkx as nx
import numpy as np

		cc[t2].append((ext2,{'charge':c,'type':t2}))

		cc, uc, code = GCC_Two_Color_Simplify(cc, uc, code, ct, cntr)
	return cc, uc, code 

def GCC_Boundary_Two_Color_Simplify(ints, cc, uc, code, ct, scale, cntr):
	cc, uc, code = clean_clusters(cc, uc, code)
	d = code.dimension
	[m0, m1] = ints
	c0, c1 = m0[1]['charge'], m1[1]['charge']
	t0, t1 = m0[1]['type'], m1[1]['type']
	t2 = code.complementaryType([t0,t1])
	if c0 == c1:
		if any((common.euclidean_dist(ext, m0[0]) < scale and common.euclidean_dist(ext, m1[0]) < scale) for ext in code.External[t2]):
			if any((ext in code.Dual[t1].neighbors(m0[0]) and ext in code.Dual[t0].neighbors(m1[0])) for ext in code.External[t2]):
				for ext in code.External[t2]:
					if ext in code.Dual[t1].neighbors(m0[0]) and ext in code.Dual[t0].neighbors(m1[0]):
						break
			else:
				ext = closest_to_point(code.External[t2],m0[0])

			uc.add_node(ext, charge = c0, type = t2)
			cc[t2].append((ext,{'charge':c0,'type':t2}))
			code.Stabilizers[t2][ext]['charge'][ct] = c0
			cc, uc, code = GCC_Two_Color_Simplify(cc, uc, code, ct, cntr)

		elif any(common.euclidean_dist(ext, m0[0]) < scale for ext in code.External[t0]) and any(common.euclidean_dist(ext, m1[0]) < scale for ext in code.External[t1]):
			cc, uc, code = GCC_Boundary_One_Color_Simplify(m0[0], cc, uc, code, t0, ct, scale, cntr)
			cc, uc, code = GCC_Boundary_One_Color_Simplify(m1[0], cc, uc, code, t1, ct, scale, cntr)


	elif any(common.euclidean_dist(ext, m0[0]) < scale for ext in code.External[t0]) and any(common.euclidean_dist(ext, m1[0]) < scale for ext in code.External[t1]):