import numpy as np
import matplotlib.pyplot as  plt
import matplotlib.mlab as mlab
from mpl_toolkits.mplot3d import Axes3D

plt.rc('font',family='Microsoft YaHei')
plt.rcParams['axes.unicode_minus'] = False

palettes = [
    "#999999",
    "#FFEE00",
    "#FF9900",
    "#FF3636",
    "#99CC33",
    "#66CCCC",
    "#3399CC",
    "#9966CC"
]

plt.scatter(0.1, 0.1, color=palettes[0])
plt.scatter(0.2, 0.2, color=palettes[1])
plt.scatter(0.3, 0.3, color=palettes[2])
plt.scatter(0.4, 0.4, color=palettes[3])
plt.scatter(0.5, 0.5, color=palettes[4])
plt.scatter(0.6, 0.6, color=palettes[5])
plt.scatter(0.7, 0.7, color=palettes[6])
plt.scatter(0.8, 0.8, color=palettes[7])

# Expressibility Entanglement

plt.figure(figsize=(8, 5))

c1 = "#FF6666"
c2 = "#FF9900"
c3 = "#66CCFF"

# layer 1
# layer 1 qubit 3
plt.grid()
plt.xticks([1, 2, 3, 4, 5, 6])
plt.ylim(0.13, 0.7)
plt.title("角度编码方案与表达能力", fontsize=14)
plt.xlabel("Qubit数", fontsize=13)
plt.ylabel("Expr", fontsize=13)
plt.scatter(3, 0.1974, color=c1, label="Rx(θ)(·)")
plt.scatter(3, 0.1997, color=c2, label="Ry(θ)H(·)")
plt.scatter(3, 0.1918, color=c3, label="Rz(θ)H(·)")

plt.scatter(4, 0.1462, color=c1)
plt.scatter(4, 0.1442, color=c2)
plt.scatter(4, 0.1331, color=c3)

plt.scatter(5, 0.1711, color=c1)
plt.scatter(5, 0.1824, color=c2)
plt.scatter(5, 0.1741, color=c3)

plt.scatter(1, 0.6515, color=c1)
plt.scatter(1, 0.6613, color=c2)
plt.scatter(1, 0.6260, color=c3)

plt.scatter(2, 0.3435, color=c1)
plt.scatter(2, 0.3355, color=c2)
plt.scatter(2, 0.3304, color=c3)

plt.scatter(6, 0.2582, color=c1)
plt.scatter(6, 0.2748, color=c2)
plt.scatter(6, 0.2644, color=c3)

plt.legend(loc='upper center')

plt.figure(figsize=(15, 3.8))

# layer 1
# layer 1 qubit 3
ax = plt.subplot(1,3,1)
plt.grid()
plt.ylim(0.3, 0.8)
plt.xlim(0.4, 2.4)
plt.title("Quibts: 3, Layers: 1")
plt.xlabel("Expr", fontsize=13)
plt.ylabel("Ent", fontsize=13)
plt.scatter(1.189, 0.625, color=palettes[0], label="C1")
plt.scatter(0.704, 0.377, color=palettes[1], label="C2")
plt.scatter(2.175, 0.702, color=palettes[2], label="C3")
plt.scatter(2.352, 0.540, color=palettes[3], label="C4")
plt.scatter(1.799, 0.542, color=palettes[4], label="C5")
plt.scatter(2.287, 0.720, color=palettes[5], label="C6")
plt.scatter(1.546, 0.338, color=palettes[6], label="C7")
plt.scatter(1.905, 0.456, color=palettes[7], label="C8")
ax.legend(loc='upper left', ncol=3, bbox_to_anchor=(0, 1.01))
plt.axvline(2.352, linestyle="--", color="#FF363666")
plt.axvline(2.175, linestyle="--", color="#FF990066")
plt.axhline(0.540, linestyle="--", color="#FF363666")
plt.axhline(0.702, linestyle="--", color="#FF990066")

# # layer 1 qubit 4
plt.subplot(1,3,2)
plt.grid()
plt.ylim(0.3, 0.8)
plt.xlim(0.4, 2.4)
plt.title("Quibts: 4, Layers: 1")
plt.xlabel("Expr", fontsize=13)
plt.scatter(1.724, 0.625, color=palettes[0])
plt.scatter(0.503, 0.375, color=palettes[1])
plt.scatter(1.881, 0.704, color=palettes[2])
plt.scatter(1.982, 0.537, color=palettes[3])
plt.scatter(1.837, 0.545, color=palettes[4])
plt.scatter(2.115, 0.721, color=palettes[5])
plt.scatter(1.219, 0.337, color=palettes[6])
plt.scatter(1.390, 0.457, color=palettes[7])
plt.axvline(1.982, linestyle="--", color="#FF363666")
plt.axvline(1.881, linestyle="--", color="#FF990066")
plt.axhline(0.537, linestyle="--", color="#FF363666")
plt.axhline(0.704, linestyle="--", color="#FF990066")

# # layer 1 qubit 5
plt.subplot(1,3,3)
plt.grid()
plt.ylim(0.3, 0.8)
plt.xlim(0.4, 2.4)
plt.title("Quibts: 5, Layers: 1")
plt.xlabel("Expr", fontsize=13)
plt.scatter(1.376, 0.625, color=palettes[0])
plt.scatter(0.456, 0.377, color=palettes[1])
plt.scatter(1.465, 0.703, color=palettes[2])
plt.scatter(1.557, 0.536, color=palettes[3])
plt.scatter(1.424, 0.547, color=palettes[4])
plt.scatter(2.113, 0.722, color=palettes[5])
plt.scatter(0.942, 0.339, color=palettes[6])
plt.scatter(1.152, 0.456, color=palettes[7])
plt.axvline(1.557, linestyle="--", color="#FF363666")
plt.axvline(1.465, linestyle="--", color="#FF990066")
plt.axhline(0.536, linestyle="--", color="#FF363666")
plt.axhline(0.703, linestyle="--", color="#FF990066")

def depth(circuit_type, n, L):
    if circuit_type == 1:
        return (2 * n + 1) * L
    elif circuit_type >= 2 and circuit_type <= 4:
        return (n + 1) * L + 1
    elif circuit_type == 5:
        return (2 + n + n // np.gcd(n, 3)) * L
    elif circuit_type == 6:
        return (n ** 2 - n + 4) * L
    elif circuit_type == 7:
        return 6 * L
    elif circuit_type == 8:
        return (n + 2) * L

colors2 = ['#FFCC33', '#FF9900', '#FF9966', '#FF6666', '#CC3333']
colors = ['#99CCFF', '#66CCFF', '#0088CC', '#6666FF', '#0000FF']
types = ['o', '^', ',', 'p', 'X']
plt.grid()
plt.title("线路深度同量子比特数量关系")
plt.xlabel("线路类型", fontsize=13)
plt.ylabel("线路深度", fontsize=13)
for n in range(2, 7):
    for ct in range(1, 9):
        if ct == 1:
            plt.scatter(ct, depth(ct, n, 1), color=colors[n - 2], marker=types[n - 2], label=f"n={n}, L=1")
        else:
            plt.scatter(ct, depth(ct, n, 1), color=colors[n - 2], marker=types[n - 2])

for n in range(2, 7):
    for ct in range(1, 9):
        if ct == 1:
            plt.scatter(ct, depth(ct, n, 3), color=colors2[n - 2], marker=types[n - 2], label=f"n={n}, L=3")
        else:
            plt.scatter(ct, depth(ct, n, 3), color=colors2[n - 2], marker=types[n - 2])
            
plt.axhline(22, 0, 8, linestyle="--", color="#CC6666")
plt.legend()

plt.figure(figsize=(7, 5))

# layer 1
# layer 1 qubit 3
plt.grid()
plt.ylim(0.4, 0.6)
plt.xlim(1, 1.7)
plt.title("原始线路与丢弃处理后线路的可表达性与纠缠能力", fontsize=13)
plt.xlabel("Expr", fontsize=13)
plt.ylabel("Ent", fontsize=13)
plt.scatter(1.6105, 0.5622, color="#FF9966", label="原始线路")
plt.scatter(1.4415, 0.5158, color="#FF6666", label="纠缠丢弃")
plt.scatter(1.1185, 0.4283, color="#3399CC", label="旋转丢弃")
plt.legend(loc='upper left')

