Skip to content

Allow measure_entanglement to calculate entanglement for multiple qubits - #206

Open
madcpf wants to merge 10 commits into
quantumlib:mainfrom
madcpf:mul
Open

madcpf wants to merge 10 commits into
quantumlib:mainfrom
madcpf:mul

Conversation

@madcpf

@madcpf madcpf commented Aug 1, 2024 •

Copy link
Copy Markdown
Collaborator

Update quantum world to

  • allow measure_entanglement to calculate entanglement for multiple qubits;
  • add a new method to print pairwise entanglement results into a table.

@madcpf
madcpf requested a review from dstrain115 August 1, 2024 23:05
Comment thread unitary/alpha/quantum_world.py Outdated
from unitary.alpha.qudit_state_transform import qudit_to_qubit_unitary, num_bits
import numpy as np
import itertools
from itertools import combinations

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Prefer import itertools then itertools.combinations below

"Use import statements for packages and modules only, not for individual types, classes, or functions."
https://google.github.io/styleguide/pyguide.html#22-imports

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 813714d: this now uses import itertools and calls itertools.combinations(...).

Comment thread unitary/alpha/quantum_world.py Outdated
entanglement[j][i] = entanglement[i][j]
names = list(self.object_name_dict.keys())
data_frame = pd.DataFrame(entanglement, index=names, columns=names)
print(data_frame.round(1))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we return the data_frame (or some other result) instead of printing it?
Printing it seems generally unhelpful if we are using this within a game.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed in 813714d and the follow-up correctness commit 2c03bc9: the pairwise helper now returns a DataFrame instead of printing it. The follow-up also returns full-precision values and names the API get_mutual_information_table() to match what it computes.

entropy = [0.0] * num_qubits
entropy_pair = np.zeros((num_qubits, num_qubits))
entanglement = np.zeros((num_qubits, num_qubits))
for i in range(num_qubits - 1):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this block is fairly tough to follow. I would add comments below or in the function's docstring to explain the implementation details.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Addressed. I expanded the docstring/comments around the multipartite entropy calculation, and the follow-up 2c03bc9 makes the definition explicit: bipartite quantum mutual information for two objects and quantum dual total correlation for N > 2, with the corresponding entropy formula and reference.

@mhucka

mhucka commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

@madcpf Thank you for this PR last year. It has been quite some time – could you let us know the status, and whether you are williing and interested in addressing the review comments above?

@mhucka mhucka added the status/awaiting-response Waiting on a response to a question or request label Aug 28, 2025
@mhucka mhucka removed the status/awaiting-response Waiting on a response to a question or request label Sep 19, 2025
@mhucka mhucka moved this to Nudged in Follow-up tracker Oct 9, 2025
@madcpf

madcpf commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

@mhucka @dstrain115 Thanks for following up, and apologies for the long delay. I’ve updated the PR and am still interested in finishing it.

I addressed the three review comments:

  • switched to import itertools / itertools.combinations(...);
  • changed the pairwise helper to return a DataFrame instead of printing, with full-precision values;
  • expanded the implementation comments/docstrings around the entropy calculation.

While revisiting the code I also found and fixed two related correctness issues in a separate follow-up commit: density matrices now preserve complex phase instead of reconstructing amplitudes from computational-basis frequencies, and the N > 2 case now uses the correct quantum dual-total-correlation entropy formula while the two-object case remains standard quantum mutual information.

The branch is synced with current main and the PR is mergeable again. Formatting and pylint checks are passing; the remaining GitHub Actions checks are currently running. Thanks again for the review.

@madcpf
madcpf requested a review from dstrain115 October 2, 2026 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants