# Measure a quantum swap between the two qubits and perform a tomography of the resulting states.
# Before you run this script, make sure that the Rabi pulses for both qubits are calibrated!
import sys
from instruments import *
from config.startup import *

importModule("scripts.state_tomography.state_simulation")


def measureSwapSequence(
    swapDuration=0,
    pulseHeight=0,
    delayBeforeTomography=0,
    measurements=["zz"],
    averaging=100,
    state=[[0, 0], [math.pi, 0]],
    piLength=0,
    tomographyLength=0,
    tomographyDelay=0,
    xyRotation=0,
    measurementRotations=None,
    use12Pulse=False,
    alpha=0,
    beta=0,
    zrot=0,
):

    f_sb1 = qubit1.parameters()["pulses.xy.f_sb"]
    f_sb2 = qubit2.parameters()["pulses.xy.f_sb"]

    from instruments.qubit import PulseSequence
	state = state/norm(state)
	rho = vectorizeRho(adjoint(state)*state)

	rhos = integrate(rho,lambda t:LL(t,signs = signs),times,dt = 0.01)
	for i in range(0,len(rhos)):
		child.set(t = times[i])
		rho = devectorizeRho(rhos[i])
		for j in range(0,len(rho)):
			for k in range(0,len(rho)):
				child.set(**{str(j)+str(k) : rho[j,k]})
		child.commit()
	child.parameters()["defaultPlot"]=[["t","11"],["t","22"],["t","33"],["t","44"]]
	rhosvec.append(rhos)
##We plot the results of the simulation...
from config.startup import importModule
importModule("scripts.state_tomography.plot_density_matrix")
from scripts.state_tomography.plot_density_matrix import *
figure("grover simulation")
clf()
k = 0
for rhos in rhosvec:
	subplot(4,4,1+k*4)
	plotDensityMatrix(devectorizeRho(rhos[0]),figureName = None,annotate = False)
	subplot(4,4,2+k*4)
	plotDensityMatrix(devectorizeRho(rhos[t1+1]),figureName = None,annotate = False)
	subplot(4,4,3+k*4)
	plotDensityMatrix(devectorizeRho(rhos[t1+t2+t3+1]),figureName = None,annotate = False)
	subplot(4,4,4+k*4)
	plotDensityMatrix(devectorizeRho(rhos[-1]),figureName = None,annotate = False)
	show()
	k+=1