Skip to content

Commit

Permalink
Fix VirtualTag (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
viathor authored May 31, 2020
1 parent caab356 commit 008eab4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
transform_op_tree,
TwoQubitDiagonalGate,
TwoQubitGate,
VirtualTag,
WaitGate,
X,
XPowGate,
Expand Down
8 changes: 6 additions & 2 deletions cirq/ops/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Canonical tags for the TaggedOperation class."""
from typing import Dict


class VirtualTag():
class VirtualTag:
"""A TaggedOperation tag indicating that the operation is virtual.
Operations marked with this tag are presumed to have zero duration of their
Expand All @@ -29,4 +30,7 @@ def __str__(self) -> str:
return '<virtual>'

def __repr__(self) -> str:
return str(self)
return 'cirq.VirtualTag()'

def _json_dict_(self) -> Dict[str, str]:
return {'cirq_type': self.__class__.__name__}
5 changes: 4 additions & 1 deletion cirq/ops/tags_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ def test_virtual_tag():
tag2 = cirq.ops.VirtualTag()

assert tag1 == tag2
assert repr(tag1) == repr(tag2) == '<virtual>'
assert str(tag1) == str(tag2) == '<virtual>'

cirq.testing.assert_equivalent_repr(tag1)
cirq.testing.assert_equivalent_repr(tag2)
1 change: 1 addition & 0 deletions cirq/protocols/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def two_qubit_matrix_gate(matrix):
'TwoQubitDiagonalGate': cirq.TwoQubitDiagonalGate,
'_UnconstrainedDevice':
cirq.devices.unconstrained_device._UnconstrainedDevice,
'VirtualTag': cirq.VirtualTag,
'WaitGate': cirq.WaitGate,
'_QubitAsQid': raw_types._QubitAsQid,
'XPowGate': cirq.XPowGate,
Expand Down
3 changes: 3 additions & 0 deletions cirq/protocols/json_test_data/VirtualTag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cirq_type": "VirtualTag"
}
1 change: 1 addition & 0 deletions cirq/protocols/json_test_data/VirtualTag.repr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cirq.VirtualTag()
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ the more general concept of a noisy open system quantum evolution.
cirq.PhaseDampingChannel
cirq.PhaseFlipChannel
cirq.ResetChannel
cirq.VirtualTag


Pauli and Clifford Groups
Expand Down

0 comments on commit 008eab4

Please sign in to comment.