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

Refactoring ZX implementation

Open ChenZhao44 opened this issue 2 months ago • 4 comments

This PR is breaking because it introduces a new design to support general ZX-diagram rewriting for potential applications beyond circuit simplification.

The previous design was specific to circuit simplification:

  • The ZXDiagram was intended to provide a circuit-level interface.
  • For circuit simplification, the ZXDiagram would be converted into a ZXGraph, as most rewriting rules are only defined on the ZXGraph.
  • Additionally, the ZXGraph would implicitly assume a circuit structure including inputs and outputs, while also tracking the master diagram for phase teleportation.

The previous design limited the application of this package. For instance, it was not possible to use this package for rewriting general ZX-diagrams when they are not from a circuit due to these design constraints.

This PR implements the following design changes:

  • The ZXGraph is now the foundational graphical infrastructure to support arbitrary ZX-diagram rewriting.
  • A new ZXCircuit has been introduced to provide additional circuit structures beyond the ZXGraph, including inputs/outputs and phase tracking.
  • The ZXDiagram has been retained to ensure compatibility with the old interface.

ChenZhao44 avatar Oct 30 '25 15:10 ChenZhao44

@Roger-luo @GiggleLiu Sorry for the gigantic PR. I believe it may be too much for a human to review all at once. I am not sure if it can be decomposed into smaller ones. Please let me know what I should do to push forward this refactoring.

ChenZhao44 avatar Oct 30 '25 16:10 ChenZhao44

I briefly checked the interface changes. I think it is a nice move.

GiggleLiu avatar Nov 01 '25 17:11 GiggleLiu

I don't have a strong opinion on the refactor, but I agree this is a good generalization of the old design.

Roger-luo avatar Nov 05 '25 19:11 Roger-luo

@GiggleLiu @Roger-luo Thanks for the comments. In this case, shall I merge the PR directly?

ChenZhao44 avatar Nov 05 '25 19:11 ChenZhao44