Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
3d5c323
commit 9811ce8
Showing
8 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
) | ||
|
||
from cirq.google.ops import ( | ||
CalibrationTag, | ||
PhysicalZTag, | ||
SycamoreGate, | ||
SYC, | ||
|
This file contains 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 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,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) |
This file contains 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,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')) |
This file contains 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 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,4 @@ | ||
{ | ||
"cirq_type": "CalibrationTag", | ||
"token": "xeb" | ||
} |
This file contains 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.google.CalibrationTag('xeb') |
This file contains 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