
import warnings
warnings.filterwarnings('ignore')

import unittest
import pandas as pd  
import numpy as np

from qiskit import Aer
from qiskit import QuantumCircuit
from qiskit.visualization import plot_histogram, plot_bloch_multivector
from QuantumAssertions import assertPhase, assertEqual
from BenchmarkQA import returnPhase
import math

import qiskit.quantum_info 

import numpy as np

backend = Aer.get_backend('aer_simulator')

# deg = 20

# backend = Aer.get_backend('aer_simulator')
# qc = QuantumCircuit(1,1)

# qc.save_statevector()
# statevector = backend.run(qc).result().get_statevector()
# plot_bloch_multivector(statevector)

qc = QuantumCircuit(2)
qc.h(0)
qc.h(1)
qc.p(10*2*math.pi/100, 0)
qc.p(20*2*math.pi/100, 1)
assertPhase(backend, qc, [0,1], [36,72], 100000, 0.01)

qc = QuantumCircuit(2)
qc.h(0)
qc.h(1)
#qc.p(0.5*2*math.pi/100, 1)
assertEqual(backend, qc, 0, 1, 300000, 0.01)

# ## benchmark 100 shots at 1000 runs 
# shots = 100
# runs = 5000
# df = pd.DataFrame(columns=['results'])
# for i in range(runs):
#     qc = QuantumCircuit(1,1)
#     qc.h(0)
#     qc.p(20*2*math.pi/100, 0)
#     df = df.append({'results': returnPhase(backend, qc, [0], [0], shots, 180)}, ignore_index=True)
#     if (i % 10 == 9):
#         print(f"progress: {i+1}/{runs}")
# df.hist(bins=12)
# print(df)


# ## benchmark 1000 shots at 1000 runs 
# shots = 1000
# runs = 5000
# df = pd.DataFrame(columns=['results'])
# for i in range(runs):
#     qc = QuantumCircuit(1,1)
#     qc.h(0)
#     qc.p(20*2*math.pi/100, 0)
#     df = df.append({'results': returnPhase(backend, qc, [0], [0], shots, 180)}, ignore_index=True)
#     if (i % 10 == 9):
#         print(f"progress: {i+1}/{runs}")
# df.hist(bins=12)
# print(df)

# shots = 10000
# runs = 5000
# df = pd.DataFrame(columns=['results'])
# for i in range(runs):
#     qc = QuantumCircuit(1,1)
#     qc.h(0)
#     qc.p(20*2*math.pi/100, 0)
#     df = df.append({'results': returnPhase(backend, qc, [0], [0], shots, 180)}, ignore_index=True)
#     if (i % 10 == 9):
#         print(f"progress: {i+1}/{runs}")
# df.hist(bins=12)
# print(df)

# shots = 100000
# runs = 5000
# df = pd.DataFrame(columns=['results'])
# for i in range(runs):
#     qc = QuantumCircuit(1,1)
#     qc.h(0)
#     qc.p(20*2*math.pi/100, 0)
#     df = df.append({'results': returnPhase(backend, qc, [0], [0], shots, 180)}, ignore_index=True)
#     if (i % 10 == 9):
#         print(f"progress: {i+1}/{runs}")
# df.hist(bins=12)
# print(df)