mirror of https://github.com/Qiskit/qiskit.git
Fix output of `DensityMatrix.partial_transpose` to match input dimensions (#10163)
* (fix) change output of partial_transpose to return DensityMatrix matching input dimensions * (test) check output dims match input dims when using DensityMatrix.partial_transpose * (docs) add bugfix reno * lint changes * Fix up release note --------- Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
This commit is contained in:
parent
c61b8162e8
commit
6f29d7be78
|
@ -832,4 +832,4 @@ class DensityMatrix(QuantumState, TolerancesMixin):
|
|||
lst[i], lst[i + n] = lst[i + n], lst[i]
|
||||
rho = np.transpose(arr, lst)
|
||||
rho = np.reshape(rho, self._op_shape.shape)
|
||||
return DensityMatrix(rho)
|
||||
return DensityMatrix(rho, dims=self.dims())
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixed the dimensions of the output density matrix from :meth:`.DensityMatrix.partial_transpose`
|
||||
so they match the dimensions of the corresponding input density matrix.
|
|
@ -1219,6 +1219,15 @@ class TestDensityMatrix(QiskitTestCase):
|
|||
self.assertEqual(rho.partial_transpose([0]), DensityMatrix(rho1))
|
||||
self.assertEqual(rho.partial_transpose([1]), DensityMatrix(rho1))
|
||||
|
||||
with self.subTest(msg="dims(3,3)"):
|
||||
mat = np.zeros((9, 9))
|
||||
mat1 = np.zeros((9, 9))
|
||||
mat[8, 0] = 1
|
||||
mat1[0, 8] = 1
|
||||
rho = DensityMatrix(mat, dims=(3, 3))
|
||||
rho1 = DensityMatrix(mat1, dims=(3, 3))
|
||||
self.assertEqual(rho.partial_transpose([0, 1]), rho1)
|
||||
|
||||
def test_clip_probabilities(self):
|
||||
"""Test probabilities are clipped to [0, 1]."""
|
||||
dm = DensityMatrix([[1.1, 0], [0, 0]])
|
||||
|
|
Loading…
Reference in New Issue