quantum
quantum copied to clipboard
Update to latest version of Cirq.
Upgrades Cirq to latest release version.
let's fix:
======================================================================
FAIL: test_adj_grad_inputs (__main__.ADJGradTest)
ADJGradTest.test_adj_grad_inputs
Make sure that the expectation op fails gracefully on bad inputs.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/.cache/bazel/_bazel_runner/865e0ada367db183bc26de9a3083631f/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.runfiles/__main__/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py", line 58, in test_adj_grad_inputs
util.convert_to_tensor([circuit_batch]), symbol_names,
File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py", line 642, in wrapper
return func(*args, **kwargs)
File "/home/runner/.cache/bazel/_bazel_runner/865e0ada367db183bc26de9a3083631f/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.runfiles/__main__/tensorflow_quantum/python/util.py", line 333, in convert_to_tensor
return tf.convert_to_tensor(recur(items_to_convert))
File "/home/runner/.cache/bazel/_bazel_runner/865e0ada367db183bc26de9a3083631f/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.runfiles/__main__/tensorflow_quantum/python/util.py", line 313, in recur
tensored_items.append(recur(item, curr_type))
File "/home/runner/.cache/bazel/_bazel_runner/865e0ada367db183bc26de9a3083631f/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.runfiles/__main__/tensorflow_quantum/python/util.py", line 324, in recur
serializer.serialize_circuit(item).SerializeToString(
File "/home/runner/.cache/bazel/_bazel_runner/865e0ada367db183bc26de9a3083631f/execroot/__main__/bazel-out/k8-opt/bin/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.runfiles/__main__/tensorflow_quantum/core/serialize/serializer.py", line 876, in serialize_circuit
assert len(
AssertionError
I realized that the real culprit is serializer code:
for i, moment in enumerate(circuit):
controlled_ops = [
op for op in moment if isinstance(op, cirq.ControlledOperation)
]
new_ops = dict()
for op in controlled_ops:
tfq_compatible = op.sub_operation
tfq_compatible._tfq_control_qubits = op.controls
val_list = list(op.control_values)
assert len(
val_list) == 1 # TFQ does not support superposition control. <----- asserted here
tfq_compatible._tfq_control_values = val_list[0]
new_ops[op.qubits] = tfq_compatible
when we use util.convert_to_tensor()
with any tests using circuit_batch
:
circuit_batch, resolver_batch = \
util.random_circuit_resolver_batch(
qubits, batch_size, include_channels=...)