Skip to content

test: add channel random circuit coverage#1080

Open
arnavnagzirkar wants to merge 2 commits into
tensorflow:masterfrom
arnavnagzirkar:fix-1066-clean
Open

test: add channel random circuit coverage#1080
arnavnagzirkar wants to merge 2 commits into
tensorflow:masterfrom
arnavnagzirkar:fix-1066-clean

Conversation

@arnavnagzirkar
Copy link
Copy Markdown

Adds regression coverage for random circuit generation with include_channels=True.\n\nThe new tests assert that generated random circuits contain at least one supported channel operation and remain serializable via util.convert_to_tensor.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds two new unit tests, test_random_circuit_resolver_batch_channels_present and test_random_symbol_circuit_resolver_batch_channels_present, to verify that channel operations are included in generated circuits when include_channels=True and that the resulting circuits are serializable. The reviewer recommends strengthening the serialization checks in both tests by performing a full round-trip serialization and deserialization verification instead of only asserting that the serialized output is not null.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tensorflow_quantum/python/util_test.py Outdated
Comment on lines +162 to +163
# Verify circuits containing channels are serializable.
self.assertIsNotNone(util.convert_to_tensor(circuits))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Asserting assertIsNotNone on the result of util.convert_to_tensor only verifies that the serialization function does not raise an exception. It does not guarantee that the channels are correctly serialized and can be deserialized back without data loss or corruption. Performing a round-trip serialization and deserialization check provides a much stronger correctness guarantee.

Suggested change
# Verify circuits containing channels are serializable.
self.assertIsNotNone(util.convert_to_tensor(circuits))
# Verify circuits containing channels are correctly serializable round-trip.
serialized = util.convert_to_tensor(circuits, deterministic_proto_serialize=True)
deserialized = util.from_tensor(serialized)
self.assertAllEqual(
serialized,
util.convert_to_tensor(deserialized, deterministic_proto_serialize=True))

Comment thread tensorflow_quantum/python/util_test.py Outdated
Comment on lines +184 to +185
# Verify circuits containing channels are serializable.
self.assertIsNotNone(util.convert_to_tensor(circuits))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Asserting assertIsNotNone on the result of util.convert_to_tensor only verifies that the serialization function does not raise an exception. It does not guarantee that the channels are correctly serialized and can be deserialized back without data loss or corruption. Performing a round-trip serialization and deserialization check provides a much stronger correctness guarantee.

        # Verify circuits containing channels are correctly serializable round-trip.
        serialized = util.convert_to_tensor(circuits, deterministic_proto_serialize=True)
        deserialized = util.from_tensor(serialized)
        self.assertAllEqual(
            serialized,
            util.convert_to_tensor(deserialized, deterministic_proto_serialize=True))

Address review feedback: verify channel-containing circuits survive a full convert_to_tensor/from_tensor round-trip instead of only asserting non-null serialization.
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.

1 participant