Skip to content

Modify apply_unitary and unitary to take in numpy unitary matrix.#7419

Merged
pavoljuhas merged 11 commits intoquantumlib:mainfrom
iamsusiep:protocol
Jun 18, 2025
Merged

Modify apply_unitary and unitary to take in numpy unitary matrix.#7419
pavoljuhas merged 11 commits intoquantumlib:mainfrom
iamsusiep:protocol

Conversation

@iamsusiep
Copy link
Copy Markdown
Contributor

@iamsusiep iamsusiep commented Jun 12, 2025

Addressing issue: #7050

TESTED=Ran following tests for files affected.

check/pytest-changed-files
check/pytest
check/format-incremental --apply
check/pylint-changed-files

@iamsusiep iamsusiep requested review from a team and vtomole as code owners June 12, 2025 12:54
@iamsusiep iamsusiep requested a review from maffoo June 12, 2025 12:54
@google-cla
Copy link
Copy Markdown

google-cla bot commented Jun 12, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added the size: M 50< lines changed <250 label Jun 12, 2025
Copy link
Copy Markdown
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.

Nice, this cleans up a lot. Beyond the one code comment, I think has_unitary should also be modified to return True for plain arrays in this PR for consistency.

Comment thread cirq-core/cirq/protocols/unitary_protocol.py
@daxfohl
Copy link
Copy Markdown
Collaborator

daxfohl commented Jun 12, 2025

Also note there are utilities in the check folder to run some of the CI tests locally so you don't have to wait on the CI. I usually use check/pytest-changed-files, check/pytest, check/format-incremental --apply, check/pylint-changed-files, check/mypy.

@iamsusiep
Copy link
Copy Markdown
Contributor Author

Also note there are utilities in the check folder to run some of the CI tests locally so you don't have to wait on the CI. I usually use check/pytest-changed-files, check/pytest, check/format-incremental --apply, check/pylint-changed-files, check/mypy.

thanks! this is really helpful

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (5ea1d04) to head (1ddd07c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7419      +/-   ##
==========================================
- Coverage   98.69%   98.68%   -0.01%     
==========================================
  Files        1112     1112              
  Lines       97957    97965       +8     
==========================================
  Hits        96679    96679              
- Misses       1278     1286       +8     

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

Copy link
Copy Markdown
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.

One small change in mixture_protocol_test if you don't mind, and two other comments I just left for awareness for the final reviewer.

Comment thread cirq-core/cirq/protocols/pauli_expansion_protocol_test.py
Comment thread cirq-core/cirq/protocols/mixture_protocol_test.py Outdated
Copy link
Copy Markdown
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 if anyone from core wants to do a final review

@iamsusiep
Copy link
Copy Markdown
Contributor Author

@vtomole could you please take a look? Thanks!

Copy link
Copy Markdown
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

LGTM with one small suggestion. Thank you for fixing this!

@pavoljuhas pavoljuhas added this pull request to the merge queue Jun 18, 2025
Merged via the queue into quantumlib:main with commit 4c9b173 Jun 18, 2025
35 checks passed
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…antumlib#7419)

Addressing issue: quantumlib#7050

TESTED=Ran following tests for files affected.
```
check/pytest-changed-files
check/pytest
check/format-incremental --apply
check/pylint-changed-files
```
ddddddanni pushed a commit to ddddddanni/Cirq that referenced this pull request Jul 15, 2025
…antumlib#7419)

Addressing issue: quantumlib#7050

TESTED=Ran following tests for files affected.
```
check/pytest-changed-files
check/pytest
check/format-incremental --apply
check/pylint-changed-files
```
pavoljuhas added a commit to pavoljuhas/Cirq that referenced this pull request Aug 21, 2025
The unitary_protocol returns `val._unitary_()` unchecked and thus
does not guarantee the output of `cirq.unitary(val)` is unitary.
Here we lift an extra check for `cirq.unitary(np_array)` so that
`unitary(unitary(val))` does not fail if `unitary(val)` works.

Resolves quantumlib#7572
Follow-up to quantumlib#7419
github-merge-queue bot pushed a commit that referenced this pull request Aug 25, 2025
The unitary_protocol returns `val._unitary_()` unchecked and thus
does not guarantee the output of `cirq.unitary(val)` is unitary.
Here we lift an extra check for `cirq.unitary(np_array)` so that
`unitary(unitary(val))` does not fail if `unitary(val)` works.

Resolves #7572
Follow-up to #7419
ddddddanni pushed a commit to ddddddanni/Cirq that referenced this pull request Sep 1, 2025
The unitary_protocol returns `val._unitary_()` unchecked and thus
does not guarantee the output of `cirq.unitary(val)` is unitary.
Here we lift an extra check for `cirq.unitary(np_array)` so that
`unitary(unitary(val))` does not fail if `unitary(val)` works.

Resolves quantumlib#7572
Follow-up to quantumlib#7419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants