Skip to content

Commit b014036

Browse files
wcourtneymaffoo
andauthored
Add single-qubit detuning parameters to CouplerPulse (#5971)
* Add single-qubit detuning parameters to CouplerPulse * Update test json data with new coupler detune parameters. * Add test to confirm that deserialization continues to work with added fields. * Fix formatting Co-authored-by: Matthew Neeley <maffoo@google.com>
1 parent 0c4f742 commit b014036

File tree

3 files changed

+85
-19
lines changed

3 files changed

+85
-19
lines changed

cirq-google/cirq_google/experimental/ops/coupler_pulse.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class CouplerPulse(cirq.ops.Gate):
4747
coupling_mhz: Target qubit-qubit coupling reached at the plateau.
4848
rise_time: Width of the rising (or falling) section of the trapezoidal pulse.
4949
padding_time: Symmetric padding around the coupler pulse.
50+
q0_detune_mhz: Detuning of the first qubit.
51+
q1_detune_mhz: Detuning of the second qubit.
5052
"""
5153

5254
def __init__(
@@ -55,6 +57,8 @@ def __init__(
5557
coupling_mhz: cirq.TParamVal,
5658
rise_time: Optional[cirq.Duration] = cirq.Duration(nanos=8),
5759
padding_time: Optional[cirq.Duration] = cirq.Duration(nanos=2.5),
60+
q0_detune_mhz: cirq.TParamVal = 0.0,
61+
q1_detune_mhz: cirq.TParamVal = 0.0,
5862
):
5963
"""Inits CouplerPulse.
6064
@@ -63,12 +67,16 @@ def __init__(
6367
coupling_mhz: Target qubit-qubit coupling reached at the plateau.
6468
rise_time: Width of the rising (or falling) action of the trapezoidal pulse.
6569
padding_time: Symmetric padding around the coupler pulse.
70+
q0_detune_mhz: Detuning of the first qubit.
71+
q1_detune_mhz: Detuning of the second qubit.
6672
6773
"""
6874
self.hold_time = hold_time
6975
self.coupling_mhz = coupling_mhz
7076
self.rise_time = rise_time or cirq.Duration(nanos=8)
7177
self.padding_time = padding_time or cirq.Duration(nanos=2.5)
78+
self.q0_detune_mhz = q0_detune_mhz
79+
self.q1_detune_mhz = q1_detune_mhz
7280

7381
def num_qubits(self) -> int:
7482
return 2
@@ -79,18 +87,22 @@ def _unitary_(self) -> np.ndarray:
7987
def __repr__(self) -> str:
8088
return (
8189
'cirq_google.experimental.ops.coupler_pulse.'
82-
+ f'CouplerPulse(hold_time={proper_repr(self.hold_time)}, '
83-
+ f'coupling_mhz={proper_repr(self.coupling_mhz)}, '
84-
+ f'rise_time={proper_repr(self.rise_time)}, '
85-
+ f'padding_time={proper_repr(self.padding_time)})'
90+
f'CouplerPulse(hold_time={proper_repr(self.hold_time)}, '
91+
f'coupling_mhz={proper_repr(self.coupling_mhz)}, '
92+
f'rise_time={proper_repr(self.rise_time)}, '
93+
f'padding_time={proper_repr(self.padding_time)}, '
94+
f'q0_detune_mhz={proper_repr(self.q0_detune_mhz)}, '
95+
f'q1_detune_mhz={proper_repr(self.q1_detune_mhz)})'
8696
)
8797

8898
def __str__(self) -> str:
8999
return (
90100
f'CouplerPulse(hold_time={self.hold_time}, '
91-
+ f'coupling_mhz={self.coupling_mhz}, '
92-
+ f'rise_time={self.rise_time}, '
93-
+ f'padding_time={self.padding_time})'
101+
f'coupling_mhz={self.coupling_mhz}, '
102+
f'rise_time={self.rise_time}, '
103+
f'padding_time={self.padding_time}, '
104+
f'q0_detune_mhz={self.q0_detune_mhz}, '
105+
f'q1_detune_mhz={self.q1_detune_mhz})'
94106
)
95107

96108
def _is_parameterized_(self) -> bool:
@@ -99,6 +111,8 @@ def _is_parameterized_(self) -> bool:
99111
or cirq.is_parameterized(self.coupling_mhz)
100112
or cirq.is_parameterized(self.rise_time)
101113
or cirq.is_parameterized(self.padding_time)
114+
or cirq.is_parameterized(self.q0_detune_mhz)
115+
or cirq.is_parameterized(self.q1_detune_mhz)
102116
)
103117

104118
def _parameter_names_(self: Any) -> AbstractSet[str]:
@@ -107,6 +121,8 @@ def _parameter_names_(self: Any) -> AbstractSet[str]:
107121
| cirq.parameter_names(self.coupling_mhz)
108122
| cirq.parameter_names(self.rise_time)
109123
| cirq.parameter_names(self.padding_time)
124+
| cirq.parameter_names(self.q0_detune_mhz)
125+
| cirq.parameter_names(self.q1_detune_mhz)
110126
)
111127

112128
def _resolve_parameters_(
@@ -117,16 +133,37 @@ def _resolve_parameters_(
117133
coupling_mhz=cirq.resolve_parameters(self.coupling_mhz, resolver, recursive=recursive),
118134
rise_time=cirq.resolve_parameters(self.rise_time, resolver, recursive=recursive),
119135
padding_time=cirq.resolve_parameters(self.padding_time, resolver, recursive=recursive),
136+
q0_detune_mhz=cirq.resolve_parameters(
137+
self.q0_detune_mhz, resolver, recursive=recursive
138+
),
139+
q1_detune_mhz=cirq.resolve_parameters(
140+
self.q1_detune_mhz, resolver, recursive=recursive
141+
),
120142
)
121143

122144
def _value_equality_values_(self) -> Any:
123-
return self.hold_time, self.coupling_mhz, self.rise_time, self.padding_time
145+
return (
146+
self.hold_time,
147+
self.coupling_mhz,
148+
self.rise_time,
149+
self.padding_time,
150+
self.q0_detune_mhz,
151+
self.q1_detune_mhz,
152+
)
124153

125154
def _circuit_diagram_info_(self, args: cirq.CircuitDiagramInfoArgs) -> Tuple[str, ...]:
126155
s = f'/‾‾({self.hold_time}@{self.coupling_mhz}MHz)‾‾\\'
127156
return (s, s)
128157

129158
def _json_dict_(self):
130159
return cirq.obj_to_dict_helper(
131-
self, ['hold_time', 'coupling_mhz', 'rise_time', 'padding_time']
160+
self,
161+
[
162+
'hold_time',
163+
'coupling_mhz',
164+
'rise_time',
165+
'padding_time',
166+
'q0_detune_mhz',
167+
'q1_detune_mhz',
168+
],
132169
)

cirq-google/cirq_google/experimental/ops/coupler_pulse_test.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,47 @@ def test_coupler_pulse_str_repr():
8686
hold_time=cirq.Duration(nanos=10), coupling_mhz=25.0, rise_time=cirq.Duration(nanos=18)
8787
)
8888
assert (
89-
str(gate)
90-
== 'CouplerPulse(hold_time=10 ns, coupling_mhz=25.0, '
91-
+ 'rise_time=18 ns, padding_time=2500.0 ps)'
89+
str(gate) == 'CouplerPulse(hold_time=10 ns, coupling_mhz=25.0, '
90+
'rise_time=18 ns, padding_time=2500.0 ps, q0_detune_mhz=0.0, q1_detune_mhz=0.0)'
9291
)
9392
assert (
94-
repr(gate)
95-
== 'cirq_google.experimental.ops.coupler_pulse.CouplerPulse('
96-
+ 'hold_time=cirq.Duration(nanos=10), '
97-
+ 'coupling_mhz=25.0, '
98-
+ 'rise_time=cirq.Duration(nanos=18), '
99-
+ 'padding_time=cirq.Duration(picos=2500.0))'
93+
repr(gate) == 'cirq_google.experimental.ops.coupler_pulse.CouplerPulse('
94+
'hold_time=cirq.Duration(nanos=10), '
95+
'coupling_mhz=25.0, '
96+
'rise_time=cirq.Duration(nanos=18), '
97+
'padding_time=cirq.Duration(picos=2500.0), '
98+
'q0_detune_mhz=0.0, '
99+
'q1_detune_mhz=0.0)'
100100
)
101101

102102

103+
def test_coupler_pulse_json_deserialization_defaults_on_missing_fields():
104+
gate = coupler_pulse.CouplerPulse(
105+
hold_time=cirq.Duration(nanos=10), coupling_mhz=25.0, rise_time=cirq.Duration(nanos=18)
106+
)
107+
json_text = """{
108+
"cirq_type": "CouplerPulse",
109+
"hold_time": {
110+
"cirq_type": "Duration",
111+
"picos": 10000
112+
},
113+
"coupling_mhz": 25.0,
114+
"rise_time": {
115+
"cirq_type": "Duration",
116+
"picos": 18000
117+
},
118+
"padding_time": {
119+
"cirq_type": "Duration",
120+
"picos": 2500.0
121+
}
122+
}"""
123+
124+
deserialized = cirq.read_json(json_text=json_text)
125+
126+
assert deserialized == gate
127+
assert deserialized.q0_detune_mhz == 0.0
128+
129+
103130
def test_coupler_pulse_circuit_diagram():
104131
a, b = cirq.LineQubit.range(2)
105132
gate = coupler_pulse.CouplerPulse(

cirq-google/cirq_google/json_test_data/CouplerPulse.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
"padding_time": {
1313
"cirq_type": "Duration",
1414
"picos": 2500.0
15-
}
15+
},
16+
"q0_detune_mhz": 0.0,
17+
"q1_detune_mhz": 0.0
1618
}

0 commit comments

Comments
 (0)