-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add is_entangled method to Statevector class (#14188) #14191
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
base: main
Are you sure you want to change the base?
Conversation
|
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:
|
ShellyGarion
left a comment
There was a problem hiding this 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): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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:
Tests:
Added unit tests covering both entangled (Bell, GHZ) and separable (product) states.