Skip to content

add Mutual Information I(a, b)#338

Draft
Fe-r-oz wants to merge 15 commits intoQuantumSavory:masterfrom
Fe-r-oz:entanglement
Draft

add Mutual Information I(a, b)#338
Fe-r-oz wants to merge 15 commits intoQuantumSavory:masterfrom
Fe-r-oz:entanglement

Conversation

@Fe-r-oz
Copy link
Contributor

@Fe-r-oz Fe-r-oz commented Aug 9, 2024

This PR aims to introduce Mutual Information I(A,B) along with improving the doctests and documentation in the entanglement.jl .

In the future, if you like, it would be better to have a entanglement introduced in the manual of either "algebra" or upcoming "circuit simulation" manual.

In the papers, there were many graphs, I think based on entanglement entropy that could be reproduced in a tutorial fashion. Hopefully, this sounds interesting.
....
If you want to submit an unfinished piece of work in order to get comments and discuss, please mark the pull request as a draft and ping the repository maintainer.

Please address only one topic or issue per pull request! Many small PRs are much easier to review and merge than one large PR.

Before merging, all changes and new functionality should be marked in the CHANGELOG file, but feel free to just leave your CHANGELOG notes in the PR description, to avoid merge conflicts with other requests modifying that file. The maintainer will add these CHANGELOG notes for you if you do so.

Before considering your pull request ready for review and merging make sure that all of the following are completed (please keep the clecklist as part of your PR):

  • The code is properly formatted and commented.
  • Substantial new functionality is documented within the docs.
  • All new functionality is tested.
  • All of the automated tests on github pass.

If possible, keep your git history not too wild (rebase and squash commits, keep commits small and semantically separated) so that review is easier.

@Fe-r-oz Fe-r-oz changed the title Mutual Information I(A,B) and improving doctests/documentation in entanglement.jl Mutual Information I(𝒶, 𝒷) and improving doctests/documentation in entanglement.jl Aug 9, 2024
@codecov
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.47%. Comparing base (0035c32) to head (92c96ec).
Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
src/entanglement.jl 85.71% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #338      +/-   ##
==========================================
- Coverage   83.48%   83.47%   -0.02%     
==========================================
  Files          72       72              
  Lines        4802     4834      +32     
==========================================
+ Hits         4009     4035      +26     
- Misses        793      799       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

thanks, this is an interesting addition. I left a few comments in.

@Fe-r-oz Fe-r-oz marked this pull request as draft August 10, 2024 20:59
@Fe-r-oz Fe-r-oz force-pushed the entanglement branch 2 times, most recently from 86d5c0a to f88334b Compare August 18, 2024 14:09
@Fe-r-oz Fe-r-oz marked this pull request as ready for review August 18, 2024 14:44
@Fe-r-oz Fe-r-oz requested a review from Krastanov August 18, 2024 14:45
Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

This looks pretty good.

Apologies for not prioritizing this style of PRs -- you have a lot and I have tried to address the higher value ones first, whenever I have time.

I left a few comments in, mainly motivated by the needs of some other parts of the ecosystem that we try to coordinate with.

# Group theory tools
groupify, minimal_generating_set, pauligroup, normalizer, centralizer, contractor, delete_columns,
# Clipped Gauge
canonicalize_clip!, bigram, entanglement_entropy,
Copy link
Member

Choose a reason for hiding this comment

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

let's not export it as this is something we would want to synchronize with QuantumInterface

Could you post an issue at https://github.com/qojulia/QuantumInterface.jl/ describing the need for a new generic function and referencing this PR. The goal would be to pick a name that can be reused by other packages.

In the meantime, keeping this unexported will let us merge this PR without waiting for that coordination.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Done!

`B(𝒢) ≡ {(𝓁(g₁),𝓇(g₁)),…,(𝓁(gₙ),𝓇(gₙ))}`

The clipped gauge `𝒢` is a specific choice of stabilizer state where exactly two stabilizer endpoints exist at each site,
ensuring `ρₗ(x) + ρᵣ(x) = 2` for all sites `x` where `ρ` represents the reduced density matrix for the subsystem under
Copy link
Member

Choose a reason for hiding this comment

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

That sentence is unclear to me. How can two density matrices sum up to be the scalar 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for helpful comment! I will correct this documentation mistake.

@test entanglement_entropy(copy(s), subsystem, Val(:rref))==2
end

@testset "Mutual information for Clifford circuits" begin
Copy link
Member

Choose a reason for hiding this comment

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

additional tests that use QuantumOptics to double check the results independently would be very valuable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for this very cool suggestion! I will use stuff from QuantumOpticsBase to complete this suggestion!

@Krastanov Krastanov marked this pull request as draft December 20, 2024 17:08
@Fe-r-oz Fe-r-oz changed the title Mutual Information I(𝒶, 𝒷) and improving doctests/documentation in entanglement.jl Mutual Information I(a, b) and improving doctests/documentation in entanglement.jl Feb 20, 2025
@Fe-r-oz Fe-r-oz changed the title Mutual Information I(a, b) and improving doctests/documentation in entanglement.jl add Mutual Information I(a, b) Feb 20, 2025
@Fe-r-oz Fe-r-oz marked this pull request as ready for review February 20, 2025 11:38
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 20, 2025

Please help review this PR, thank you!

My apologies for the delay in adding code review suggestions. I had initially planned to work on the generalized code paper for some time, but I got caught up in them as they seemed quite exciting to read.

Thank you so much for your helpful suggestions! I especially found the suggestion to add QuantumOpticsBase tests in #338 (comment) very helpful and wonderful! I have reduced the code repetition that I did before (my bad) and also added the QuantumOpticsBase tests. I hope that the PR is now polished thanks to your helpful codereview suggestions!

There is now warning that using QOpticsBase.entanglement_entropy conflicts withQC.entanglement_entropy 😅 in the tests!

@Fe-r-oz Fe-r-oz requested a review from Krastanov February 20, 2025 16:28
Copy link
Member

@Krastanov Krastanov left a comment

Choose a reason for hiding this comment

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

  • the addition to docs are great
  • the new capability is definitely very useful
  • the tests for it are great

Couple of notes to double check:

  • the suggested commit simplifies things a bit, but now we need to see what type of error it raises if we try to use :clip
  • making a default does not need kwargs... You can just do mutual_information(state::..., rangea::..., rangeb::...) = mutual_information(state, rangea, rangeb, Val{:rref}())
  • why did the test fail to catch the mistake with union of ranges with a large gap between them? Is something missing from the tests

Last thing, let's add mutual_information to QuantumInterface.jl and import it here (just make a very small PR to QuantumInterface, bump the version number, add changelog, and it will get merged pretty quickly)

@Krastanov Krastanov marked this pull request as draft April 29, 2025 12:07
Fe-r-oz added 2 commits May 4, 2025 18:49
…on-contiguous ranges in with by throwing error as clip has unitrange, so valid only for contiguous regions that don't wrap around
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented May 5, 2025

why did the test fail to catch the mistake with union of ranges with a large gap between them? Is something missing from the tests

Thank you so much for your insights! I’ve fixed an issue where the tests weren’t properly checking for large gaps in the system. The clipped gauge now ensures stabilizers have well-defined left/right endpoints, and the entanglement entropy calculation now correctly errors when non-contiguous regions (e.g., subsystem_rangeA = 1:2, subsystem_rangeB = 5:6) are provided. Additionally, I addressed the out-of-memory errors by using more moderate system sizes, as ket{} becomes computationally expensive for larger systems. The previous implementation was faulty. My bad 🙏🏼

@Fe-r-oz Fe-r-oz marked this pull request as ready for review May 5, 2025 04:20
@Fe-r-oz Fe-r-oz requested a review from Krastanov May 5, 2025 04:39
@Krastanov
Copy link
Member

I have not had a chance to look into this one for a while. Could you let me know whether there is any bitrot and whether we can restart the attempt to merge it. That would require you to re-review your old work before we can proceed.

Marking it as a draft for now, but feel free to convert to non-draft when ready for review.

@Krastanov Krastanov marked this pull request as draft December 31, 2025 21:37
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.

2 participants