-
Notifications
You must be signed in to change notification settings - Fork 1.1k
KetBraSum #3386
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
Closed
Closed
KetBraSum #3386
Changes from 9 commits
Commits
Show all changes
193 commits
Select commit
Hold shift + click to select a range
bd3c8b8
Add projector class
tonybruguier 3d876c8
attempt to address some failures
tonybruguier b21b531
nits
tonybruguier 6fbda8c
nits
tonybruguier 3b96978
nits
tonybruguier f797d68
nits
tonybruguier 08b0c24
add missing coverage in test
tonybruguier 68fefb5
Merge branch 'master' into projection
tonybruguier d10ea5a
Merge branch 'master' into projection
tonybruguier 8ba55f5
Merge branch 'master' into projection
tonybruguier d826f8b
Address comments
tonybruguier 3a83156
nits
tonybruguier 7f18128
nits
tonybruguier d8ac239
nits
tonybruguier efe0ed3
Address comments
tonybruguier d8cb496
nits
tonybruguier 0dd7385
mypy fix attempt
tonybruguier 7e1eb61
Merge branch 'master' into projection
tonybruguier 9cb3056
address reviewer's comments
tonybruguier 09ea03f
nits
tonybruguier 3361b2a
address comment
tonybruguier 9506301
nits
tonybruguier 79f841f
Merge branch 'master' into projection
tonybruguier b6fbd13
Merge branch 'master' into projection
tonybruguier 9d75e1c
Merge branch 'master' into projection
tonybruguier d572dfc
Merge branch 'master' into projection
tonybruguier 98482fd
Address comments
tonybruguier f77154c
Add check for orthogonal basis
tonybruguier a89fe35
nits
tonybruguier 154a350
Address comments
tonybruguier be2f1d4
Merge branch 'master' into projection
tonybruguier 80f469d
address comments
tonybruguier 577f258
Merge branch 'master' into projection
tonybruguier 7099cfd
nits
tonybruguier ed29f5b
nits
tonybruguier c95ab3b
nits
tonybruguier 019547b
Merge branch 'master' into projection
tonybruguier 9aadda2
Merge branch 'master' into projection
tonybruguier d5096e7
Update cirq/ops/projectors.py
tonybruguier b10b8ed
address comments
tonybruguier e82914c
nits
tonybruguier 96f5549
nits
tonybruguier 1763c2d
nits
tonybruguier c11edb6
Merge branch 'master' into projection
tonybruguier 03c000c
Update cirq/ops/projectors.py
tonybruguier 097b7d0
Update cirq/ops/projectors.py
tonybruguier 860c660
Update cirq/ops/projectors.py
tonybruguier e22966c
Update cirq/ops/projectors.py
tonybruguier 69068f2
Update cirq/ops/projectors.py
tonybruguier 8d21ee8
Update cirq/ops/projectors.py
tonybruguier ba62458
address comments
tonybruguier 2424712
nits
tonybruguier f20d9d5
Merge branch 'master' into projection
tonybruguier 28521cc
Merge branch 'master' into projection
tonybruguier daa4038
Merge branch 'master' into projection
tonybruguier fb058f6
Merge branch 'projection' of github.com:tonybruguier/Cirq into projec…
tonybruguier 0bb39ea
Merge branch 'master' into projection
tonybruguier bc43a38
Merge branch 'master' into projection
tonybruguier a4c7df2
Merge branch 'master' into projection
tonybruguier 2304030
Merge branch 'master' into projection
tonybruguier 2b498b2
Merge branch 'master' into projection
tonybruguier 364d5fe
Use STATE_VECTOR_LIKE, some cleanups
tonybruguier 206491a
Refactor to be like Pauli
tonybruguier 75fa3a1
Merge branch 'master' into projection
tonybruguier 33e3028
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier ede292c
nits
tonybruguier 576d775
nits
tonybruguier e2b57d4
add tolerance to orthonormality test
tonybruguier dcafe0f
nits
tonybruguier e8d827b
nits
tonybruguier 211eeff
Merge branch 'master' into projection
tonybruguier 28fdf56
Multi dim bug fix + added unit test
tonybruguier 41cd189
nits
tonybruguier ec8f7a6
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier fe8032a
bugfix: Reorder the qubits by their true index + expand unit test
tonybruguier 84b2d4c
nits
tonybruguier 47643f8
Merge branch 'master' into projection
tonybruguier b640f48
nits
tonybruguier 6b962b1
Fix bug by missing conjugation + added unit test
tonybruguier 5a1d34d
Merge branch 'master' into projection
tonybruguier 6be4acd
nits
tonybruguier ca8890f
Make sure all qids are present
tonybruguier a361014
Merge branch 'master' into projection
tonybruguier 61e6461
nits
tonybruguier 16d1453
nits
tonybruguier 88df73b
Merge branch 'master' into projection
tonybruguier 75a2477
Merge branch 'master' into projection
tonybruguier e226a7d
Support split QIDs
tonybruguier bf0dac3
replace with pre-computed variable
tonybruguier ded7a4e
nits
tonybruguier 5a31738
nits
tonybruguier 0624df9
add test for unchecked line
tonybruguier e425000
Re-instate accidently deleted new lint
tonybruguier 5b3cef7
Merge branch 'master' into projection
tonybruguier 53abee5
re-nit with new code formatter
tonybruguier e546fc6
Merge branch 'master' into projection
tonybruguier 9d0357c
add the ability to directly specify the matrix
tonybruguier 7a068d9
Merge branch 'master' into projection
tonybruguier e9ce104
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier c297d20
undo the usage of the matrices
tonybruguier 7a3fa0a
Merge branch 'projection' of github.com:tonybruguier/Cirq into projec…
tonybruguier 7571951
nits
tonybruguier a9c4408
Merge branch 'master' into projection
tonybruguier a469a9d
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 8b3b0dd
Merge branch 'projection' of github.com:tonybruguier/Cirq into projec…
tonybruguier f9386e6
Merge branch 'master' into projection
tonybruguier a533361
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier a3e2368
Merge branch 'master' into projection
tonybruguier 5512918
Merge branch 'master' into projection
tonybruguier c52f475
Rename to KetBraSum
tonybruguier 3fe19d3
Implement witt KetBra
tonybruguier 1cb7fa9
nits
tonybruguier e868614
attempt fix annotations
tonybruguier d10dad7
change conjugation convention
tonybruguier 22c90d7
Merge branch 'master' into projection
tonybruguier 34a5b92
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier e53e644
fix typo
tonybruguier 0e97309
Merge branch 'master' into projection
tonybruguier a338502
Merge branch 'master' into projection
tonybruguier 44cff04
Merge branch 'master' into projection
tonybruguier 4dc703f
Merge branch 'master' into projection
tonybruguier 55485c7
Merge branch 'master' into projection
tonybruguier 7a01c67
Merge branch 'master' into projection
tonybruguier 4d5598b
Merge branch 'master' into projection
tonybruguier f764a2e
Merge branch 'master' into projection
tonybruguier de37e7b
Merge branch 'master' into projection
tonybruguier ddc581f
Merge branch 'master' into projection
tonybruguier a50f7ef
Merge branch 'master' into projection
tonybruguier 35c5851
Merge branch 'master' into projection
tonybruguier a0b3ae5
Merge branch 'master' into projection
tonybruguier 74e008e
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 2ce1332
Merge branch 'master' into projection
tonybruguier f39c9a7
Merge branch 'master' into projection
tonybruguier 178817b
Merge branch 'projection' of github.com:tonybruguier/Cirq into projec…
tonybruguier 4d24648
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier d3a71b9
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 3136f19
Merge branch 'master' into projection
tonybruguier 65a57fd
Merge branch 'master' into projection
tonybruguier 5289de4
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier e081fbc
Merge branch 'master' into projection
tonybruguier c0558a6
Merge branch 'projection' of github.com:tonybruguier/Cirq into projec…
tonybruguier fee7ce0
Merge branch 'master' into projection
tonybruguier 245190e
Merge branch 'master' into projection
tonybruguier 8293730
KetBra object
tonybruguier d01292c
remove unused code
tonybruguier 0bce8e1
Merge branch 'master' into projection
tonybruguier 6c349d1
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 74d8b6c
Merge branch 'projection' of github.com:tonybruguier/Cirq into projec…
tonybruguier 9dfea5e
Merge branch 'master' into projection
tonybruguier 3d800c0
Merge branch 'master' into projection
tonybruguier d930aa6
Merge branch 'master' into projection
tonybruguier c1d35f8
fix broken test
tonybruguier f3f50bd
Merge branch 'master' into projection
tonybruguier 13fcecf
Merge branch 'master' into projection
tonybruguier e511480
Merge branch 'master' into projection
tonybruguier 5f2d327
Merge branch 'master' into projection
tonybruguier 471fd61
Merge branch 'master' into projection
tonybruguier 41d0289
Merge branch 'master' into projection
tonybruguier 8b2f75c
Merge branch 'master' into projection
tonybruguier 13d8350
Merge branch 'master' into projection
tonybruguier ad569d7
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 0bc8307
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier f63f0ca
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier c986c80
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 0b0aa4d
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 84f5aaf
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier bc6a926
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 3deda08
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier a1df8c9
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier cb704d7
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier fd05074
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier fe9a102
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier b13f938
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier bbd8602
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier ae06c90
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 1441383
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 9de05ab
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier f084ddd
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier b9a0882
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 3099d75
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier d730d6a
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier ebf5478
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 1c03f62
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier c81533c
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier dee3919
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 39020c4
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 1d8a119
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier e31ac83
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 7cee2f7
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier f8e0ac6
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier 9611ef0
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier e185852
Merge branch 'master' of github.com:quantumlib/Cirq into projection
tonybruguier e69d3f4
nit
tonybruguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,6 +245,7 @@ | |
PhasedXZGate, | ||
PhaseFlipChannel, | ||
RandomGateChannel, | ||
Projector, | ||
qft, | ||
QFT, | ||
Qid, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import Any, Dict, Tuple, TYPE_CHECKING | ||
|
||
import numpy as np | ||
|
||
from cirq import value | ||
from cirq.ops import raw_types | ||
|
||
if TYPE_CHECKING: | ||
import cirq | ||
|
||
|
||
@value.value_equality | ||
class Projector(raw_types.Gate): | ||
"""A non-unitary gate that projects onto a single qubit.""" | ||
tonybruguier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def __init__(self, projector_id: int, qid_shape: Tuple[int, ...] = (2,)): | ||
""" | ||
Args: | ||
projector_id: An integer smaller than qid_shape that specifies the | ||
projector on the qubit. | ||
qid_shape: Specifies the dimension of the projection. The default is | ||
2 (qubit). | ||
|
||
Raises: | ||
ValueError: If the length of invert_mask is greater than num_qubits. | ||
or if the length of qid_shape doesn't equal num_qubits. | ||
""" | ||
if len(qid_shape) != 1: | ||
raise ValueError(f"qid_shape must have a single entry.") | ||
if projector_id >= qid_shape[0]: | ||
raise ValueError(f"projector_id={projector_id} must be less " + | ||
f"than qid_shape[0]={qid_shape[0]}") | ||
self._projector_id = projector_id | ||
self._qid_shape = qid_shape | ||
|
||
def _projector_id_(self) -> int: | ||
return self._projector_id | ||
|
||
def _qid_shape_(self) -> Tuple[int, ...]: | ||
return self._qid_shape | ||
|
||
def _has_unitary_(self) -> bool: | ||
return False | ||
|
||
def _is_parameterized_(self) -> bool: | ||
return False | ||
|
||
def _channel_(self): | ||
tonybruguier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result = np.zeros((self._qid_shape[0], self._qid_shape[0])) | ||
result[self._projector_id][self._projector_id] = 1.0 | ||
return (result,) | ||
tonybruguier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def _has_channel_(self): | ||
return True | ||
|
||
def __repr__(self): | ||
tonybruguier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return (f"cirq.Projector(projector_id={self._projector_id}," + | ||
f"qid_shape={self._qid_shape})") | ||
|
||
def _json_dict_(self) -> Dict[str, Any]: | ||
return { | ||
'cirq_type': self.__class__.__name__, | ||
'projector_id': self._projector_id, | ||
'qid_shape': self._qid_shape, | ||
} | ||
|
||
def _value_equality_values_(self) -> Any: | ||
return self._projector_id, self._qid_shape |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import re | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
import cirq | ||
|
||
|
||
def test_projector_qubit(): | ||
zero_projector = cirq.Projector(projector_id=0) | ||
one_projector = cirq.Projector(projector_id=1) | ||
|
||
np.testing.assert_allclose(cirq.channel(zero_projector), | ||
([[1.0, 0.0], [0.0, 0.0]],)) | ||
|
||
np.testing.assert_allclose(cirq.channel(one_projector), | ||
([[0.0, 0.0], [0.0, 1.0]],)) | ||
|
||
|
||
def test_projector_qutrit(): | ||
zero_projector = cirq.Projector(projector_id=0, qid_shape=[3]) | ||
one_projector = cirq.Projector(projector_id=1, qid_shape=[3]) | ||
two_projector = cirq.Projector(projector_id=2, qid_shape=[3]) | ||
|
||
np.testing.assert_allclose( | ||
cirq.channel(zero_projector), | ||
([[1.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]],)) | ||
|
||
np.testing.assert_allclose( | ||
cirq.channel(one_projector), | ||
([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 0.0]],)) | ||
|
||
np.testing.assert_allclose( | ||
cirq.channel(two_projector), | ||
([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 1.0]],)) | ||
|
||
|
||
def test_bad_constructors(): | ||
with pytest.raises(ValueError, match="qid_shape must have a single entry."): | ||
cirq.Projector(projector_id=0, qid_shape=[2, 2]) | ||
|
||
with pytest.raises( | ||
ValueError, | ||
match=re.escape("projector_id=2 must be less than qid_shape[0]=2")): | ||
cirq.Projector(projector_id=2, qid_shape=[2]) | ||
|
||
|
||
def test_get_values(): | ||
d = cirq.Projector(projector_id=0) | ||
|
||
assert d._projector_id_() == 0 | ||
assert d._qid_shape_() == (2,) | ||
assert not d._has_unitary_() | ||
assert not d._is_parameterized_() | ||
assert d._has_channel_() | ||
|
||
|
||
def test_repr(): | ||
d = cirq.Projector(projector_id=0) | ||
|
||
assert d.__repr__() == "cirq.Projector(projector_id=0,qid_shape=(2,))" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"cirq_type": "Projector", | ||
"projector_id": 1, | ||
"qid_shape": [ | ||
2 | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cirq.Projector(projector_id=1,qid_shape=[2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.