Skip to content

Add tests for random_symbol_circuit_resolver_batch and random_circuit_resolver_batch#1029

Draft
mhucka wants to merge 1 commit intotensorflow:masterfrom
mhucka:testing-improvement-random-symbol-circuit-resolver-batch-8868936467708589382
Draft

Add tests for random_symbol_circuit_resolver_batch and random_circuit_resolver_batch#1029
mhucka wants to merge 1 commit intotensorflow:masterfrom
mhucka:testing-improvement-random-symbol-circuit-resolver-batch-8868936467708589382

Conversation

@mhucka
Copy link
Copy Markdown
Member

@mhucka mhucka commented Mar 27, 2026

This adds unit tests to tensorflow_quantum/python/util_test.py to verify the output shapes and types of random_symbol_circuit_resolver_batch and random_circuit_resolver_batch. These tests ensure that the batch generators return the correct number of cirq.Circuit and cirq.ParamResolver objects, and that symbols are correctly present in the resolvers when applicable.

…batch and random_circuit_resolver_batch

Added comprehensive unit tests to `tensorflow_quantum/python/util_test.py` to verify the output shapes and types of `random_symbol_circuit_resolver_batch` and `random_circuit_resolver_batch`. These tests ensure that the batch generators return the correct number of `cirq.Circuit` and `cirq.ParamResolver` objects, and that symbols are correctly present in the resolvers when applicable.
Copy link
Copy Markdown

@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 unit tests for random_circuit_resolver_batch and random_symbol_circuit_resolver_batch in util_test.py. The review feedback suggests improving the robustness of these tests by verifying that the generated circuits are non-empty and contain the expected symbols.

Comment on lines +439 to +440
for circuit in circuits:
self.assertIsInstance(circuit, cirq.Circuit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This test can be made more robust by also verifying that the generated circuits are not empty and do not contain any symbols, which is part of the function's contract.

Suggested change
for circuit in circuits:
self.assertIsInstance(circuit, cirq.Circuit)
for circuit in circuits:
self.assertIsInstance(circuit, cirq.Circuit)
self.assertGreater(len(circuit), 0, "Generated circuit should not be empty.")
self.assertEqual(len(util.get_circuit_symbols(circuit)), 0, "Circuit should not have symbols.")

Comment on lines +454 to +455
for circuit in circuits:
self.assertIsInstance(circuit, cirq.Circuit)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This test should also verify that the generated circuits contain the expected symbols. This is a key part of the function's contract, and the current test only checks the type of the circuit.

Suggested change
for circuit in circuits:
self.assertIsInstance(circuit, cirq.Circuit)
for circuit in circuits:
self.assertIsInstance(circuit, cirq.Circuit)
extracted_symbols = util.get_circuit_symbols(circuit)
expected_symbols = sorted([str(s) for s in symbols])
self.assertListEqual(expected_symbols, sorted(extracted_symbols))

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