Skip to content

Add channel random circuit test coverage#1080

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

Add channel random circuit test 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.
@mhucka
Copy link
Copy Markdown
Member

mhucka commented Jun 5, 2026

@arnavnagzirkar Thank you for this contribution. Gemini Code Assist's review comments seem reasonable. If you don't disagree with them, could you got ahead and make those changes?

Also, in the PR description, it talks about include_channels=True, but it doesn't mention which function or module that refers to. Could you add that information to the description?

@mhucka mhucka self-assigned this Jun 5, 2026
@mhucka mhucka added area/health Involves general matters of project configuration, health, maintenance, and similar concerns area/tests Involves tests and testing of the TFQ codebase labels Jun 5, 2026
@mhucka mhucka changed the title test: add channel random circuit coverage Add channel random circuit test coverage Jun 5, 2026
@mhucka mhucka added status/awaiting-response Waiting on a response from someone priority/before-0.7.7 To be done before releasing TFQ version 0.7.7 labels Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/health Involves general matters of project configuration, health, maintenance, and similar concerns area/tests Involves tests and testing of the TFQ codebase priority/before-0.7.7 To be done before releasing TFQ version 0.7.7 status/awaiting-response Waiting on a response from someone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants