Skip to content

Conversation

@ChenZhao44
Copy link
Member

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 ChenZhao44 requested a review from Copilot October 30, 2025 15:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the ZXCalculus package to improve code organization and maintainability by:

  • Splitting monolithic files into modular interface and implementation structures
  • Reorganizing test files to match the new source structure
  • Deprecating ZXDiagram in favor of ZXCircuit for circuit operations
  • Introducing abstract interfaces for ZX-diagrams and circuits

Key Changes:

  • Split large files (zx_diagram.jl, zx_graph.jl, rules.jl) into smaller, focused modules
  • Created interface definitions for AbstractZXDiagram and AbstractZXCircuit
  • Reorganized tests into module-scoped testsets with proper nesting
  • Added deprecation warnings for ZXDiagram and convert_to_zxd

Reviewed Changes

Copilot reviewed 110 out of 114 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/runtests.jl Restructured test organization with module scoping and new testset hierarchy
test/ZX/zx_layout.jl New test file for ZXLayout type
test/ZX/rules/*.jl Split rule tests into individual files by rule type
test/ZX/interfaces/*.jl New interface tests for abstract types
test/ZX/implementations/*.jl New implementation tests for concrete types
src/ZX/types/*.jl Extracted type definitions (SpiderType, EdgeType, ZXLayout)
src/ZX/interfaces/*.jl New interface definitions for abstract types
src/ZX/implementations/*.jl Extracted implementations for ZXGraph, ZXDiagram, ZXCircuit
src/ZX/rules/*.jl Split rules into individual files with named rule types
src/ZX/ir.jl Refactored IR conversion with deprecation warnings
src/Utils/conversion.jl Extracted conversion utilities from zx_diagram.jl

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ChenZhao44
Copy link
Member Author

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

@GiggleLiu
Copy link
Member

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

@Roger-luo
Copy link
Member

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

@ChenZhao44
Copy link
Member Author

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

@ChenZhao44 ChenZhao44 merged commit c28e542 into master Dec 18, 2025
8 checks passed
@ChenZhao44 ChenZhao44 deleted the chen/refactor-zx branch December 18, 2025 22:04
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.

4 participants