Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new condition that allows easy control by bitmasks and Add a new classical Update the notebook for 'Classical control' to reflect new features" #7166

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

NoureldinYosri
Copy link
Collaborator

@NoureldinYosri NoureldinYosri commented Mar 19, 2025

This PR creates BitMaskKeyCondition a condition that can be used to create multiqubit classical conditions with bitmasks. This will be much easier than using sympy indexedbase

cc: @ikd-sci


Examples:

Any bit from 0, 2, 3 => 0b1101 = 13

In [4]: cond = cirq.BitMaskKeyCondition('m', bitmask=13)
   ...: c = cirq.Circuit(
   ...:     cirq.H.on_each(qs),
   ...:     cirq.measure(qs, key='m'),
   ...:     cirq.Y(cirq.q(5)).with_classical_controls(cond),
   ...: 
   ...: )
   ...: c
Out[4]: 
0: ───H───M────────────────────────────
          ║
1: ───H───M────────────────────────────
          ║
2: ───H───M────────────────────────────
          ║
3: ───H───M────────────────────────────
          ║
4: ───H───M────────────────────────────
          ║
5: ───────╫───Y(conditions=[m & 13])───
          ║   ║
m: ═══════@═══^════════════════════════

Contains 0b1011 = 11 as bitmask

In [5]: cond = cirq.BitMaskKeyCondition.create_equal_mask('m', bitmask=11)
   ...: c = cirq.Circuit(
   ...:     cirq.H.on_each(qs),
   ...:     cirq.measure(qs, key='m'),
   ...:     cirq.Y(cirq.q(5)).with_classical_controls(cond),
   ...: 
   ...: )
   ...: c
Out[5]: 
0: ───H───M────────────────────────────────────
          ║
1: ───H───M────────────────────────────────────
          ║
2: ───H───M────────────────────────────────────
          ║
3: ───H───M────────────────────────────────────
          ║
4: ───H───M────────────────────────────────────
          ║
5: ───────╫───Y(conditions=[(m & 11) == 11])───
          ║   ║
m: ═══════@═══^════════════════════════════════

Doesn't contain 11 as a bitmask

In [6]: cond = cirq.BitMaskKeyCondition.create_not_equal_mask('m', bitmask=11)
   ...: c = cirq.Circuit(
   ...:     cirq.H.on_each(qs),
   ...:     cirq.measure(qs, key='m'),
   ...:     cirq.Y(cirq.q(5)).with_classical_controls(cond),
   ...: 
   ...: )
   ...: c
Out[6]: 
0: ───H───M────────────────────────────────────
          ║
1: ───H───M────────────────────────────────────
          ║
2: ───H───M────────────────────────────────────
          ║
3: ───H───M────────────────────────────────────
          ║
4: ───H───M────────────────────────────────────
          ║
5: ───────╫───Y(conditions=[(m & 11) != 11])───
          ║   ║
m: ═══════@═══^════════════════════════════════

update the notebook to reflect the upgraded sympy support from #6914 and the new bitmask condition from #7165

Copy link

codecov bot commented Mar 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.13%. Comparing base (71c3cf1) to head (dcc3ad9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7166   +/-   ##
=======================================
  Coverage   98.13%   98.13%           
=======================================
  Files        1095     1095           
  Lines       95649    95732   +83     
=======================================
+ Hits        93866    93948   +82     
- Misses       1783     1784    +1     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@NoureldinYosri NoureldinYosri changed the title Update the notebook for 'Classical control' to reflect new features" Create a new condition that allows easy control by bitmasks and Add a new classical Update the notebook for 'Classical control' to reflect new features" Mar 21, 2025
@NoureldinYosri NoureldinYosri marked this pull request as ready for review March 21, 2025 23:55
@NoureldinYosri NoureldinYosri requested review from vtomole and a team as code owners March 21, 2025 23:55
Copy link
Collaborator

@daxfohl daxfohl left a comment

Choose a reason for hiding this comment

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

Lgtm. ALL my concerns were addressed in previous PR.

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.

2 participants