def _subsystem_apply_reference(state, channel, mask): if isket(state): state = ket2dm(state) if isoper(channel): full_oper = tensor([channel if mask[j] else qeye(state.dims[0][j]) for j in range(len(state.dims[0]))]) return full_oper * state * full_oper.dag() else: # Go to Choi, then Kraus # chan_mat = array(channel.data.todense()) choi_matrix = super_to_choi(channel) vals, vecs = eig(choi_matrix.full()) vecs = list(map(array, zip(*vecs))) kraus_list = [sqrt(vals[j]) * vec2mat(vecs[j]) for j in range(len(vals))] # Kraus operators to be padded with identities: k_qubit_kraus_list = product(kraus_list, repeat=sum(mask)) rho_out = Qobj(inpt=zeros(state.shape), dims=state.dims) for operator_iter in k_qubit_kraus_list: operator_iter = iter(operator_iter) op_iter_list = [next(operator_iter).conj().T if mask[j] else qeye(state.dims[0][j]) for j in range(len(state.dims[0]))] full_oper = tensor(list(map(Qobj, op_iter_list))) rho_out = rho_out + full_oper * state * full_oper.dag() return Qobj(rho_out)
def _subsystem_apply_reference(state, channel, mask): if isket(state): state = ket2dm(state) if isoper(channel): full_oper = tensor([ channel if mask[j] else qeye(state.dims[0][j]) for j in range(len(state.dims[0])) ]) return full_oper * state * full_oper.dag() else: # Go to Choi, then Kraus # chan_mat = array(channel.data.todense()) choi_matrix = super_to_choi(channel) vals, vecs = eig(choi_matrix.full()) vecs = list(map(array, zip(*vecs))) kraus_list = [ sqrt(vals[j]) * vec2mat(vecs[j]) for j in range(len(vals)) ] # Kraus operators to be padded with identities: k_qubit_kraus_list = product(kraus_list, repeat=sum(mask)) rho_out = Qobj(inpt=zeros(state.shape), dims=state.dims) for operator_iter in k_qubit_kraus_list: operator_iter = iter(operator_iter) op_iter_list = [ next(operator_iter) if mask[j] else qeye(state.dims[0][j]) for j in range(len(state.dims[0])) ] full_oper = tensor(list(map(Qobj, op_iter_list))) rho_out = rho_out + full_oper * state * full_oper.dag() return Qobj(rho_out)
def test_SuperChoiSuper(self): """ Superoperator: Converting superoperator to Choi matrix and back. """ h_5 = rand_herm(5) superoperator = propagator(h_5, scipy.rand(), [create(5), destroy(5), jmat(2, 'z')]) choi_matrix = super_to_choi(superoperator) test_supe = choi_to_super(choi_matrix) assert_((test_supe - superoperator).norm() < 1e-12)
def test_ChoiKrausChoi(self): """ Superoperator: Converting superoperator to Choi matrix and back. """ h_5 = rand_herm(5) superoperator = propagator(h_5, scipy.rand(), [create(5), destroy(5), jmat(2, 'z')]) choi_matrix = super_to_choi(superoperator) kraus_ops = choi_to_kraus(choi_matrix) test_choi = kraus_to_choi(kraus_ops) assert_((test_choi - choi_matrix).norm() < 1e-12)
def test_SuperChoiSuper(self): """ Superoperator: Converting superoperator to Choi matrix and back. """ h_5 = rand_herm(5) superoperator = propagator( h_5, scipy.rand(), [create(5), destroy(5), jmat(2, 'z')]) choi_matrix = super_to_choi(superoperator) test_supe = choi_to_super(choi_matrix) assert_((test_supe - superoperator).norm() < 1e-12)
def test_ChoiKrausChoi(self): """ Superoperator: Converting superoperator to Choi matrix and back. """ h_5 = rand_herm(5) superoperator = propagator( h_5, scipy.rand(), [create(5), destroy(5), jmat(2, 'z')]) choi_matrix = super_to_choi(superoperator) kraus_ops = choi_to_kraus(choi_matrix) test_choi = kraus_to_choi(kraus_ops) assert_((test_choi - choi_matrix).norm() < 1e-12)