ZXCalculus.jl icon indicating copy to clipboard operation
ZXCalculus.jl copied to clipboard

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

Open contra-bit opened this issue 1 year ago • 8 comments

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

contra-bit avatar Sep 25 '23 15:09 contra-bit

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?

exAClior avatar Sep 26 '23 02:09 exAClior

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")

contra-bit avatar Sep 26 '23 10:09 contra-bit

@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.

ChenZhao44 avatar Sep 27 '23 20:09 ChenZhao44

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

contra-bit avatar Feb 04 '24 22:02 contra-bit

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
@@            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.

codecov[bot] avatar Feb 05 '24 00:02 codecov[bot]

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

  • You don't need to keep the original tutorial.jl notebook since it is out-of-date.
  • There are a lot of indent changes in this PR. The default indent of this repo is 4, but some of the indents are set to 2. These changes have created a lot of unnecessary differences, making it difficult to keep track of the real changes. Could please you fix the indent issue?

ChenZhao44 avatar Feb 05 '24 00:02 ChenZhao44

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

Roger-luo avatar Feb 05 '24 01:02 Roger-luo

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 avatar Feb 07 '24 22:02 contra-bit

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

Thank you for being patient.

contra-bit avatar Jul 09 '24 19:07 contra-bit

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

contra-bit avatar Jul 11 '24 11:07 contra-bit

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

exAClior avatar Jul 11 '24 12:07 exAClior

LGTM

Roger-luo avatar Jul 12 '24 06:07 Roger-luo