This is an automated email from the ASF dual-hosted git repository.

guanmingchiu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/mahout.git


The following commit(s) were added to refs/heads/main by this push:
     new 929edd7c1 MAHOUT-828 Add unit tests for single-qubit gates and swap 
test functionality (#837)
929edd7c1 is described below

commit 929edd7c1e458d3f6ba5dc032f9d9d2dbd271ccb
Author: Ryan Huang <[email protected]>
AuthorDate: Fri Jan 16 11:45:51 2026 +0800

    MAHOUT-828 Add unit tests for single-qubit gates and swap test 
functionality (#837)
    
    * Add unit tests for single-qubit gates and swap test functionality
    
    - Implemented comprehensive tests for Pauli X, Y, Z, Hadamard, NOT, U, and 
T gates, ensuring correct state transitions and probabilities across different 
backends.
    - Added edge case tests for single-qubit gates, including handling 
uninitialized circuits and invalid qubit indices.
    - Introduced a swap test class to validate the behavior of swap tests with 
identical, orthogonal, and identical one states, including consistency checks 
across backends.
    - Verified the existence and functionality of the CSWAP gate.
    
    * Skip QDP tests if dependencies are not available in pytest configuration
---
 testing/conftest.py                                | 32 ++++++++++++++++++++++
 testing/qdp/__init__.py                            | 16 +++++++++++
 .../tests => testing/qdp}/test_bindings.py         |  0
 .../tests => testing/qdp}/test_high_fidelity.py    |  0
 .../qdp-python/tests => testing/qdp}/test_numpy.py |  0
 testing/qumat/__init__.py                          | 16 +++++++++++
 testing/{ => qumat}/test_create_circuit.py         |  2 +-
 testing/{ => qumat}/test_final_quantum_states.py   |  4 +--
 testing/{ => qumat}/test_multi_qubit_gates.py      |  2 +-
 testing/{ => qumat}/test_overlap_measurement.py    |  2 +-
 testing/{ => qumat}/test_parameter_binding.py      |  2 +-
 testing/{ => qumat}/test_rotation_gates.py         |  2 +-
 testing/{ => qumat}/test_single_qubit_gates.py     |  2 +-
 testing/{ => qumat}/test_swap_test.py              |  2 +-
 14 files changed, 73 insertions(+), 9 deletions(-)

diff --git a/testing/conftest.py b/testing/conftest.py
new file mode 100644
index 000000000..ee9624b81
--- /dev/null
+++ b/testing/conftest.py
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+"""Shared pytest configuration and fixtures for all tests."""
+
+# Skip qdp tests if dependencies are not available
+collect_ignore_glob = []
+
+try:
+    import _qdp  # noqa: F401
+    import torch  # noqa: F401
+except ImportError:
+    collect_ignore_glob.append("qdp/*.py")
+
+
+def pytest_configure(config):
+    """Register custom markers."""
+    config.addinivalue_line("markers", "gpu: mark test as requiring GPU")
diff --git a/testing/qdp/__init__.py b/testing/qdp/__init__.py
new file mode 100644
index 000000000..cce3acad3
--- /dev/null
+++ b/testing/qdp/__init__.py
@@ -0,0 +1,16 @@
+#
+# 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.
+#
diff --git a/qdp/qdp-python/tests/test_bindings.py 
b/testing/qdp/test_bindings.py
similarity index 100%
rename from qdp/qdp-python/tests/test_bindings.py
rename to testing/qdp/test_bindings.py
diff --git a/qdp/qdp-python/tests/test_high_fidelity.py 
b/testing/qdp/test_high_fidelity.py
similarity index 100%
rename from qdp/qdp-python/tests/test_high_fidelity.py
rename to testing/qdp/test_high_fidelity.py
diff --git a/qdp/qdp-python/tests/test_numpy.py b/testing/qdp/test_numpy.py
similarity index 100%
rename from qdp/qdp-python/tests/test_numpy.py
rename to testing/qdp/test_numpy.py
diff --git a/testing/qumat/__init__.py b/testing/qumat/__init__.py
new file mode 100644
index 000000000..cce3acad3
--- /dev/null
+++ b/testing/qumat/__init__.py
@@ -0,0 +1,16 @@
+#
+# 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.
+#
diff --git a/testing/test_create_circuit.py 
b/testing/qumat/test_create_circuit.py
similarity index 98%
rename from testing/test_create_circuit.py
rename to testing/qumat/test_create_circuit.py
index f9305b3d8..69f741a72 100644
--- a/testing/test_create_circuit.py
+++ b/testing/qumat/test_create_circuit.py
@@ -17,7 +17,7 @@
 
 import pytest
 
-from .utils import TESTING_BACKENDS, get_backend_config
+from ..utils import TESTING_BACKENDS, get_backend_config
 from qumat import QuMat
 
 
diff --git a/testing/test_final_quantum_states.py 
b/testing/qumat/test_final_quantum_states.py
similarity index 96%
rename from testing/test_final_quantum_states.py
rename to testing/qumat/test_final_quantum_states.py
index 87398bdcf..dba8b9d74 100644
--- a/testing/test_final_quantum_states.py
+++ b/testing/qumat/test_final_quantum_states.py
@@ -19,8 +19,8 @@ import pytest
 import numpy as np
 from importlib import import_module
 
-from .utils import TESTING_BACKENDS
-from .utils.qumat_helpers import get_qumat_example_final_state_vector
+from ..utils import TESTING_BACKENDS
+from ..utils.qumat_helpers import get_qumat_example_final_state_vector
 
 
 @pytest.mark.parametrize("backend_name", TESTING_BACKENDS)
diff --git a/testing/test_multi_qubit_gates.py 
b/testing/qumat/test_multi_qubit_gates.py
similarity index 99%
rename from testing/test_multi_qubit_gates.py
rename to testing/qumat/test_multi_qubit_gates.py
index 9c5febbd6..d78cebae0 100644
--- a/testing/test_multi_qubit_gates.py
+++ b/testing/qumat/test_multi_qubit_gates.py
@@ -17,7 +17,7 @@
 
 import pytest
 
-from .utils import TESTING_BACKENDS, get_backend_config, get_state_probability
+from ..utils import TESTING_BACKENDS, get_backend_config, get_state_probability
 from qumat import QuMat
 
 
diff --git a/testing/test_overlap_measurement.py 
b/testing/qumat/test_overlap_measurement.py
similarity index 99%
rename from testing/test_overlap_measurement.py
rename to testing/qumat/test_overlap_measurement.py
index f76df296e..4dbc45b99 100644
--- a/testing/test_overlap_measurement.py
+++ b/testing/qumat/test_overlap_measurement.py
@@ -18,7 +18,7 @@
 import pytest
 import numpy as np
 
-from .utils import TESTING_BACKENDS, get_backend_config
+from ..utils import TESTING_BACKENDS, get_backend_config
 from qumat import QuMat
 
 
diff --git a/testing/test_parameter_binding.py 
b/testing/qumat/test_parameter_binding.py
similarity index 99%
rename from testing/test_parameter_binding.py
rename to testing/qumat/test_parameter_binding.py
index 66b88cbeb..b304e8e5c 100644
--- a/testing/test_parameter_binding.py
+++ b/testing/qumat/test_parameter_binding.py
@@ -21,7 +21,7 @@ import pytest
 
 from qumat import QuMat
 
-from .utils import TESTING_BACKENDS, get_backend_config
+from ..utils import TESTING_BACKENDS, get_backend_config
 
 
 def get_state_probability(results, target_state, num_qubits=1):
diff --git a/testing/test_rotation_gates.py 
b/testing/qumat/test_rotation_gates.py
similarity index 99%
rename from testing/test_rotation_gates.py
rename to testing/qumat/test_rotation_gates.py
index 36f50820b..70f8d0c30 100644
--- a/testing/test_rotation_gates.py
+++ b/testing/qumat/test_rotation_gates.py
@@ -21,7 +21,7 @@ import pytest
 
 from qumat import QuMat
 
-from .utils import TESTING_BACKENDS, get_backend_config
+from ..utils import TESTING_BACKENDS, get_backend_config
 
 
 def get_state_probability(results, target_state, num_qubits=1):
diff --git a/testing/test_single_qubit_gates.py 
b/testing/qumat/test_single_qubit_gates.py
similarity index 99%
rename from testing/test_single_qubit_gates.py
rename to testing/qumat/test_single_qubit_gates.py
index af1e379ea..6bf7f5b60 100644
--- a/testing/test_single_qubit_gates.py
+++ b/testing/qumat/test_single_qubit_gates.py
@@ -18,7 +18,7 @@
 import math
 import pytest
 
-from .utils import TESTING_BACKENDS, get_backend_config, get_state_probability
+from ..utils import TESTING_BACKENDS, get_backend_config, get_state_probability
 from qumat import QuMat
 
 
diff --git a/testing/test_swap_test.py b/testing/qumat/test_swap_test.py
similarity index 99%
rename from testing/test_swap_test.py
rename to testing/qumat/test_swap_test.py
index ac98643f4..26530bb2f 100644
--- a/testing/test_swap_test.py
+++ b/testing/qumat/test_swap_test.py
@@ -17,7 +17,7 @@
 
 import pytest
 
-from .utils import TESTING_BACKENDS, get_backend_config
+from ..utils import TESTING_BACKENDS, get_backend_config
 from qumat import QuMat
 
 

Reply via email to