Skip to content

Commit

Permalink
Add CalibrationTag (#3423)
Browse files Browse the repository at this point in the history
* Add CalibrationTag

- Adds a tag to designate a token on a tag to use a specific
calibration.
- Since we are adjusting the name from Focused Calibration to
Calibration API, I have changed this from the formerly named
FocusedCalibrationTag to CalibrationTag
  • Loading branch information
dstrain115 committed Oct 19, 2020
1 parent 3d5c323 commit 9811ce8
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 3 deletions.
1 change: 1 addition & 0 deletions cirq/google/__init__.py
Expand Up @@ -55,6 +55,7 @@
)

from cirq.google.ops import (
CalibrationTag,
PhysicalZTag,
SycamoreGate,
SYC,
Expand Down
9 changes: 6 additions & 3 deletions cirq/google/ops/__init__.py
Expand Up @@ -12,10 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from cirq.google.ops.calibration_tag import (
CalibrationTag,)

from cirq.google.ops.physical_z_tag import (
PhysicalZTag,)

from cirq.google.ops.sycamore_gate import (
SycamoreGate,
SYC,
)

from cirq.google.ops.physical_z_tag import (
PhysicalZTag,)
42 changes: 42 additions & 0 deletions cirq/google/ops/calibration_tag.py
@@ -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.
from typing import Any, Dict

from cirq import protocols


class CalibrationTag:
"""Tag to add onto an Operation that specifies alternate parameters.
Google devices support the ability to run a procedure from calibration API
that can tune the device for a specific circuit. This will return a token
as part of the result. Attaching a `CalibrationTag` with that token
specifies that the gate should use parameters from that specific
calibration, instead of the default gate parameters.
"""

def __init__(self, token: str):
self.token = token

def __str__(self) -> str:
return f'CalibrationTag({self.token!r})'

def __repr__(self) -> str:
return f'cirq.google.CalibrationTag({self.token!r})'

def _json_dict_(self) -> Dict[str, Any]:
return protocols.obj_to_dict_helper(self, ['token'])

def __eq__(self, other) -> bool:
return (isinstance(other, CalibrationTag) and self.token == other.token)
29 changes: 29 additions & 0 deletions cirq/google/ops/calibration_tag_test.py
@@ -0,0 +1,29 @@
# 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():
eq = cirq.testing.EqualsTester()
eq.add_equality_group(cirq.google.CalibrationTag('blah'),
cirq.google.CalibrationTag('blah'))
eq.add_equality_group(cirq.google.CalibrationTag('blah2'))


def test_str_repr():
example_tag = cirq.google.CalibrationTag('foo')
assert str(example_tag) == 'CalibrationTag(\'foo\')'
assert repr(example_tag) == 'cirq.google.CalibrationTag(\'foo\')'
cirq.testing.assert_equivalent_repr(example_tag,
setup_code=('import cirq\n'))
1 change: 1 addition & 0 deletions cirq/protocols/json_serialization.py
Expand Up @@ -85,6 +85,7 @@ def two_qubit_matrix_gate(matrix):
'CCXPowGate': cirq.CCXPowGate,
'CCZPowGate': cirq.CCZPowGate,
'CNotPowGate': cirq.CNotPowGate,
'CalibrationTag': cirq.google.CalibrationTag,
'ControlledGate': cirq.ControlledGate,
'ControlledOperation': cirq.ControlledOperation,
'CSwapGate': cirq.CSwapGate,
Expand Down
4 changes: 4 additions & 0 deletions cirq/protocols/json_test_data/CalibrationTag.json
@@ -0,0 +1,4 @@
{
"cirq_type": "CalibrationTag",
"token": "xeb"
}
1 change: 1 addition & 0 deletions cirq/protocols/json_test_data/CalibrationTag.repr
@@ -0,0 +1 @@
cirq.google.CalibrationTag('xeb')
1 change: 1 addition & 0 deletions rtd_docs/api.rst
Expand Up @@ -524,6 +524,7 @@ Functionality specific to quantum hardware and services from Google.
cirq.google.AnnealSequenceSearchStrategy
cirq.google.Bristlecone
cirq.google.Calibration
cirq.google.CalibrationTag
cirq.google.ConvertToSqrtIswapGates
cirq.google.ConvertToSycamoreGates
cirq.google.ConvertToXmonGates
Expand Down

0 comments on commit 9811ce8

Please sign in to comment.