Skip to content

Conversation

@default741
Copy link

@default741 default741 commented Apr 7, 2025

Summary

This PR addresses issue #14188 by introducing a new method is_entangled to the Statevector class. This method efficiently determines if a given quantum state is entangled based on the Von Neumann entropy criterion, evaluating individual qubit subsystems.

Details and comments

The added method simplifies the entanglement analysis process for users by providing a clear, built-in functionality directly within the Statevector class.

Implementation:

    def is_entangled(self, epsilon: float = 1e-10) -> bool:
        """Returns True is a Statevector is Entangled else False."""
        from qiskit.quantum_info import DensityMatrix, partial_trace, entropy

        density_matrix = DensityMatrix(self)

        for qubit in range(self.num_qubits):
            trace_out = [i for i in range(self.num_qubits) if i != qubit]
            subsystem_entropy = entropy(partial_trace(density_matrix, trace_out))

            if subsystem_entropy > epsilon:
                return True
        return False

Tests:
Added unit tests covering both entangled (Bell, GHZ) and separable (product) states.

def test_is_entangled(self):
        """Test is_entangled method."""
        qc_2 = QuantumCircuit(2)
        qc_3 = QuantumCircuit(3)
        qc_2.h(0)
        qc_2.cx(0, 1)
        qc_3.h(0)
        qc_3.cx(0, 1)
        qc_3.cx(0, 2)
        ne_state_2 = Statevector.from_label("++")
        ne_state_3 = Statevector.from_label("+++")
        self.assertFalse(ne_state_2.is_entangled())
        self.assertFalse(ne_state_3.is_entangled())
        e_state_2 = Statevector.from_instruction(qc_2)
        e_state_3 = Statevector.from_instruction(qc_3)
        self.assertTrue(e_state_2.is_entangled())
        self.assertTrue(e_state_3.is_entangled())

@default741 default741 requested a review from a team as a code owner April 7, 2025 17:04
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Apr 7, 2025
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@CLAassistant
Copy link

CLAassistant commented Apr 7, 2025

CLA assistant check
All committers have signed the CLA.

@ShellyGarion ShellyGarion added the mod: quantum info Related to the Quantum Info module (States & Operators) label Apr 12, 2025
Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution to qiskit, this seems as a potentially interesting and useful method to add. Do you have a reference for it?

Could you please better explain what you mean by "entangled" vs. "separable".
For example, take this state which is a tensor product of two entangled states:

        qc_4 = QuantumCircuit(4)
        qc_4.h(0)
        qc_4.cx(0, 1)
        qc_4.h(2)
        qc_4.cx(2, 3)
        state_4 = Statevector(qc_4)
        print(state_4.is_entangled()) # outputs True

What is the relation between the is_entangled method and other functions like
https://docs.quantum.ibm.com/api/qiskit/quantum_info#schmidt_decomposition and
https://docs.quantum.ibm.com/api/qiskit/quantum_info#entanglement_of_formation

I also have a few minor comments. In addition, could you add some release notes?

pass

@abstractmethod
def is_entangled(self, epsilon: float = 1e-10):
Copy link
Member

Choose a reason for hiding this comment

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

it is better to use the existing atol/rtol parameters than epsilon (see the is_valid function above)

norm = np.linalg.norm(self.data)
return np.allclose(norm, 1, rtol=rtol, atol=atol)

def is_entangled(self, epsilon: float = 1e-10) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

it is better to use the existing atol/rtol parameters than epsilon (see the is_valid function above)


def is_entangled(self, epsilon: float = 1e-10) -> bool:
"""Returns True is a Statevector is Entangled else False."""
from qiskit.quantum_info import DensityMatrix, partial_trace, entropy
Copy link
Member

Choose a reason for hiding this comment

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

these imports yield lint errors due to cyclic imports.
can you try importing each one from the relevant file to avoid the lint errors?

trace_out = [i for i in range(self.num_qubits) if i != qubit]
subsystem_entropy = entropy(partial_trace(density_matrix, trace_out))

if subsystem_entropy > epsilon:
Copy link
Member

Choose a reason for hiding this comment

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

can subsystem_entropy be negative?

self.assertFalse(ne_state_2.is_entangled())
self.assertFalse(ne_state_3.is_entangled())
e_state_2 = Statevector.from_instruction(qc_2)
e_state_3 = Statevector.from_instruction(qc_3)
Copy link
Member

Choose a reason for hiding this comment

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

you can use:

        e_state_2 = Statevector(qc_2)
        e_state_3 = Statevector(qc_3)

directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: quantum info Related to the Quantum Info module (States & Operators)

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Add is_entangled Method to Statevector Class for Entanglement Check

4 participants