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

Add TwoQubitDiagonalGate #2891

Merged
merged 7 commits into from
May 8, 2020
Merged

Add TwoQubitDiagonalGate #2891

merged 7 commits into from
May 8, 2020

Conversation

ajhanus
Copy link
Contributor

@ajhanus ajhanus commented Apr 5, 2020

Part of #2587

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@ajhanus ajhanus force-pushed the two_diag_edits branch 3 times, most recently from cc8ff4d to fa7fed9 Compare April 5, 2020 22:21
@vtomole vtomole mentioned this pull request Apr 6, 2020
@vtomole vtomole requested a review from cduck April 6, 2020 14:12
@vtomole
Copy link
Collaborator

vtomole commented Apr 6, 2020

Hey @cduck, @hanusaj will be taking this implementation from me.

cirq/ops/two_qubit_diagonal_gate.py Outdated Show resolved Hide resolved
@vtomole
Copy link
Collaborator

vtomole commented Apr 6, 2020

@hanusaj The Travis tests are failing.

@vtomole vtomole changed the title Two diag edits Add TwoQubitDiagonalGate Apr 6, 2020
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@vtomole
Copy link
Collaborator

vtomole commented Apr 14, 2020

@hanusaj You'll need to squash my commits and commit them as your own.

@ajhanus ajhanus force-pushed the two_diag_edits branch 5 times, most recently from 7192a41 to 63bd918 Compare April 17, 2020 22:29
@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Makes googlebot stop complaining. and removed cla: no labels Apr 17, 2020
@ajhanus ajhanus force-pushed the two_diag_edits branch 3 times, most recently from 73a1e38 to 47bf076 Compare April 17, 2020 23:19
@ajhanus ajhanus force-pushed the two_diag_edits branch 3 times, most recently from 84de6da to cb06057 Compare April 19, 2020 14:31
@ajhanus ajhanus force-pushed the two_diag_edits branch 3 times, most recently from 3aaf0c9 to 239246c Compare April 19, 2020 21:12
cirq/ops/two_qubit_diagonal_gate.py Outdated Show resolved Hide resolved
cirq/ops/two_qubit_diagonal_gate.py Outdated Show resolved Hide resolved
cirq/protocols/json_serialization_test.py Outdated Show resolved Hide resolved
@ajhanus ajhanus force-pushed the two_diag_edits branch 2 times, most recently from 8244669 to 17cd6cd Compare April 19, 2020 21:38
format

Respond to reviews

revetr

revert again

ignore global phase

lint

Fixed edits for the Add TwoQubitDiagonalGate.

Change the docstring for the two_qubit_diagonal_gate.py
Copy link
Collaborator

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Creates the Gate instrance for a two qubit diagonal gate.
Copy link
Collaborator

Choose a reason for hiding this comment

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

lower case 'g` for gate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has been addressed.

# limitations under the License.
"""Creates the Gate instrance for a two qubit diagonal gate.

The Gate is used to create a 4x4 matrix with the diagonal elements
Copy link
Collaborator

Choose a reason for hiding this comment

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

lower case g for gate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has been addressed.

# limitations under the License.
"""Creates the Gate instrance for a two qubit diagonal gate.

The Gate is used to create a 4x4 matrix with the diagonal elements
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use latex notation for multiplication sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has been addressed.


@value.value_equality()
class TwoQubitDiagonalGate(gate_features.TwoQubitGate):
"""A gate given by a diagonal 4x4 matrix."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use latex notation for multiplication sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has been addressed.

def _unitary_(self) -> np.ndarray:
if self._is_parameterized_():
return None
return np.diag(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It did not work for tuples. I got a the following error. TypeError: can't multiply sequence by non-int of type 'complex'.

return NotImplemented
for index, angle in enumerate(self._diag_angles_radians):
subspace_index = args.subspace_index(big_endian_bits_int=index)
args.target_tensor[subspace_index] *= np.exp(1j * angle)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

args.target_tensor *= np.exp(1j * self._diag_angles_radians.reshape((2,2))) did not work since self._diag_angles_radians was not a numpy.array. Similar to above, the np.exp(1j * self_diag_angles_radians) didn't work with tuples.

return NotImplemented
angles = []
for angle in self._diag_angles_radians:
mulAngle = protocols.mul(angle, exponent, NotImplemented)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that the code I added returned NotImplemented from the __pow__ function. If I should address the comment in another way, let me know.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ping @cduck

sqrt_diagonal_gate = diagonal_gate**.5

expected_angles = [prime / 2 for prime in diagonal_angles]
np.testing.assert_allclose(expected_angles,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has been addressed.

Copy link
Collaborator

@vtomole vtomole left a comment

Choose a reason for hiding this comment

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

Merging as "pretty decent" reasons were given for not fixing some of @cduck's suggestions.

@vtomole vtomole added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 8, 2020
@CirqBot
Copy link
Collaborator

CirqBot commented May 8, 2020

Automerge cancelled: "automerge" label was never added.

@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 8, 2020
@vtomole vtomole added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 8, 2020
@CirqBot
Copy link
Collaborator

CirqBot commented May 8, 2020

Automerge cancelled: "automerge" label was never added.

@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label May 8, 2020
@vtomole vtomole merged commit 4a0ded7 into quantumlib:master May 8, 2020
tonybruguier pushed a commit to tonybruguier/Cirq that referenced this pull request Aug 23, 2020
* Add TwoQubitDiagonalGate

format

Respond to reviews

revetr

revert again

ignore global phase

lint

Fixed edits for the Add TwoQubitDiagonalGate.

Change the docstring for the two_qubit_diagonal_gate.py

* Pull request review edits.

* GitHub merge fail fixes.

* Update two_qubit_diagonal_gate.py

Co-authored-by: Victory Omole <vtomole2@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants