From fb51c1f3c5f02d1ddc0b8dc65c51e9ebab58fbd2 Mon Sep 17 00:00:00 2001 From: kenya-sk <30319295+kenya-sk@users.noreply.github.com> Date: Mon, 27 Apr 2026 13:44:33 +0900 Subject: [PATCH 1/5] add: unit test for random circuit generation --- tensorflow_quantum/python/util_test.py | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index 00715899b..70b6465fc 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -84,6 +84,42 @@ def test_get_supported_channels(self): len(serializer.SERIALIZER.supported_gate_types()) - len(util.get_supported_gates())) + def test_random_circuit_resolver_batch_shapes_and_types(self): + """Confirm random_circuit_resolver_batch returns the expected types.""" + qubits = cirq.GridQubit.rect(1, 3) + batch_size = 4 + + circuits, resolvers = util.random_circuit_resolver_batch( + qubits, batch_size, n_moments=5) + + self.assertLen(circuits, batch_size) + self.assertLen(resolvers, batch_size) + for circuit in circuits: + self.assertIsInstance(circuit, cirq.Circuit) + for resolver in resolvers: + self.assertIsInstance(resolver, cirq.ParamResolver) + self.assertEmpty(resolver.param_dict) + + def test_random_symbol_circuit_resolver_batch_shapes_and_types(self): + """Confirm random_symbol_circuit_resolver_batch returns the expected types.""" + qubits = cirq.GridQubit.rect(1, 3) + symbols = ['alpha', 'beta', 'gamma'] + batch_size = 4 + + circuits, resolvers = util.random_symbol_circuit_resolver_batch( + qubits, symbols, batch_size, n_moments=5) + + self.assertLen(circuits, batch_size) + self.assertLen(resolvers, batch_size) + for circuit in circuits: + self.assertIsInstance(circuit, cirq.Circuit) + for resolver in resolvers: + self.assertIsInstance(resolver, cirq.ParamResolver) + self.assertEqual(set(resolver.param_dict.keys()), set(symbols)) + self.assertTrue( + all(isinstance(value, float) + for value in resolver.param_dict.values())) + @parameterized.parameters(_items_to_tensorize()) def test_convert_to_tensor(self, item): """Test that the convert_to_tensor function works correctly by manually From 2bcda0839da620bd33ade12a1e66e8eb07561563 Mon Sep 17 00:00:00 2001 From: kenya-sk <30319295+kenya-sk@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:29:22 +0900 Subject: [PATCH 2/5] add: symbol check --- tensorflow_quantum/python/util_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index 70b6465fc..00f012aa5 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -96,6 +96,7 @@ def test_random_circuit_resolver_batch_shapes_and_types(self): self.assertLen(resolvers, batch_size) for circuit in circuits: self.assertIsInstance(circuit, cirq.Circuit) + self.assertFalse(cirq.is_parameterized(circuit)) for resolver in resolvers: self.assertIsInstance(resolver, cirq.ParamResolver) self.assertEmpty(resolver.param_dict) @@ -113,6 +114,7 @@ def test_random_symbol_circuit_resolver_batch_shapes_and_types(self): self.assertLen(resolvers, batch_size) for circuit in circuits: self.assertIsInstance(circuit, cirq.Circuit) + self.assertSetEqual(set(util.get_circuit_symbols(circuit)), set(symbols)) for resolver in resolvers: self.assertIsInstance(resolver, cirq.ParamResolver) self.assertEqual(set(resolver.param_dict.keys()), set(symbols)) From 69c0b6abc8cdd5d09d6b5bf3112fb29194f85cdd Mon Sep 17 00:00:00 2001 From: kenya-sk <30319295+kenya-sk@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:32:53 +0900 Subject: [PATCH 3/5] add: parameterized channels argments --- tensorflow_quantum/python/util_test.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index 00f012aa5..297616a8b 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -84,13 +84,18 @@ def test_get_supported_channels(self): len(serializer.SERIALIZER.supported_gate_types()) - len(util.get_supported_gates())) - def test_random_circuit_resolver_batch_shapes_and_types(self): + @parameterized.named_parameters( + ('without_channels', False), + ('with_channels', True), + ) + def test_random_circuit_resolver_batch_shapes_and_types( + self, include_channels): """Confirm random_circuit_resolver_batch returns the expected types.""" qubits = cirq.GridQubit.rect(1, 3) batch_size = 4 circuits, resolvers = util.random_circuit_resolver_batch( - qubits, batch_size, n_moments=5) + qubits, batch_size, n_moments=5, include_channels=include_channels) self.assertLen(circuits, batch_size) self.assertLen(resolvers, batch_size) @@ -101,20 +106,30 @@ def test_random_circuit_resolver_batch_shapes_and_types(self): self.assertIsInstance(resolver, cirq.ParamResolver) self.assertEmpty(resolver.param_dict) - def test_random_symbol_circuit_resolver_batch_shapes_and_types(self): + @parameterized.named_parameters( + ('without_channels', False), + ('with_channels', True), + ) + def test_random_symbol_circuit_resolver_batch_shapes_and_types( + self, include_channels): """Confirm random_symbol_circuit_resolver_batch returns the expected types.""" qubits = cirq.GridQubit.rect(1, 3) symbols = ['alpha', 'beta', 'gamma'] batch_size = 4 circuits, resolvers = util.random_symbol_circuit_resolver_batch( - qubits, symbols, batch_size, n_moments=5) + qubits, + symbols, + batch_size, + n_moments=5, + include_channels=include_channels) self.assertLen(circuits, batch_size) self.assertLen(resolvers, batch_size) for circuit in circuits: self.assertIsInstance(circuit, cirq.Circuit) - self.assertSetEqual(set(util.get_circuit_symbols(circuit)), set(symbols)) + self.assertSetEqual(set(util.get_circuit_symbols(circuit)), + set(symbols)) for resolver in resolvers: self.assertIsInstance(resolver, cirq.ParamResolver) self.assertEqual(set(resolver.param_dict.keys()), set(symbols)) From cba4d5d87eb39c89ff3c68f11208b7b68ecd6df4 Mon Sep 17 00:00:00 2001 From: kenya-sk <30319295+kenya-sk@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:34:48 +0900 Subject: [PATCH 4/5] chore: format test file --- tensorflow_quantum/python/util_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index 297616a8b..96dcb01df 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -134,7 +134,8 @@ def test_random_symbol_circuit_resolver_batch_shapes_and_types( self.assertIsInstance(resolver, cirq.ParamResolver) self.assertEqual(set(resolver.param_dict.keys()), set(symbols)) self.assertTrue( - all(isinstance(value, float) + all( + isinstance(value, float) for value in resolver.param_dict.values())) @parameterized.parameters(_items_to_tensorize()) From ebaf379ce12f57fea5c929f210972d8031433063 Mon Sep 17 00:00:00 2001 From: kenya-sk <30319295+kenya-sk@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:39:08 +0900 Subject: [PATCH 5/5] chore: format test file --- tensorflow_quantum/python/util_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index 96dcb01df..8860ba1f4 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -112,7 +112,8 @@ def test_random_circuit_resolver_batch_shapes_and_types( ) def test_random_symbol_circuit_resolver_batch_shapes_and_types( self, include_channels): - """Confirm random_symbol_circuit_resolver_batch returns the expected types.""" + """Confirm random_symbol_circuit_resolver_batch returns + the expected types.""" qubits = cirq.GridQubit.rect(1, 3) symbols = ['alpha', 'beta', 'gamma'] batch_size = 4