Extend partial trace over mulitple subsystems
In quantum information, it's often the case that we need to trace out multiple subsystems. This was useful for me, maybe it will be for others.
I just add the possibility to pass a list or a tuple to parameter k
. Element of this list will be indices of subsystems to trace out.
In practice, nothing is new on the code: the partial_trace
method is called recursively with corrected list of subsystems dimension parameter dim
(deletion of subsystem traced out) for each element in k.
Here is an example:
import picos as pcs
import numpy as np
A = pcs.new_param('A',np.array([[1,2],[3,4]]))
B = pcs.new_param('B',np.array([[5,6],[7,8]]))
C = pcs.new_param('C',np.array([[8,9,10],[1,1,1],[7,8,1]]))
# We construct M from three partitions
M = pcs.kron(pcs.kron(A,B),C)
# Partial trace over one subsystem
M.partial_trace(k=1,dim=[2,2,3])
# New: partial trace other a list of subsystems (here trace out Alice and Charlie)
M.partial_trace(k=[0,2],dim=[2,2,3])
M.partial_trace(k=(2,0),dim=[2,2,3])