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

Quantum Shannon Decomposition #6020

Merged
merged 56 commits into from
Jun 5, 2023
Merged

Conversation

uzzzzzzz
Copy link
Contributor

Added Quantum Shannon Decomposition in file in Cirq / cirq-core / cirq / transformers / analytical_decompostions

@uzzzzzzz uzzzzzzz requested review from a team, vtomole and cduck as code owners February 25, 2023 07:43
@google-cla
Copy link

google-cla bot commented Feb 25, 2023

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.

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

Thank you for opening the PR Uzair. Some high level comments:

  1. Please rename the file quantum_shannon_decomposition to quantum_shannon_decomposition.py
  2. Please add tests using pytest in a new file quantum_shannon_decomposition_test.py in the same directory. Make sure the test coverage checks pass.
  3. Please sign the CLA.

@tanujkhattar tanujkhattar self-assigned this Feb 27, 2023
@CirqBot CirqBot added the size: M 50< lines changed <250 label Mar 2, 2023
@uzzzzzzz
Copy link
Contributor Author

Thank you for opening the PR Uzair. Some high level comments:

  1. Please rename the file quantum_shannon_decomposition to quantum_shannon_decomposition.py
  2. Please add tests using pytest in a new file quantum_shannon_decomposition_test.py in the same directory. Make sure the test coverage checks pass.
  3. Please sign the CLA.

Thank you for opening the PR Uzair. Some high level comments:

  1. Please rename the file quantum_shannon_decomposition to quantum_shannon_decomposition.py
  2. Please add tests using pytest in a new file quantum_shannon_decomposition_test.py in the same directory. Make sure the test coverage checks pass.
  3. Please sign the CLA.

Made these changes accordingly

@uzzzzzzz uzzzzzzz requested review from tanujkhattar and removed request for mpharrigan March 27, 2023 15:09
Copy link
Contributor Author

@uzzzzzzz uzzzzzzz left a comment

Choose a reason for hiding this comment

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

Formatted file to address previous test failures

Copy link
Contributor Author

@uzzzzzzz uzzzzzzz left a comment

Choose a reason for hiding this comment

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

Added testing file and formatted this file

@uzzzzzzz
Copy link
Contributor Author

Made edits for test coverage, formatting, lint

@uzzzzzzz
Copy link
Contributor Author

uzzzzzzz commented Apr 3, 2023

Made changes with formatting new test functions and fixed error in test function for multiplexed cossin

Copy link
Contributor Author

@uzzzzzzz uzzzzzzz left a comment

Choose a reason for hiding this comment

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

Changes for QSD

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

This is looking great. Left a round of comments mostly around styling and more robust testing.

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

Left another round of comments. This is looking good overall. We should be able to merge once the comments are resolved.

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

Don't directly import the symbol names. Instead, import the sub-module which the symbol is a part of and then use <submodule_name>.<object_name>.

For example:

from cirq import ops, protocols, linalg

if TYPE_CHECKING:
    import cirq

Note that we have our import cirq under a if TYPE_CHECKING guard so that the entire module is available only for mypy checks. Now, for type checking you can use 'cirq.Qid' instead of Qid. For eg: def quantum_shannon_decomposition(qubits: List['cirq.Qid'], u: np.ndarray)

See other files in analytical decomposition for a reference.

Copy link
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

LGTM % nits

import cirq


def quantum_shannon_decomposition(qubits: 'List[cirq.Qid]', u: np.ndarray) -> 'cirq.OP_TREE':
Copy link
Collaborator

Choose a reason for hiding this comment

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

The arguments to a method should use the most general type (eg: Sequence instead of List) and the return type should be as specific as possible.

Suggested change
def quantum_shannon_decomposition(qubits: 'List[cirq.Qid]', u: np.ndarray) -> 'cirq.OP_TREE':
def quantum_shannon_decomposition(qubits: Sequence['cirq.Qid'], u: np.ndarray) -> 'cirq.OP_TREE':

yield from _msb_demuxer(qubits, u1, u2)


def _single_qubit_decomposition(qubit: 'cirq.Qid', u: np.ndarray) -> 'cirq.OP_TREE':
Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed offline, consider updating the return type if internal helpers to cirq.ops.OpTree instead, which should be enough to fix errors in yield from () statements.

Quantum Shannon Decomposition for cirq written by Uzair Faruqui, February 2023

Decomposes an arbitrary (2^n x 2^n) unitary matrix into a set of 1-qubit operations and 2-qubit CNOT gates.
Implementation loosely based on this paper: https://arxiv.org/pdf/quant-ph/0406176.pdf
Update descriptions and tidy code
Remove extra whitespace
Initial creation of test file. Will clean up and edit
Correction to argument name of 'test_random_qsd_n_qubit'
Missed a trailing whitespace
Correct argument for test_nth_gray
uzzzzzzz and others added 26 commits June 5, 2023 15:15
Added qsd to init
added qsd to init
…shannon_decomposition_test.py

Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
…shannon_decomposition_test.py

Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
…shannon_decomposition.py

Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
…shannon_decomposition.py

Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
Remove circuit_1 and circuit_2 from test_qsd_n_qubit
@tanujkhattar tanujkhattar merged commit 1ed879d into quantumlib:master Jun 5, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
* Create quantum_shannon_decomposition

Quantum Shannon Decomposition for cirq written by Uzair Faruqui, February 2023

Decomposes an arbitrary (2^n x 2^n) unitary matrix into a set of 1-qubit operations and 2-qubit CNOT gates.
Implementation loosely based on this paper: https://arxiv.org/pdf/quant-ph/0406176.pdf

---------

Co-authored-by: Tanuj Khattar <tanujkhattar@google.com>
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