QuantumBFS / ZXCalculus.jl

An implementation of ZX-calculus in Julia
http://yaoquantum.org/ZXCalculus.jl/dev/
MIT License
47 stars 7 forks source link

Plotting for ZXDiagrams and ZXGraphs, Equality for ZXDiagrams and converting ZX to ZXW #102

Closed contra-bit closed 2 weeks ago

contra-bit commented 10 months ago

Dear Maintainers,

This pull request introduces several improvements, including the addition of optional plotting functionality for ZXDiagrams and ZXGraphs and closes #101 and fixes #100. The plotting function uses Vega and DataFrames, which will only be loaded when necessary to improve load times and reduce memory usage. The color scheme of spider graphs has been updated to be more accessible for individuals with Color Vision Deficiency (CVD) and improved label readability. Further information on accessibility can be found at <https://zxcalculus.com>.

Additional testing has been implemented for both ZXDiagrams and ZXGraphs, with plots added to most tests and the creation of a new notebook focused on equivalence checking. Existing tutorial notebooks have also been refined, and users will now benefit from automated diagram generation within these notebooks.

Furthermore, the YaoHIR package has gained the capability to import OpenQASM files, enabling easy conversion from openQASM to ZXDiagrams and providing another useful approach to building. optimizing and verifying quantum circuits.

The pull request further includes various bug fixes and improvements, such as addressing issues with the match and apply function for the ZXGraph :id rule, enhancing the overall user experience for plots, resolving testing issues, and handling miscellaneous bugs.

Regards and thanks for reviewing my pull request

exAClior commented 10 months ago

Hello @contra-bit , thank you very much for working on adding plot into ZXCalculus.jl. I was trying out the notebook tutorial.jl. I was able to see the new plots, they looked cool! But were you able to install all the required packages that are at the beginning of this notebook? I could not do it. I noticed that you added CompilerPluginTools to dependency. That was causing a little trouble for us. It will probably cause more trouble for us when Julia v1.10 is out. Roger is planning on updating YaoHIR and removing this completely see link. Is this a hard requirement for your future work regarding this dependency?

contra-bit commented 10 months ago

Good catch. It is not required.

I only added CompilerPluginTools as an explicit dependency because it was causing trouble for me, when it was being imported as a dependency by YaoHIR. The import failed because the version required could not be resolved. The only way for me to resolve the YaoHIR dependency was to add the master branch from the git repo because the julia package had the wrong version. In order for it to be imported correctly I ran the following command:

pkg> add https://github.com/JuliaCompilerPlugins/CompilerPluginTools.jl

Then I added the equivalent command to the notebook as well.

Pkg.add(url="https://github.com/JuliaCompilerPlugins/CompilerPluginTools.jl")
ChenZhao44 commented 10 months ago

@contra-bit Thanks for the PR. I suggest removing the dependency that is only used in the notebook, and keeping the main package as clean as possible. Perhaps it would be better to set up a separate environment in the notebook folder to include CompilerPluginTools and DataFrames.

contra-bit commented 5 months ago

I am thrilled to share several improvements in this pull request! I have introduced plotting functionality as an optional extension using Vega and DataFrames. This change ensures that these dependencies will only be loaded when needed, leading to faster load times and reduced memory usage.

To enhance accessibility, I have updated the color scheme of spider graphs so that they are distinguishable for people with Color Vision Deficiency (CVD), and improved the readability of phase labels. For further details, kindly consult the accessibility guidelines provided at zxcalculus.com.

My latest contributions enhance testing for both ZXDiagrams and ZXGraphs by adding plots to most tests, along with creating a brand-new notebook dedicated to equivalence checking and refining the existing tutorial notebook. Users will benefit from automatic generation of diagrams within these notebooks.

Moreover, YaoHIR has gained the ability to import OpenQASM files, allowing seamless conversion to ZXDiagrams—providing yet another practical method to construct quantum circuits. I will try to get all my contributions merged and then update the Pkg in the notebooks.

As part of my efforts, I fixed the match and apply function for the ZXGraph :id rule while adding the new equivalence checking functionality. Now, it is possible to determine if two diagrams are identical through the built-in equivalency checks.

Last but not least, I took care of numerous housekeeping tasks such as updating imports, resolving problems discovered during testing, enhancing overall user experience for plots, and dealing with miscellaneous glitches

codecov[bot] commented 5 months ago

Codecov Report

Attention: 36 lines in your changes are missing coverage. Please review.

Comparison is base (146e39b) 82.49% compared to head (f3f1967) 89.21%.

:exclamation: Current head f3f1967 differs from pull request most recent head f89197d. Consider uploading reports for the commit f89197d to get more accurate results

Files Patch % Lines
src/ZX/ir.jl 84.93% 22 Missing :warning:
src/ZX/zx_diagram.jl 82.89% 13 Missing :warning:
src/ZX/zx_graph.jl 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #102 +/- ## ========================================== + Coverage 82.49% 89.21% +6.71% ========================================== Files 28 30 +2 Lines 3537 3691 +154 ========================================== + Hits 2918 3293 +375 + Misses 619 398 -221 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ChenZhao44 commented 5 months ago

@contra-bit Thanks for working on this PR. It looks decent. Before merging this PR, I have only two minor suggestions.

Roger-luo commented 5 months ago

FYI you don't have to use the package env for notebooks, every Pluto notebook has its own env by default.

contra-bit commented 5 months ago

I hope I have fixed the indentation issues, further I have increased the test coverage and added a .JuliaFormatter.toml that species that the default indentation is 4.

The notebooks are now configured to use the Yao upstream repositories. My next goal is to improve the notebooks and improve the documentation.

contra-bit commented 3 weeks ago

I have addressed the feedback and think this can be merged now. @ChenZhao44

Thank you for being patient.

contra-bit commented 2 weeks ago

I reformatted the mentioned files by hand. Thank you for the thorough review.

exAClior commented 2 weeks ago

Great! This PR looks good to me. Let's see if Dr. Zhao and Dr. Luo has any further comments!

Roger-luo commented 2 weeks ago

LGTM