Skip to content

Addition of CZ instruction and related components, and removal of meas_index from R instructions#379

Merged
emlynsg merged 23 commits intomasterfrom
add_cz_instruction
Dec 16, 2025
Merged

Addition of CZ instruction and related components, and removal of meas_index from R instructions#379
emlynsg merged 23 commits intomasterfrom
add_cz_instruction

Conversation

@emlynsg
Copy link
Contributor

@emlynsg emlynsg commented Nov 28, 2025

Context:
Up to now, Graphix has not explicitly included a CZ instruction. This may be something users pass as a gate in a circuit. It is also a useful addition for using in alternative transpilers including JCZ.

Description of the change:
A CZ gate has been added to the set of instructions in instruction.py.
Downstream changes have been made including:

  • Added to InstructionKind enumeration
  • Added to multiple points in transpiler.py for circuit transpilation.

This PR also updates other instructions. It removes an unused variable meas_index in the RZZ, RZ, RY, RX instructions. Other minor typing fixes have also been made to some test suites where identified during testing.

Related issue:
See parallel PR in graphix-qasm-parser.

Given parallel PR was required, some workarounds have been included to prevent dependency problems. These can be reverted when CI is shown to be passing in both repos.

@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.09%. Comparing base (85c419b) to head (951a20f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
graphix/qasm3_exporter.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #379      +/-   ##
==========================================
+ Coverage   85.89%   86.09%   +0.20%     
==========================================
  Files          45       45              
  Lines        6542     6565      +23     
==========================================
+ Hits         5619     5652      +33     
+ Misses        923      913      -10     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@emlynsg emlynsg changed the title Addition of CZ instruction and related components, and removal of meas_index from RZZ Addition of CZ instruction and related components, and removal of meas_index from R instructions Nov 28, 2025
Copy link
Collaborator

@thierry-martinez thierry-martinez left a comment

Choose a reason for hiding this comment

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

Nice job! I just wonder why we need to introduce requirements-no-deps.txt instead of just pinning graphix-qasm-parser in requirements-dev.txt.

Otherwise, the J-CZ transpiler would require to introduce a J gate in addition to the CZ gate. I suppose you plan to add that in a subsequent PR, is that right?

Copy link
Contributor

@matulni matulni left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Emlyn Graham and others added 8 commits December 5, 2025 11:38
This commit adds type annotations to `random_objects.py`, along with
its corresponding tests, enabling full type-checking with mypy while
preserving existing functionality.

The exclusion of `device_interface.py` is removed from
`pyproject.toml` since this module was removed in #261.

`scipy-stubs` is added to `requirements-dev.txt` since `scipy` is used
in `random_objects.py`.

Revealed bad type annotation for `unitary_group.rvs`: scipy/scipy-stubs#987

**Related issue:**
This PR continues the work started in #302, #308, #312 and #347.
---------

Co-authored-by: matulni <m.uldemolins@gmail.com>
This commit adapts the existing method `graphix.opengraph.OpenGraph.isclose` to the new API introduced in #358. Additionally, it introduces the new methods `graphix.opengraph.OpenGraph.is_equal_structurally` which compares the underlying structure of two open graphs, and `graphix.fundamentals.AbstractMeasurement.isclose` which defaults to `==` comparison.
This commit adapts the existing method `:func: OpenGraph.compose` to the new API introduced in #358.
This commit fixes domains in the transpiler so that every pattern
transpiled from a circuit has a flow.  Previously, some domains were
incompatible with any flow, despite the patterns being deterministic,
because some measurement angles were zero, causing the measurements to
ignore certain signals.

This commit also adds `optimization.remove_useless_domains` to remove
the domains ignored by measurements with angle zero, to recover the
same "optimized" patterns as before when needed.

This commit also adds `rand_state_vector` to draw a random state vector.
@mgarnier59
Copy link
Contributor

Looks good.

Maybe this is out of scope of this PR but why are all _gate_command of the Circuit class class methods? They are always called on selfwhich is a Circuit instance. Could even just be a static method no?

Once the issue of the extra requirements.txt is solved I'll be happy to approve.

@thierry-martinez
Copy link
Collaborator

Command routines can indeed be static methods, or even just plain functions, but I think the change in the structure of the transpiler can be postponed until a more global refactoring.

@thierry-martinez
Copy link
Collaborator

I think we can now remove the version pinning for graphix-qasm-parser.

Emlyn Graham and others added 3 commits December 10, 2025 17:16
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@emlynsg
Copy link
Contributor Author

emlynsg commented Dec 10, 2025

Agree @thierry-martinez I think this is ready to go now.

Copy link
Collaborator

@thierry-martinez thierry-martinez left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks.

@emlynsg emlynsg merged commit 5440aa0 into master Dec 16, 2025
22 checks passed
@emlynsg emlynsg deleted the add_cz_instruction branch December 16, 2025 11:55
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