import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import numpy as np
from ipywidgets import interact, interactive, fixed, interact_manual, FloatSlider, Layout
import ipywidgets as widgets
sns.set(style='whitegrid', palette='deep', font_scale=1.1, rc={'figure.figsize': [8, 5]})
plt.rcParams['figure.figsize'] = [12, 8]


# load dataframe
filepath = "../datasets/universal_error/DepolOnly/U3_19.csv"
df = pd.read_csv(filepath)

# reorder columns
df = df[['theta', 'phi', 'lam', 'E', 'depol_prob', 't1', 't2', 'population', 'p0_0', 'p0_1', 'p1_0', 'p1_1']]

# filters
labels = ['theta', 'phi', 'lam', 'E']
depol_columns = ['depol_prob']
thermal_columns = ['t1', 't2', 'population']
readout_columns = ['p0_0', 'p0_1', 'p1_0', 'p1_1']

# filtered dataframes
ideal_only = df.query('depol_prob == 0 & t1 == inf & t2 == inf & p0_0 == 1 & p1_1 == 1')

@interact
def show_gates_more_than(theta_range=widgets.FloatRangeSlider(value=[0, 6.3], min = 0.0, max=2*np.pi, layout=Layout(width='80%')),
                         lam_range=widgets.FloatRangeSlider(value=[0, 6.3], min = 0.0, max=2*np.pi, layout=Layout(width='80%')),
                        phi_values=widgets.SelectMultiple(options=ideal_only['phi'].unique(), value=tuple(ideal_only['phi'].unique()))):
    filtered = ideal_only.loc[(ideal_only['theta'].between(theta_range[0],theta_range[1])) & (ideal_only['lam'].between(lam_range[0],lam_range[1])) & (ideal_only['phi'].isin(phi_values))]
    #     filtered = filtered.loc[filtered[]]
    sns.scatterplot(x='theta', y='E', hue="lam", data=filtered);

depol_only = df.query('p0_0 == 1 & p1_1 == 1 & t1 == inf & t2 == inf')[labels + depol_columns]

sns.scatterplot(x=depol_only['theta'], y=depol_only['E']);


sns.regplot(x=depol_only['lam'], y=depol_only['E'])