Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/pre-commit/spellcheck_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ matrix:
sources:
# Exclude test directories, third-party code (tpls/), build artifacts, sphinx config,
# and files with f-string syntax that pyspelling's parser can't handle
- '**/*.py|!python/tests/**/*.py|!cudaq/test/**/*.py|!targettests/**/*.py|!tpls/**/*.py|!_skbuild/**/*.py|!build/**/*.py|!build_*/**/*.py|!_version.py|!docs/sphinx/conf.py|!utils/mock_qpu/qci/__init__.py'
- '**/*.py|!python/tests/**/*.py|!cudaq/test/**/*.py|!targettests/**/*.py|!tpls/**/*.py|!_skbuild/**/*.py|!build/**/*.py|!build_*/**/*.py|!_version.py|!docs/sphinx/conf.py'
glob_flags: N|G|B
expect_match: false
aspell:
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/test_in_devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,26 +309,17 @@ jobs:
echo "::error file=test_in_devenv.yml::Python tests failed with status $pytest_status."
exit 1
fi
mock_qpu_failures=""
for backendTest in python/tests/backends/*.py; do
output=$(python -m pytest -v -s --durations=0 $backendTest 2>&1)
pytest_status=$?
echo "$output"
if echo "$output" | grep -q "Mock qpu not available"; then
echo "::error file=test_in_devenv.yml::Mock QPU unavailable for $backendTest"
mock_qpu_failures="$mock_qpu_failures $backendTest"
fi
# Exit code 5 indicates that no tests were collected,
# i.e. all tests in this file were skipped.
if [ ! $pytest_status -eq 0 ] && [ ! $pytest_status -eq 5 ]; then
echo "::error file=test_in_devenv.yml::Python $backendTest tests failed with status $pytest_status."
exit 1
fi
done
if [ -n "$mock_qpu_failures" ]; then
echo "::error file=test_in_devenv.yml::Mock QPU tests skipped due to missing startServer:$mock_qpu_failures"
exit 1
fi

retry pip install qiskit
python -m pytest -v --durations=0 python/tests/contrib
Expand Down
12 changes: 4 additions & 8 deletions docs/sphinx/using/extending/backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ Create unit tests for your server helper:
.. code-block:: bash

#!/bin/bash

# Start the mock server
python3 utils/start_mock_qpu.py <provider_name> &
python3 python/tests/utils/start_mock_qpu.py <provider_name> &
SERVER_PID=$!

# Wait for server to start
Expand Down Expand Up @@ -371,7 +371,7 @@ Create a mock server for testing:

.. code-block:: text

utils/mock_qpu/<provider_name>/
python/tests/utils/mock_qpu/<provider_name>/
└── __init__.py

Implement the mock server:
Expand Down Expand Up @@ -457,11 +457,7 @@ Create Python tests for your backend:
not (cudaq.has_target("<provider_name>")),
reason='Could not find `<provider_name>` in installation')

try:
from utils.mock_qpu.<provider_name> import startServer
except:
print("Mock qpu not available, skipping Provider Name tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.<provider_name> import startServer

# Define the port for the mock server - make sure this is unique
# across all tests.
Expand Down
5 changes: 1 addition & 4 deletions python/tests/backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ def quantinuum_mock_server():
Yields the path to the credentials file.
"""
from network_utils import check_server_connection
try:
from utils.mock_qpu.quantinuum import startServer
except Exception:
pytest.skip("Mock qpu not available.", allow_module_level=False)
from utils.mock_qpu.quantinuum import startServer

with open(QUANTINUUM_CREDS_FILE, 'w') as f:
f.write('key: {}\nrefresh: {}\ntime: 0'.format("nexus_key",
Expand Down
8 changes: 2 additions & 6 deletions python/tests/backends/test_IQM.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@

iqm_client = pytest.importorskip("iqm.iqm_client")

try:
from utils.mock_qpu.iqm import startServer
from utils.mock_qpu.iqm.mock_iqm_cortex_cli import write_a_mock_tokens_file
except:
pytest.skip("Mock qpu not available, skipping IQM tests.",
allow_module_level=True)
from utils.mock_qpu.iqm import startServer
from utils.mock_qpu.iqm.mock_iqm_cortex_cli import write_a_mock_tokens_file

# Define the port for the mock server
port = 62443
Expand Down
6 changes: 1 addition & 5 deletions python/tests/backends/test_IonQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
from typing import List
from multiprocessing import Process
from network_utils import check_server_connection
try:
from utils.mock_qpu.ionq import startServer
except:
print("Mock qpu not available, skipping IonQ tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.ionq import startServer

# Define the port for the mock server
port = 62441
Expand Down
6 changes: 1 addition & 5 deletions python/tests/backends/test_OQC.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
from cudaq import spin
import numpy as np

try:
from utils.mock_qpu.oqc import startServer
except:
print("Mock qpu not available, skipping OQC tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.oqc import startServer

# Define the port for the mock server
port = 62442
Expand Down
6 changes: 1 addition & 5 deletions python/tests/backends/test_QCI.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
from cudaq import spin
from network_utils import check_server_connection

try:
from utils.mock_qpu.qci import startServer
except:
print("Mock qpu not available, skipping QCI tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.qci import startServer

# Define the port for the mock server
port = 62449
Expand Down
2 changes: 1 addition & 1 deletion python/tests/backends/test_Quantinuum_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


def assert_close(got) -> bool:
return got < -1.1 and got > -2.2
return got < -1.1 and got > -2.21


@pytest.fixture(scope="function", autouse=True)
Expand Down
7 changes: 1 addition & 6 deletions python/tests/backends/test_Quantum_Machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import pytest
from multiprocessing import Process
from network_utils import check_server_connection

try:
from utils.mock_qpu.quantum_machines import start_server
except:
print("Mock qpu not available, skipping Quantum Machines tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.quantum_machines import start_server

skipIfQuantumMachinesNotInstalled = pytest.mark.skipif(
not (cudaq.has_target("quantum_machines")),
Expand Down
8 changes: 2 additions & 6 deletions python/tests/backends/test_qbraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
from cudaq import spin
from network_utils import check_server_connection

try:
from utils.mock_qpu.qbraid import startServer
except ImportError:
print("Mock qpu not available, skipping qBraid tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.qbraid import startServer

port = 62454

# Default machine for tests. Mirrors the real qBraid device string format.
TEST_MACHINE = "qbraid:qbraid:sim:qir-sv"
TEST_API_KEY = "00000000000000000000000000000000"

# The qbraid mock server in utils/mock_qpu/qbraid/__init__.py doesn't simulate
# The qbraid mock server in python/tests/utils/mock_qpu/qbraid/__init__.py doesn't simulate
# quantum mechanics - it only inspects the QASM for `h` and `measure` ops and
# generates random outcomes for qubits with H. It does NOT model entanglement
# via CNOT. Assertions below reflect the mock's behavior, not physical truth.
Expand Down
6 changes: 1 addition & 5 deletions python/tests/backends/test_scaleway_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
DEFAULT_SHOT_COUNT = 3000
DEFAULT_DEDUPLICATION_ID = "cudaq-test-scaleway"

try:
from utils.mock_qpu.scaleway import startServer
except:
pytest.skip("Mock qpu not available, skipping Scaleway tests.",
allow_module_level=True)
from utils.mock_qpu.scaleway import startServer


@pytest.fixture(scope="session", autouse=True)
Expand Down
6 changes: 1 addition & 5 deletions python/tests/backends/test_tii_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@
not (cudaq.has_target("tii")),
reason='Could not find `tii` in installation')

try:
from utils.mock_qpu.tii import startServer
except:
print("Mock qpu not available, skipping tii tests.")
pytest.skip("Mock qpu not available.", allow_module_level=True)
from utils.mock_qpu.tii import startServer

# Define the port for the mock server - make sure this is unique
# across all tests.
Expand Down
7 changes: 7 additions & 0 deletions python/tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ============================================================================ #
# Copyright (c) 2026 NVIDIA Corporation & Affiliates. #
# All rights reserved. #
# #
# This source code and the accompanying materials are made available under #
# the terms of the Apache License 2.0 which accompanies this distribution. #
# ============================================================================ #
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions unittests/backends/anyon/AnyonStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# EOF
# }

# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/anyon) under main/utils
# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/anyon) under python/test/utils
checkServerConnection() {
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ - << EOF
import socket
Expand All @@ -34,9 +34,9 @@ except Exception:
EOF
}

# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/anyon) under main/utils
# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/anyon) under python/test/utils
# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py anyon &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py anyon &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
6 changes: 3 additions & 3 deletions unittests/backends/braket/BraketStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# EOF
# }

# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/braket) under main/utils
# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/braket) under python/test/utils
checkServerConnection() {
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ - << EOF
import socket
Expand All @@ -34,9 +34,9 @@ except Exception:
EOF
}

# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/braket) under main/utils
# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/braket) under python/test/utils
# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py braket &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py braket &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF
}

# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py infleqtion &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py infleqtion &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
2 changes: 1 addition & 1 deletion unittests/backends/ionq/IonQStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF
}

# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py ionq &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py ionq &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
4 changes: 2 additions & 2 deletions unittests/backends/iqm/IQMStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ EOF

# Create fake auth tokens file
tmp_file=$(mktemp)
@Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/mock_qpu/iqm/mock_iqm_cortex_cli.py $tmp_file
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/mock_qpu/iqm/mock_iqm_cortex_cli.py $tmp_file
# Launch the fake server
@Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py iqm &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py iqm &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
2 changes: 1 addition & 1 deletion unittests/backends/oqc/OQCStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EOF

@Python_EXECUTABLE@ -m pip install requests llvmlite
# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py oqc &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py oqc &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
2 changes: 1 addition & 1 deletion unittests/backends/qbraid/QbraidStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF
}

# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/mock_qpu/qbraid/__init__.py &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/mock_qpu/qbraid/__init__.py &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
2 changes: 1 addition & 1 deletion unittests/backends/qci/QCIStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EOF


# Launch the mock server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py qci &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py qci &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ except Exception:
EOF
}
# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py quantinuum &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py quantinuum &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ except Exception:
EOF
}
# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py quantinuum &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py quantinuum &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ EOF
}

# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py quantum_machines &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py quantum_machines &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
4 changes: 2 additions & 2 deletions unittests/backends/scaleway/ScalewayStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ except Exception:
EOF
}

# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/scaleway) under main/utils
# Uncomment this and connect to mock_qpu backend server within the container (mock_qpu/scaleway) under python/test/utils
# Launch the fake server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py scaleway &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py scaleway &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
2 changes: 1 addition & 1 deletion unittests/backends/tii/TiiStartServerAndTest.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ EOF


# Launch the mock server
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_SOURCE_DIR@/utils/start_mock_qpu.py tii &
PYTHONPATH=@CMAKE_BINARY_DIR@/python @Python_EXECUTABLE@ @CMAKE_BINARY_DIR@/python/tests/utils/start_mock_qpu.py tii &
# we'll need the process id to kill it
pid=$(echo "$!")
n=0
Expand Down
Loading