Skip to content

Commit

Permalink
Add PhysicalZTag (#2753)
Browse files Browse the repository at this point in the history
* Add PhysicalZTag

- Simple class in cirq.google.ops that can denote physical Z gates.
- Just includes the class definition so far, no functionality.
  • Loading branch information
dstrain115 committed Feb 12, 2020
1 parent ce13a73 commit 89653aa
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cirq/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
LinePlacementStrategy,
)

from cirq.google.ops.sycamore_gate import (
from cirq.google.ops import (
PhysicalZTag,
SycamoreGate,
SYC,
)
Expand Down
3 changes: 3 additions & 0 deletions cirq/google/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
SycamoreGate,
SYC,
)

from cirq.google.ops.physical_z_tag import (
PhysicalZTag,)
42 changes: 42 additions & 0 deletions cirq/google/ops/physical_z_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2020 The Cirq Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
"""A class that can be used to denote a physical Z gate."""
from cirq import protocols


class PhysicalZTag:
"""Class to add as a tag onto an Operation to denote a Physical Z operation.
By default, all Z rotations on Google devices are considered to be virtual.
When performing the Z operation, the device will update its internal phase
tracking mechanisms, essentially commuting it forwards through the circuit
until it hits a non-commuting operation (Such as a sqrt(iSwap)).
When applied to a Z rotation operation, this tag indicates to the hardware
that an actual physical operation should be done instead. This class can
only be applied to instances of `cirq.ZPowGate`. If applied to other gates
(such as PhasedXZGate), this class will have no effect.
"""

def __str__(self):
return 'PhysicalZTag()'

def __repr__(self):
return 'cirq.google.PhysicalZTag()'

def _json_dict_(self):
return protocols.obj_to_dict_helper(self, [])

def __eq__(self, other):
return isinstance(other, PhysicalZTag)
25 changes: 25 additions & 0 deletions cirq/google/ops/physical_z_tag_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2020 The Cirq Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
import cirq


def test_equality():
assert cirq.google.PhysicalZTag() == cirq.google.PhysicalZTag()


def test_syc_str_repr():
assert str(cirq.google.PhysicalZTag()) == 'PhysicalZTag()'
assert repr(cirq.google.PhysicalZTag()) == 'cirq.google.PhysicalZTag()'
cirq.testing.assert_equivalent_repr(cirq.google.PhysicalZTag(),
setup_code=('import cirq\n'))
1 change: 1 addition & 0 deletions cirq/protocols/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def two_qubit_matrix_gate(matrix):
'PhasedISwapPowGate': cirq.PhasedISwapPowGate,
'PhasedXPowGate': cirq.PhasedXPowGate,
'PhasedXZGate': cirq.PhasedXZGate,
'PhysicalZTag': cirq.google.PhysicalZTag,
'QuantumFourierTransformGate': cirq.QuantumFourierTransformGate,
'ResetChannel': cirq.ResetChannel,
'SingleQubitMatrixGate': single_qubit_matrix_gate,
Expand Down
3 changes: 3 additions & 0 deletions cirq/protocols/json_test_data/PhysicalZTag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cirq_type": "PhysicalZTag"
}
1 change: 1 addition & 0 deletions cirq/protocols/json_test_data/PhysicalZTag.repr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cirq.google.PhysicalZTag()
4 changes: 3 additions & 1 deletion cirq/protocols/json_test_data/TaggedOperation.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"tags":
[
"tag1",
"tag2"
{
"cirq_type": "PhysicalZTag"
}
]
}
2 changes: 1 addition & 1 deletion cirq/protocols/json_test_data/TaggedOperation.repr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cirq.TaggedOperation(cirq.X.on(cirq.NamedQubit('q1')), 'tag1', 'tag2')
cirq.TaggedOperation(cirq.X.on(cirq.NamedQubit('q1')), 'tag1', cirq.google.PhysicalZTag())
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ Functionality specific to quantum hardware and services from Google.
cirq.google.GreedySequenceSearchStrategy
cirq.google.JobConfig
cirq.google.LinePlacementStrategy
cirq.google.PhysicalZTag
cirq.google.ProtoVersion
cirq.google.QuantumEngineSampler
cirq.google.SerializableDevice
Expand Down

0 comments on commit 89653aa

Please sign in to comment.