Beispiel #1
0
    def steadystate_parfor(self,
                           Deltas,
                           num_cpus=None,
                           recalc=True,
                           savefile=None):

        savefile_exists = os.path.isfile(str(savefile) + '.qu')

        # If 1) we ask for it to be recalculated or 2) it *must* be calculated
        # because no savefile exists: do the steady state calc. Else load file.
        if (recalc or not savefile_exists):

            # Reset rho_Delta in case of multiple calcs
            self.rho_Delta = [None] * len(self.Delta_range)
            Deltas_i = list(Deltas)  # Make copy, don't modify in place

            Delta_steps = len(self.Delta_range) - 1

            self.rho_Delta = qu.parfor(steadystate_parfor_func,
                                       self.Delta_range,
                                       Delta_idx=self.Delta_idx,
                                       Deltas=Deltas_i,
                                       ob_obj=self.ob_obj,
                                       num_cpus=num_cpus)

            # Only save the file if we have a place to save it
            if (savefile != None):
                qu.qsave(self.rho_Delta, savefile)

        # Otherwise load the steady state rho_v_delta from file
        else:
            self.rho_Delta = qu.qload(savefile)

        return self.rho_Delta
Beispiel #2
0
    def mesolve(self,
                tlist,
                rho0=None,
                td=False,
                e_ops=[],
                args={},
                opts=qu.Options(),
                recalc=True,
                savefile=None,
                show_pbar=False):

        if not rho0:
            rho0 = self.ground_state()

        savefile_exists = os.path.isfile(str(savefile) + '.qu')

        # Solve if 1) we ask for it to be recalculated or 2) it *must* be
        # calculated because no savefile exists.
        if recalc or not savefile_exists:

            # Is the Hamiltonian time-dependent?
            if td:  # If so H is a list of [H_i, t_func_i] pairs.
                H = [self.H_0, self.H_Delta]
                H.extend(self.H_I_list())
            else:  # If not it's a single QObj
                H = self.H_0 + self.H_Delta + self.H_I_sum()

            if show_pbar:
                pbar = qu.ui.progressbar.TextProgressBar()
            else:
                pbar = qu.ui.progressbar.BaseProgressBar()

            self.result = qu.mesolve(H,
                                     rho0,
                                     tlist,
                                     self.c_ops,
                                     e_ops,
                                     args=args,
                                     options=opts,
                                     progress_bar=pbar)

            self.rho = self.result.states[-1]  #  Set rho to the final state.

            # Only save the file if we have a place to save it.
            if savefile:

                print('Saving OBBase to {0}.qu'.format(savefile))

                qu.qsave(self.result, savefile)

        # Otherwise load the steady state rho_v_delta from file
        else:

            print('Loading from {0}.qu'.format(savefile))

            self.result = qu.qload(savefile)
            self.rho = self.result.states[-1]

        return self.result
Beispiel #3
0
    def essolve(self, tlist, rho0=None, recalc=True, savefile=None):
        """ 
        Evolution of the density matrix by
        expressing the ODE as an exponential series.

        Args:
            tlist: The list of times for which to find the density matrix.
            rho0: Define an initial density matrix. Default is ground state.
            recalc: Rerun the calculation if a saved file exists?
            savefile: (string) Save the data to savefile.qu

        Returns:
            result: qutip result object containing the solved data.

        Notes:
            QuTiP essolve method doesn't return the states properly so I use
            the underlying ode2es method.

            Unlike the mesolve method, the tlist here doesn't have any need 
            for high resolution to solve. So better when the density matrix 
            is only needed at a few points.

        """

        if not rho0:
            rho0 = self.ground_state() * self.ground_state().dag()

        savefile_exists = os.path.isfile(str(savefile) + '.qu')

        # Solve if 1) we ask for it to be recalculated or 2) it *must* be
        # calculated because no savefile exists.
        if (recalc or not savefile_exists):

            H = self.H_0 + self.H_Delta + self.H_I_sum()
            L = qu.liouvillian(H, self.c_ops)

            es = qu.ode2es(L, rho0)
            states = es.value(tlist)

            self.result = qu.solver.Result()
            self.result.states = states
            self.result.solver = "essolve"
            self.result.times = tlist

            self.rho = self.result.states[-1]  # Set rho to the final state.

            # Only save the file if we have a place to save it.
            if (savefile != None):
                qu.qsave(self.result, savefile)

        # Otherwise load the steady state rho_v_delta from file
        else:
            self.result = qu.qload(savefile)
            self.rho = self.result.states[-1]

        return self.result
Beispiel #4
0
def test_qsave_qload():
    ops_in = [
        qutip.sigmax(),
        qutip.num(_dimension),
        qutip.coherent_dm(_dimension, 1j)
    ]
    filename = _random_file_name()
    qutip.qsave(ops_in, filename)
    ops_out = qutip.qload(filename)
    assert ops_in == ops_out
Beispiel #5
0
 def save_results(self):
     """ Saves the solution to a QuTiP pickle file.
     
     Notes:
         - The path to which the results will be saved is taken from
             self.savefile.
     """
     # Only save the file if we have a place to save it.
     if self.savefile:
         print('Saving MBSolve to', self.savefile+'.qu')
         qu.qsave((self.Omegas_zt, self.states_zt), self.savefile)
Beispiel #6
0
def test_qsave_qload(use_path, suffix):
    ops_in = [
        qutip.sigmax(),
        qutip.num(_dimension),
        qutip.coherent_dm(_dimension, 1j)
    ]
    filename = _random_file_name() + suffix
    if use_path:
        filename = Path.cwd() / filename
    qutip.qsave(ops_in, filename)
    ops_out = qutip.qload(filename)
    assert ops_in == ops_out
Beispiel #7
0
def _default_save_element_fun(save_path, output, ii):
    """ Saves the element using qutip qsave function

    Parameters
    ----------
    save_path : str
        The path to which the data is saved.
    output : obj
        The object to save.
    ii : int
        The serial index of the output element in the simulation.
    """
    import qutip as qutip
    qutip.qsave(output, os.path.join(save_path, 'qobject_' + str(ii)))
Beispiel #8
0
def test_qsave_qload():
    # qsave _always_ appends a suffix to the file name at the time of writing,
    # but in case this changes in the future, to ensure that we never leak a
    # temporary file into the user's folders, we simply apply this test in a
    # temporary directory rather than manually creating a temporary file and
    # modifying the name.
    ops_in = [
        qutip.sigmax(),
        qutip.num(_dimension),
        qutip.coherent_dm(_dimension, 1j)
    ]
    filename = "qsave_qload_test"
    qutip.qsave(ops_in, filename)
    ops_out = qutip.qload(filename)
    assert ops_in == ops_out
Beispiel #9
0
    def essolve(self, Deltas, tlist, rho0=None, recalc=True, savefile=None):

        savefile_exists = os.path.isfile(str(savefile) + '.qu')

        # If 1) we ask for it to be recalculated or 2) it *must* be calculated
        # because no savefile exists: do the steady state calc. Else load file.
        if (recalc or not savefile_exists):

            # Reset rho_Delta in case of multiple calcs
            self.rho_Delta = [None] * len(self.Delta_range)
            self.result_Delta = [None] * len(self.Delta_range)

            Deltas_i = list(Deltas)  # Make copy, don't modify in place

            Delta_steps = len(self.Delta_range) - 1

            for i, Delta_i in enumerate(self.Delta_range):

                print("\rDelta: " + str(Delta_i) + ", " + str(i) + "/" +
                      str(Delta_steps))

                # Set the omega of the chosen beam to the current delta step.
                Deltas_i[self.Delta_idx] = Delta_i
                self.ob_obj.set_H_Delta(Deltas_i)

                try:
                    result = self.ob_obj.essolve(tlist, rho0=rho0)

                except ValueError:
                    print("Failed to solve.")

                self.result_Delta[i] = result
                self.rho_Delta[i] = result.states[-1]

            # Only save the file if we have a place to save it
            if (savefile != None):
                qu.qsave((self.rho_Delta, self.result_Delta), savefile)

        # Otherwise load the steady state rho_v_delta from file
        else:
            (self.rho_Delta, self.result_Delta) = qu.qload(savefile)

        return self.rho_Delta, self.result_Delta
Beispiel #10
0
def excitation(args):
    H0 = args['parity']*args['vFermi']*(args['kpoint'][0]*qp.sigmax() + args['kpoint'][1]*qp.sigmay())
    H1 = qp.sigmax()
    H2 = qp.sigmay()
    Hamiltonian = [H0,[H1,HCoeff]]
    states = H0.eigenstates()  
    psi0 = states[1][0]
    psi1 = states[1][1]
    import hashlib
    label = hashlib.sha224(str(args)).hexdigest()
    import os
    if os.path.exists('Data/'+label+'.qu'):
      result = qp.qload('Data/'+label)
      print 'Loading'
    else:
      result = qp.mesolve(Hamiltonian, psi0, args['times'], [], [], args=args)
      print 'Recalculate'
      qp.qsave(result, 'Data/'+   label)
    proj0 =  np.array([(state.dag()*psi0).norm() for state in result.states])
    proj1 =  np.array([(state.dag()*psi1).norm() for state in result.states])
    return result, proj0, proj1
Beispiel #11
0
    print("Errors:")
    print("OK: ", I_OK)
    print("NOK: ", I_NOK)
    print("E: ", E)
    print("Env E: ", env_error_rate(t_max, a1))
    print("TOTAL E: ", env_error_rate(t_max, a1) + E)
    print("-------------")

    ############################################
    ############################################

    ##################### SAVE DATA ############
    name = names.ghz(ps, pm, pg, eta, a0, a1, theta, len(rho.dims[0]),
                     protocol_name)
    print(name)
    qt.qsave(rhos, name)

    name_time = names.ghz_times(ps, pm, pg, eta, a0, a1, theta,
                                len(rho.dims[0]), protocol_name)
    # np.save("FIDELITY_EPL" + str(a0) + ".npy", fidelity)
    np.save(name_time, times)
    ############################################

# plt.plot(times[indices_sorted], fidelity[indices_sorted], "k.")
# if ignore_number != 0:
#     vline = np.linspace(min(fidelity), max(fidelity))
#     o = np.ones_like(vline)*(t_max)
#     plt.plot(o, vline, 'r--')
#
# plt.ylabel(r"Fidelity", fontsize=17)
# plt.xlabel(r"Time (seg)", fontsize=17)
Beispiel #12
0
ylab = rhoLis[np.clip(np.int_((xlab - eMin)/binSize), 0, 47)]
plt.plot(xlab, ylab)
"""

# Normalized Energy Spacing
grp = 4
per = 0.1 * nEigs
half = int(per/2)
spc = []
for j in range(int((nEigs - per)/grp)):
    avg = (eigs[half + grp*j] - eigs[half + grp*(j-1)])/grp
    for i in range(grp*(j-1), grp*j):
        spc.append((eigs[half + i] - eigs[half + i -1])/avg)
binSize = 0.1
spcM = np.max(spc)
dELis = binSize * (np.arange(int(spcM/binSize)) - 1.)
spcLis = np.zeros(len(dELis) - 1)
for i in range(len(dELis) - 1):
    spcLis[i] = len([x for x in spc if dELis[i] <= x <= dELis[i+1]])
spcLis = np.array(spcLis)/sum(spcLis * binSize)
xlab = np.linspace(0.,spcM,200)
ylab = spcLis[np.clip(np.int_((xlab)/binSize), 0, len(spcLis) - 1)]
wiglab = np.pi * xlab/2. * np.exp(-np.pi * xlab**2 /4.)
poilab = np.exp(- xlab)
fig, ax = plt.subplots(figsize = (10,6))
ax.plot(xlab, ylab, label = "Energy Spacing")
ax.plot(xlab, wiglab, label = "Wigner-like Spacing")
ax.plot(xlab, poilab, label = "Poisson-like Spacing")

quantum.qsave()
Beispiel #13
0
imrhoVVTekk=0.5*((LDVVT-LAVVT-RDVVT+RAVVT)+(DLVVT-DRVVT-ALVVT+ARVVT))/normconstant
rerhoHHTekkCorrection=rerhoHHTekkComplete-rerhoHHTekk
imrhoHHTekkCorrection=imrhoHHTekkComplete-imrhoHHTekk
rerhoHVTekkCorrection=rerhoHVTekkComplete-rerhoHVTekk
imrhoHVTekkCorrection=imrhoHVTekkComplete-imrhoHVTekk
rerhoVHTekkCorrection=rerhoVHTekkComplete-rerhoVHTekk
imrhoVHTekkCorrection=imrhoVHTekkComplete-imrhoVHTekk
rerhoVVTekkCorrection=rerhoVVTekkComplete-rerhoVVTekk
imrhoVVTekkCorrection=imrhoVVTekkComplete-imrhoVVTekk

resultTekkComplete=qutip.Qobj([[rerhoHHTekkComplete+imrhoHHTekkComplete*1j , rerhoHVTekkComplete+imrhoHVTekkComplete*1j],[rerhoVHTekkComplete+imrhoVHTekkComplete*1j, rerhoVVTekkComplete+imrhoVVTekkComplete*1j]])
resultTekk=qutip.Qobj([[rerhoHHTekk+imrhoHHTekk*1j , rerhoHVTekk+imrhoHVTekk*1j],[rerhoVHTekk+imrhoVHTekk*1j, rerhoVVTekk+imrhoVVTekk*1j]])
resultTekkCorrection=qutip.Qobj([[rerhoHHTekkCorrection+imrhoHHTekkCorrection*1j , rerhoHVTekkCorrection+imrhoHVTekkCorrection*1j],[rerhoVHTekkCorrection+imrhoVHTekkCorrection*1j, rerhoVVTekkCorrection+imrhoVVTekkCorrection*1j]])

#save qobjs
qutip.qsave([resultQST, resultDirac, resultTwoAnc, resultTekkComplete, resultTekk, resultTekkCorrection], outputfilename[:-4])
    
#output of final results
print("Final result")
print("rawResultQST = ", rawResultQST)
print("resultQST = ", resultQST)
print("resultDirac = ", resultDirac)
print("resultTwoAnc = ", resultTwoAnc)
print("resultTekkComplete = ", resultTekkComplete)
print("resultTekk = ", resultTekk)
print("resultTekkCorrection = ", resultTekkCorrection)

print("Final result", file = outputFile)
print("rawResultQST = ", rawResultQST, file = outputFile)
print("resultQST = ", resultQST, file = outputFile)
print("resultDirac = ", resultDirac, file = outputFile)
Beispiel #14
0
    def save_results(self):

        # Only save the file if we have a place to save it.
        if self.savefile:
            print('Saving MBSolve to', self.savefile + '.qu')
            qu.qsave((self.Omegas_zt, self.states_zt), self.savefile)
Beispiel #15
0
VVVV = measure(rotQWP1Angle0, rotHWP1Angle0, rotQWP2Angle45, rotHWP2Angle315, rotHWPFinAngle45, lcc1Voltage180, lcc2Voltage0)
print("Counts for VVVV = ", VVVV)
print("Counts for VVVV = ", VVVV, file = outputFile)
resultdata.update({"VVVV": VVVV})

normconstant=4*(VVHH+VVVV)/(np.sin(np.radians(strengthA))**2 * np.sin(np.radians(strengthB))**2)

rhoHHTwoAnc=4*VVHH/normconstant/(np.sin(np.radians(strengthA))**2 * np.sin(np.radians(strengthB))**2)
rhoVVTwoAnc=4*VVVV/normconstant/(np.sin(np.radians(strengthA))**2 * np.sin(np.radians(strengthB))**2)
rerhoHVTwoAnc=strSignA*(RLHV+LRHV-RRHV-LLHV)/normconstant/(np.sin(np.radians(strengthA)) * np.sin(np.radians(strengthB)))
imrhoHVTwoAnc=strSignA*(DLHV-DRHV+ARHV-ALHV)/normconstant/(np.sin(np.radians(strengthA)) * np.sin(np.radians(strengthB)))
rerhoVHTwoAnc=strSignA*(RLVH+LRVH-RRVH-LLVH)/normconstant/(np.sin(np.radians(strengthA)) * np.sin(np.radians(strengthB)))
imrhoVHTwoAnc=strSignA*(DLVH-DRVH+ARVH-ALVH)/normconstant/(np.sin(np.radians(strengthA)) * np.sin(np.radians(strengthB)))
resultTwoAnc=qutip.Qobj([[rhoHHTwoAnc , rerhoHVTwoAnc+imrhoHVTwoAnc*1j],[rerhoVHTwoAnc+imrhoVHTwoAnc*1j, rhoVVTwoAnc]])

qutip.qsave([resultTwoAnc], outputfilename[:-4])

#output of final results
print("Final result")
print("Result = ", resultTwoAnc)

print("The following results are obtained using the diagonal measurements for normalization", file = outputFile)
print("Corrected normalization constant = {0}".format(normconstant), file = outputFile)
print("rhoHH = {0}".format(rhoHHTwoAnc), file = outputFile)
print("\nrhoVV = {0}".format(rhoVVTwoAnc), file = outputFile)
print("\nrerhoHV = {0}".format(rerhoHVTwoAnc), file = outputFile)
print("\nimrhoHV = {0}".format(imrhoHVTwoAnc), file = outputFile)
print("\nrerhoVH = {0}".format(rerhoVHTwoAnc), file = outputFile)
print("\nimrhoVH = {0}".format(imrhoVHTwoAnc), file = outputFile)
print("\nresult = ", resultTwoAnc, file = outputFile)
        return val**0.5
    
    def funcApiB(t, args=0):
        val = complex(i(t))
        return val**0.5
    
    A =k2**0.5*(b_tensor**2-1./2*alpha_inf_abs*(a_tensor+alpha_inf_abs*I_tensor))
    B =k2**0.5*(1./2*alpha_inf_abs*(a_tensor-alpha_inf_abs*I_tensor))
    
    cops = [k1**0.5*a_tensor,k1**0.5*b_tensor]
    cops.append(k2**0.5*(a_tensor**2-alpha_inf_abs**2*I_tensor)) #stabilization control cat
    
    cops.append([A, funcA])
    cops.append([B, funcB])
    cops.append([A+B, funcApB])
    cops.append([A+1j*B, funcApiB])
    
    init_state_C=C_alpha_plus
    control_on=True
    init_state_T=C_alpha_plus
    init_state_tensor=qt.tensor(init_state_C,init_state_T)#initial state
    
    tlist = np.linspace(0,T_final, n_t)
    res_CNOT = qt.mesolve(0*a_tensor, init_state_tensor, tlist, cops,progress_bar=TextProgressBar())#,progress_bar=TextProgressBar())
    
    #np.save(path+'tab_values',res_CNOT.states)
    # cannot save the data because it is an array of Quantum objects
    name='density_with_loss_k2_over_%d'%(ratio)  
    qt.qsave(res_CNOT,path+name)

Beispiel #17
0
import numpy as np
import sys
import json
import os
import qutip as qt
sys.path.append('..')

ROOT = "/Users/btimar/Code/quantum-data-gen"
sys.path.append(ROOT)

from timeev import generate_xy_states

system_sizes = [2, 4, 6, 8, 10]
times = list(np.linspace(0, .01, 5))

SAVEDIR = "/Users/btimar/Dropbox/data/states/qutip/timeev/generate_timeev_states_001"

settings = {'model': 'xy', 'system_sizes': system_sizes, 'times': times}
with open(os.path.join(SAVEDIR, 'settings.json'), 'w') as f:
    json.dump(settings, f)

for L in system_sizes:
    states = generate_xy_states(L, times).states
    for i in range(len(states)):
        qt.qsave(
            states[i],
            os.path.join(SAVEDIR, 'xy_timeev_L={0}_tindex={1}'.format(L, i)))
Beispiel #18
0
rerhoVVCorrection = rerhoVV-rerhoVVTekk

imrhoVV=0.5*((CLDVV-CLAVV-CRDVV+CRAVV)+(CDLVV-CDRVV-CALVV+CARVV)+2*(CLVVV-CRVVV))/normconstant
imrhoVVTekk=0.5*((CLDVV-CLAVV-CRDVV+CRAVV)+(CDLVV-CDRVV-CALVV+CARVV))/normconstant  
imrhoVVCorrection = imrhoVV-imrhoVVTekk

result=qutip.Qobj([[rerhoHH+imrhoHH*1j , rerhoHV+imrhoHV*1j],[rerhoVH+imrhoVH*1j, rerhoVV+imrhoVV*1j]])
resquad=result**2
purity= resquad.tr()
resultTekk=qutip.Qobj([[rerhoHHTekk+imrhoHHTekk*1j , rerhoHVTekk+imrhoHVTekk*1j],[rerhoVHTekk+imrhoVHTekk*1j, rerhoVVTekk+imrhoVVTekk*1j]])
resquadTekk=result**2
purityTekk= resquad.tr()
resultCorrection=qutip.Qobj([[rerhoHHCorrection+imrhoHHCorrection*1j , rerhoHVCorrection+imrhoHVCorrection*1j],[rerhoVHCorrection+imrhoVHCorrection*1j, rerhoVVCorrection+imrhoVVCorrection*1j]])

#save qobjs
qutip.qsave([result, resquad, resultTekk, resquadTekk, resultCorrection], outputfilename[:-4])

jsonfilename=outputfilename[:-4]+".json"
with open(jsonfilename, 'w') as outfile:
    json.dump(resultdata, outfile)

#output of final results
print("Final result")
print("Result = ", result)
print("Resquad = ", resquad)
print("Purity (as trace of resquad) = ", purity)
print("ResultTekk = ", resultTekk)
print("ResquadTekk = ", resquadTekk)
print("Purity (as trace of resquad) = ", purityTekk)
print("Correction = ", resultCorrection)
Beispiel #19
0
normconstant= QSTH+QSTV

rhoHHQST=QSTH/normconstant
rhoVVQST=QSTV/normconstant
rerhoHVQST=strSignA*0.5*(QSTD-QSTA)/(QSTD+QSTA)
imrhoHVQST=strSignA*0.5*(QSTR-QSTL)/(QSTR+QSTL)
rerhoVHQST=rerhoHVQST
imrhoVHQST=-imrhoHVQST

rawresult=qutip.Qobj([[rhoHHQST , rerhoHVQST+imrhoHVQST*1j],[rerhoVHQST+imrhoVHQST*1j, rhoVVQST]])
correction = qutip.Qobj([[1,0],[0,-1]])
result=correction.dag()*rawresult*correction

#save qobjs
qutip.qsave([result, rawresult], outputfilename[:-4])

#output of final results
print("Final results")
print("Raw result = ", rawresult)
print("Corrected result = ", result)

print("Final results", file=outputFile)
print("Raw result = ", rawresult, file=outputFile)
print("Corrected result = ", result, file=outputFile)

stoptime=datetime.datetime.now()
resultdata.update({ "StartTime":str(starttime), "StopTime":str(stoptime)})                    

jsonfilename=outputfilename[:-4]+".json"
with open(jsonfilename, 'w') as outfile:
Beispiel #20
0
#useful values
rho10HA = 0.5* (CDHA-CAHA+1.0j*(CLHA-CRHA))/normconstant
rho10VA = 0.5* (CDVA-CAVA+1.0j*(CLVA-CRVA))/normconstant

d=2
rhoHH=(d*rho11HD+ rho10HA+rho10HD )
rhoHV=(rho10HD-rho10HA )
rhoVH=(rho10VD-rho10VA )
rhoVV=(d*rho11VD+ rho10VA+rho10VD )

result=qutip.Qobj([[rhoHH , rhoHV],[rhoVH, rhoVV]])
resquad=result**2
purity= resquad.tr()

#save qobjs
qutip.qsave([result, resquad], outputfilename[:-4])

jsonfilename=outputfilename[:-4]+".json"
with open(jsonfilename, 'w') as outfile:
    json.dump(resultdata, outfile)

print("\n\n\n")
print("\n\n\n", file = outputFile)
        
print("Finished all measurements\n\n")

print("\n\n\n")
print("\n\n\n", file = outputFile)

#output of final results
print("Final result")
Beispiel #21
0
print("Measuring QSTD")
QSTD = measure(rotQWP1Angle0, rotHWP1Angle45, rotQWP2Angle45, rotHWP2Angle0, rotHWPFinAngle225, lcc1Voltage180, lcc2Voltage90)
print("Counts for QSTD = ", QSTD)
print("Counts for QSTD = ", QSTD, file = outputFile)
resultdata.update({"QSTD": QSTD})

normconstant= QSTH+QSTV

rhoHHQST=QSTH/normconstant
rhoVVQST=QSTV/normconstant
rerhoHVQST=QSTD/normconstant-0.5
imrhoHVQST=QSTR/normconstant-0.5
rerhoVHQST=rerhoHVQST
imrhoVHQST=-imrhoHVQST

resultQST=qutip.Qobj([[rhoHHQST , rerhoHVQST+imrhoHVQST*1j],[rerhoVHQST+imrhoVHQST*1j, rhoVVQST]])

#save qobjs
qutip.qsave([resultQST], outputfilename[:-4])

#output of final results
print("Final result")
print("Result = ", resultQST)

stoptime=datetime.datetime.now()
resultdata.update({ "StartTime":str(starttime), "StopTime":str(stoptime)})                    

jsonfilename=outputfilename[:-4]+".json"
with open(jsonfilename, 'w') as outfile:
    json.dump(resultdata, outfile)
Beispiel #22
0
        
print("Finished all measurements\n\n")

print("\n\n\n")
print("\n\n\n", file = outputFile)

result=qutip.Qobj([[rhoHH , rerhoHV+imrhoHV*1j],[rerhoVH+imrhoVH*1j, rhoVV]])
resquad=result**2
purity= resquad.tr()

resultscheme=qutip.Qobj([[rhoHHscheme , rerhoHVscheme+imrhoHVscheme*1j],[rerhoVHscheme+imrhoVHscheme*1j, rhoVVscheme]])
resquadscheme=resultscheme**2
purityscheme= resquadscheme.tr()

#save qobjs
qutip.qsave([result, resquad, resultscheme, resquadscheme], outputfilename[:-4])

jsonfilename=outputfilename[:-4]+".json"
with open(jsonfilename, 'w') as outfile:
    json.dump(resultdata, outfile)

#output of final results
print("Final result")
print("Result = ", result)
print("Resquad = ", resquad)
print("Purity (as trace of resquad) = ", purity)

print("The following results are obtained using the diagonal measurements for normalization", file = outputFile)
print("Corrected normalization constant = {0}".format(normconstant), file = outputFile)
print("rhoHH = {0}".format(rhoHH), file = outputFile)
print("\nrhoVV = {0}".format(rhoVV), file = outputFile)
Beispiel #23
0
    'rydberg': rydberg_params,
    'heisenberg': heisenberg_params,
    'tfim': tfim_params,
    'ghz': ghz_params
}

SAVEDIR = "/Users/btimar/Dropbox/data/states/qutip"


def get_state(state_name, system_size):
    if state_name == 'ghz':
        param_dict = {**params['ghz'], 'L': system_size}
        return get_ghz_state(param_dict)
    else:
        model_name = state_name.split('_')[0]
        param_dict = {**params[model_name], 'L': system_size}
        return get_ground_state(model_name, param_dict)


with open(os.path.join(SAVEDIR, 'settings.json'), 'w') as f:
    settings = dict(params=params,
                    system_sizes=list(system_sizes),
                    state_names=state_names)
    json.dump(settings, f)

for L in system_sizes:
    for state_name in state_names:
        print("computing state {0} for system size {1}".format(state_name, L))
        psi = get_state(state_name, L)
        qt.qsave(psi, os.path.join(SAVEDIR, "{0}_L={1}".format(state_name, L)))