QuantumBFS / ZXCalculus.jl

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

WIP: Update Tutorial to use Vegaplot #101

Closed contra-bit closed 10 months ago

contra-bit commented 10 months ago

Hello dear maintainers,

the removal of the plotting availability in YaoPlots (#100) has impeded, my research into the ZX-Calculus. I have created this PR to make plotting work and have updates the tutorial.jl notebook to the plot diagrams and graphs, when returned.

My current goal is to work with the chen/zxwh branch and to have an up to date tutorial notebook that provides a brief overview of what is possible with ZX-Calculus and tests for plotting.

Have I understood correctly that the plotting capabilities for ZX(W)-Diagrams and Graphs will stay in this package? Please excuse me If I have misunderstood your plans.

Thank you all for the great software which already exist and lets work together improve it even more :)

Please tell me if this PR is moving in the right direction and what you would like to improve.

ChenZhao44 commented 10 months ago

Dear @contra-bit,

Thank you for your PR! It is greatly helpful for maintaining the plotting support.

Currently, we have defined several different calculi in this package, including the original ZX-calculus (ZXDiagram and ZXGraph), the ZXWH-calculus (ZXWDiagram) implemented by @exAClior, and also the (pW/ZW)-calculus (ZWDiagram) that requires a planar graph data structure #99.

My plan is to only support visualizing the Multigraph based calculi. Furthermore, I intend to utilize the weak-dependency feature that has been introduced in Julia 1.9 to include the previous plotting part. I suggest you follow the current master branch for the ZX(W)-Diagrams instead of the deprecated chen/zxwh branch.

Please feel free to ask any questions. We could also arrange an online meeting for a more detailed discussion.

Best regards, Chen

contra-bit commented 10 months ago

Thank you for your answer. I think a meeting would be great for us to that align our development efforts. Did you receive my message on slack?

Based on your input, I have ignored this branch and freshly implemented the plotting functionality which this PR provides in the main branch here. All of the existing test for plots already pass.

I am currently converting the dependencies Vega and Compose et al into weak dependencies.

Regarding the tests: the notebook from this PR and the zx_plots testfile work, yet plotting Multigraph ZXDiagram such as this fail:

 g = Multigraph([0 1 0; 1 0 1; 0 1 0])
ps = [Rational(0) for i = 1:3]
v_t = [SpiderType.X, SpiderType.Z, SpiderType.X]
zxd = ZXDiagram(g, v_t, ps)
plot(zxd)

Due to the error:

  LoadError: MethodError: reducing over an empty collection is not allowed; consider supplying `init` to the reducer

Is this because no gates have been added and thus there are no spiders yet? Can you take a look why this error occurs?

Before creating the PR, I would like to know:

  1. Is every of diagram created in test/zx_diagram.jl a correct and valid ZXDiagram? In this case we should decide if we want to move the tests for the ploting directly into the tests of the different diagram types. What do you think?
  2. Will there be a generic diagram struct such as AbstractZDiagram, which encompasses all diagram types?
  3. Would this change the function definition for plot to plot(diagram::AbstractZDiagram) ?
  4. What is different about the multigraph approach compared to the prior use of BlockIR and Chain?
  5. I am developing a parser for converting OpenQASM via BlockIR into AbstractZDiagrams and back into OpenQASM. Will I be able to use the BlockIR and Chain as an intermediate or should I change my implementation and directly convert OpenQASM to ZXCalculus?
  6. Which papers or documents will help me to understand the new Multigraph implementation. I would like to inform myself better by reading them.

I hope that the ZX or ZXW universality will allow us to build a great tool for quantum scientists, which can be applied in many different quantum research areas due to the intuitive approach to quantum theory it gives us. I am grateful and thankful for all the good work you and the team have already provided :)

contra-bit commented 10 months ago

Closing this PR, in favor of #102