I want to calculate the 2nd Renyi entropy using the density matrix in Qiskit. To do this, I need to calculate the $Tr(\rho^2)$ for subsystem. The complete system consists of 12 qubits from which I want to choose a subsystem from two specific ones (for example, #3 and #5). I thought to use qiskit.quantum_info.Statevector but if there are other methods I will be glad to hear from you.

Here is my quantum state:

num_qubits = 12
measureZZ = QuantumCircuit(num_qubits,num_qubits)

measureZZ.cx(0, 2)
measureZZ.cx(1, 3)
measureZZ.cx(5, 7)
measureZZ.cx(6, 8)

measureZZ.cx(0, 3)
measureZZ.cx(1, 4)
measureZZ.cx(5, 8)
measureZZ.cx(6, 9)
measureZZ.cx(2, 5)
measureZZ.cx(4, 6)
measureZZ.cx(7, 10)
measureZZ.cx(9, 11)

1 Answer 1


In general, a subsystem could be entangled with the rest of the system and we can not describe it using a state vector. A general method that can be always used to describe the state of a subsystem is density matrix.

To get the reduced density matrix of a subsystem you can use partial_trace.

For example, to get the density matrix for 3rd and 5th qubits:

from qiskit.quantum_info import DensityMatrix
from qiskit.quantum_info.states import partial_trace

traced_over = list(range(0, num_qubits))

rho = DensityMatrix.from_instruction(measureZZ)
rho_3_5 = partial_trace(rho, traced_over)

Note that, in Qiskit you can use DensityMatrix.purity to get $Tr(\rho^2)$

  • $\begingroup$ How do we get the subsystem statevector if we know that the state if separable? For example, if we run Statevector.measure() on some qubits, we know that the state will be separable wrt to these qubits. $\endgroup$
    – mavzolej
    Commented May 24, 2022 at 20:48
  • $\begingroup$ You can get the density matrix of this subsystem using partial_trace as explained. Then call DensityMatrix.to_statevector $\endgroup$ Commented May 25, 2022 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.