Skip to content

Commit fc3cc70

Browse files
authored
Add FSimViaModelTag (#6527)
* Add FSimViaModelTag * Add json resolver * Address the comment
1 parent 2e28ae1 commit fc3cc70

7 files changed

+80
-0
lines changed

cirq-google/cirq_google/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from cirq_google.ops import (
5858
CalibrationTag,
5959
FSimGateFamily,
60+
FSimViaModelTag,
6061
InternalGate,
6162
PhysicalZTag,
6263
SYC,

cirq-google/cirq_google/json_resolver_cache.py

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def _old_xmon(*args, **kwargs):
5050
'GateTabulation': TwoQubitGateTabulation,
5151
'PhysicalZTag': cirq_google.PhysicalZTag,
5252
'FSimGateFamily': cirq_google.FSimGateFamily,
53+
'FSimViaModelTag': cirq_google.FSimViaModelTag,
5354
'SycamoreTargetGateset': cirq_google.SycamoreTargetGateset,
5455
'cirq.google.BitstringsMeasurement': cirq_google.BitstringsMeasurement,
5556
'cirq.google.QuantumExecutable': cirq_google.QuantumExecutable,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cirq_type": "FSimViaModelTag"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq_google.FSimViaModelTag()

cirq-google/cirq_google/ops/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
from cirq_google.ops.fsim_gate_family import FSimGateFamily
2020

21+
from cirq_google.ops.fsim_via_model_tag import FSimViaModelTag
22+
2123
from cirq_google.ops.physical_z_tag import PhysicalZTag
2224

2325
from cirq_google.ops.sycamore_gate import SycamoreGate, SYC
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2024 The Cirq Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""A class that can be used to denote FSim gate implementation using polynomial model."""
15+
from typing import Any, Dict
16+
17+
import cirq
18+
19+
20+
class FSimViaModelTag:
21+
"""A tag class to denote FSim gate implementation using polynomial model.
22+
23+
Without the tag, the translation of FSim gate implementation is possible only for a certain
24+
angles. For example, when theta=pi/2, phi=0, it translates into the same implementation
25+
as the SWAP gate. If FSimGate is tagged with this class, the translation will become
26+
a coupler gate that with proper coupler strength and coupler length via some polynomial
27+
modelling. Note not all combination of theta and phi in FSim gate are feasible and
28+
you need the calibration for these angle in advance before using them.
29+
"""
30+
31+
def __str__(self) -> str:
32+
return 'FSimViaModelTag()'
33+
34+
def __repr__(self) -> str:
35+
return 'cirq_google.FSimViaModelTag()'
36+
37+
def _json_dict_(self) -> Dict[str, Any]:
38+
return cirq.obj_to_dict_helper(self, [])
39+
40+
def __eq__(self, other) -> bool:
41+
return isinstance(other, FSimViaModelTag)
42+
43+
def __hash__(self) -> int:
44+
return hash("FSimViaModelTag")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2024 The Cirq Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import cirq
15+
import cirq_google
16+
17+
18+
def test_equality():
19+
assert cirq_google.FSimViaModelTag() == cirq_google.FSimViaModelTag()
20+
assert hash(cirq_google.FSimViaModelTag()) == hash(cirq_google.FSimViaModelTag())
21+
22+
23+
def test_str_repr():
24+
assert str(cirq_google.FSimViaModelTag()) == 'FSimViaModelTag()'
25+
assert repr(cirq_google.FSimViaModelTag()) == 'cirq_google.FSimViaModelTag()'
26+
cirq.testing.assert_equivalent_repr(
27+
cirq_google.FSimViaModelTag(), setup_code=('import cirq\nimport cirq_google\n')
28+
)

0 commit comments

Comments
 (0)