ryankert01 commented on code in PR #1387:
URL: https://github.com/apache/mahout/pull/1387#discussion_r3448850925


##########
testing/qdp/test_batch_throughput.py:
##########
@@ -0,0 +1,67 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+import torch
+from qumat_qdp import QdpEngine
+from qumat_qdp.torch_ref import iqp_encode as iqp_encode_baseline
+
+
[email protected](scope="module")
+def engine():
+    try:
+        return QdpEngine(precision="float64")
+    except Exception as e:
+        pytest.skip(f"Could not initialize QdpEngine: {e}")
+
+
[email protected]("n_qubits", [2, 4, 6])
[email protected]("batch_size", [1, 16, 64])
[email protected]("enable_zz", [True, False])
+def test_batch_throughput_opt_correctness(engine, n_qubits, batch_size, 
enable_zz):
+    """
+    Test that the batched IQP logic introduced in PR2 (which splits phase
+    and transposes for Tensor Cores) yields identical outputs to the 
theoretical
+    PyTorch baseline for various batch sizes.
+    """
+    if enable_zz:
+        n_params = n_qubits + n_qubits * (n_qubits - 1) // 2
+        method = "iqp"
+    else:
+        n_params = n_qubits
+        method = "iqp-z"
+
+    # Generate random parameters (batched)
+    data = torch.randn(batch_size, n_params, dtype=torch.float64, 
device="cuda")

Review Comment:
   Let's not use truely random numbers because it introduces flackiness.



##########
testing/qdp/test_batch_throughput.py:
##########
@@ -0,0 +1,67 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+import torch
+from qumat_qdp import QdpEngine
+from qumat_qdp.torch_ref import iqp_encode as iqp_encode_baseline
+
+
[email protected](scope="module")
+def engine():
+    try:
+        return QdpEngine(precision="float64")
+    except Exception as e:
+        pytest.skip(f"Could not initialize QdpEngine: {e}")
+
+
[email protected]("n_qubits", [2, 4, 6])
[email protected]("batch_size", [1, 16, 64])

Review Comment:
   Add weird `n_qubits` and `batch_size` for robustness.



##########
testing/qdp/test_batch_throughput.py:
##########
@@ -0,0 +1,67 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import pytest
+import torch
+from qumat_qdp import QdpEngine
+from qumat_qdp.torch_ref import iqp_encode as iqp_encode_baseline
+
+
[email protected](scope="module")
+def engine():
+    try:
+        return QdpEngine(precision="float64")
+    except Exception as e:
+        pytest.skip(f"Could not initialize QdpEngine: {e}")
+
+
[email protected]("n_qubits", [2, 4, 6])
[email protected]("batch_size", [1, 16, 64])
[email protected]("enable_zz", [True, False])
+def test_batch_throughput_opt_correctness(engine, n_qubits, batch_size, 
enable_zz):
+    """
+    Test that the batched IQP logic introduced in PR2 (which splits phase
+    and transposes for Tensor Cores) yields identical outputs to the 
theoretical
+    PyTorch baseline for various batch sizes.
+    """
+    if enable_zz:
+        n_params = n_qubits + n_qubits * (n_qubits - 1) // 2
+        method = "iqp"
+    else:
+        n_params = n_qubits
+        method = "iqp-z"
+
+    # Generate random parameters (batched)
+    data = torch.randn(batch_size, n_params, dtype=torch.float64, 
device="cuda")
+
+    # 1. Baseline logic (pure PyTorch, O(4^n) equivalent or reference)
+    expected_state = iqp_encode_baseline(
+        data, n_qubits, enable_zz=enable_zz, device="cuda"
+    )
+
+    # 2. QDP Engine (Testing the Batch throughput C++ / Rust API path)
+    actual_state_dlpack = engine.encode(data, n_qubits, encoding_method=method)
+    actual_state = torch.from_dlpack(actual_state_dlpack)
+
+    # 3. Validation
+    # We use a strict tolerance since both should be deterministic FP64 or 
properly scaled.
+    torch.testing.assert_close(
+        actual_state,
+        expected_state,
+        rtol=1e-10,
+        atol=1e-10,

Review Comment:
   with different precision can have different tolerances(f32,f64)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to