Page MenuHomec4science

QRSP_qutip.py
No OneTemporary

File Metadata

Created
Mon, May 20, 21:33

QRSP_qutip.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Feb 28 16:35:36 2020
@author: david
"""
import qutip
import numpy as np
from math import factorial as fac
from math import sqrt
def rho_out(rho, w, aa):
"""
Calculate output density matrix
Parameters
----------
rho : qutip.Qobj
input density matrix of dims [[Nmax] * Nmodes, [Nmax] * Nmodes]
w : array-like
List or array of mixing elements of lengt (2 * Nmodes)
see
Returns
-------
rho_final : TYPE
DESCRIPTION.
"""
dims = rho.dims
N_states = np.prod(dims[0])
N_fock = rho.dims[0][0]
N_modes = int(len(w)/2)
aa_out = aa_mixed(w, aa)
# rho_final = qutip.Qobj(dims=[[N_max**N_modes], [N_max**N_modes]])
vac = qutip.tensor([qutip.fock(N_fock, 0)]*N_modes)
mat = np.empty((N_fock, N_fock), dtype=complex)
for n1 in range(N_fock):
for n2 in range(N_fock):
rho_op = (aa_out**n1) * rho * (aa_out.dag() **n2)
mat[n1, n2] = qutip.expect(rho_op, vac) / sqrt(fac(n1)*fac(n2))
rho_final = qutip.Qobj(mat)
rho_final /= rho_final.tr()
return rho_final
def aa_mixed(w, aa):
N_modes = len(aa)
aa_out = qutip.Qobj(dims=aa[0].dims)
c = w.reshape((N_modes, 2))
coeffs = c[:,0] + 1j * c[:,1]
for i in range(N_modes):
aa_out += coeffs[i] * aa[i]
return aa_out
def error_fidelity(w, rho1, rho_target, aa):
"""cost function to minimize. currently: tracedistance"""
rho = rho_out(rho1, w, aa) # mixing the output modes
res = 1 - qutip.fidelity(rho, rho_target)# qutip.tracedist(rho, rho_target) # calculate the tracedistance
return res
def constraint(w):
"define constraints for the absolut values of the mixing coeffs"
return sum(abs(w)**2) - 1 # returns zero if constraint is satisfied

Event Timeline