QuantumBFS / ZXCalculus.jl

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

ZXW Diagram implementation #92

Closed exAClior closed 1 year ago

exAClior commented 1 year ago

Implement ZXWDiagram. Moving functions under zx_diagram.jl to utils.jl for reusing them for ZXWDiagram.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 85.67% and project coverage change: -11.46 :warning:

Comparison is base (bbc19ab) 94.34% compared to head (1f5787b) 82.88%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #92 +/- ## =========================================== - Coverage 94.34% 82.88% -11.46% =========================================== Files 11 16 +5 Lines 2085 2478 +393 =========================================== + Hits 1967 2054 +87 - Misses 118 424 +306 ``` | [Impacted Files](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS) | Coverage Δ | | |---|---|---| | [src/ZXCalculus.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL1pYQ2FsY3VsdXMuamw=) | `100.00% <ø> (ø)` | | | [src/phase.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL3BoYXNlLmps) | `74.24% <50.00%> (-8.58%)` | :arrow_down: | | [src/utils.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL3V0aWxzLmps) | `75.77% <75.77%> (ø)` | | | [src/zxw\_diagram.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL3p4d19kaWFncmFtLmps) | `86.20% <86.20%> (ø)` | | | [src/parameter.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL3BhcmFtZXRlci5qbA==) | `96.34% <96.34%> (ø)` | | | [src/to\_eincode.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL3RvX2VpbmNvZGUuamw=) | `98.78% <98.78%> (ø)` | | | [src/scalar.jl](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS#diff-c3JjL3NjYWxhci5qbA==) | `100.00% <100.00%> (ø)` | | ... and [7 files with indirect coverage changes](https://app.codecov.io/gh/QuantumBFS/ZXCalculus.jl/pull/92/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=QuantumBFS)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

ChenZhao44 commented 1 year ago

Thank you for the pull request; it looks great overall. I have a few minor suggestions. It seems that you have extended the SpiderType and used it in the ZXWDiagram. This extension also makes the original ZXDiagram capable of handling ZXW, resulting in no difference between the new ZXWDiagram. I suggest defining a new spider type for ZXWDiagram only to avoid affecting the previous data structures and algorithms.

exAClior commented 1 year ago

Thank you for the pull request; it looks great overall. I have a few minor suggestions. It seems that you have extended the SpiderType and used it in the ZXWDiagram. This extension also makes the original ZXDiagram capable of handling ZXW, resulting in no difference between the new ZXWDiagram. I suggest defining a new spider type for ZXWDiagram only to avoid affecting the previous data structures and algorithms.

This makes much more sense. I will change it accordingly. Thank you!

exAClior commented 1 year ago

Since we are implementing ZXWDiagram with as little coupling with the original implementation with ZXDiagram as possible, I want to take this opportunity to remove redundant data fields in ZXWDiagram. For example, in #77 and #72, it was suggested that ZXLayout is not necessary. I agree with this point and went ahead to remove ZXLayout from ZXWDiagram for now. @ChenZhao44 please let me know if this raises a concern and I would be happy to add those features back.

ChenZhao44 commented 1 year ago

Since we want to separate the original implementation, we can also use algebraic data types to represent the node type and its parameters. An algebraic data type is a type that combines several data types in a type-stable way. An implementation of ADTs can be found in Expronicon. By using ADT pattern matching, as implemented in MLStyle, we can replace the if else statements during matching calculus rules in an elegant way. We can discuss this in more detail during our next meeting.

exAClior commented 1 year ago

The latest commits on ADT of Parameters used to represent parameters for spider didn't pass the CI because YaoHIR and CompilerPluginTools are restricting Expronicon to be 0.6.0. I have already made a PR in YaoHIR to partially solve the problem. I am temporarily removing CompilerPluginTools from Project.toml since Roger said he wants to rewrite CompilerPluginTools instead of fixing it.

exAClior commented 1 year ago

Hello, @ChenZhao44 I have finished correcting for ZXWDiagram, and Parameter and copied from your branch the implementation of converting a ZXWDiagram to eincode and then to Matrix. I am waiting for @Roger-luo 's comment on my edits on CompilerPluginTools. For the sake of passing CI, I have removed all tests related to CompilerPluginTools.