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

fix #43: Validate and add docs for Gaussian states containing symbolic variables #44

Merged
merged 32 commits into from
Feb 7, 2025

Conversation

Fe-r-oz
Copy link
Contributor

@Fe-r-oz Fe-r-oz commented Feb 4, 2025

This PR aims to resolve #43 by validating via tests and adding docs for Gaussian objects containing symbolic variables. Symbolics.jl is added to manifest. When I added the packages, the manifest got updated on it's own, so I didn't directly edit it per se, it got automated by machine. Please let me know should I revert the changes to manifest? I am using 1.11.3 so it changed Julia version to 1.11.3 from 1.11.1

I think we have to check all the states to validate which states actually support symbolic operations. So, far I have tested the following states:

  • Symbolic squeezedstate
  • Symbolic coherentstate
  • Symbolic EPR states
  • Symbolic Partial Trace of Beamsplitter-EPR State

Please let me know your thoughts! Thanks you!

@apkille apkille self-requested a review February 4, 2025 16:24
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 4, 2025

I forgot to add the Symbolics.jl to test project.toml that caused the errors! 😅 The tests passed on REPL! Apologies for many spam errors that would have caused. I will test the package on REPL before pushing now.

REPL tests :)

     Testing Running tests...
Starting tests with 1 threads out of `Sys.CPU_THREADS = 4`...
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: Skipped ExpandTemplates step (doctest only).
[ Info: Skipped CrossReferences step (doctest only).
[ Info: Skipped CheckDocument step (doctest only).
[ Info: Skipped Populate step (doctest only).
[ Info: Skipped RenderDocument step (doctest only).
Test Summary: | Pass  Total     Time
Package       |  264    264  2m57.4s
     Testing Gabs tests passed 

We have to add "Missings" that is in the manifest to typos as that causes the spell checker error during the first run of CI.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/Gabs.jl 100.00% <ø> (ø)
src/states.jl 98.13% <100.00%> (+0.01%) ⬆️

Project.toml Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
@Fe-r-oz Fe-r-oz marked this pull request as ready for review February 4, 2025 18:40
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 4, 2025

The PR is ready for review :), Please let me know your thoughts, Thank you!

Copy link
Owner

@apkille apkille left a comment

Choose a reason for hiding this comment

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

Hi Feroz, thanks for this contribution! I left some minor comments on your proposed changes, but besides that it looks good to me. Could you also please do the following:

  • Add tests for thermalstate.
  • Add tests for tensor products of Gaussian states containing symbolic variables.
  • Not in this PR, but in the future, validations should be done with Gaussian unitaries, channels, and application products onto Gaussian states. If you don't plan to submit a PR related to this anytime soon, then could you add a comment in Validate and add docs for Gaussian objects containing symbolic variables #43 that references this PR and states that more tests need to be done for Gaussian operations?

docs/src/tutorials.md Show resolved Hide resolved
docs/src/tutorials.md Outdated Show resolved Hide resolved
test/test_symbolic_states.jl Show resolved Hide resolved
test/test_symbolic_states.jl Show resolved Hide resolved
test/test_symbolic_states.jl Outdated Show resolved Hide resolved
docs/src/tutorials.md Outdated Show resolved Hide resolved
docs/src/tutorials.md Outdated Show resolved Hide resolved
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 6, 2025

The CI errors occurred are due doctest error caused by:

    ERROR: ArgumentError: Package Latexify not found in current path.
│    - Run `import Pkg; Pkg.add("Latexify")` to install the Latexify package.
│    Hint: Latexify is loaded but not imported in the active module Main.
│    Stacktrace:
│     [1] top-level scope
│       @ none:1

I think we can remove Latexify from doctest as that might be a better option as it's not strictly a test 😅. We can mention and use it in the documentation.

Something like: Use Latexify to render newst.covar in LaTeX using Latexify.latexify(newst.covar).

The tests pass now :)

     Testing Running tests...
Starting tests with 1 threads out of `Sys.CPU_THREADS = 4`...
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: Skipped ExpandTemplates step (doctest only).
[ Info: Skipped CrossReferences step (doctest only).
[ Info: Skipped CheckDocument step (doctest only).
[ Info: Skipped Populate step (doctest only).
[ Info: Skipped RenderDocument step (doctest only).
Test Summary: | Pass  Total     Time
Package       |  279    279  2m00.3s
     Testing Gabs tests passed 

@Fe-r-oz Fe-r-oz marked this pull request as draft February 6, 2025 04:47
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 6, 2025

Hi, Andrew,

The thermalstate is currently has hard coded Float64 matrix so symbolic variables don't work:

covar = Matrix{Float64}((photons + 1/2) * I, 2*nmodes, 2*nmodes)

Similar to other states, we can use Rt = float(eltype(P)) in this function and the subsequent two _thermalstate functions for and then use it to create the symbolic covariance matrix and mean matrix.

Rt = eltype(R)

or

Rt = real(eltype(A))

Following this fix, we can do

julia> using Gabs

julia> using Symbolics

julia> nmodes = rand(1:5)
4

julia> qpairbasis = QuadPairBasis(nmodes)
QuadPairBasis(4)

julia> qblockbasis = QuadBlockBasis(nmodes)
QuadBlockBasis(4)

julia> @variables n
1-element Vector{Num}:
 n

julia> thermalstate(qpairbasis, n)
GaussianState for 4 modes.
  symplectic basis: QuadPairBasis
mean: 8-element Vector{Num}:
 0
 0
 0
 0
 0
 0
 0
 0
covariance: 8×8 Matrix{Num}:
 0.5 + n        0        0        0        0        0        0        0
       0  0.5 + n        0        0        0        0        0        0
       0        0  0.5 + n        0        0        0        0        0
       0        0        0  0.5 + n        0        0        0        0
       0        0        0        0  0.5 + n        0        0        0
       0        0        0        0        0  0.5 + n        0        0
       0        0        0        0        0        0  0.5 + n        0
       0        0        0        0        0        0        0  0.5 + n

Although, we need to make sure that adding the symbolic support does not break anything.

@Fe-r-oz Fe-r-oz marked this pull request as ready for review February 6, 2025 06:54
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 6, 2025

Thank you for your comments! I have incorporated all of your comments :)

I have tweaked the thermal states methods so they work with symbolic states as well and tested the symbolic thermal states with both variables and arrays of variables so that it does not break with the any tests that use typeof(P) as Int

Test summary :)

     Testing Running tests...
Starting tests with 1 threads out of `Sys.CPU_THREADS = 4`...
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: Skipped ExpandTemplates step (doctest only).
[ Info: Skipped CrossReferences step (doctest only).
[ Info: Skipped CheckDocument step (doctest only).
[ Info: Skipped Populate step (doctest only).
[ Info: Skipped RenderDocument step (doctest only).
Test Summary: | Pass  Total     Time
Package       |  287    287  2m31.4s
     Testing Gabs tests passed 

Copy link
Owner

@apkille apkille left a comment

Choose a reason for hiding this comment

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

Hi Feroz, thanks for all of these additions! To deal with the Manifest.toml file (which shouldn't be in this repository and is a result of only me working on it so far 😄 ), can you add a .gitignore file with the Manifest file in it? Then we can merge this!

docs/src/tutorials.md Outdated Show resolved Hide resolved
docs/src/tutorials.md Outdated Show resolved Hide resolved
test/test_symbolic_states.jl Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
@Fe-r-oz
Copy link
Contributor Author

Fe-r-oz commented Feb 7, 2025

Thank you for your comments! I have incorporated all of your suggestions!

Test summary :)

     Testing Running tests...
Starting tests with 1 threads out of `Sys.CPU_THREADS = 4`...
[ Info: SetupBuildDirectory: setting up build directory.
[ Info: Doctest: running doctests.
[ Info: Skipped ExpandTemplates step (doctest only).
[ Info: Skipped CrossReferences step (doctest only).
[ Info: Skipped CheckDocument step (doctest only).
[ Info: Skipped Populate step (doctest only).
[ Info: Skipped RenderDocument step (doctest only).
Test Summary: | Pass  Total     Time
Package       |  280    280  2m08.9s
     Testing Gabs tests passed 

Edit: Sorry, I didn't understood properly your request about Manifest.toml after adding it to .gitignore! 😅 Thank you!

@apkille apkille changed the title fix #43: Validate and add docs for Gaussian objects containing symbolic variables fix #43: Validate and add docs for Gaussian states containing symbolic variables Feb 7, 2025
@apkille apkille merged commit 4c4956e into apkille:main Feb 7, 2025
14 of 15 checks passed
@apkille
Copy link
Owner

apkille commented Feb 7, 2025

Merged! Thank you for the contribution!

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.

Validate and add docs for Gaussian objects containing symbolic variables
2 participants