When simulating a circuit using qasm simulator, if there is a depolarizing channel in the noise model, then the results could be mixed states. How can I calculate the density matrix of the mixed states?
The easiest way to do this would be to probably use the density matrix snapshot instruction: https://qiskit.org/documentation/stubs/qiskit.providers.aer.extensions.SnapshotDensityMatrix.html#qiskit.providers.aer.extensions.SnapshotDensityMatrix basically just add
circuit.snapshot_density_matrix('density_matrix') to your circuit where you want to get the density matrix. That will store the density matrix in the output results. Here is an example script:
from qiskit.test.mock import FakeVigo from qiskit import QuantumCircuit from qiskit.providers.aer import extensions # import aer snapshot instructions from qiskit import execute qc = QuantumCircuit(2) qc.h(0) qc.cx(0, 1) qc.snapshot_density_matrix('density_matrix') result = execute(qc, FakeVigo()).result() # Extract density matrix snapshot from result object: density_matrix = result.data()['snapshots']['density_matrix']['density_matrix']['value'] print(density_matrix)
In that script
FakeVigo is just running Aer under the covers with a noise model taken from a snapshot of the backend properties from the IBMQ vigo device.