Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial transpose function in quantum_info #9566

Merged
merged 31 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5ba4856
partial_transpose included
PayalSolanki2906 Feb 9, 2023
a93623a
included partial_transpose
PayalSolanki2906 Feb 9, 2023
1a162dd
included partial_transpose
PayalSolanki2906 Feb 9, 2023
a7cbffe
included partial_transpose
PayalSolanki2906 Feb 9, 2023
95d99a5
included partial_transpose
PayalSolanki2906 Feb 9, 2023
ea9f8f0
included partial_transpose
PayalSolanki2906 Feb 10, 2023
2ff5294
included partial_transpose
PayalSolanki2906 Feb 10, 2023
ae400f1
included partial_transpose
PayalSolanki2906 Feb 10, 2023
28ba225
included partial_transpose
PayalSolanki2906 Feb 10, 2023
91cc3c1
included partial_transpose
PayalSolanki2906 Feb 10, 2023
d03e70e
included partial_transpose
PayalSolanki2906 Feb 10, 2023
fc1d655
included partial_transpose
PayalSolanki2906 Feb 10, 2023
a2c8a05
included test for partial transpose
PayalSolanki2906 Feb 10, 2023
35882a4
included test for partial transpose
PayalSolanki2906 Feb 10, 2023
3934c8c
included test for partial transpose
PayalSolanki2906 Feb 10, 2023
2a22078
added docstring
PayalSolanki2906 Feb 10, 2023
788f960
included DensityMatrix(rho1)
PayalSolanki2906 Feb 10, 2023
a3a16fb
changed rho1
PayalSolanki2906 Feb 10, 2023
c498c77
addition of release note
PayalSolanki2906 Feb 10, 2023
68f1ef6
Merge branch 'main' into pp-parttr
PayalSolanki2906 Feb 11, 2023
8e2684a
Merge branch 'main' into pp-parttr
PayalSolanki2906 Feb 14, 2023
934941f
Merge branch 'pp-parttr' of https://github.com/PayalSolanki2906/qiski…
PayalSolanki2906 Feb 14, 2023
3832e74
fix
PayalSolanki2906 Feb 16, 2023
11d5adc
fix
PayalSolanki2906 Feb 16, 2023
0ab74ea
fir partial_transpose
PayalSolanki2906 Feb 16, 2023
d944e23
Update utils.py
PayalSolanki2906 Feb 16, 2023
4f0a8c8
Merge branch 'main' into pp-parttr
ikkoham Apr 12, 2023
84bd450
refactor and add tests
ikkoham Apr 12, 2023
e7c53ee
Merge pull request #1 from ikkoham/pp-parttr
PayalSolanki2906 Apr 13, 2023
5edcf20
Merge branch 'main' into pp-parttr
PayalSolanki2906 Apr 13, 2023
1b92492
Merge branch 'main' into pp-parttr
PayalSolanki2906 Apr 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions qiskit/quantum_info/states/densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,3 +809,29 @@ def to_statevector(self, atol=None, rtol=None):

psi = evecs[:, np.argmax(evals)] # eigenvectors returned in columns.
return Statevector(psi)

def partial_transpose(self, qargs):
"""Return partially transposed density matrix.

Args:
qargs (list): The subsystems to be transposed.

Returns:
DensityMatrix: The partially transposed density matrix.

Raises:
QiskitError: if input state is invalid.

"""
from qiskit.quantum_info.states import utils

state = utils._format_state(self, validate=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need _format_state and reshape? self is DensityMatrix by definition.

arr = state._data.reshape(state._op_shape.tensor_shape)
qargs = len(state._op_shape.dims_l()) - 1 - np.array(qargs)
n = len(state.dims())
lst = list(range(2 * n))
for i in qargs:
lst[i], lst[i + n] = lst[i + n], lst[i]
rho = np.transpose(arr, lst)
rho = np.reshape(rho, state._op_shape.shape)
return DensityMatrix(rho)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

features:
- |
The partial transpose operation has been integrated into the quantum_info module, allowing for partial transposition of matrices.
This operation is key in detecting entanglement between bipartite quantum system.
11 changes: 11 additions & 0 deletions test/python/quantum_info/states/test_densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,17 @@ def test_drawings(self):
with self.subTest(msg=f"draw('{drawtype}')"):
dm.draw(drawtype)

def test_density_matrix_partial_transpose(self):
"""Test partial_transpose function on density matrices"""
rho = DensityMatrix.from_label("10+")
rho1 = np.zeros((8, 8), complex)
rho1[4, 4] = 0.5
rho1[4, 5] = 0.5
rho1[5, 4] = 0.5
rho1[5, 5] = 0.5
self.assertEqual(DensityMatrix.partial_transpose(rho, [0, 1]), DensityMatrix(rho1))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DensityMatrix.partial_transpose is not classmethod, so DensityMatrix(rho).partial_transpose([0, 1]) is correct.

self.assertEqual(DensityMatrix.partial_transpose(rho, [0, 2]), DensityMatrix(rho1))


if __name__ == "__main__":
unittest.main()