Skip to content

Commit de37106

Browse files
Add Willow gate (#7301)
* Add Willow gate - On Willow processors, the parasitic c-phase parameter for iswap-like gates has changed from the Sycamore processors. - Update the parameter and add a new gate for simulation purposes. * Change to pi/9 * Update cirq-google/cirq_google/ops/willow_gate.py Co-authored-by: Pavol Juhas <pavol.juhas@gmail.com> * format * pi / 9 --------- Co-authored-by: Pavol Juhas <pavol.juhas@gmail.com>
1 parent 22284fe commit de37106

File tree

10 files changed

+153
-0
lines changed

10 files changed

+153
-0
lines changed

cirq-google/cirq_google/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
PhysicalZTag as PhysicalZTag,
6464
SYC as SYC,
6565
SycamoreGate as SycamoreGate,
66+
WILLOW as WILLOW,
67+
WillowGate as WillowGate,
6668
)
6769

6870
from cirq_google.transformers import (

cirq-google/cirq_google/json_resolver_cache.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _old_xmon(*args, **kwargs):
4747
'Coupler': cirq_google.Coupler,
4848
'GoogleNoiseProperties': cirq_google.GoogleNoiseProperties,
4949
'SycamoreGate': cirq_google.SycamoreGate,
50+
'WillowGate': cirq_google.WillowGate,
5051
# cirq_google.GateTabulation has been removed and replaced by cirq.TwoQubitGateTabulation.
5152
'GateTabulation': TwoQubitGateTabulation,
5253
'PhysicalZTag': cirq_google.PhysicalZTag,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cirq_type": "WillowGate"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq_google.WILLOW
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"cirq_type": "WillowGate"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cirq_google.WILLOW

cirq-google/cirq_google/ops/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@
3333
from cirq_google.ops.dynamical_decoupling_tag import (
3434
DynamicalDecouplingTag as DynamicalDecouplingTag,
3535
)
36+
37+
from cirq_google.ops.willow_gate import WillowGate as WillowGate, WILLOW as WILLOW

cirq-google/cirq_google/ops/sycamore_gate.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class SycamoreGate(cirq.FSimGate):
3333
is close to the gates that were used to demonstrate beyond
3434
classical resuts used in this paper:
3535
https://www.nature.com/articles/s41586-019-1666-5
36+
37+
Note that this gate will be transformed to a "ISWAP-like" gate
38+
on hardware and that the C-phase value (phi) may change from
39+
processor to processor. In particular, if executed on newer
40+
Willow processors, the phi value will be closer to π/9.
41+
Use the Willow gate for simulation of this gate on newer devices.
3642
"""
3743

3844
def __init__(self):
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Copyright 2025 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+
"""An instance of FSimGate that works naturally on Google's Sycamore chip"""
15+
16+
import numpy as np
17+
18+
import cirq
19+
from cirq._doc import document
20+
21+
22+
class WillowGate(cirq.FSimGate):
23+
"""The Willow gate is a two-qubit gate equivalent to FSimGate(π/2, π/9).
24+
25+
The unitary of this gate is simulated as:
26+
27+
[[1, 0, 0, 0],
28+
[0, 0, -1j, 0],
29+
[0, -1j, 0, 0],
30+
[0, 0, 0, exp(- 1j * π/9)]]
31+
32+
This gate can be performed on the Google's Willow chip. Note that
33+
this gate will be transformed to a "ISWAP-like" gate on hardware
34+
and that the C-phase angle (phi) may change from processor to
35+
processor. The specified value is provided only for simulation
36+
purposes.
37+
"""
38+
39+
def __init__(self):
40+
super().__init__(theta=np.pi / 2, phi=np.pi / 9)
41+
42+
def __repr__(self) -> str:
43+
return 'cirq_google.WILLOW'
44+
45+
def __str__(self) -> str:
46+
return 'WILLOW'
47+
48+
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs):
49+
return 'WILLOW', 'WILLOW'
50+
51+
def _json_dict_(self):
52+
return cirq.obj_to_dict_helper(self, [])
53+
54+
55+
WILLOW = WillowGate()
56+
document(
57+
WILLOW,
58+
"""The Willow gate is a two-qubit gate equivalent to FSimGate(π/2, π/9).
59+
60+
The unitary of this gate is simulated as:
61+
62+
[[1, 0, 0, 0],
63+
[0, 0, -1j, 0],
64+
[0, -1j, 0, 0],
65+
[0, 0, 0, exp(- 1j * π/9)]]
66+
67+
This gate can be performed on the Google's Willow chip. Note that
68+
this gate will be transformed to a "ISWAP-like" gate on hardware
69+
and that the C-phase value (phi) may change from processor to
70+
processor. The specified value is provided only for simulation
71+
purposes.""",
72+
)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2025 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 numpy as np
15+
16+
import cirq
17+
import cirq_google as cg
18+
19+
20+
def test_consistent_protocols():
21+
cirq.testing.assert_implements_consistent_protocols(
22+
cg.WILLOW,
23+
setup_code='import cirq\nimport numpy as np\nimport sympy\nimport cirq_google',
24+
qubit_count=2,
25+
)
26+
27+
28+
def test_willow_str_repr():
29+
assert str(cg.WILLOW) == 'WILLOW'
30+
assert repr(cg.WILLOW) == 'cirq_google.WILLOW'
31+
32+
33+
def test_willow_circuit_diagram():
34+
a, b = cirq.LineQubit.range(2)
35+
circuit = cirq.Circuit(cg.WILLOW(a, b))
36+
cirq.testing.assert_has_diagram(
37+
circuit,
38+
"""
39+
0: ───WILLOW───
40+
41+
1: ───WILLOW───
42+
""",
43+
)
44+
45+
46+
def test_willow_is_specific_fsim():
47+
assert cg.WILLOW == cirq.FSimGate(theta=np.pi / 2, phi=np.pi / 9)
48+
49+
50+
def test_willow_unitary():
51+
cirq.testing.assert_allclose_up_to_global_phase(
52+
cirq.unitary(cg.WILLOW),
53+
np.array(
54+
[
55+
[1.0, 0.0, 0.0, 0.0],
56+
[0.0, 0.0, -1.0j, 0.0],
57+
[0.0, -1.0j, 0.0, 0.0],
58+
[0.0, 0.0, 0.0, np.exp(-1j * np.pi / 9)],
59+
]
60+
),
61+
atol=1e-6,
62+
)

0 commit comments

Comments
 (0)