Skip to content

Commit 929edd7

Browse files
authored
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
1 parent b29f381 commit 929edd7

14 files changed

+73
-9
lines changed

testing/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
"""Shared pytest configuration and fixtures for all tests."""
19+
20+
# Skip qdp tests if dependencies are not available
21+
collect_ignore_glob = []
22+
23+
try:
24+
import _qdp # noqa: F401
25+
import torch # noqa: F401
26+
except ImportError:
27+
collect_ignore_glob.append("qdp/*.py")
28+
29+
30+
def pytest_configure(config):
31+
"""Register custom markers."""
32+
config.addinivalue_line("markers", "gpu: mark test as requiring GPU")

testing/qdp/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
File renamed without changes.

testing/qumat/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import pytest
1919

20-
from .utils import TESTING_BACKENDS, get_backend_config
20+
from ..utils import TESTING_BACKENDS, get_backend_config
2121
from qumat import QuMat
2222

2323

testing/test_final_quantum_states.py renamed to testing/qumat/test_final_quantum_states.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import numpy as np
2020
from importlib import import_module
2121

22-
from .utils import TESTING_BACKENDS
23-
from .utils.qumat_helpers import get_qumat_example_final_state_vector
22+
from ..utils import TESTING_BACKENDS
23+
from ..utils.qumat_helpers import get_qumat_example_final_state_vector
2424

2525

2626
@pytest.mark.parametrize("backend_name", TESTING_BACKENDS)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import pytest
1919

20-
from .utils import TESTING_BACKENDS, get_backend_config, get_state_probability
20+
from ..utils import TESTING_BACKENDS, get_backend_config, get_state_probability
2121
from qumat import QuMat
2222

2323

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import pytest
1919
import numpy as np
2020

21-
from .utils import TESTING_BACKENDS, get_backend_config
21+
from ..utils import TESTING_BACKENDS, get_backend_config
2222
from qumat import QuMat
2323

2424

0 commit comments

Comments
 (0)