Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest version of Cirq. #697

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

MichaelBroughton
Copy link
Collaborator

Upgrades Cirq to latest release version.

Copy link
Member

@jaeyoo jaeyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

jaeyoo
jaeyoo previously approved these changes Mar 20, 2023
Copy link
Member

@jaeyoo jaeyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

jaeyoo
jaeyoo previously approved these changes Mar 22, 2023
@jaeyoo
Copy link
Member

jaeyoo commented Mar 22, 2023

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

Copy link
Member

@jaeyoo jaeyoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjoint gradient has some issue dealing with new cirq version circuit/paulisum input shapes.

@jaeyoo
Copy link
Member

jaeyoo commented Mar 25, 2023

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=...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants