Skip to content

Conversation

@ACE07-Sev
Copy link
Contributor

Closes #7650 .

@ACE07-Sev ACE07-Sev requested review from a team and vtomole as code owners November 13, 2025 11:02
@ACE07-Sev ACE07-Sev requested a review from viathor November 13, 2025 11:02
@github-actions github-actions bot added the size: L 250< lines changed <1000 label Nov 13, 2025
@codecov
Copy link

codecov bot commented Nov 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.38%. Comparing base (ad37bb7) to head (45e4cab).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7752      +/-   ##
==========================================
- Coverage   99.38%   99.38%   -0.01%     
==========================================
  Files        1090     1093       +3     
  Lines       98248    98388     +140     
==========================================
+ Hits        97643    97782     +139     
- Misses        605      606       +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.

@ACE07-Sev
Copy link
Contributor Author

I added single qubit state prep manually, it should be removed when cirq gets state preparation added. I'll be sure to remind in the next cirq cynq.

@pavoljuhas
Copy link
Collaborator

I need to check a few things with colleagues; I will have an update early next week.

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

Please see inline comments. Otherwise LGTM, thank you for contributing this.

PS: I'd like to loop in @tanujkhattar for more comments after we converge on the initial review.

derived from the input matrix. If a column is (approximately) zero, it
is replaced with a random vector.
"""
num_rows, num_columns = matrix.shape
Copy link
Collaborator

@pavoljuhas pavoljuhas Dec 10, 2025

Choose a reason for hiding this comment

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

The only caller of this function passes a square matrix.
Can we require the matrix to be square here?

Copy link
Contributor Author

@ACE07-Sev ACE07-Sev Dec 13, 2025

Choose a reason for hiding this comment

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

Okay if I add this for safety? I'll add it for now, and later before merge I can remove it if you don't want it.

if matrix.shape[0] != matrix.shape[1]:
        raise ValueError(
            "Input matrix is expected to be square. "
            f"Got shape {matrix.shape} instead. "
            "If this is not an error, please file an issue at "
            "https://github.com/quantumlib/Cirq/issues"
        )

Comment on lines +50 to +51
unitary = np.zeros((num_rows, num_columns), dtype=np.complex128)
orthonormal_basis: list[NDArray[np.complex128]] = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please rewrite using scipy.linalg.org and scipy.linalg.null_space

Comment on lines +39 to +40
state = np.random.rand(2**N) + 1j * np.random.rand(2**N)
state /= np.linalg.norm(state)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please reuse cirq.testing.random_superposition instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something I noticed is that cirq.testing.random_superposition is not sampling from a uniform distribution, but a normal distribution. Is it okay if I make a quick PR to change np.random.randn to np.random.rand to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: L 250< lines changed <1000

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide features for MPS state preparation

3 participants