I would like to measure the ancillae to know about the information of the system density matrix. I have a system density matrix and I would like to evolve through a unitary operator after adding some ancillae qubits. Further I would like to trace out the enviornment like all the ancillae qubits and wants to evaluate the purity of the system density matrix. Here when I would like to impliment this things in pennylane how to perform indirect measurement towards ancillae qubits. I am attaching my code please have a look.
devRho = qml.device("default.mixed", wires=n)
@qml.qnode(devRho)
def processRho(thetas, rho):
'''
Input is parameter of thetas of unitary, and rho is the system enviornment density matrix where wire 0 is for system and rest for the enviornment.
'''
qml.QubitDensityMatrix(rho, wires=wireList)
# qml.adjoint(qml.SpecialUnitary(thetas, wires=wireList))
# qml.ApproxTimeEvolution(H, tau, 100)
qml.SpecialUnitary(thetas, wires=wireList)
return qml.density_matrix([0])
The purity function for that theta is follows :
@qml.qnode(devRho)
def purity(thetas):
'''
Initializes a density matrix and takes its purity.
'''
qml.QubitDensityMatrix(processRho(thetas, rho), wires=0)
return qml.purity(0)
def cost(thetas):
'''
Computes linear entropy from purity.
'''
return 1 - purity(thetas)
My point is we know measurment is required to know the information about the system qubit before tracing out ancillae so when I need to perform the measurement and through which operator I need to perform measurement.