Add tests for random_symbol_circuit_resolver_batch and random_circuit_resolver_batch#1029
Conversation
…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.
There was a problem hiding this comment.
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.
| for circuit in circuits: | ||
| self.assertIsInstance(circuit, cirq.Circuit) |
There was a problem hiding this comment.
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.
| 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.") |
| for circuit in circuits: | ||
| self.assertIsInstance(circuit, cirq.Circuit) |
There was a problem hiding this comment.
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.
| 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)) |
This adds unit tests to
tensorflow_quantum/python/util_test.pyto verify the output shapes and types ofrandom_symbol_circuit_resolver_batchandrandom_circuit_resolver_batch. These tests ensure that the batch generators return the correct number ofcirq.Circuitandcirq.ParamResolverobjects, and that symbols are correctly present in the resolvers when applicable.