diff --git a/cirq-google/cirq_google/__init__.py b/cirq-google/cirq_google/__init__.py index 0301afbfb20..68cf6fb0a40 100644 --- a/cirq-google/cirq_google/__init__.py +++ b/cirq-google/cirq_google/__init__.py @@ -57,6 +57,7 @@ from cirq_google.ops import ( CalibrationTag, FSimGateFamily, + FSimViaModelTag, InternalGate, PhysicalZTag, SYC, diff --git a/cirq-google/cirq_google/json_resolver_cache.py b/cirq-google/cirq_google/json_resolver_cache.py index 068c43be046..c767a79650d 100644 --- a/cirq-google/cirq_google/json_resolver_cache.py +++ b/cirq-google/cirq_google/json_resolver_cache.py @@ -50,6 +50,7 @@ def _old_xmon(*args, **kwargs): 'GateTabulation': TwoQubitGateTabulation, 'PhysicalZTag': cirq_google.PhysicalZTag, 'FSimGateFamily': cirq_google.FSimGateFamily, + 'FSimViaModelTag': cirq_google.FSimViaModelTag, 'SycamoreTargetGateset': cirq_google.SycamoreTargetGateset, 'cirq.google.BitstringsMeasurement': cirq_google.BitstringsMeasurement, 'cirq.google.QuantumExecutable': cirq_google.QuantumExecutable, diff --git a/cirq-google/cirq_google/json_test_data/FSimViaModelTag.json b/cirq-google/cirq_google/json_test_data/FSimViaModelTag.json new file mode 100644 index 00000000000..34c8def0f2d --- /dev/null +++ b/cirq-google/cirq_google/json_test_data/FSimViaModelTag.json @@ -0,0 +1,3 @@ +{ + "cirq_type": "FSimViaModelTag" +} \ No newline at end of file diff --git a/cirq-google/cirq_google/json_test_data/FSimViaModelTag.repr b/cirq-google/cirq_google/json_test_data/FSimViaModelTag.repr new file mode 100644 index 00000000000..65908348a93 --- /dev/null +++ b/cirq-google/cirq_google/json_test_data/FSimViaModelTag.repr @@ -0,0 +1 @@ +cirq_google.FSimViaModelTag() \ No newline at end of file diff --git a/cirq-google/cirq_google/ops/__init__.py b/cirq-google/cirq_google/ops/__init__.py index 4f9f848f209..b52e000c314 100644 --- a/cirq-google/cirq_google/ops/__init__.py +++ b/cirq-google/cirq_google/ops/__init__.py @@ -18,6 +18,8 @@ from cirq_google.ops.fsim_gate_family import FSimGateFamily +from cirq_google.ops.fsim_via_model_tag import FSimViaModelTag + from cirq_google.ops.physical_z_tag import PhysicalZTag from cirq_google.ops.sycamore_gate import SycamoreGate, SYC diff --git a/cirq-google/cirq_google/ops/fsim_via_model_tag.py b/cirq-google/cirq_google/ops/fsim_via_model_tag.py new file mode 100644 index 00000000000..b0480f7ec0a --- /dev/null +++ b/cirq-google/cirq_google/ops/fsim_via_model_tag.py @@ -0,0 +1,44 @@ +# Copyright 2024 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 FSim gate implementation using polynomial model.""" +from typing import Any, Dict + +import cirq + + +class FSimViaModelTag: + """A tag class to denote FSim gate implementation using polynomial model. + + Without the tag, the translation of FSim gate implementation is possible only for a certain + angles. For example, when theta=pi/2, phi=0, it translates into the same implementation + as the SWAP gate. If FSimGate is tagged with this class, the translation will become + a coupler gate that with proper coupler strength and coupler length via some polynomial + modelling. Note not all combination of theta and phi in FSim gate are feasible and + you need the calibration for these angle in advance before using them. + """ + + def __str__(self) -> str: + return 'FSimViaModelTag()' + + def __repr__(self) -> str: + return 'cirq_google.FSimViaModelTag()' + + def _json_dict_(self) -> Dict[str, Any]: + return cirq.obj_to_dict_helper(self, []) + + def __eq__(self, other) -> bool: + return isinstance(other, FSimViaModelTag) + + def __hash__(self) -> int: + return hash("FSimViaModelTag") diff --git a/cirq-google/cirq_google/ops/fsim_via_model_tag_test.py b/cirq-google/cirq_google/ops/fsim_via_model_tag_test.py new file mode 100644 index 00000000000..a25076d955e --- /dev/null +++ b/cirq-google/cirq_google/ops/fsim_via_model_tag_test.py @@ -0,0 +1,28 @@ +# Copyright 2024 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 +import cirq_google + + +def test_equality(): + assert cirq_google.FSimViaModelTag() == cirq_google.FSimViaModelTag() + assert hash(cirq_google.FSimViaModelTag()) == hash(cirq_google.FSimViaModelTag()) + + +def test_str_repr(): + assert str(cirq_google.FSimViaModelTag()) == 'FSimViaModelTag()' + assert repr(cirq_google.FSimViaModelTag()) == 'cirq_google.FSimViaModelTag()' + cirq.testing.assert_equivalent_repr( + cirq_google.FSimViaModelTag(), setup_code=('import cirq\nimport cirq_google\n') + )