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

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

contra-bit
Copy link

@contra-bit contra-bit commented Sep 25, 2023

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
Copy link
Collaborator

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
Copy link
Author

contra-bit commented Sep 26, 2023

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
Copy link
Member

@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
Copy link
Author

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

Copy link

codecov bot commented Feb 5, 2024

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

❗ 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 ⚠️
src/ZX/zx_diagram.jl 82.89% 13 Missing ⚠️
src/ZX/zx_graph.jl 0.00% 1 Missing ⚠️
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     

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

@ChenZhao44
Copy link
Member

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

@Roger-luo
Copy link
Member

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

@contra-bit contra-bit changed the title Plotting for ZXDiagrams and ZXGraphs Plotting for ZXDiagrams and ZXGraphs, Equality for ZXDiagrams and converting ZX to ZXW Feb 7, 2024
@contra-bit
Copy link
Author

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.

Comment on lines 11 to 18
Pkg.add("OpenQASM")
Pkg.add("Vega")
Pkg.add("DataFrames")
Pkg.add("YaoHIR.jl")
Pkg.add("ZXCalculus.jl")
Pkg.add("YaoHIR")
Pkg.add("ZXCalculus")
Pkg.add(
url = "https://gitlab.informatik.uni-bremen.de/qce/quantumequivalencechecker.jl",
rev = "feat/zx",
Copy link
Member

Choose a reason for hiding this comment

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

can we use Pluto builtin env instead of doing this?

Copy link
Member

@ChenZhao44 ChenZhao44 left a comment

Choose a reason for hiding this comment

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

Please address the feedback and resolve the notebook environment issues as pointed out by @Roger-luo

.JuliaFormatter.toml Outdated Show resolved Hide resolved
src/ZX/equality.jl Outdated Show resolved Hide resolved
src/ZX/rules.jl Show resolved Hide resolved
src/ZX/zx_diagram.jl Show resolved Hide resolved
src/ZX/rules.jl Show resolved Hide resolved
@@ -38,3 +38,9 @@ zxg2 = clifford_simplification(zxd)

zxg3 = full_reduction(zxd)
cir = circuit_extraction(zxg3)

# Plotting
@test plot(zxd) !== nothing
Copy link
Member

Choose a reason for hiding this comment

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

use isnothing

@@ -75,6 +75,8 @@ function gen_cir()
end

cir = gen_cir()
@test plot(cir)!== nothing
Copy link
Member

Choose a reason for hiding this comment

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

use isnothing

ZX.insert_spider!(zxd, 1, 2, SpiderType.Z)
zxg = ZXGraph(zxd)

@test plot(zxd) !== nothing
Copy link
Member

Choose a reason for hiding this comment

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

use isnothing

@@ -10,6 +10,7 @@ matches = match(Rule{:f}(), zxd)
rewrite!(Rule{:f}(), zxd, matches)
@test sort!(spiders(zxd)) == [1, 3]
@test phase(zxd, 1) == phase(zxd, 3) == 3 // 4
@test plot(zxd) !== nothing
Copy link
Member

Choose a reason for hiding this comment

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

use isnothing

@@ -7,11 +7,13 @@ v_t = [SpiderType.X, SpiderType.Z, SpiderType.X]
zxd = ZXDiagram(g, v_t, ps)
zxd2 = ZXDiagram(g, Dict(zip(1:3, v_t)), Dict(zip(1:3, ps)))
@test zxd.mg == zxd2.mg && zxd.st == zxd2.st && zxd.ps == zxd2.ps
@test plot(zxd) !== nothing
Copy link
Member

Choose a reason for hiding this comment

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

use isnothing

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.

Cannot Plot ZXDiagram with YaoPlots
4 participants