Skip to content

Commit 41be90d

Browse files
Bumped Version to cirq 0.8. (#234)
* Bumped Version to cirq 0.8. * format. * oops 0.9 * pinned sympy. * Fixed notebooks. * pinned sympy in setup as well.
1 parent 82270b3 commit 41be90d

File tree

17 files changed

+86
-83
lines changed

17 files changed

+86
-83
lines changed

docs/tutorials/barren_plateaus.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
" \"\"\"Generate random QNN's with the same structure from McClean et al.\"\"\"\n",
200200
" circuit = cirq.Circuit()\n",
201201
" for qubit in qubits:\n",
202-
" circuit += cirq.Ry(np.pi / 4.0)(qubit)\n",
202+
" circuit += cirq.ry(np.pi / 4.0)(qubit)\n",
203203
"\n",
204204
" for d in range(depth):\n",
205205
" # Add a series of single qubit rotations.\n",
@@ -209,13 +209,13 @@
209209
" ) * 2.0 * np.pi if i != 0 or d != 0 else symbol\n",
210210
" if random_n > 2. / 3.:\n",
211211
" # Add a Z.\n",
212-
" circuit += cirq.Rz(random_rot)(qubit)\n",
212+
" circuit += cirq.rz(random_rot)(qubit)\n",
213213
" elif random_n > 1. / 3.:\n",
214214
" # Add a Y.\n",
215-
" circuit += cirq.Ry(random_rot)(qubit)\n",
215+
" circuit += cirq.ry(random_rot)(qubit)\n",
216216
" else:\n",
217217
" # Add a X.\n",
218-
" circuit += cirq.Rx(random_rot)(qubit)\n",
218+
" circuit += cirq.rx(random_rot)(qubit)\n",
219219
"\n",
220220
" # Add CZ ladder.\n",
221221
" for src, dest in zip(qubits, qubits[1:]):\n",

docs/tutorials/qcnn.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
"\n",
290290
"<img src=\"./images/qcnn_2.png\" width=\"1000\">\n",
291291
"\n",
292-
"An \"excited\" cluster state is defined as a cluster state that had a `cirq.Rx` gate applied to any of its qubits. Qconv and QPool are discussed later in this tutorial."
292+
"An \"excited\" cluster state is defined as a cluster state that had a `cirq.rx` gate applied to any of its qubits. Qconv and QPool are discussed later in this tutorial."
293293
]
294294
},
295295
{
@@ -318,7 +318,7 @@
318318
},
319319
"source": [
320320
"### 1.4 Data\n",
321-
"Before building your model, you can generate your data. In this case it's going to be excitations to the cluster state (The original paper uses a more complicated dataset). Excitations are represented with `cirq.Rx` gates. A large enough rotation is deemed an excitation and is labeled `1` and a rotation that isn't large enough is labeled `-1` and deemed not an excitation."
321+
"Before building your model, you can generate your data. In this case it's going to be excitations to the cluster state (The original paper uses a more complicated dataset). Excitations are represented with `cirq.rx` gates. A large enough rotation is deemed an excitation and is labeled `1` and a rotation that isn't large enough is labeled `-1` and deemed not an excitation."
322322
]
323323
},
324324
{
@@ -339,7 +339,7 @@
339339
" for n in range(n_rounds):\n",
340340
" for bit in qubits:\n",
341341
" rng = np.random.uniform(-np.pi, np.pi)\n",
342-
" excitations.append(cirq.Circuit(cirq.Rx(rng)(bit)))\n",
342+
" excitations.append(cirq.Circuit(cirq.rx(rng)(bit)))\n",
343343
" labels.append(1 if (-np.pi / 2) <= rng <= (np.pi / 2) else -1)\n",
344344
"\n",
345345
" split_ind = int(len(excitations) * 0.7)\n",

release/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def finalize_options(self):
5050
self.install_lib = self.install_platlib
5151

5252

53-
REQUIRED_PACKAGES = ['cirq == 0.7.0', 'pathos == 0.2.5']
53+
REQUIRED_PACKAGES = ['cirq == 0.8.0', 'pathos == 0.2.5', 'sympy == 1.4']
5454
CUR_VERSION = '0.3.0'
5555

5656

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
cirq==0.7.0
1+
cirq==0.8.0
2+
sympy==1.4
23
nbconvert==5.6.1
34
nbformat==4.4.0
45
pylint==2.4.4

tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def test_empty(self):
671671
def test_rotation_gates(self):
672672
"""Test that rotation gates work."""
673673
bit = cirq.GridQubit(0, 0)
674-
circuit = cirq.Circuit(cirq.Rx(sympy.Symbol('alpha') * 5.0)(bit))
674+
circuit = cirq.Circuit(cirq.rx(sympy.Symbol('alpha') * 5.0)(bit))
675675
inputs = util.convert_to_tensor([circuit])
676676
symbols = tf.convert_to_tensor(['alpha'])
677677
res = tfq_ps_util_ops.tfq_ps_weights_from_symbols(inputs, symbols)

tensorflow_quantum/core/serialize/serializer.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _scalar_extractor(x):
4646
In the future we should likely get rid of this in favor of proper
4747
expression parsing once cirq supports it. See cirq.op_serializer
4848
and cirq's program protobuf for details. This is needed for things
49-
like cirq.Rx('alpha').
49+
like cirq.rx('alpha').
5050
"""
5151
if not isinstance(x, (numbers.Real, sympy.Expr)):
5252
raise TypeError("Invalid input argument for exponent.")
@@ -111,14 +111,15 @@ def _eigen_gate_serializer(gate_type, serialized_id):
111111
cirq.google.SerializingArg(
112112
serialized_name="exponent",
113113
serialized_type=float,
114-
gate_getter=lambda x: _symbol_extractor(x.exponent)),
114+
op_getter=lambda x: _symbol_extractor(x.gate.exponent)),
115115
cirq.google.SerializingArg(
116116
serialized_name="exponent_scalar",
117117
serialized_type=float,
118-
gate_getter=lambda x: _scalar_extractor(x.exponent)),
119-
cirq.google.SerializingArg(serialized_name="global_shift",
120-
serialized_type=float,
121-
gate_getter=lambda x: float(x._global_shift))
118+
op_getter=lambda x: _scalar_extractor(x.gate.exponent)),
119+
cirq.google.SerializingArg(
120+
serialized_name="global_shift",
121+
serialized_type=float,
122+
op_getter=lambda x: float(x.gate._global_shift))
122123
]
123124
return cirq.google.GateOpSerializer(gate_type=gate_type,
124125
serialized_gate_id=serialized_id,
@@ -134,7 +135,7 @@ def _scalar_combiner(exponent, global_shift, exponent_scalar):
134135
In the future we should likely get rid of this in favor of proper
135136
expression parsing once cirq supports it. See cirq.op_serializer
136137
and cirq's program protobuf for details. This is needed for things
137-
like cirq.Rx('alpha').
138+
like cirq.rx('alpha').
138139
"""
139140
if exponent_scalar == 1.0:
140141
return gate_type(exponent=exponent, global_shift=global_shift)
@@ -161,19 +162,19 @@ def _fsim_gate_serializer():
161162
cirq.google.SerializingArg(
162163
serialized_name="theta",
163164
serialized_type=float,
164-
gate_getter=lambda x: _symbol_extractor(x.theta)),
165+
op_getter=lambda x: _symbol_extractor(x.gate.theta)),
165166
cirq.google.SerializingArg(
166167
serialized_name="phi",
167168
serialized_type=float,
168-
gate_getter=lambda x: _symbol_extractor(x.phi)),
169+
op_getter=lambda x: _symbol_extractor(x.gate.phi)),
169170
cirq.google.SerializingArg(
170171
serialized_name="theta_scalar",
171172
serialized_type=float,
172-
gate_getter=lambda x: _scalar_extractor(x.theta)),
173+
op_getter=lambda x: _scalar_extractor(x.gate.theta)),
173174
cirq.google.SerializingArg(
174175
serialized_name="phi_scalar",
175176
serialized_type=float,
176-
gate_getter=lambda x: _scalar_extractor(x.phi)),
177+
op_getter=lambda x: _scalar_extractor(x.gate.phi)),
177178
]
178179
return cirq.google.GateOpSerializer(gate_type=cirq.FSimGate,
179180
serialized_gate_id="FSIM",
@@ -209,7 +210,7 @@ def _identity_gate_serializer():
209210
"""Make a standard serializer for the single qubit identity."""
210211

211212
def _identity_check(x):
212-
if x.num_qubits() != 1:
213+
if x.gate.num_qubits() != 1:
213214
raise ValueError("Multi-Qubit identity gate not supported."
214215
"Given: {}. To work around this, use "
215216
"cirq.I.on_each instead.".format(str(x)))
@@ -220,7 +221,7 @@ def _identity_check(x):
220221
args = [
221222
cirq.google.SerializingArg(serialized_name="unused",
222223
serialized_type=bool,
223-
gate_getter=_identity_check)
224+
op_getter=_identity_check)
224225
]
225226
return cirq.google.GateOpSerializer(gate_type=cirq.IdentityGate,
226227
serialized_gate_id="I",
@@ -250,22 +251,23 @@ def _phased_eigen_gate_serializer(gate_type, serialized_id):
250251
cirq.google.SerializingArg(
251252
serialized_name="phase_exponent",
252253
serialized_type=float,
253-
gate_getter=lambda x: _symbol_extractor(x.phase_exponent)),
254+
op_getter=lambda x: _symbol_extractor(x.gate.phase_exponent)),
254255
cirq.google.SerializingArg(
255256
serialized_name="phase_exponent_scalar",
256257
serialized_type=float,
257-
gate_getter=lambda x: _scalar_extractor(x.phase_exponent)),
258+
op_getter=lambda x: _scalar_extractor(x.gate.phase_exponent)),
258259
cirq.google.SerializingArg(
259260
serialized_name="exponent",
260261
serialized_type=float,
261-
gate_getter=lambda x: _symbol_extractor(x.exponent)),
262+
op_getter=lambda x: _symbol_extractor(x.gate.exponent)),
262263
cirq.google.SerializingArg(
263264
serialized_name="exponent_scalar",
264265
serialized_type=float,
265-
gate_getter=lambda x: _scalar_extractor(x.exponent)),
266-
cirq.google.SerializingArg(serialized_name="global_shift",
267-
serialized_type=float,
268-
gate_getter=lambda x: float(x.global_shift))
266+
op_getter=lambda x: _scalar_extractor(x.gate.exponent)),
267+
cirq.google.SerializingArg(
268+
serialized_name="global_shift",
269+
serialized_type=float,
270+
op_getter=lambda x: float(x.gate.global_shift))
269271
]
270272
return cirq.google.GateOpSerializer(gate_type=gate_type,
271273
serialized_gate_id=serialized_id,
@@ -282,7 +284,7 @@ def _scalar_combiner(exponent, global_shift, exponent_scalar,
282284
In the future we should likely get rid of this in favor of proper
283285
expression parsing once cirq supports it. See cirq.op_serializer
284286
and cirq's program protobuf for details. This is needed for things
285-
like cirq.Rx('alpha').
287+
like cirq.rx('alpha').
286288
"""
287289
# Do this to help with rounding. it's ugly.
288290
exponent = exponent if exponent_scalar == 1.0 \

tensorflow_quantum/core/serialize/serializer_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,15 @@ def _get_valid_circuit_proto_pairs():
346346
# RX, RY, RZ with symbolization is tested in special cases as the
347347
# string comparison of the float converted sympy.pi does not happen
348348
# smoothly. See: test_serialize_deserialize_special_case_one_qubit
349-
(cirq.Circuit(cirq.Rx(np.pi)(q0)),
349+
(cirq.Circuit(cirq.rx(np.pi)(q0)),
350350
_build_gate_proto("XP",
351351
['exponent', 'exponent_scalar', 'global_shift'],
352352
[1.0, 1.0, -0.5], ['0_0'])),
353-
(cirq.Circuit(cirq.Ry(np.pi)(q0)),
353+
(cirq.Circuit(cirq.ry(np.pi)(q0)),
354354
_build_gate_proto("YP",
355355
['exponent', 'exponent_scalar', 'global_shift'],
356356
[1.0, 1.0, -0.5], ['0_0'])),
357-
(cirq.Circuit(cirq.Rz(np.pi)(q0)),
357+
(cirq.Circuit(cirq.rz(np.pi)(q0)),
358358
_build_gate_proto("ZP",
359359
['exponent', 'exponent_scalar', 'global_shift'],
360360
[1.0, 1.0, -0.5], ['0_0'])),
@@ -591,13 +591,13 @@ def test_serialize_deserialize_paulisum_consistency(self, sum_proto_pair):
591591

592592
@parameterized.parameters([
593593
{
594-
'gate': cirq.Rx(3.0 * sympy.Symbol('alpha'))
594+
'gate': cirq.rx(3.0 * sympy.Symbol('alpha'))
595595
},
596596
{
597-
'gate': cirq.Ry(-1.0 * sympy.Symbol('alpha'))
597+
'gate': cirq.ry(-1.0 * sympy.Symbol('alpha'))
598598
},
599599
{
600-
'gate': cirq.Rz(sympy.Symbol('alpha'))
600+
'gate': cirq.rz(sympy.Symbol('alpha'))
601601
},
602602
])
603603
def test_serialize_deserialize_special_case_one_qubit(self, gate):

tensorflow_quantum/python/differentiators/parameter_shift_util_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_parse_programs(self):
4848
q = cirq.GridQubit.rect(1, n_qubits)
4949
c = cirq.Circuit()
5050
c.append([
51-
cirq.Rz(coeff[i] * sympy_symbols[i % 2]).on(q[i])
51+
cirq.rz(coeff[i] * sympy_symbols[i % 2]).on(q[i])
5252
for i in range(n_qubits)
5353
])
5454
circuit_batch = [c] * n_programs

tensorflow_quantum/python/differentiators/stochastic_differentiator_util_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def _example_circuit_helper(n_qubits, n_programs):
3434
coeff = [1.0, -2.0, 3.0, -4.0, 5.0]
3535
q = cirq.GridQubit.rect(1, n_qubits)
3636
c = cirq.Circuit([
37-
cirq.Rz(coeff[i] * sympy_symbols[i % 2]).on(q[i])
37+
cirq.rz(coeff[i] * sympy_symbols[i % 2]).on(q[i])
3838
for i in range(n_qubits)
3939
])
4040
circuit_batch = [c] * n_programs

tensorflow_quantum/python/layers/circuit_executors/expectation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class Expectation(tf.keras.layers.Layer):
3838
... \"""Generate a toy problem on 1 qubit.\"""
3939
... starting_state = [0.123, 0.456, 0.789]
4040
... circuit = cirq.Circuit(
41-
... cirq.Rx(starting_state[0])(bit),
42-
... cirq.Ry(starting_state[1])(bit),
43-
... cirq.Rz(starting_state[2])(bit),
44-
... cirq.Rz(symbols[2])(bit),
45-
... cirq.Ry(symbols[1])(bit),
46-
... cirq.Rx(symbols[0])(bit)
41+
... cirq.rx(starting_state[0])(bit),
42+
... cirq.ry(starting_state[1])(bit),
43+
... cirq.rz(starting_state[2])(bit),
44+
... cirq.rz(symbols[2])(bit),
45+
... cirq.ry(symbols[1])(bit),
46+
... cirq.rx(symbols[0])(bit)
4747
... )
4848
... return circuit
4949

0 commit comments

Comments
 (0)